spacepy.datamodel.SpaceData¶
- class spacepy.datamodel.SpaceData(*args, **kwargs)[source]¶
Datamodel class extending dict by adding attributes.
Although the format of attributes is not enforced, using ISTP metadata enables the use of methods from
ISTPContainer.- __init__(*args, **kwargs)[source]¶
Base class for “Data Model” representation data
Abstract method, reimplement
- Attributes:
- attrsdict
dictionary of the attributes of the SpaceData object
Methods
flatten()Method to collapse datamodel to one level deep
toCDF(**kwargs)Create CDF file from this SpaceData.
toHDF5(**kwargs)Create HDF5 file from this SpaceData.
toJSONheadedASCII(**kwargs)Create JSON-headed ASCII file from this SpaceData.
tree(**kwargs)Print the contents of the SpaceData object in a visual tree
Attributes
- flatten()[source]¶
Method to collapse datamodel to one level deep
Examples
>>> import spacepy.datamodel as dm >>> import spacepy.toolbox as tb >>> a = dm.SpaceData() >>> a['1'] = dm.SpaceData(dog = 5, pig = dm.SpaceData(fish=dm.SpaceData(a='carp', b='perch'))) >>> a['4'] = dm.SpaceData(cat = 'kitty') >>> a['5'] = 4 >>> a.tree() + |____1 |____dog |____pig |____fish |____a |____b |____4 |____cat |____5
>>> b = dm.flatten(a) >>> b.tree() + |____1<--dog |____1<--pig<--fish<--a |____1<--pig<--fish<--b |____4<--cat |____5
>>> a.flatten() >>> a.tree() + |____1<--dog |____1<--pig<--fish<--a |____1<--pig<--fish<--b |____4<--cat |____5
- toCDF(**kwargs)[source]¶
Create CDF file from this SpaceData.
See
toCDF; this object is provided forSDobject.
- toHDF5(**kwargs)[source]¶
Create HDF5 file from this SpaceData.
See
toHDF5; this object is provided forSDObject.
- toJSONheadedASCII(**kwargs)[source]¶
Create JSON-headed ASCII file from this SpaceData.
See
toJSONheadedASCII; this object is provided forinsd.
- tree(**kwargs)[source]¶
Print the contents of the SpaceData object in a visual tree
- Other Parameters:
- verbosebool, default False
print more info
- spacesstr (optional)
string will added for every line
- levelsint (optional)
number of levels to recurse through (True, the default, means all)
- attrsbool, default False
display information for attributes
- print_outbool, default True
Added in version 0.5.0.
Print output (original behavior); if
False, return the output.
See also
Examples
>>> import spacepy.datamodel as dm >>> import spacepy.toolbox as tb >>> a = dm.SpaceData() >>> a['1'] = dm.SpaceData(dog = 5) >>> a['4'] = dm.SpaceData(cat = 'kitty') >>> a['5'] = 4 >>> a.tree() + |____1 |____dog |____4 |____cat |____5
