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
) – Apandas.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 toNone
.units (
dict
, optional) – A mapping from column names indata
to the physical units of that column. Defaults toNone
.
-
data
¶ A
pandas.DataFrame
representing one or more fields as a function of time.- Type
-
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']) >>> ts = TimeSeries(df) >>> ts.peek()
References
Attributes Summary
A list of all the names of the columns in the data.
The time index of the data.
A string/object used to specify the source class of the TimeSeries.
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 givenTimeSeries
.to_dataframe
(**kwargs)Return a
DataFrame
of the givenTimeSeries
.to_table
(**kwargs)Return an
astropy.table.Table
of 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.
-
index
¶ The time index of the data.
-
source
¶ A string/object used to specify the source class of the TimeSeries.
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
orndarray
) – 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
(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
- Returns
TimeSeries
– A newTimeSeries
.
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 newTimeSeries
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
.
-
quantity
(colname, **kwargs)[source] [edit on github]¶ Return a
Quantity
for the given column.
-
sort_index
(**kwargs)[source] [edit on github]¶ Returns a sorted version of a
TimeSeries
. Generally this shouldn’t be necessary as mostTimeSeries
operations sort the data anyway to ensure consistent behavior when truncating.- Returns
TimeSeries
– A newTimeSeries
in ascending chronological order.
-
to_array
(**kwargs)[source] [edit on github]¶ Return a
numpy.array
of the givenTimeSeries
.- Parameters
kwargs (
dict
) – All keyword arguments are passed topandas.DataFrame.to_numpy
.- Returns
ndarray
– If the data is heterogeneous and contains booleans or objects, the result will be ofdtype=object
.
-
to_dataframe
(**kwargs)[source] [edit on github]¶ Return a
DataFrame
of the givenTimeSeries
.- Returns
DataFrame
– ADataFrame
containing the data.
-
to_table
(**kwargs)[source] [edit on github]¶ Return an
astropy.table.Table
of the givenTimeSeries
.- Returns
Table
– A newastropy.table.Table
containing the data from theTimeSeries
. 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
orint
, 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 newTimeSeries
with only the selected times.