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
 28class NarrayConnec(NtvConnector):
 29
 30    '''NTV connector for Numpy ndarray.'''
 31
 32    clas_obj = 'ndarray'
 33    clas_typ = 'narray'
 34
 35    @staticmethod
 36    def to_obj_ntv(ntv_value, **kwargs):
 37        ''' convert json ntv_value into a np.ndarray.
 38
 39        *Parameters*
 40
 41        - **convert** : boolean (default True) - If True, convert json data with
 42        non Numpy ntv_type into data with python type'''
 43        return Ndarray.read_json(ntv_value, **kwargs).darray
 44
 45    @staticmethod
 46    def to_json_ntv(value, name=None, typ=None, **kwargs):
 47        ''' convert a np.ndarray (value, name, type) into NTV json (json-value, name, ntv_type).
 48
 49        *Parameters*
 50
 51        - **typ** : string (default None) - ntv_type of the np.ndarray object,
 52        - **name** : string (default None) - name of the ndarray object
 53        - **value** : np.ndarray value
 54        - **noshape** : Boolean (default True) - if True, without shape if dim < 1
 55        - **notype** : Boolean (default False) - including data type if False
 56        - **novalue** : Boolean (default False) - including value if False
 57        - **format** : string (default 'full') - representation format of the ndarray,
 58        - **encoded** : Boolean (default False) - json-value if False else json-text
 59        - **header** : Boolean (default True) - including ndarray type
 60        '''
 61        option = {'format': 'full', 'header': True, 'encoded': False,
 62                  'notype': False, 'noshape': True, 'novalue': False} | kwargs
 63        if not option['format'] in ['full', 'complete']:
 64            option['noshape'] = False
 65        option['header'] = False
 66        return (Ndarray(value).to_json(**option), name, 'narray')
 67
 68
 69class NdarrayConnec(NtvConnector):
 70
 71    '''NTV connector for Ndarray.'''
 72
 73    clas_obj = 'Ndarray'
 74    clas_typ = 'ndarray'
 75
 76    @staticmethod
 77    def to_obj_ntv(ntv_value, **kwargs):
 78        ''' convert json ntv_value into a Ndarray.
 79
 80        *Parameters*
 81
 82        - **convert** : boolean (default True) - If True, convert json data with
 83        non-Numpy ntv_type into data with python type'''
 84        return Ndarray.read_json(ntv_value, **kwargs)
 85
 86    @staticmethod
 87    def to_json_ntv(value, name=None, typ=None, **kwargs):
 88        ''' convert a Ndarray (value, name, type) into NTV json (json-value, name, ntv_type).
 89
 90        *Parameters*
 91
 92        - **typ** : string (default None) - ntv_type of the ndarray object,
 93        - **name** : string (default None) - name of the ndarray object
 94        - **value** : Ndarray value (or np.ndarray value)
 95        - **noshape** : Boolean (default True) - if True, without shape if dim < 1
 96        - **notype** : Boolean (default False) - including data type if False
 97        - **novalue** : Boolean (default False) - including value if False
 98        - **format** : string (default 'full') - representation format of the ndarray,
 99        - **encoded** : Boolean (default False) - json-value if False else json-text
100        - **header** : Boolean (default True) - including ndarray type
101        '''
102        option = {'format': 'full', 'header': True, 'encoded': False,
103                  'notype': False, 'noshape': True, 'novalue': False} | kwargs
104        if not option['format'] in ['full', 'complete']:
105            option['noshape'] = False
106        return (Ndarray(value).to_json(**option), name, 'ndarray')
107
108
109class XndarrayConnec(NtvConnector):
110
111    '''NTV connector for Xndarray.'''
112
113    clas_obj = 'Xndarray'
114    clas_typ = 'xndarray'
115
116    @staticmethod
117    def to_obj_ntv(ntv_value, **kwargs):
118        ''' convert json ntv_value into a Xndarray.
119
120        *Parameters*
121
122        - **convert** : boolean (default True) - If True, convert json data with
123        non-umpy ntv_type into Xndarray with python type
124        '''
125        print(ntv_value)
126        return Xndarray.read_json(ntv_value, **kwargs)
127
128    @staticmethod
129    def to_json_ntv(value, name=None, typ=None, **kwargs):
130        ''' convert a Xndarray (value) into NTV json (json-value, name, ntv_type).
131
132        *Parameters*
133
134        - **typ** : string (default None) - not used,
135        - **name** : string (default None) - not used
136        - **value** : Xndarray values
137        - **encoded** : Boolean (default False) - json-value if False else json-text
138        - **header** : Boolean (default True) - including xndarray type
139        - **notype** : Boolean (default False) - including data type if False
140        - **novalue** : Boolean (default False) - including value if False
141        - **noshape** : Boolean (default True) - if True, without shape if dim < 1
142        - **format** : string (default 'full') - representation format of the ndarray,
143        - **extension** : string (default None) - type extension
144        '''
145        option = {'notype': False, 'extension': None, 'format': 'full',
146                  'noshape': True, 'header': True, 'encoded': False,
147                  'novalue': False, 'noname': False} | kwargs
148        if not option['format'] in ['full', 'complete']:
149            option['noshape'] = False
150        return (value.to_json(**option), name, 'xndarray')
151
152
153class XdatasetConnec(NtvConnector):
154
155    '''NTV connector for Xdataset.'''
156
157    clas_obj = 'Xdataset'
158    clas_typ = 'xdataset'
159
160    @staticmethod
161    def to_obj_ntv(ntv_value, **kwargs):  # reindex=True, decode_str=False):
162        ''' convert json ntv_value into a Xdataset.
163
164        *Parameters*
165
166        - **convert** : boolean (default True) - If True, convert json data with
167        non-Numpy ntv_type into Xdataset with python type
168        '''
169        return Xdataset.read_json(ntv_value, **kwargs)
170
171    @staticmethod
172    def to_json_ntv(value, name=None, typ=None, **kwargs):
173        ''' convert a Xdataset (value) into NTV json (json-value, name, ntv_type).
174
175        *Parameters*
176
177        - **typ** : string (default None) - not used,
178        - **name** : string (default None) - not used
179        - **value** : Xdataset entity
180        - **encoded** : Boolean (default False) - json value if False else json text
181        - **header** : Boolean (default True) - including 'xdataset' type
182        - **notype** : list of Boolean (default list of None) - including data type if False
183        - **novalue** : Boolean (default False) - including value if False
184        - **noshape** : Boolean (default False) - if True, without shape if dim < 1
185        - **format** : list of string (default list of 'full') - representation format
186        of the np.ndarray,
187        '''
188        option = {'notype': False, 'extension': None, 'format': 'full',
189                  'noshape': True, 'header': True, 'encoded': False,
190                  'novalue': False, 'noname': False} | kwargs
191        if not option['format'] in ['full', 'complete']:
192            option['noshape'] = False
193        option['noname'] = True
194        return (value.to_json(**option), name, 'xdataset')
class NarrayConnec(json_ntv.ntv_util.NtvConnector):
29class NarrayConnec(NtvConnector):
30
31    '''NTV connector for Numpy ndarray.'''
32
33    clas_obj = 'ndarray'
34    clas_typ = 'narray'
35
36    @staticmethod
37    def to_obj_ntv(ntv_value, **kwargs):
38        ''' convert json ntv_value into a np.ndarray.
39
40        *Parameters*
41
42        - **convert** : boolean (default True) - If True, convert json data with
43        non Numpy ntv_type into data with python type'''
44        return Ndarray.read_json(ntv_value, **kwargs).darray
45
46    @staticmethod
47    def to_json_ntv(value, name=None, typ=None, **kwargs):
48        ''' convert a np.ndarray (value, name, type) into NTV json (json-value, name, ntv_type).
49
50        *Parameters*
51
52        - **typ** : string (default None) - ntv_type of the np.ndarray object,
53        - **name** : string (default None) - name of the ndarray object
54        - **value** : np.ndarray value
55        - **noshape** : Boolean (default True) - if True, without shape if dim < 1
56        - **notype** : Boolean (default False) - including data type if False
57        - **novalue** : Boolean (default False) - including value if False
58        - **format** : string (default 'full') - representation format of the ndarray,
59        - **encoded** : Boolean (default False) - json-value if False else json-text
60        - **header** : Boolean (default True) - including ndarray type
61        '''
62        option = {'format': 'full', 'header': True, 'encoded': False,
63                  'notype': False, 'noshape': True, 'novalue': False} | kwargs
64        if not option['format'] in ['full', 'complete']:
65            option['noshape'] = False
66        option['header'] = False
67        return (Ndarray(value).to_json(**option), name, 'narray')

