spacepy.datamodel.ISTPContainer

class spacepy.datamodel.ISTPContainer[source]

Mixin class for containers using ISTP metadata.

Container types like SpaceData provide all these methods; they assume attributes of the container and the arrays it contains use the ISTP metadata standard and are unlikely to give good results if that is not the case.

New in version 0.5.0.

fromDataFrame(df[, copy])

Convert from Pandas DataFrame

lineplot(vname[, target])

Line plot of a value (array) from this container

main_vars()

Return names of the 'main' variables in this container.

plot([vnames, fig])

Plot one or more values (arrays) from this container

spectrogram(vname[, target])

Spectrogram plot of a value (array) from this container

toDataFrame([vname, copy])

Convert to Pandas DataFrame

classmethod fromDataFrame(df, copy=True)[source]

Convert from Pandas DataFrame

Converts a Pandas DataFrame to ISTP-compliant type. nan are replaced with fill.

Parameters:
dfDataFrame

Data frame to convert

Returns:
ISTPContainer

ISTP-compliant container representing the dataframe’s data. This may not be fully ISTP-compliant; the minimium attributes required to represent the DataFrame are used.

Other Parameters:
copybool, default True

Copy data from the DataFrame. If False, changes to the output may affect the DataFrame. In some cases a copy may be made even if False.

Notes

New in version 0.6.0.

lineplot(vname, target=None)[source]

Line plot of a value (array) from this container

Parameters:
vnamestr

The key into this container of the value to plot (i.e., the name of the variable).

targetmatplotlib.axes.Axes or matplotlib.figure.Figure, optional

Where to draw the plot. Default is to create a new figure with a single subplot. If Axes, will draw into that subplot (and will not draw a legend or figure title); if Figure, will make a single subplot (and not set figure title). Handled by set_target.

Returns:
axmatplotlib.axes.Axes

The subplot on which the variable was plotted

Notes

New in version 0.5.0.

main_vars()[source]

Return names of the ‘main’ variables in this container.

These are variables that are likely to be of direct interest, rather than dependencies and support data. They are chosen primarily by not being dependencies of other variables, but if the VAR_TYPE attribute is present it must be data.

Returns:
list of str

Notes

New in version 0.5.0.

plot(vnames=None, fig=None)[source]

Plot one or more values (arrays) from this container

Parameters:
vnameslist of str, optional.

The key into this container of the value(s) to plot (i.e., the name of the variable). If not specified, plots all ‘main’ variables which are not dependencies of others; see main_vars.

figmatplotlib.figure.Figure, optional

Where to draw the plot. Default is to create a new figure. If given, subplots will be added to this figure (it should start empty).

Returns:
figmatplotlib.figure.Figure

The figure on which the variables were plotted

See also

lineplot

to line plot a single variable

spectrogram

to make a spectrogram of a single variable

Notes

New in version 0.5.0.

Examples

>>> import spacepy.datamodel
# https://rbsp-ect.newmexicoconsortium.org/data_pub/rbspa/ECT/level2/
>>> data = spacepy.datamodel.fromCDF(
...     'rbspa_ect-elec-L2_20140115_v2.1.0.cdf')
>>> fig = data.plot(['FESA', 'Position'])
>>> fig.show()  # if needed
>>> import spacepy.pycdf
# https://rbsp-ect.newmexicoconsortium.org/data_pub/rbspa/hope/level2/spinaverage/
>>> with spacepy.pycdf.CDF('rbspa_rel04_ect-hope-sci-L2SA_20140108_v6.1.0.cdf') as f:
...     data = f.copy()
>>> fig = data.plot(['FESA', 'FPSA'])
>>> fig.show()  # if needed
>>> import spacepy.pycdf
# https://spp-isois.sr.unh.edu/data_public/ISOIS/level2/
>>> with spacepy.pycdf.CDF('psp_isois_l2-summary_20201130_v13.cdf') as f:
...     data = f.copy()
>>> fig = data.plot(['A_H_Rate_TS', 'H_CountRate_ChanP_SP'])
>>> fig.show()  # if needed
spectrogram(vname, target=None)[source]

Spectrogram plot of a value (array) from this container

Parameters:
vnamestr

The key into this container of the value to plot (i.e., the name of the variable).

targetmatplotlib.axes.Axes or matplotlib.figure.Figure, optional

Where to draw the plot. Default is to create a new figure with a single subplot. If Axes, will draw into that subplot (and will not set figure title); if Figure, will make a single subplot (and not set figure title). Handled by set_target.

Returns:
axmatplotlib.axes.Axes

The subplot on which the variable was plotted

Notes

New in version 0.5.0.

toDataFrame(vname=None, copy=True)[source]

Convert to Pandas DataFrame

Converts one variable (and its dependencies) to a Pandas DataFrame. Invalid values are replaced with nan.

Parameters:
vnamestr, optional

The key into this container of the value to convert (i.e., the name of the variable). Strongly recommended; if not specified, will try to find one using main_vars, and raise ValueError if there is more than one candidate.

Returns:
DataFrame

Data from the array named by vname and its dependencies.

Other Parameters:
copybool, default True

Copy data to the DataFrame. If False, changes to the DataFrame may affect the source data. In some cases a copy may be made even if False.

Notes

New in version 0.6.0.

Examples

>>> import spacepy.datamodel
# https://rbsp-ect.newmexicoconsortium.org/data_pub/rbspa/ECT/level2/
>>> data = spacepy.datamodel.fromCDF(
...     'rbspa_ect-elec-L2_20140115_v2.1.0.cdf')
>>> df = data.toDataFrame('Position')
>>> df.plot()