GenericTimeSeries

class sunpy.timeseries.GenericTimeSeries(data, meta=None, units=None, **kwargs)[source]

Bases: object

A generic time series object.

Parameters
  • data (DataFrame) – A pandas.DataFrame representing one or more fields as a function of time.

  • meta (TimeSeriesMetaData, optional) – The metadata giving details about the time series data/instrument. Defaults to None.

  • units (dict, optional) – A mapping from column names in data to the physical units of that column. Defaults to None.

meta

The metadata giving details about the time series data/instrument.

Type

TimeSeriesMetaData

units

A mapping from column names in data to the physical units ofthat column.

Type

dict

Examples

>>> from sunpy.timeseries import TimeSeries
>>> from sunpy.time import parse_time
>>> from astropy.time import TimeDelta
>>> import astropy.units as u
>>> import numpy as np
>>> import pandas as pd
>>> times = parse_time("now") - TimeDelta(np.arange(24 * 60)*u.minute)
>>> intensity = np.sin(np.arange(0, 12 * np.pi, step=(12 * np.pi) / (24 * 60)))
>>> df = pd.DataFrame(intensity, index=times, columns=['intensity'])
>>> ts = TimeSeries(df)
>>> ts.peek()  

References

Attributes Summary

columns

A list of all the names of the columns in the data.

data

A pandas.DataFrame representing one or more fields as a function of time.

index

The time index of the data.

shape

The shape of the data, a tuple (nrows, ncols).

source

A string/object used to specify the source class of the TimeSeries.

time_range

The start and end times of the TimeSeries as a TimeRange.

Methods Summary

add_column(colname, quantity[, unit, overwrite])

Return a new TimeSeries with the given column added or updated.

concatenate(otherts[, same_source])

Concatenate with another TimeSeries.

extract(column_name)

Returns a new time series with the chosen column.

peek(**kwargs)

Displays a graphical overview of the data in this object for user evaluation.

plot([axes])

Plot a plot of the TimeSeries.

quantity(colname, **kwargs)

Return a Quantity for the given column.

remove_column(colname)

Remove a column.

sort_index(**kwargs)

Returns a sorted version of a TimeSeries.

to_array(**kwargs)

Return a numpy.array of the given TimeSeries.

to_dataframe(**kwargs)

Return a DataFrame of the given TimeSeries.

to_table(**kwargs)

Return an astropy.table.Table of the given TimeSeries.

truncate(a[, b, int])

Returns a truncated version of the TimeSeries object.

Attributes Documentation

columns

A list of all the names of the columns in the data.

data

A pandas.DataFrame representing one or more fields as a function of time.

index

The time index of the data.

shape

The shape of the data, a tuple (nrows, ncols).

source

A string/object used to specify the source class of the TimeSeries.

time_range

The start and end times of the TimeSeries as a TimeRange.

Methods Documentation

add_column(colname, quantity, unit=False, overwrite=True, **kwargs)[source]

Return a new TimeSeries with the given column added or updated.

Parameters
  • colname (str) – The heading of the column you want output.

  • quantity (Quantity or ndarray) – The values to be placed within the column. If updating values only then a numpy array is permitted.

  • overwrite (bool, optional) – Defaults to True, allowing the method to overwrite a column already present in the TimeSeries.

Returns

sunpy.timeseries.TimeSeries – A new TimeSeries.

concatenate(otherts, same_source=False, **kwargs)[source]

Concatenate with another TimeSeries. This function will check and remove any duplicate times. It will keep the column values from the original timeseries to which the new time series is being added.

Parameters
Returns

TimeSeries – A new TimeSeries.

Notes

Extra keywords are passed to pandas.concat.

extract(column_name)[source]

Returns a new time series with the chosen column.

Parameters

column_name (str) – A valid column name.

Returns

TimeSeries – A new TimeSeries with only the selected column.

peek(**kwargs)[source]

Displays a graphical overview of the data in this object for user evaluation. For the creation of plots, users should instead use the plot method and Matplotlib’s pyplot framework.

Parameters

**kwargs (dict) – Any additional plot arguments that should be used when plotting.

plot(axes=None, **plot_args)[source]

Plot a plot of the TimeSeries.

Parameters
  • axes (Axes, optional) – If provided the image will be plotted on the given axes. Defaults to None, so the current axes will be used.

  • **plot_args (dict, optional) – Additional plot keyword arguments that are handed to pandas.DataFrame.plot().

Returns

axes (Axes) – The plot axes.

quantity(colname, **kwargs)[source]

Return a Quantity for the given column.

Parameters

colname (str) – The heading of the column you want to output.

Returns

Quantity

remove_column(colname)[source]

Remove a column.

Parameters

colname (str) – The heading of the column to remove.

Returns

sunpy.timeseries.TimeSeries – A new TimeSeries.

sort_index(**kwargs)[source]

Returns a sorted version of a TimeSeries. Generally this shouldn’t be necessary as most TimeSeries operations sort the data anyway to ensure consistent behavior when truncating.

Returns

TimeSeries – A new TimeSeries in ascending chronological order.

to_array(**kwargs)[source]

Return a numpy.array of the given TimeSeries.

Parameters

kwargs (dict) – All keyword arguments are passed to pandas.DataFrame.to_numpy.

Returns

ndarray – If the data is heterogeneous and contains booleans or objects, the result will be of dtype=object.

to_dataframe(**kwargs)[source]

Return a DataFrame of the given TimeSeries.

Returns

DataFrame – A DataFrame containing the data.

to_table(**kwargs)[source]

Return an astropy.table.Table of the given TimeSeries.

Returns

Table – A new astropy.table.Table containing the data from the TimeSeries. The table will include units where relevant.

truncate(a, b=None, int=None)[source]

Returns a truncated version of the TimeSeries object.

Parameters
  • a (sunpy.time.TimeRange, str, int) – Either a time range to truncate to, or a start time in some format recognized by pandas, or a index integer.

  • b (str or int, optional) – If specified, the end time of the time range in some format recognized by pandas, or a index integer. Defaults to None.

  • int (int, optional) – If specified, the integer indicating the slicing intervals. Defaults to None.

Returns

TimeSeries – A new TimeSeries with only the selected times.