GenericTimeSeries#

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

Bases: object

A generic time series object.

Parameters:
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 of that 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'])
>>> header = {}
>>> units = {'intensity': u.W/u.m**2}
>>> ts = TimeSeries(df, header, units)
>>> 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.

observatory

A string/object used to specify the observatory for the TimeSeries.

shape

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

source

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

time

The timestamps of the data.

time_range

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

url

URL to the mission website.

Methods Summary

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

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

concatenate(others[, same_source])

Concatenate with another TimeSeries or an iterable containing multiple TimeSeries.

extract(column_name)

Returns a new time series with the chosen column.

peek(*[, columns, title])

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

plot([axes, columns])

Plot a plot of the TimeSeries.

quantity(colname, **kwargs)

Return a Quantity for the given column.

quicklook()

Display a quicklook summary of the Timeseries instance in the default webbrowser.

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.

observatory#

A string/object used to specify the observatory for the TimeSeries.

shape#

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

source#

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

time#

The timestamps of the data.

time_range#

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

url#

URL to the mission website.

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(others, same_source=False, **kwargs)[source]#

Concatenate with another TimeSeries or an iterable containing multiple 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.

Examples

A single TimeSeries or an collections.abc.Iterable containing multiple TimeSeries can be passed to concatenate.

>>> timeseries_1.concatenate(timeseries_2) 
>>> timeseries_1.concatenate([timeseries_2, timeseries_3]) 

Set same_source to True if the sources of the time series are the same.

>>> timeseries_1.concatenate([timeseries_2, timeseries_3], same_source=True) 
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(*, columns=None, title=None, **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:
  • columns (list[str], optional) – If provided, only plot the specified columns.

  • title (str, optional) – If provided, set the plot title. Custom timeseries sources may set a default value for this.

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

plot(axes=None, columns=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.

  • columns (list[str], optional) – If provided, only plot the specified columns.

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

Returns:

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

quicklook()[source]#

Display a quicklook summary of the Timeseries instance in the default webbrowser.

Example

>>> from sunpy.timeseries import TimeSeries
>>> import sunpy.data.sample  
>>> goes_lc = TimeSeries(sunpy.data.sample.GOES_XRS_TIMESERIES)  
>>> goes_lc.quicklook()  
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

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.