ntv-numpy.ntv_numpy.numpy_ntv_connector
@author: Philippe@loco-labs.io
The numpy_ntv_connector
module is part of the ntv-numpy.ntv_numpy
package
(specification document).
A NtvConnector is defined by:
- clas_obj: str - define the class name of the object to convert
- clas_typ: str - define the NTVtype of the converted object
- to_obj_ntv: method - converter from JsonNTV to the object
- to_json_ntv: method - converter from the object to JsonNTV
It contains the child classes of NTV.json_ntv.ntv.NtvConnector
abstract class:
- NarrayConnec
: 'narray' connector for np.ndarray data
- NdarrayConnec
: 'ndarray' connector for Ndarray data
- XndarrayConnec
: 'xndarray' connector for Xndarray data
- XdatasetConnec
: 'xdataset' connector for Xdataset data
1# -*- coding: utf-8 -*- 2""" 3@author: Philippe@loco-labs.io 4 5The `numpy_ntv_connector` module is part of the `ntv-numpy.ntv_numpy` package 6([specification document]( 7https://loco-philippe.github.io/ES/JSON%20semantic%20format%20(JSON-NTV).htm)). 8 9A NtvConnector is defined by: 10- clas_obj: str - define the class name of the object to convert 11- clas_typ: str - define the NTVtype of the converted object 12- to_obj_ntv: method - converter from JsonNTV to the object 13- to_json_ntv: method - converter from the object to JsonNTV 14 15It contains the child classes of `NTV.json_ntv.ntv.NtvConnector` abstract class: 16 - `NarrayConnec`: 'narray' connector for np.ndarray data 17 - `NdarrayConnec`: 'ndarray' connector for Ndarray data 18 - `XndarrayConnec`: 'xndarray' connector for Xndarray data 19 - `XdatasetConnec`: 'xdataset' connector for Xdataset data 20""" 21from json_ntv import NtvConnector 22 23from ntv_numpy.ndarray import Ndarray 24from ntv_numpy.xndarray import Xndarray 25from ntv_numpy.xdataset import Xdataset 26 27"""def read_json(jsn, **kwargs): 28 ''' convert JSON text or JSON Value to Numpy ndarray. 29 30 *parameters* 31 32 - **noadd** : boolean (default False) - If True additional data is not include 33 - **header** : boolean (default True) - If True NTV entity with NTVtype is included 34 - **convert** : boolean (default True) - If True, convert json data with 35 non Numpy ntv_type into Xndarray with python type 36 ''' 37 option = {'noadd': False, 'header': True, 'convert': True} | kwargs 38 jso = json.loads(jsn) if isinstance(jsn, str) else jsn 39 if isinstance(jso, dict) and len(jso) == 1: 40 if 'xndarray' in list(jso)[0]: 41 arr = XndarrayConnec.to_obj_ntv(list(jso.values())[0], **option) 42 return arr 43 else: 44 arr = NdarrayConnec.to_obj_ntv(list(jso.values())[0], **option) 45 return arr 46 if isinstance(jso, list): 47 option = {'noadd': False, 'header': False} | kwargs 48 arr = NdarrayConnec.to_obj_ntv(jso, **option) 49 return arr 50 return None 51 52 53def to_json(ndarray, **kwargs): 54 ''' convert Numpy ndarray to JSON text or JSON Value. 55 56 *parameters* 57 - **encoded** : Boolean (default False) - json value if False else json text 58 - **header** : Boolean (default True) - including ndarray or xndarray type 59 - **notype** : Boolean (default False) - including data type if True 60 - **noshape** : Boolean (default True) - if True, without shape if dim < 1 61 - **novalue** : Boolean (default False) - including value if False 62 - **name** : string (default None) - name of the ndarray 63 - **typ** : string (default None) - type of the NTV object, 64 - **format** : string (default 'full') - representation format of the ndarray, 65 - **extension** : string (default None) - type extension 66 - **add** : dict (default None) - additional data : 67 - **attrs** : dict (default none) - metadata 68 - **dims** : array (default none) - name of axis 69 - **coords** : dict (default none) - dict of 'xndarray' 70 ''' 71 option = {'encoded': False, 'format': 'full', 'header': True, 72 'name': None, 'typ': None, 'extension':None, 'notype': False, 73 'noshape': True, 'novalue': False, 'add': None} | kwargs 74 if ndarray.__class__.__name__ == 'ndarray' and not kwargs.get('add'): 75 jsn, nam, typ = NdarrayConnec.to_json_ntv(ndarray, **option) 76 else: 77 jsn, nam, typ = XndarrayConnec.to_json_ntv(ndarray, **option) 78 name = nam if nam else '' 79 return Nutil.json_ntv(name, typ, jsn, header=option['header'], 80 encoded=option['encoded'])""" 81 82"""def to_json_tab(ndarray, add=None, header=True): 83 period = ndarray.shape 84 dim = ndarray.ndim 85 coefi = ndarray.size 86 coef = [] 87 for per in period: 88 coefi = coefi // per 89 coef.append(coefi) 90 91 add = add if add else {} 92 axe_n = add['dims'] if 'dims' in add else ['dim_' + str(i) for i in range(dim)] 93 axe_v = [add['coords'][axe] for axe in axe_n if axe in add['coords']] if 'coords' in add else [] 94 axe_v = [axe[-1] for axe in axe_v] if len(axe_v) == len(axe_n) else [ 95 list(range(period[i])) for i in range(dim)] 96 jsn = {nam: [var, [coe]] for nam, var, coe in zip(axe_n, axe_v, coef)} | { 97 'data::' + ndarray.dtype.name: ndarray.flatten().tolist()} 98 if header: 99 return {':tab': jsn} 100 return jsn 101 102def read_json_tab(js): 103 js = js[':tab'] if ':tab' in js else js 104 shape = [] 105 axes_n = [] 106 axes_v = [] 107 coef = [] 108 nda = None 109 for name, val in js.items(): 110 if len(val) == 2 and isinstance(val[1], list) and len(val[1]) == 1: 111 shape.append(len(val[0])) 112 coef.append(val[1]) 113 axes_v.append(val[0]) 114 axes_n.append(name) 115 else: 116 spl = name.split('::') 117 nda = np.array(val, dtype=spl[1]) if len(spl)==2 else np.array(val) 118 coef, shape, axes_n, axes_v = list(zip(*sorted(zip(coef, shape, axes_n, 119 axes_v), reverse=True))) 120 return (nda.reshape(shape), {'dims': list(axes_n), 121 'coords': {axe_n: [axe_v] for axe_n, axe_v in zip(axes_n, axes_v)}})""" 122 123 124class NarrayConnec(NtvConnector): 125 126 '''NTV connector for Numpy ndarray.''' 127 128 clas_obj = 'ndarray' 129 clas_typ = 'narray' 130 131 @staticmethod 132 def to_obj_ntv(ntv_value, **kwargs): 133 ''' convert json ntv_value into a np.ndarray. 134 135 *Parameters* 136 137 - **convert** : boolean (default True) - If True, convert json data with 138 non Numpy ntv_type into data with python type''' 139 return Ndarray.read_json(ntv_value, **kwargs).darray 140 141 @staticmethod 142 def to_json_ntv(value, name=None, typ=None, **kwargs): 143 ''' convert a np.ndarray (value, name, type) into NTV json (json-value, name, ntv_type). 144 145 *Parameters* 146 147 - **typ** : string (default None) - ntv_type of the np.ndarray object, 148 - **name** : string (default None) - name of the ndarray object 149 - **value** : np.ndarray value 150 - **noshape** : Boolean (default True) - if True, without shape if dim < 1 151 - **notype** : Boolean (default False) - including data type if False 152 - **novalue** : Boolean (default False) - including value if False 153 - **format** : string (default 'full') - representation format of the ndarray, 154 - **encoded** : Boolean (default False) - json-value if False else json-text 155 - **header** : Boolean (default True) - including ndarray type 156 ''' 157 option = {'format': 'full', 'header': True, 'encoded': False, 158 'notype': False, 'noshape': True, 'novalue': False} | kwargs 159 if not option['format'] in ['full', 'complete']: 160 option['noshape'] = False 161 option['header'] = False 162 return (Ndarray(value).to_json(**option), name, 'narray') 163 164 165class NdarrayConnec(NtvConnector): 166 167 '''NTV connector for Ndarray.''' 168 169 clas_obj = 'Ndarray' 170 clas_typ = 'ndarray' 171 172 @staticmethod 173 def to_obj_ntv(ntv_value, **kwargs): 174 ''' convert json ntv_value into a Ndarray. 175 176 *Parameters* 177 178 - **convert** : boolean (default True) - If True, convert json data with 179 non-Numpy ntv_type into data with python type''' 180 return Ndarray.read_json(ntv_value, **kwargs) 181 182 @staticmethod 183 def to_json_ntv(value, name=None, typ=None, **kwargs): 184 ''' convert a Ndarray (value, name, type) into NTV json (json-value, name, ntv_type). 185 186 *Parameters* 187 188 - **typ** : string (default None) - ntv_type of the ndarray object, 189 - **name** : string (default None) - name of the ndarray object 190 - **value** : Ndarray value (or np.ndarray value) 191 - **noshape** : Boolean (default True) - if True, without shape if dim < 1 192 - **notype** : Boolean (default False) - including data type if False 193 - **novalue** : Boolean (default False) - including value if False 194 - **format** : string (default 'full') - representation format of the ndarray, 195 - **encoded** : Boolean (default False) - json-value if False else json-text 196 - **header** : Boolean (default True) - including ndarray type 197 ''' 198 option = {'format': 'full', 'header': True, 'encoded': False, 199 'notype': False, 'noshape': True, 'novalue': False} | kwargs 200 if not option['format'] in ['full', 'complete']: 201 option['noshape'] = False 202 return (Ndarray(value).to_json(**option), name, 'ndarray') 203 204 205class XndarrayConnec(NtvConnector): 206 207 '''NTV connector for Xndarray.''' 208 209 clas_obj = 'Xndarray' 210 clas_typ = 'xndarray' 211 212 @staticmethod 213 def to_obj_ntv(ntv_value, **kwargs): 214 ''' convert json ntv_value into a Xndarray. 215 216 *Parameters* 217 218 - **convert** : boolean (default True) - If True, convert json data with 219 non-umpy ntv_type into Xndarray with python type 220 ''' 221 print(ntv_value) 222 return Xndarray.read_json(ntv_value, **kwargs) 223 224 @staticmethod 225 def to_json_ntv(value, name=None, typ=None, **kwargs): 226 ''' convert a Xndarray (value) into NTV json (json-value, name, ntv_type). 227 228 *Parameters* 229 230 - **typ** : string (default None) - not used, 231 - **name** : string (default None) - not used 232 - **value** : Xndarray values 233 - **encoded** : Boolean (default False) - json-value if False else json-text 234 - **header** : Boolean (default True) - including xndarray type 235 - **notype** : Boolean (default False) - including data type if False 236 - **novalue** : Boolean (default False) - including value if False 237 - **noshape** : Boolean (default True) - if True, without shape if dim < 1 238 - **format** : string (default 'full') - representation format of the ndarray, 239 - **extension** : string (default None) - type extension 240 ''' 241 option = {'notype': False, 'extension': None, 'format': 'full', 242 'noshape': True, 'header': True, 'encoded': False, 243 'novalue': False, 'noname': False} | kwargs 244 if not option['format'] in ['full', 'complete']: 245 option['noshape'] = False 246 return (value.to_json(**option), name, 'xndarray') 247 248 249class XdatasetConnec(NtvConnector): 250 251 '''NTV connector for Xdataset.''' 252 253 clas_obj = 'Xdataset' 254 clas_typ = 'xdataset' 255 256 @staticmethod 257 def to_obj_ntv(ntv_value, **kwargs): # reindex=True, decode_str=False): 258 ''' convert json ntv_value into a Xdataset. 259 260 *Parameters* 261 262 - **convert** : boolean (default True) - If True, convert json data with 263 non-Numpy ntv_type into Xdataset with python type 264 ''' 265 return Xdataset.read_json(ntv_value, **kwargs) 266 267 @staticmethod 268 def to_json_ntv(value, name=None, typ=None, **kwargs): 269 ''' convert a Xdataset (value) into NTV json (json-value, name, ntv_type). 270 271 *Parameters* 272 273 - **typ** : string (default None) - not used, 274 - **name** : string (default None) - not used 275 - **value** : Xdataset entity 276 - **encoded** : Boolean (default False) - json value if False else json text 277 - **header** : Boolean (default True) - including 'xdataset' type 278 - **notype** : list of Boolean (default list of None) - including data type if False 279 - **novalue** : Boolean (default False) - including value if False 280 - **noshape** : Boolean (default False) - if True, without shape if dim < 1 281 - **format** : list of string (default list of 'full') - representation format 282 of the np.ndarray, 283 ''' 284 option = {'notype': False, 'extension': None, 'format': 'full', 285 'noshape': True, 'header': True, 'encoded': False, 286 'novalue': False, 'noname': False} | kwargs 287 if not option['format'] in ['full', 'complete']: 288 option['noshape'] = False 289 option['noname'] = True 290 return (value.to_json(**option), name, 'xdataset')
125class NarrayConnec(NtvConnector): 126 127 '''NTV connector for Numpy ndarray.''' 128 129 clas_obj = 'ndarray' 130 clas_typ = 'narray' 131 132 @staticmethod 133 def to_obj_ntv(ntv_value, **kwargs): 134 ''' convert json ntv_value into a np.ndarray. 135 136 *Parameters* 137 138 - **convert** : boolean (default True) - If True, convert json data with 139 non Numpy ntv_type into data with python type''' 140 return Ndarray.read_json(ntv_value, **kwargs).darray 141 142 @staticmethod 143 def to_json_ntv(value, name=None, typ=None, **kwargs): 144 ''' convert a np.ndarray (value, name, type) into NTV json (json-value, name, ntv_type). 145 146 *Parameters* 147 148 - **typ** : string (default None) - ntv_type of the np.ndarray object, 149 - **name** : string (default None) - name of the ndarray object 150 - **value** : np.ndarray value 151 - **noshape** : Boolean (default True) - if True, without shape if dim < 1 152 - **notype** : Boolean (default False) - including data type if False 153 - **novalue** : Boolean (default False) - including value if False 154 - **format** : string (default 'full') - representation format of the ndarray, 155 - **encoded** : Boolean (default False) - json-value if False else json-text 156 - **header** : Boolean (default True) - including ndarray type 157 ''' 158 option = {'format': 'full', 'header': True, 'encoded': False, 159 'notype': False, 'noshape': True, 'novalue': False} | kwargs 160 if not option['format'] in ['full', 'complete']: 161 option['noshape'] = False 162 option['header'] = False 163 return (Ndarray(value).to_json(**option), name, 'narray')
NTV connector for Numpy ndarray.
132 @staticmethod 133 def to_obj_ntv(ntv_value, **kwargs): 134 ''' convert json ntv_value into a np.ndarray. 135 136 *Parameters* 137 138 - **convert** : boolean (default True) - If True, convert json data with 139 non Numpy ntv_type into data with python type''' 140 return Ndarray.read_json(ntv_value, **kwargs).darray
convert json ntv_value into a np.ndarray.
Parameters
- convert : boolean (default True) - If True, convert json data with non Numpy ntv_type into data with python type
142 @staticmethod 143 def to_json_ntv(value, name=None, typ=None, **kwargs): 144 ''' convert a np.ndarray (value, name, type) into NTV json (json-value, name, ntv_type). 145 146 *Parameters* 147 148 - **typ** : string (default None) - ntv_type of the np.ndarray object, 149 - **name** : string (default None) - name of the ndarray object 150 - **value** : np.ndarray value 151 - **noshape** : Boolean (default True) - if True, without shape if dim < 1 152 - **notype** : Boolean (default False) - including data type if False 153 - **novalue** : Boolean (default False) - including value if False 154 - **format** : string (default 'full') - representation format of the ndarray, 155 - **encoded** : Boolean (default False) - json-value if False else json-text 156 - **header** : Boolean (default True) - including ndarray type 157 ''' 158 option = {'format': 'full', 'header': True, 'encoded': False, 159 'notype': False, 'noshape': True, 'novalue': False} | kwargs 160 if not option['format'] in ['full', 'complete']: 161 option['noshape'] = False 162 option['header'] = False 163 return (Ndarray(value).to_json(**option), name, 'narray')
convert a np.ndarray (value, name, type) into NTV json (json-value, name, ntv_type).
Parameters
- typ : string (default None) - ntv_type of the np.ndarray object,
- name : string (default None) - name of the ndarray object
- value : np.ndarray value
- noshape : Boolean (default True) - if True, without shape if dim < 1
- notype : Boolean (default False) - including data type if False
- novalue : Boolean (default False) - including value if False
- format : string (default 'full') - representation format of the ndarray,
- encoded : Boolean (default False) - json-value if False else json-text
- header : Boolean (default True) - including ndarray type
Inherited Members
- json_ntv.ntv_util.NtvConnector
- DIC_NTV_CL
- DIC_GEO_CL
- DIC_DAT_CL
- DIC_FCT
- DIC_GEO
- DIC_CBOR
- DIC_OBJ
- castable
- dic_obj
- dic_type
- connector
- dic_connec
- cast
- uncast
- is_json_class
- is_json
- keysfromderkeys
- encode_coef
- keysfromcoef
- format_field
- init_ntv_keys
166class NdarrayConnec(NtvConnector): 167 168 '''NTV connector for Ndarray.''' 169 170 clas_obj = 'Ndarray' 171 clas_typ = 'ndarray' 172 173 @staticmethod 174 def to_obj_ntv(ntv_value, **kwargs): 175 ''' convert json ntv_value into a Ndarray. 176 177 *Parameters* 178 179 - **convert** : boolean (default True) - If True, convert json data with 180 non-Numpy ntv_type into data with python type''' 181 return Ndarray.read_json(ntv_value, **kwargs) 182 183 @staticmethod 184 def to_json_ntv(value, name=None, typ=None, **kwargs): 185 ''' convert a Ndarray (value, name, type) into NTV json (json-value, name, ntv_type). 186 187 *Parameters* 188 189 - **typ** : string (default None) - ntv_type of the ndarray object, 190 - **name** : string (default None) - name of the ndarray object 191 - **value** : Ndarray value (or np.ndarray value) 192 - **noshape** : Boolean (default True) - if True, without shape if dim < 1 193 - **notype** : Boolean (default False) - including data type if False 194 - **novalue** : Boolean (default False) - including value if False 195 - **format** : string (default 'full') - representation format of the ndarray, 196 - **encoded** : Boolean (default False) - json-value if False else json-text 197 - **header** : Boolean (default True) - including ndarray type 198 ''' 199 option = {'format': 'full', 'header': True, 'encoded': False, 200 'notype': False, 'noshape': True, 'novalue': False} | kwargs 201 if not option['format'] in ['full', 'complete']: 202 option['noshape'] = False 203 return (Ndarray(value).to_json(**option), name, 'ndarray')
NTV connector for Ndarray.
173 @staticmethod 174 def to_obj_ntv(ntv_value, **kwargs): 175 ''' convert json ntv_value into a Ndarray. 176 177 *Parameters* 178 179 - **convert** : boolean (default True) - If True, convert json data with 180 non-Numpy ntv_type into data with python type''' 181 return Ndarray.read_json(ntv_value, **kwargs)
convert json ntv_value into a Ndarray.
Parameters
- convert : boolean (default True) - If True, convert json data with non-Numpy ntv_type into data with python type
183 @staticmethod 184 def to_json_ntv(value, name=None, typ=None, **kwargs): 185 ''' convert a Ndarray (value, name, type) into NTV json (json-value, name, ntv_type). 186 187 *Parameters* 188 189 - **typ** : string (default None) - ntv_type of the ndarray object, 190 - **name** : string (default None) - name of the ndarray object 191 - **value** : Ndarray value (or np.ndarray value) 192 - **noshape** : Boolean (default True) - if True, without shape if dim < 1 193 - **notype** : Boolean (default False) - including data type if False 194 - **novalue** : Boolean (default False) - including value if False 195 - **format** : string (default 'full') - representation format of the ndarray, 196 - **encoded** : Boolean (default False) - json-value if False else json-text 197 - **header** : Boolean (default True) - including ndarray type 198 ''' 199 option = {'format': 'full', 'header': True, 'encoded': False, 200 'notype': False, 'noshape': True, 'novalue': False} | kwargs 201 if not option['format'] in ['full', 'complete']: 202 option['noshape'] = False 203 return (Ndarray(value).to_json(**option), name, 'ndarray')
convert a Ndarray (value, name, type) into NTV json (json-value, name, ntv_type).
Parameters
- typ : string (default None) - ntv_type of the ndarray object,
- name : string (default None) - name of the ndarray object
- value : Ndarray value (or np.ndarray value)
- noshape : Boolean (default True) - if True, without shape if dim < 1
- notype : Boolean (default False) - including data type if False
- novalue : Boolean (default False) - including value if False
- format : string (default 'full') - representation format of the ndarray,
- encoded : Boolean (default False) - json-value if False else json-text
- header : Boolean (default True) - including ndarray type
Inherited Members
- json_ntv.ntv_util.NtvConnector
- DIC_NTV_CL
- DIC_GEO_CL
- DIC_DAT_CL
- DIC_FCT
- DIC_GEO
- DIC_CBOR
- DIC_OBJ
- castable
- dic_obj
- dic_type
- connector
- dic_connec
- cast
- uncast
- is_json_class
- is_json
- keysfromderkeys
- encode_coef
- keysfromcoef
- format_field
- init_ntv_keys
206class XndarrayConnec(NtvConnector): 207 208 '''NTV connector for Xndarray.''' 209 210 clas_obj = 'Xndarray' 211 clas_typ = 'xndarray' 212 213 @staticmethod 214 def to_obj_ntv(ntv_value, **kwargs): 215 ''' convert json ntv_value into a Xndarray. 216 217 *Parameters* 218 219 - **convert** : boolean (default True) - If True, convert json data with 220 non-umpy ntv_type into Xndarray with python type 221 ''' 222 print(ntv_value) 223 return Xndarray.read_json(ntv_value, **kwargs) 224 225 @staticmethod 226 def to_json_ntv(value, name=None, typ=None, **kwargs): 227 ''' convert a Xndarray (value) into NTV json (json-value, name, ntv_type). 228 229 *Parameters* 230 231 - **typ** : string (default None) - not used, 232 - **name** : string (default None) - not used 233 - **value** : Xndarray values 234 - **encoded** : Boolean (default False) - json-value if False else json-text 235 - **header** : Boolean (default True) - including xndarray type 236 - **notype** : Boolean (default False) - including data type if False 237 - **novalue** : Boolean (default False) - including value if False 238 - **noshape** : Boolean (default True) - if True, without shape if dim < 1 239 - **format** : string (default 'full') - representation format of the ndarray, 240 - **extension** : string (default None) - type extension 241 ''' 242 option = {'notype': False, 'extension': None, 'format': 'full', 243 'noshape': True, 'header': True, 'encoded': False, 244 'novalue': False, 'noname': False} | kwargs 245 if not option['format'] in ['full', 'complete']: 246 option['noshape'] = False 247 return (value.to_json(**option), name, 'xndarray')
NTV connector for Xndarray.
213 @staticmethod 214 def to_obj_ntv(ntv_value, **kwargs): 215 ''' convert json ntv_value into a Xndarray. 216 217 *Parameters* 218 219 - **convert** : boolean (default True) - If True, convert json data with 220 non-umpy ntv_type into Xndarray with python type 221 ''' 222 print(ntv_value) 223 return Xndarray.read_json(ntv_value, **kwargs)
convert json ntv_value into a Xndarray.
Parameters
- convert : boolean (default True) - If True, convert json data with non-umpy ntv_type into Xndarray with python type
225 @staticmethod 226 def to_json_ntv(value, name=None, typ=None, **kwargs): 227 ''' convert a Xndarray (value) into NTV json (json-value, name, ntv_type). 228 229 *Parameters* 230 231 - **typ** : string (default None) - not used, 232 - **name** : string (default None) - not used 233 - **value** : Xndarray values 234 - **encoded** : Boolean (default False) - json-value if False else json-text 235 - **header** : Boolean (default True) - including xndarray type 236 - **notype** : Boolean (default False) - including data type if False 237 - **novalue** : Boolean (default False) - including value if False 238 - **noshape** : Boolean (default True) - if True, without shape if dim < 1 239 - **format** : string (default 'full') - representation format of the ndarray, 240 - **extension** : string (default None) - type extension 241 ''' 242 option = {'notype': False, 'extension': None, 'format': 'full', 243 'noshape': True, 'header': True, 'encoded': False, 244 'novalue': False, 'noname': False} | kwargs 245 if not option['format'] in ['full', 'complete']: 246 option['noshape'] = False 247 return (value.to_json(**option), name, 'xndarray')
convert a Xndarray (value) into NTV json (json-value, name, ntv_type).
Parameters
- typ : string (default None) - not used,
- name : string (default None) - not used
- value : Xndarray values
- encoded : Boolean (default False) - json-value if False else json-text
- header : Boolean (default True) - including xndarray type
- notype : Boolean (default False) - including data type if False
- novalue : Boolean (default False) - including value if False
- noshape : Boolean (default True) - if True, without shape if dim < 1
- format : string (default 'full') - representation format of the ndarray,
- extension : string (default None) - type extension
Inherited Members
- json_ntv.ntv_util.NtvConnector
- DIC_NTV_CL
- DIC_GEO_CL
- DIC_DAT_CL
- DIC_FCT
- DIC_GEO
- DIC_CBOR
- DIC_OBJ
- castable
- dic_obj
- dic_type
- connector
- dic_connec
- cast
- uncast
- is_json_class
- is_json
- keysfromderkeys
- encode_coef
- keysfromcoef
- format_field
- init_ntv_keys
250class XdatasetConnec(NtvConnector): 251 252 '''NTV connector for Xdataset.''' 253 254 clas_obj = 'Xdataset' 255 clas_typ = 'xdataset' 256 257 @staticmethod 258 def to_obj_ntv(ntv_value, **kwargs): # reindex=True, decode_str=False): 259 ''' convert json ntv_value into a Xdataset. 260 261 *Parameters* 262 263 - **convert** : boolean (default True) - If True, convert json data with 264 non-Numpy ntv_type into Xdataset with python type 265 ''' 266 return Xdataset.read_json(ntv_value, **kwargs) 267 268 @staticmethod 269 def to_json_ntv(value, name=None, typ=None, **kwargs): 270 ''' convert a Xdataset (value) into NTV json (json-value, name, ntv_type). 271 272 *Parameters* 273 274 - **typ** : string (default None) - not used, 275 - **name** : string (default None) - not used 276 - **value** : Xdataset entity 277 - **encoded** : Boolean (default False) - json value if False else json text 278 - **header** : Boolean (default True) - including 'xdataset' type 279 - **notype** : list of Boolean (default list of None) - including data type if False 280 - **novalue** : Boolean (default False) - including value if False 281 - **noshape** : Boolean (default False) - if True, without shape if dim < 1 282 - **format** : list of string (default list of 'full') - representation format 283 of the np.ndarray, 284 ''' 285 option = {'notype': False, 'extension': None, 'format': 'full', 286 'noshape': True, 'header': True, 'encoded': False, 287 'novalue': False, 'noname': False} | kwargs 288 if not option['format'] in ['full', 'complete']: 289 option['noshape'] = False 290 option['noname'] = True 291 return (value.to_json(**option), name, 'xdataset')
NTV connector for Xdataset.
257 @staticmethod 258 def to_obj_ntv(ntv_value, **kwargs): # reindex=True, decode_str=False): 259 ''' convert json ntv_value into a Xdataset. 260 261 *Parameters* 262 263 - **convert** : boolean (default True) - If True, convert json data with 264 non-Numpy ntv_type into Xdataset with python type 265 ''' 266 return Xdataset.read_json(ntv_value, **kwargs)
convert json ntv_value into a Xdataset.
Parameters
- convert : boolean (default True) - If True, convert json data with non-Numpy ntv_type into Xdataset with python type
268 @staticmethod 269 def to_json_ntv(value, name=None, typ=None, **kwargs): 270 ''' convert a Xdataset (value) into NTV json (json-value, name, ntv_type). 271 272 *Parameters* 273 274 - **typ** : string (default None) - not used, 275 - **name** : string (default None) - not used 276 - **value** : Xdataset entity 277 - **encoded** : Boolean (default False) - json value if False else json text 278 - **header** : Boolean (default True) - including 'xdataset' type 279 - **notype** : list of Boolean (default list of None) - including data type if False 280 - **novalue** : Boolean (default False) - including value if False 281 - **noshape** : Boolean (default False) - if True, without shape if dim < 1 282 - **format** : list of string (default list of 'full') - representation format 283 of the np.ndarray, 284 ''' 285 option = {'notype': False, 'extension': None, 'format': 'full', 286 'noshape': True, 'header': True, 'encoded': False, 287 'novalue': False, 'noname': False} | kwargs 288 if not option['format'] in ['full', 'complete']: 289 option['noshape'] = False 290 option['noname'] = True 291 return (value.to_json(**option), name, 'xdataset')
convert a Xdataset (value) into NTV json (json-value, name, ntv_type).
Parameters
- typ : string (default None) - not used,
- name : string (default None) - not used
- value : Xdataset entity
- encoded : Boolean (default False) - json value if False else json text
- header : Boolean (default True) - including 'xdataset' type
- notype : list of Boolean (default list of None) - including data type if False
- novalue : Boolean (default False) - including value if False
- noshape : Boolean (default False) - if True, without shape if dim < 1
- format : list of string (default list of 'full') - representation format of the np.ndarray,
Inherited Members
- json_ntv.ntv_util.NtvConnector
- DIC_NTV_CL
- DIC_GEO_CL
- DIC_DAT_CL
- DIC_FCT
- DIC_GEO
- DIC_CBOR
- DIC_OBJ
- castable
- dic_obj
- dic_type
- connector
- dic_connec
- cast
- uncast
- is_json_class
- is_json
- keysfromderkeys
- encode_coef
- keysfromcoef
- format_field
- init_ntv_keys