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.
  • units (dict, optional) – A mapping from column names in data to the physical units of that column.
data

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

meta

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

units

dict – A mapping from column names in data to the physical units of that column.

Examples

>>> from sunpy.timeseries import TimeSeries
>>> import datetime
>>> import numpy as np
>>> import pandas as pd
>>> base = datetime.datetime.today()
>>> times = [base - datetime.timedelta(minutes=x) for x in range(0, 24 * 60)]
>>> 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 object

Methods Summary

add_column(colname, quantity[, unit, overwrite]) Return an new TimeSeries with the given column added or updated.
concatenate(otherts, **kwargs) Concatenate with another TimeSeries.
extract(column_name) Returns a new time series with the chosen column.
peek(**kwargs) Displays the time series in a new figure.
plot([axes]) Plot a plot of the time series
quantity(colname, **kwargs) Return a Quantity for the given column.
sort_index(**kwargs) Returns a sorted version of the TimeSeries object.
to_array(**kwargs) Return a numpy array of the give TimeSeries object.
to_dataframe(**kwargs) Return a Pandas DataFrame of the give TimeSeries object.
to_table(**kwargs) Return an Astropy Table of the give TimeSeries object.
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 object

Methods Documentation

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

Return an 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, default:True) – Set to true to allow the method to overwrite a column already present in the TimeSeries.
Returns:

newts (TimeSeries)

concatenate(otherts, **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 time series to which the new time series is being added.

Parameters:
  • otherts (TimeSeries) – Another time series.
  • same_source (bool Optional) – Set to true to check if the sources of the time series match.
Returns:

  • newts (TimeSeries) – A new time series.
  • Debate (decide if we want to be able to concatenate multiple time series)
  • at once.

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:newts (TimeSeries) – A new time series with only the selected column.
peek(**kwargs)[source] [edit on github]

Displays the time series in a new figure.

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 time series

Parameters:
  • axes (Axes or None) – If provided the image will be plotted on the given axes. Otherwise the current axes will be used.
  • **plot_args (dict) – 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 output.
Returns:quantity (Quantity)
sort_index(**kwargs)[source] [edit on github]

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

Returns:newts (TimeSeries) – A new time series in ascending chronological order.
to_array(**kwargs)[source] [edit on github]

Return a numpy array of the give TimeSeries object.

Parameters:columns (list, optional, default:None) – If None, return all columns minus the index, otherwise, returns specified columns.
Returns:values (ndarray) – If the caller is heterogeneous and contains booleans or objects, the result will be of dtype=object. See Notes.
to_dataframe(**kwargs)[source] [edit on github]

Return a Pandas DataFrame of the give TimeSeries object.

Returns:newdf (DataFrame) – A Pandas Dataframe containing the data.
to_table(**kwargs)[source] [edit on github]

Return an Astropy Table of the give TimeSeries object.

Returns:newtable (table) – A new astropy table containing the data from the time series. 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 or int) – Either a time range to truncate to, or a start time in some format recognised by pandas, or a index integer.
  • b (str or int) – If specified, the end time of the time range in some format recognised by pandas, or a index integer.
  • int (int) – If specified, the integer indicating the slicing intervals.
Returns:

newts (TimeSeries) – A new time series with only the selected times.