NTV connector for Numpy ndarray.

clas_obj = 'ndarray'
clas_typ = 'narray'
@staticmethod
def to_obj_ntv(ntv_value, **kwargs):
36    @staticmethod
37    def to_obj_ntv(ntv_value, **kwargs):
38        ''' convert json ntv_value into a np.ndarray.
39
40        *Parameters*
41
42        - **convert** : boolean (default True) - If True, convert json data with
43        non Numpy ntv_type into data with python type'''
44        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
@staticmethod
def to_json_ntv(value, name=None, typ=None, **kwargs):
46    @staticmethod
47    def to_json_ntv(value, name=None, typ=None, **kwargs):
48        ''' convert a np.ndarray (value, name, type) into NTV json (json-value, name, ntv_type).
49
50        *Parameters*
51
52        - **typ** : string (default None) - ntv_type of the np.ndarray object,
53        - **name** : string (default None) - name of the ndarray object
54        - **value** : np.ndarray value
55        - **noshape** : Boolean (default True) - if True, without shape if dim < 1
56        - **notype** : Boolean (default False) - including data type if False
57        - **novalue** : Boolean (default False) - including value if False
58        - **format** : string (default 'full') - representation format of the ndarray,
59        - **encoded** : Boolean (default False) - json-value if False else json-text
60        - **header** : Boolean (default True) - including ndarray type
61        '''
62        option = {'format': 'full', 'header': True, 'encoded': False,
63                  'notype': False, 'noshape': True, 'novalue': False} | kwargs
64        if not option['format'] in ['full', 'complete']:
65            option['noshape'] = False
66        option['header'] = False
67        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
class NdarrayConnec(json_ntv.ntv_util.NtvConnector):
 70class NdarrayConnec(NtvConnector):
 71
 72    '''NTV connector for Ndarray.'''
 73
 74    clas_obj = 'Ndarray'
 75    clas_typ = 'ndarray'
 76
 77    @staticmethod
 78    def to_obj_ntv(ntv_value, **kwargs):
 79        ''' convert json ntv_value into a Ndarray.
 80
 81        *Parameters*
 82
 83        - **convert** : boolean (default True) - If True, convert json data with
 84        non-Numpy ntv_type into data with python type'''
 85        return Ndarray.read_json(ntv_value, **kwargs)
 86
 87    @staticmethod
 88    def to_json_ntv(value, name=None, typ=None, **kwargs):
 89        ''' convert a Ndarray (value, name, type) into NTV json (json-value, name, ntv_type).
 90
 91        *Parameters*
 92
 93        - **typ** : string (default None) - ntv_type of the ndarray object,
 94        - **name** : string (default None) - name of the ndarray object
 95        - **value** : Ndarray value (or np.ndarray value)
 96        - **noshape** : Boolean (default True) - if True, without shape if dim < 1
 97        - **notype** : Boolean (default False) - including data type if False
 98        - **novalue** : Boolean (default False) - including value if False
 99        - **format** : string (default 'full') - representation format of the ndarray,
100        - **encoded** : Boolean (default False) - json-value if False else json-text
101        - **header** : Boolean (default True) - including ndarray type
102        '''
103        option = {'format': 'full', 'header': True, 'encoded': False,
104                  'notype': False, 'noshape': True, 'novalue': False} | kwargs
105        if not option['format'] in ['full', 'complete']:
106            option['noshape'] = False
107        return (Ndarray(value).to_json(**option), name, 'ndarray')

