speasy.products package

class speasy.products.Catalog(name: str, meta: dict | None = None, events: List[Event] | None = None)[source]

Bases: SpeasyProduct

The Catalog class allows to manipulate a goup of events like a simple Python list of Event plus some meta data.

Examples

>>> import speasy
>>> from speasy.products import Catalog, Event
>>> my_catalog = Catalog(name='MyCatalog', meta={'tags':['demo', 'docstrings']}, events=[])
>>> my_catalog.append(Event('2018-01-01', '2018-01-02', meta={'name':'My first event!'}))
>>> my_catalog += Event('2019-01-01', '2019-01-02', meta={'name':'My second event!'})
>>> for e in my_catalog:
...     print(e)
...
<Event: 2018-01-01T00:00:00+00:00 -> 2018-01-02T00:00:00+00:00 | {'name': 'My first event!'}>
<Event: 2019-01-01T00:00:00+00:00 -> 2019-01-02T00:00:00+00:00 | {'name': 'My second event!'}>
Attributes:
namestr

Catalog name

metadict

All additional Catalog meta data

Methods

append:

Append an Event or a list of Event to the end of the Catalog

pop:

Remove and return Event at index (default last)

append(events: Event) None[source]

Append an Event or a list of Event to the end of the Catalog.

Parameters:
eventsEvent or List[Event]
Raises:
TypeError

If events is neither an Event or a list of Event

See also

Catalog.pop
meta
name
pop(index: int = -1) Event[source]

Remove and return Event at index (default last).

Parameters:
indexint
Returns:
Event

The removed event

Raises:
IndexError

if list is empty or index is out of range.

to_dataframe() DataFrame[source]
class speasy.products.DataContainer(values: array, meta: Dict | None = None, name: str | None = None, is_time_dependent: bool = True)[source]

Bases: object

static from_dictionary(dictionary: ~typing.Dict[str, str], dtype=<class 'numpy.float64'>) DataContainer[source]
property is_time_dependent: bool
property meta
property name
property nbytes: int
replace_val_by_nan(val)[source]
static reserve_like(other: DataContainer, length: int = 0) DataContainer[source]
reshape(new_shape)[source]
property shape
to_dictionary(array_to_list=False) Dict[str, object][source]
property unit: str
unit_applied(unit: str | None = None) DataContainer[source]
property values: array
view(index_range: slice)[source]
class speasy.products.Dataset(name: str, variables: dict, meta: dict)[source]

Bases: SpeasyProduct

A Dataset is basically a collection of SpeasyVariables

meta
name
plot(ax=None, **kwargs)[source]
time_range() DateTimeRange | None[source]
variables
class speasy.products.Event(start_time: datetime, stop_time: datetime, meta=None)[source]

Bases: DateTimeRange

The Event class is a DatetimeRange with some meta data. It is supposed to be used with Catalog

Notes

This class support the same operations as a speasy.common.datetime_range.DateTimeRange.

Attributes:
start_timedatetime.datetime
stop_timedatetime.datetime
metadict

Additional event data

Methods

meta
class speasy.products.SpeasyVariable(axes: List[VariableAxis], values: DataContainer, columns: List[str] | None = None)[source]

Bases: SpeasyProduct

SpeasyVariable object. Base class for storing variable data.

Attributes:
time: numpy.ndarray

time vector (x-axis data)

values: numpy.ndarray

data

meta: Optional[dict]

metadata

columns: Optional[List[str]]

column names, might be empty for spectrograms or 3D+ data

axes: List[np.ndarray]

Collection composed of time axis plus eventual additional axes according to values’ shape

axes_labels: List[str]

Axes names

unit: str

Values physical unit

name: str

SpeasyVariable name

nbytes: int

memory usage in bytes

Methods

view:

Returns a view of the current variable within the desired index_range

to_dataframe:

Converts the variable to a pandas.DataFrame object

from_dataframe:

Builds a SpeasyVariable from a pandas.DataFrame object

to_astropy_table:

Converts the variable to an astropy.table.Table

unit_applied:

Returns a copy where values are astropy.units.Quantity

filter_columns:

Returns a copy only containing selected columns

replace_fillval_by_nan:

Returns a SpeasyVaraible with NaN instead of fill value if fill value is set in meta data

plot:

Plot the data with matplotlib by default

to_dictionary:

Converts a SpeasyVariable to a Python dictionary, mostly used for serialization purposes

copy:

Returns a copy

property axes: List[VariableTimeAxis]

SpeasyVariable axes, axis 0 is always a VariableTimeAxis, there should be the same number of axes than values dimensions

Returns:
List[VariableTimeAxis or VariableAxis]

list of variable axes

property axes_labels: List[str]

Axes names respecting axes order

Returns:
List[str]

list of axes names

property columns: List[str]

SpeasyVariable columns names when it makes sense

Returns:
List[str]

list of columns names

copy() SpeasyVariable[source]

Makes a deep copy the variable

Returns:
SpeasyVariable

deep copy the variable

filter_columns(columns: List[str]) SpeasyVariable[source]

Builds a SpeasyVariable with only selected columns

Parameters:
columnsList[str]

list of column names to keep

Returns:
SpeasyVariable

a SpeasyVariable with only selected columns

