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.Added in version 0.5.0.
- __init__(*args, **kwargs)¶
Methods
fromDataFrame
(df[, copy])Convert from Pandas DataFrame
get_deltas
(vname)Return deltas for an array
lineplot
(vname[, target])Line plot of a value (array) from this container
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
Attributes
- classmethod fromDataFrame(df, copy=True)[source]¶
Convert from Pandas DataFrame
Converts a Pandas
DataFrame
to ISTP-compliant type.nan
are replaced with fill.- Parameters:
- df
DataFrame
Data frame to convert
- df
- 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:
- copy
bool
, defaultTrue
Copy data from the DataFrame. If
False
, changes to the output may affect the DataFrame. In some cases a copy may be made even ifFalse
.
- copy
Notes
Added in version 0.6.0.
- get_deltas(vname)[source]¶
Return deltas for an array
Returns ISTP delta values. These may be uncertainties or may be e.g. bin widths; interpretation is undefined.
Invalid values are replaced with
nan
.- Parameters:
- vname
str
The key into this container of the value to get delta (i.e., the name of the variable).
- vname
- Returns:
Notes
Added in version 0.5.0.
- lineplot(vname, target=None)[source]¶
Line plot of a value (array) from this container
- Parameters:
- vname
str
The key into this container of the value to plot (i.e., the name of the variable).
- target
matplotlib.axes.Axes
ormatplotlib.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); ifFigure
, will make a single subplot (and not set figure title). Handled byset_target
.
- vname
- Returns:
- ax
matplotlib.axes.Axes
The subplot on which the variable was plotted
- ax
Notes
Added 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 bedata
.Notes
Added in version 0.5.0.
- plot(vnames=None, fig=None)[source]¶
Plot one or more values (arrays) from this container
- Parameters:
- vnames
list
ofstr
, 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
.- fig
matplotlib.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).
- vnames
- Returns:
- fig
matplotlib.figure.Figure
The figure on which the variables were plotted
- fig
See also
lineplot
to line plot a single variable
spectrogram
to make a spectrogram of a single variable
Notes
Added 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:
- vname
str
The key into this container of the value to plot (i.e., the name of the variable).
- target
matplotlib.axes.Axes
ormatplotlib.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); ifFigure
, will make a single subplot (and not set figure title). Handled byset_target
.
- vname
- Returns:
- ax
matplotlib.axes.Axes
The subplot on which the variable was plotted
- ax
Notes
Added 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 withnan
.- Parameters:
- vname
str
, 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 raiseValueError
if there is more than one candidate.
- vname
- Returns:
DataFrame
Data from the array named by
vname
and its dependencies.
- Other Parameters:
- copy
bool
, defaultTrue
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 ifFalse
.
- copy
Notes
Added 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()