TimeSeriesMetaData

class sunpy.timeseries.TimeSeriesMetaData(meta=None, timerange=None, colnames=None, **kwargs)[source] [edit on github]

Bases: object

An object used to store metadata for TimeSeries objects that enables multiple TimeSeries metadata to be concatenated in an organised fashion.

metadata

list of tuple – The list of 3-tuples which each represent a source files metadata. The tuples consist of: ( TimeRange, [ colnames ], MetaDict(metadata) )

Examples

>>> from sunpy.timeseries import TimeSeriesMetaData
>>> from sunpy.time import TimeRange, parse_time
>>> from sunpy.util import MetaDict
>>> tr = TimeRange('2012-06-01 00:00','2012-06-02 00:00')
>>> md = TimeSeriesMetaData(timerange=tr, colnames=['GOES'], meta=MetaDict([('goes_key','goes_val')]))
>>> tr2 = TimeRange('2012-06-01 12:00','2012-06-02 12:00')
>>> md.append(tr2, ['EVE'], MetaDict([('eve_key','eve_val')]))
>>> md.find(parse_time('2012-06-01T21:08:12'))
>>> md.find(parse_time('2012-06-01T21:08:12')).columns
>>> md.find(parse_time('2012-06-01T21:08:12')).values()
>>> md.find(parse_time('2012-06-01T21:08:12')).metas
>>> md.find(parse_time('2012-06-01T21:08:12'), 'GOES')   

Attributes Summary

columns Returns a list of all the names of the columns in the metadata.
metas Returns a list of all the metadict objects in the TimeSeriesMetaData object.
time_range Returns the TimeRange of the entire time series meta data.
timeranges Returns a list of all the TimeRange objects the TimeSeriesMetaData object.

Methods Summary

append(timerange, columns, metadata, **kwargs) Add the given metadata MetaDict into the metadata list as a tuple with it’s TimeRange and colnames (list).
concatenate(tsmetadata2, **kwargs) Combine the metadata from a TimeSeriesMetaData object with the current TimeSeriesMetaData and return as a new TimeSeriesMetaData object.
find([time, colname]) Find all metadata matching the given filters for datetime and/or column name.
find_indices([time, colname]) Find the indices for all the metadata entries matching the given filters for datetime and/or column name.
get(keys[, time, colname]) Return a TimeSeriesMetaData object of all entries matching the time and colname filters with the dictionaries containing only the key value pairs with the key matching the given input key.
get_index(index) Return the dictionary entry at the given index.
to_string([depth, width]) Print a table-like representation of the TimeSeriesMetaData object.
update(dictionary[, time, colname, row, …]) Make updates to the MetaDict metadata for all matching metadata entries.
values() Returns a list of all the values from the metadict objects in each entry in the TimeSeriesMetaData object.

Attributes Documentation

columns

Returns a list of all the names of the columns in the metadata.

metas

Returns a list of all the metadict objects in the TimeSeriesMetaData object.

time_range

Returns the TimeRange of the entire time series meta data.

timeranges

Returns a list of all the TimeRange objects the TimeSeriesMetaData object.

Methods Documentation

append(timerange, columns, metadata, **kwargs)[source] [edit on github]

Add the given metadata MetaDict into the metadata list as a tuple with it’s TimeRange and colnames (list). Will add the new entry so the list is in chronological order for the TimeRange.start datetime values.

Parameters:
  • timerange (TimeRange) – The timerange for which a given metadict is relevant. This will generally initilly be the full range of the original file, but if the TimeSeries gets truncated this may change appropriately.
  • columns (str) – A list of the colomn name strings that the metadata is relevant for.
  • metadata (MetaDict or OrderedDict or dict) – The dictionary holding the metadata.
concatenate(tsmetadata2, **kwargs)[source] [edit on github]

Combine the metadata from a TimeSeriesMetaData object with the current TimeSeriesMetaData and return as a new TimeSeriesMetaData object.

Parameters:tsmetadata2 (TimeSeriesMetaData) – The second TimeSeriesMetaData object.
find(time=None, colname=None, **kwargs)[source] [edit on github]

Find all metadata matching the given filters for datetime and/or column name. Will return all metadata entries if no filters are given.

Parameters:
  • time (str or datetime optional) – The string (parsed using the parse_time) or datetime that you need metadata for.
  • colname (str optional) – A string that can be used to narrow results to specific columns.
Returns:

metadata (TimeSeriesMetaData) – A TimeSeriesMetaData that contain all matching metadata entries.

find_indices(time=None, colname=None, **kwargs)[source] [edit on github]

Find the indices for all the metadata entries matching the given filters for datetime and/or column name. Will return all metadata entry indices if no filters are given.

Parameters:
  • time (str or datetime optional) – The string (parsed using the parse_time) or datetime that you need metadata for.
  • colname (str optional) – A string that can be used to narrow results to specific columns.
  • indices (bool optional) – If True then return a list of indices, not of MetaDict items. Used when other methods use the filters for selecting metadata entries.
Returns:

list (list) – A list of integers that contain all matching metadata.

get(keys, time=None, colname=None, **kwargs)[source] [edit on github]

Return a TimeSeriesMetaData object of all entries matching the time and colname filters with the dictionaries containing only the key value pairs with the key matching the given input key.

Parameters:
  • keys (str) – The Key/s to be searched in the dictionary.
  • time (str or datetime optional) – The string (parsed using the parse_time) or datetime that you need metadata for.
  • colname (str optional) – A string that can be used to narrow results to specific columns.
  • itemised (bool optional) – Option to allow the return of the time ranges and column names (as list) that match each given value.
Returns:

metadata (TimeSeriesMetaData) – A TimeSeriesMetaData that contain all matching metadata entries but with only the requested key/value pairs in the MetaDict objects.

get_index(index)[source] [edit on github]

Return the dictionary entry at the given index.

Parameters:index (int) – The integer index of the metadata entry in the list.
Returns:metadata (MetaDict) – An ordered Dictionary containing the metadata at the given index.
to_string(depth=10, width=99)[source] [edit on github]

Print a table-like representation of the TimeSeriesMetaData object.

Parameters:
  • depth (int) – The maximum number of lines to show for each entry. Metadata dictionaries and column lists will be truncated if this is small.
  • width (int) – The number of characters wide to make the entire table.
update(dictionary, time=None, colname=None, row=None, overwrite=False, **kwargs)[source] [edit on github]

Make updates to the MetaDict metadata for all matching metadata entries.

Parameters:
  • dictionary (dict or OrderedDict or MetaDict) – The second TimeSeriesMetaData object.
  • time (str or datetime optional) – The string (parsed using the parse_time) or datetime to filter the metadata entries updated.
  • colname (str optional) – A string that can be used to narrow results to specific columns.
  • overwrite (bool optional) – Option to define if the user is able to overwrite already present keys. Defaults to False, designed to stop users from being able to corrupt/damage the metadict values so easily.
values()[source] [edit on github]

Returns a list of all the values from the metadict objects in each entry in the TimeSeriesMetaData object.