static from_dataframe(df: DataFrame) SpeasyVariable[source]

Load from pandas.DataFrame object.

Parameters:
df: pandas.DataFrame

Input DataFrame to convert

Returns:
SpeasyVariable:

Variable created from DataFrame

See also

to_dataframe

exports a SpeasyVariable to a pandas DataFrame

to_astropy_table

exports a SpeasyVariable to an astropy.Table object

static from_dictionary(dictionary: Dict[str, object]) SpeasyVariable[source]

Builds a SpeasyVariable from a well formed dictionary

Returns:
SpeasyVariable or None

See also

to_dictionary

exports SpeasyVariable to dictionary

property meta: Dict

SpeasyVariable meta-data

Returns:
Dict

SpeasyVariable meta-data

property name: str

SpeasyVariable name

Returns:
str

SpeasyVariable name

property nbytes: int

SpeasyVariable’s values and axes memory usage

Returns:
int

number of bytes used to store values and axes

property plot

Plot the variable, tries to do its best to detect variable type and to populate plot labels

replace_fillval_by_nan(inplace=False) SpeasyVariable[source]

Replaces fill values by NaN, non float values are automatically converted to float. Fill value is taken from metadata field “FILLVAL”

Parameters:
inplacebool, optional

Modifies source variable when true else modifies and returns a copy, by default False

Returns:
SpeasyVariable

source variable or copy with fill values replaced by NaN

static reserve_like(other: SpeasyVariable, length: int = 0) SpeasyVariable[source]

Create a SpeasyVariable of given length and with the same properties than given variable but unset values

Parameters:
otherSpeasyVariable

variable used as reference for shape and meta-data

lengthint, optional

output variable length, by default 0

Returns:
SpeasyVariable

a SpeasyVariable similar to given one of given length

property time: array

Time axis values, equivalent to var.axes[0].values

Returns:
np.array

time axis values as numpy array of datetime64[ns]

to_astropy_table() Table[source]

Convert the variable to an astropy.Table object.

Parameters:
datetime_index: bool

boolean indicating that the index is datetime

Returns:
astropy.Table:

Variable converted to astropy.Table

See also

from_dataframe

builds a SpeasyVariable from a pandas DataFrame

to_dataframe

exports a SpeasyVariable to a pandas DataFrame

to_dataframe() DataFrame[source]

Convert the variable to a pandas.DataFrame object.

Returns:
pandas.DataFrame:

Variable converted to Pandas DataFrame

See also

from_dataframe

builds a SpeasyVariable from a pandas DataFrame

to_astropy_table

exports a SpeasyVariable to an astropy.Table object

to_dictionary(array_to_list=False) Dict[str, object][source]

Converts SpeasyVariable to dictionary

Parameters:
array_to_listbool, optional

Converts numpy arrays to Python Lists when true, by default False

Returns:
Dict[str, object]

See also

from_dictionary

builds variable from dictionary

property unit: str

SpeasyVariable unit if found in meta-data

Returns:
str

unit if found in meta-data

unit_applied(unit: str | None = None, copy=True) SpeasyVariable[source]

Returns a SpeasyVariable with given or automatically found unit applied to values

Parameters:
unitstr or None, optional

Use given unit or gets one from variable metadata, by default None

copybool, optional

Preserves source variable and returns a modified copy if true, by default True

Returns:
SpeasyVariable

SpeasyVariable identic to source one with values converted to astropy.units.Quantity according to given or found unit

See also

unit

returns variable unit if found in meta-data

property values: array

SpeasyVariable values

Returns:
np.array

SpeasyVariable values

view(index_range: slice) SpeasyVariable[source]

Return view of the current variable within the desired index_range.

Parameters:
index_range: slice

index range

Returns:
speasy.common.variable.SpeasyVariable

view of the variable on the given range

class speasy.products.TimeTable(name: str, meta: dict | None = None, dt_ranges: List[DateTimeRange] | None = None)[source]

Bases: SpeasyProduct

A TimeTable is basically a collection of DateTimeRange

append(dt_range: DateTimeRange)[source]
meta
name
pop(index=-1)[source]
to_dataframe() DataFrame[source]
class speasy.products.VariableAxis(values: array | None = None, meta: Dict | None = None, name: str = '', is_time_dependent: bool = False, data: DataContainer | None = None)[source]

Bases: object

static from_dictionary(dictionary: Dict[str, str], time=None) VariableAxis[source]
property is_time_dependent: bool
property name: str
property nbytes: int
static reserve_like(other: VariableAxis, length: int = 0) VariableAxis[source]
property shape
to_dictionary(array_to_list=False) Dict[str, object][source]
property unit: str
property values: array
view(index_range: slice) VariableAxis[source]
class speasy.products.VariableTimeAxis(values: array | None = None, meta: Dict | None = None, data: DataContainer | None = None)[source]

Bases: object

static from_dictionary(dictionary: Dict[str, str], time=None) VariableTimeAxis[source]
property is_time_dependent: bool
property name: str
property nbytes: int
static reserve_like(other: VariableTimeAxis, length: int = 0) VariableTimeAxis[source]
property shape
to_dictionary(array_to_list=False) Dict[str, object][source]
property unit: str
property values: array
view(index_range: slice) VariableTimeAxis[source]

Submodules