NTV connector for Ndarray.

clas_obj = 'Ndarray'
clas_typ = 'ndarray'
@staticmethod
def to_obj_ntv(ntv_value, **kwargs):
77    @staticmethod
78    def to_obj_ntv(ntv_value, **kwargs):
79        ''' convert json ntv_value into a Ndarray.
80
81        *Parameters*
82
83        - **convert** : boolean (default True) - If True, convert json data with
84        non-Numpy ntv_type into data with python type'''
85        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
@staticmethod
def to_json_ntv(value, name=None, typ=None, **kwargs):
 87    @staticmethod
 88    def to_json_ntv(value, name=None, typ=None, **kwargs):
 89        ''' convert a Ndarray (value, name, type) into NTV json (json-value, name, ntv_type).
 90
 91        *Parameters*
 92
 93        - **typ** : string (default None) - ntv_type of the ndarray object,
 94        - **name** : string (default None) - name of the ndarray object
 95        - **value** : Ndarray value (or np.ndarray value)
 96        - **noshape** : Boolean (default True) - if True, without shape if dim < 1
 97        - **notype** : Boolean (default False) - including data type if False
 98        - **novalue** : Boolean (default False) - including value if False
 99        - **format** : string (default 'full') - representation format of the ndarray,
100        - **encoded** : Boolean (default False) - json-value if False else json-text
101        - **header** : Boolean (default True) - including ndarray type
102        '''
103        option = {'format': 'full', 'header': True, 'encoded': False,
104                  'notype': False, 'noshape': True, 'novalue': False} | kwargs
105        if not option['format'] in ['full', 'complete']:
106            option['noshape'] = False
107        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
class XndarrayConnec(json_ntv.ntv_util.NtvConnector):
110class XndarrayConnec(NtvConnector):
111
112    '''NTV connector for Xndarray.'''
113
114    clas_obj = 'Xndarray'
115    clas_typ = 'xndarray'
116
117    @staticmethod
118    def to_obj_ntv(ntv_value, **kwargs):
119        ''' convert json ntv_value into a Xndarray.
120
121        *Parameters*
122
123        - **convert** : boolean (default True) - If True, convert json data with
124        non-umpy ntv_type into Xndarray with python type
125        '''
126        print(ntv_value)
127        return Xndarray.read_json(ntv_value, **kwargs)
128
129    @staticmethod
130    def to_json_ntv(value, name=None, typ=None, **kwargs):
131        ''' convert a Xndarray (value) into NTV json (json-value, name, ntv_type).
132
133        *Parameters*
134
135        - **typ** : string (default None) - not used,
136        - **name** : string (default None) - not used
137        - **value** : Xndarray values
138        - **encoded** : Boolean (default False) - json-value if False else json-text
139        - **header** : Boolean (default True) - including xndarray type
140        - **notype** : Boolean (default False) - including data type if False
141        - **novalue** : Boolean (default False) - including value if False
142        - **noshape** : Boolean (default True) - if True, without shape if dim < 1
143        - **format** : string (default 'full') - representation format of the ndarray,
144        - **extension** : string (default None) - type extension
145        '''
146        option = {'notype': False, 'extension': None, 'format': 'full',
147                  'noshape': True, 'header': True, 'encoded': False,
148                  'novalue': False, 'noname': False} | kwargs
149        if not option['format'] in ['full', 'complete']:
150            option['noshape'] = False
151        return (value.to_json(**option), name, 'xndarray')

