GenericTimeSeries

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

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.

data

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

Type

DataFrame

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.

index

The time index of the data.

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.

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.

index

The time index of the data.

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] [edit on github]

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] [edit on github]

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
  • otherts (TimeSeries) – Another TimeSeries.

  • same_source (bool, optional) – Set to True to check if the sources of the time series match. Defaults to False.

Returns

TimeSeries – A new TimeSeries.

Notes

Extra keywords are passed to pandas.concat.

extract(column_name)[source] [edit on github]

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] [edit on github]

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] [edit on github]

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) – Any additional plot arguments that should be used when plotting.

Returns

axes (Axes) – The plot axes.

quantity(colname, **kwargs)[source] [edit on github]

Return a Quantity for the given column.

Parameters

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

Returns

Quantity

sort_index(**kwargs)[source] [edit on github]

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] [edit on github]

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] [edit on github]

Return a DataFrame of the given TimeSeries.

Returns

DataFrame – A DataFrame containing the data.

to_table(**kwargs)[source] [edit on github]

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] [edit on github]

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.