GenericTimeSeries#
- class sunpy.timeseries.GenericTimeSeries(data, meta=None, units=None, **kwargs)[source]#
Bases:
objectA generic time series object.
- Parameters:
data (
DataFrameornumpy.array) – Apandas.DataFrameornumpy.arrayrepresenting one or more fields as a function of time.meta (
TimeSeriesMetaData, optional) – The metadata giving details about the time series data/instrument. Defaults toNone.units (
dict, optional) – A mapping from column names indatato the physical units of that column. Defaults toNone.
- meta#
The metadata giving details about the time series data/instrument.
- Type:
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
A list of all the names of the columns in the data.
A
pandas.DataFramerepresenting one or more fields as a function of time.A string/object used to specify the observatory for the TimeSeries.
The shape of the data, a tuple (nrows, ncols).
A string/object used to specify the source class of the TimeSeries.
The timestamps of the data.
The start and end times of the TimeSeries as a
TimeRange.URL to the mission website.
Methods Summary
add_column(colname, quantity[, unit, overwrite])Return a new
TimeSerieswith the given column added or updated.concatenate(others[, same_source])Concatenate with another
TimeSeriesor an iterable containing multipleTimeSeries.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
Quantityfor the given column.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.arrayof the givenTimeSeries.to_dataframe(**kwargs)Return a
DataFrameof the givenTimeSeries.to_table(**kwargs)Return an
astropy.table.Tableof the givenTimeSeries.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.DataFramerepresenting 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.
- url#
URL to the mission website.
Methods Documentation
- add_column(
- colname,
- quantity,
- unit=False,
- overwrite=True,
- **kwargs,
Return a new
TimeSerieswith the given column added or updated.- Parameters:
colname (
str) – The heading of the column you want output.quantity (
Quantityorndarray) – The values to be placed within the column. If updating values only then a numpy array is permitted.overwrite (
bool, optional) – Defaults toTrue, allowing the method to overwrite a column already present in theTimeSeries.
- Returns:
sunpy.timeseries.TimeSeries– A newTimeSeries.
- concatenate(others, same_source=False, **kwargs)[source]#
Concatenate with another
TimeSeriesor an iterable containing multipleTimeSeries. 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:
others (
TimeSeriesorcollections.abc.Iterable) – AnotherTimeSeriesor an iterable containing multipleTimeSeries.same_source (
bool, optional) – Set toTrueto check if the sources of the time series match. Defaults toFalse.
- Returns:
TimeSeries– A newTimeSeries.
Notes
Extra keywords are passed to
pandas.concat.Examples
A single
TimeSeriesor ancollections.abc.Iterablecontaining multipleTimeSeriescan be passed to concatenate.>>> timeseries_1.concatenate(timeseries_2) >>> timeseries_1.concatenate([timeseries_2, timeseries_3])
Set
same_sourcetoTrueif 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 newTimeSerieswith 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
plotmethod 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 toNone, 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 topandas.DataFrame.plot().
- Returns:
Axes– The plot axes.
- 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 newTimeSeries.
- sort_index(**kwargs)[source]#
Returns a sorted version of a
TimeSeries. Generally this shouldn’t be necessary as mostTimeSeriesoperations sort the data anyway to ensure consistent behavior when truncating.- Returns:
TimeSeries– A newTimeSeriesin ascending chronological order.
- to_array(**kwargs)[source]#
Return a
numpy.arrayof the givenTimeSeries.
- to_dataframe(**kwargs)[source]#
Return a
DataFrameof the givenTimeSeries.- Returns:
- to_table(**kwargs)[source]#
Return an
astropy.table.Tableof the givenTimeSeries.- Returns:
Table– A newastropy.table.Tablecontaining the data from theTimeSeries. 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 (
strorint, optional) – If specified, the end time of the time range in some format recognized by pandas, or a index integer. Defaults toNone.int (
int, optional) – If specified, the integer indicating the slicing intervals. Defaults toNone.
- Returns:
TimeSeries– A newTimeSerieswith only the selected times.