speasy package

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

Bases: object

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: speasy.products.catalog.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) speasy.products.catalog.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.

class speasy.Dataset(name: str, variables: dict, meta: dict)[source]

Bases: object

A Dataset is basically a collection of SpeasyVariables

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

Bases: speasy.core.datetime_range.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.SpeasyVariable(time=array([], dtype=float64), data=array([], shape=(0, 1), dtype=float64), meta: Optional[dict] = None, columns: Optional[List[str]] = None, y: Optional[numpy.ndarray] = None)[source]

Bases: object

SpeasyVariable object. Base class for storing variable data.

Attributes
time: numpy.ndarray

time vector (x-axis data)

data: numpy.ndarray

data

meta: Optional[dict]

metadata

columns: Optional[List[str]]

column names

y: Optional[np.ndarray]

y-axis for 2D data

Methods

view:

Return view of the current variable within the desired time_range

to_dataframe:

Convert the variable to a pandas.DataFrame object

plot:

Plot the data with matplotlib

columns
property data
static from_dataframe(df: pandas.core.frame.DataFrame) speasy.products.variable.SpeasyVariable[source]

Load from pandas.DataFrame object.

Parameters
dr: pandas.DataFrame

Input DataFrame to convert

Returns
SpeasyVariable:

Variable created from DataFrame

meta
plot(*args, **kwargs)[source]

Plot the variable.

See https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.html

time
to_dataframe(datetime_index=False) pandas.core.frame.DataFrame[source]

Convert the variable to a pandas.DataFrame object.

Parameters
datetime_index: bool

boolean indicating that the index is datetime

Returns
pandas.DataFrame:

Variable converted to Pandas DataFrame

values
view(time_range)[source]

Return view of the current variable within the desired time_range.

Parameters
time_range: speasy.common.datetime_range.DateTimeRange

time range

Returns
speasy.common.variable.SpeasyVariable

view of the variable on the given range

y
class speasy.TimeTable(name: str, meta: Optional[dict] = None, dt_ranges: Optional[List[speasy.core.datetime_range.DateTimeRange]] = None)[source]

Bases: object

A TimeTable is basically a collection of DateTimeRange

append(dt_range: speasy.core.datetime_range.DateTimeRange)[source]
meta
name
pop(index=- 1)[source]
speasy.get_data(product: str, start_time=None, stop_time=None, **kwargs) Optional[Union[speasy.products.dataset.Dataset, speasy.products.variable.SpeasyVariable, speasy.products.catalog.Catalog, speasy.products.timetable.TimeTable]][source]

Download given product, this function accepts string paths like “sscweb/moon” or index objects from inventory trees.

Parameters
productstr or SpeasyIndex

The product you want to download, either path like “sscweb/moon” or index objects.

start_timestr or datetime.datetime, optional

Start time, mandatory for time-series.

stop_timestr or datetime.datetime, optional

Stop time, mandatory for time-series.

kwargs
Returns
MaybeAnyProduct

The requested product if available or None

Examples

>>> moon=spz.get_data('sscweb/moon', '2000-01-01', '2000-09-02T12:00:00+00:00')
>>> moon.columns
['X', 'Y', 'Z']
>>> moon.data
<Quantity [[ 183940.73767809, -354329.74995782,   36559.09278865],
           [ 183989.39891203, -354307.09633046,   36558.99256677],
           [ 184038.04489285, -354284.42184423,   36558.88913279],
           ...,
           [ 230448.57392717,  305986.424528  ,   33999.47652102],
           [ 230405.72253792,  306023.74218105,   33998.89651167],
           [ 230362.93800137,  306061.10305253,   33998.32408929]] km>
speasy.get_orbit(body: str, start_time, stop_time, coordinate_system: str = 'gse', **kwargs) speasy.products.variable.SpeasyVariable[source]

Subpackages