NTV connector for Xndarray.

clas_obj = 'Xndarray'
clas_typ = 'xndarray'
@staticmethod
def to_obj_ntv(ntv_value, **kwargs):
117    @staticmethod
118    def to_obj_ntv(ntv_value, **kwargs):
119        ''' convert json ntv_value into a Xndarray.
120
121        *Parameters*
122
123        - **convert** : boolean (default True) - If True, convert json data with
124        non-umpy ntv_type into Xndarray with python type
125        '''
126        print(ntv_value)
127        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
@staticmethod
def to_json_ntv(value, name=None, typ=None, **kwargs):
129    @staticmethod
130    def to_json_ntv(value, name=None, typ=None, **kwargs):
131        ''' convert a Xndarray (value) into NTV json (json-value, name, ntv_type).
132
133        *Parameters*
134
135        - **typ** : string (default None) - not used,
136        - **name** : string (default None) - not used
137        - **value** : Xndarray values
138        - **encoded** : Boolean (default False) - json-value if False else json-text
139        - **header** : Boolean (default True) - including xndarray type
140        - **notype** : Boolean (default False) - including data type if False
141        - **novalue** : Boolean (default False) - including value if False
142        - **noshape** : Boolean (default True) - if True, without shape if dim < 1
143        - **format** : string (default 'full') - representation format of the ndarray,
144        - **extension** : string (default None) - type extension
145        '''
146        option = {'notype': False, 'extension': None, 'format': 'full',
147                  'noshape': True, 'header': True, 'encoded': False,
148                  'novalue': False, 'noname': False} | kwargs
149        if not option['format'] in ['full', 'complete']:
150            option['noshape'] = False
151        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
class XdatasetConnec(json_ntv.ntv_util.NtvConnector):
154class XdatasetConnec(NtvConnector):
155
156    '''NTV connector for Xdataset.'''
157
158    clas_obj = 'Xdataset'
159    clas_typ = 'xdataset'
160
161    @staticmethod
162    def to_obj_ntv(ntv_value, **kwargs):  # reindex=True, decode_str=False):
163        ''' convert json ntv_value into a Xdataset.
164
165        *Parameters*
166
167        - **convert** : boolean (default True) - If True, convert json data with
168        non-Numpy ntv_type into Xdataset with python type
169        '''
170        return Xdataset.read_json(ntv_value, **kwargs)
171
172    @staticmethod
173    def to_json_ntv(value, name=None, typ=None, **kwargs):
174        ''' convert a Xdataset (value) into NTV json (json-value, name, ntv_type).
175
176        *Parameters*
177
178        - **typ** : string (default None) - not used,
179        - **name** : string (default None) - not used
180        - **value** : Xdataset entity
181        - **encoded** : Boolean (default False) - json value if False else json text
182        - **header** : Boolean (default True) - including 'xdataset' type
183        - **notype** : list of Boolean (default list of None) - including data type if False
184        - **novalue** : Boolean (default False) - including value if False
185        - **noshape** : Boolean (default False) - if True, without shape if dim < 1
186        - **format** : list of string (default list of 'full') - representation format
187        of the np.ndarray,
188        '''
189        option = {'notype': False, 'extension': None, 'format': 'full',
190                  'noshape': True, 'header': True, 'encoded': False,
191                  'novalue': False, 'noname': False} | kwargs
192        if not option['format'] in ['full', 'complete']:
193            option['noshape'] = False
194        option['noname'] = True
195        return (value.to_json(**option), name, 'xdataset')

