spacepy.datamodel.SpaceData

class spacepy.datamodel.SpaceData(*args, **kwargs)[source]

Datamodel class extending dict by adding attributes.

flatten()

Method to collapse datamodel to one level deep

tree(**kwargs)

Print the contents of the SpaceData object in a visual tree

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
tree(**kwargs)[source]

Print the contents of the SpaceData object in a visual tree

Other Parameters
verboseboolean (optional)

print more info

spacesstring (optional)

string will added for every line

levelsinteger (optional)

number of levels to recurse through (True means all)

attrsboolean (optional)

display information for attributes

See also

toolbox.dictree

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