NTV connector for Xdataset.

clas_obj = 'Xdataset'
clas_typ = 'xdataset'
@staticmethod
def to_obj_ntv(ntv_value, **kwargs):
161    @staticmethod
162    def to_obj_ntv(ntv_value, **kwargs):  # reindex=True, decode_str=False):
163        ''' convert json ntv_value into a Xdataset.
164
165        *Parameters*
166
167        - **convert** : boolean (default True) - If True, convert json data with
168        non-Numpy ntv_type into Xdataset with python type
169        '''
170        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
@staticmethod
def to_json_ntv(value, name=None, typ=None, **kwargs):
172    @staticmethod
173    def to_json_ntv(value, name=None, typ=None, **kwargs):
174        ''' convert a Xdataset (value) into NTV json (json-value, name, ntv_type).
175
176        *Parameters*
177
178        - **typ** : string (default None) - not used,
179        - **name** : string (default None) - not used
180        - **value** : Xdataset entity
181        - **encoded** : Boolean (default False) - json value if False else json text
182        - **header** : Boolean (default True) - including 'xdataset' type
183        - **notype** : list of Boolean (default list of None) - including data type if False
184        - **novalue** : Boolean (default False) - including value if False
185        - **noshape** : Boolean (default False) - if True, without shape if dim < 1
186        - **format** : list of string (default list of 'full') - representation format
187        of the np.ndarray,
188        '''
189        option = {'notype': False, 'extension': None, 'format': 'full',
190                  'noshape': True, 'header': True, 'encoded': False,
191                  'novalue': False, 'noname': False} | kwargs
192        if not option['format'] in ['full', 'complete']:
193            option['noshape'] = False
194        option['noname'] = True
195        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