ltbio.biosignals.timeseries.Timeseries#
Overview#
Classes#
An OverlappingTimeseries is a Timeseries that violates the rule that to each time point of its domain it must |
|
A Timeseries is a sequence of data points that occur in successive order over some period of time. |
Contents#
- class ltbio.biosignals.timeseries.Timeseries.OverlappingTimeseries(samples: ndarray | list | tuple, initial_datetime: datetime.datetime, sampling_frequency: float, units: ltbio.biosignals.timeseries.Unit.Unit = None, name: str = None)#
Bases:
digraph inheritance094e9b78a5 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "OverlappingTimeseries" [URL="#ltbio.biosignals.timeseries.Timeseries.OverlappingTimeseries",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="An OverlappingTimeseries is a Timeseries that violates the rule that to each time point of its domain it must"]; "Timeseries" -> "OverlappingTimeseries" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Timeseries" [URL="#ltbio.biosignals.timeseries.Timeseries.Timeseries",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A Timeseries is a sequence of data points that occur in successive order over some period of time."]; }TimeseriesAn OverlappingTimeseries is a Timeseries that violates the rule that to each time point of its domain it must correspond one and only one sample. This special kind of Timeseries allows overlapping Segments, although it looses all its interpretational meaning in the context of being successive data points in time. This kind is useful to extract features from modalities or to train machine learning models.
It inherits all properties of Timeseries and most of its behaviour. In order to have overlapping Segments, indexing an exact timepoint is no longer possible; Although it is legal to index slices. # FIXME
- property domain: Tuple[datetimerange.DateTimeRange]#
The intervals of date and time in which the Timeseries is defined, i.e., samples were acquired.
- property duration: datetime.timedelta#
Returns real time passed from start to end, without overlaps.
- property subdomains: Tuple[datetimerange.DateTimeRange]#
- append(initial_datetime: datetime.datetime, samples: ndarray | list | tuple)#
Appends a new sequence of samples in a separate Segment. :param initial_datetime: The date and time of the first sample in ‘samples’. :param samples: The sequence of samples to add as a separate Segment. :return: None
- class ltbio.biosignals.timeseries.Timeseries.Timeseries(samples: ndarray | list | tuple, initial_datetime: datetime.datetime, sampling_frequency: float, units: ltbio.biosignals.timeseries.Unit.Unit = None, name: str = None)#
A Timeseries is a sequence of data points that occur in successive order over some period of time. In a Biosignal, one Timeseries’ data points are the measurement of a biological variable, in some unit, taken from a sensor or channel. This data points are often called samples, and are acquired at fixed sampling frequency.
To each time point of a Timeseries’ domain corresponds one and only one sample. However, a Timeseries might be contiguous if a sample was acquired at every sampling time point, or discontiguous if there were interruptions. Each interval/sequence of contiguous samples is called a Segment, but those are managed internally.
- Timeseries: default
Instantiates a Timeseries with a contiguous sequence of samples.
- Timeseries.withDiscontiguousSegments
Instantiates a Timeseries with discontiguous sequences of samples.
- name: str
The name of the Timeseries, if any.
- samples: array # FIXME
Contiguous or discontiguous sequence of samples.
- sampling_frequency: float
The frequency at which the samples were acquired, in Hz.
- units: Unit
The physical unit at which the samples should be interpreted.
- events: tuple[Event]
The events timely associated to the Timeseries.
- initial_datetime: datetime
The date and time of the first sample.
- final_datetime: datetime
The date and time of the last sample.
- duration: timedelta
The total time of acquired samples, excluding interruptions.
- domain: tuple[DateTimeRange]
The intervals of date and time in which the Timeseries is defined, i.e., samples were acquired.
- is_equally_segmented: bool
The logic value stating if each interval in the domain has the same duration.
- segment_duration: timedelta:
Duration of all segments, if is_equally_segmented is True.
len: Returns the total number of samples.
copy: Copies all Timeseries’ content.
iter: Returns an iterator over the samples of all Timeseries’ Segments.
in: Returns True if a date, time or event is contained in the Timeseries.
[] : Indexes by date, time or events.
: Adds Timeseries.
+= : Appends more samples to the last Timeseries’ Segment.
- append(datetime, array):
Appends a new sequence of samples in a separate Segment.
- associate(Event):
Timely associates a given Event to the Timeseries.
- dissociate(str):
Removes any association the Timeseries has with an Event with the given name.
- filter(Filter):
Filters the Timeseries with the given design.
- undo_filters():
Reverts the effect of all filters.
- plot():
Plots the Timeseries amplitude over time, with all its interruptions, if any.
- plot():
Plots the Timeseries frequency spectrum.
Full documentation in: https://github.com/jomy-kk/IT-LongTermBiosignals/wiki/%5BClass%5D-Timeseries
- property domain: Tuple[datetimerange.DateTimeRange]#
The intervals of date and time in which the Timeseries is defined, i.e., samples were acquired.
- property duration: datetime.timedelta#
returns actual recorded time without interruptions
- property events: Tuple[ltbio.biosignals.timeseries.Event.Event]#
The events timely associated to the Timeseries, timely ordered.
- property final_datetime: datetime.datetime#
The date and time of the last sample.
- property initial_datetime: datetime.datetime#
The date and time of the first sample.
- property is_contiguous: bool#
The logic value stating if there are no interruptions in time.
- property is_equally_segmented: bool#
The logic value stating if each interval in the domain has the same duration.
- property n_segments: int#
The number of uninterrupted segments.
- property name#
The name of the Timeseries, if any.
- property samples: list | ndarray#
- property sampling_frequency: float#
The frequency at which the samples were acquired, in Hz.
- property segment_duration: datetime.timedelta#
Duration of segments, if equally segmented.
- property segment_length: int#
Number of samples of segments, if equally segmented.
- property segments: list#
- property subdomains: Tuple[datetimerange.DateTimeRange]#
- property tags: tuple[str]#
- property units#
The physical unit at which the samples should be interpreted.
- append(initial_datetime: datetime.datetime, samples: ndarray | list | tuple)#
Appends a new sequence of samples in a separate Segment. :param initial_datetime: The date and time of the first sample in ‘samples’. :param samples: The sequence of samples to add as a separate Segment. :return: None
- associate(events: Event | Collection[Event] | Dict[str, Event])#
Associates an Event with the Timeseries. Events have names that serve as keys. If keys are given, i.e. if ‘events’ is a dict, then the Event names are override. :param events: One or multiple Event objects. :return: None
- delete_events()#
- disassociate(event_name: str)#
Dissociate the event named after the given name. :param event_name: The name of the event to dissociate. :return: None :raise NameError: If there is no associated Event with the given name.
- max()#
Returns the maximum aplitude value of the Timeseries.
- min()#
Returns the minimum aplitude value of the Timeseries.
- overlap(other) Tuple[datetimerange.DateTimeRange]#
- tag(tags: str | tuple[str])#
Mark the Timeseries with a tag. Useful to mark machine learning targets. :param tags: The label or labels to tag the Timeseries. :return: None
- classmethod withDiscontiguousSegments(segments_by_time: Dict[Timeseries.withDiscontiguousSegments.datetime, ndarray | list | tuple], sampling_frequency: float, units: ltbio.biosignals.timeseries.Unit.Unit = None, name: str = None)#
Give a dictionary of discontiguous sequences of samples, keyed by their initial date and time. It also receives the sampling frequency of the samples. Additionally, it can receive the samples’ units and a name, if needed.
- samples: dict [datetime, ndarray | list | tuple]
The sequence of samples to store as separate Segments, in the format { datetime: [, … ], … }.
- initial_datetime: datetime
The date and time of the first sample.
- sampling_frequency: float | Frequency
The frequency at which the samples where sampled.
- units: Unit
The physical units of the variable measured.
- name: str
A symbolic name for the Timeseries. It is mentioned in plots, reports, error messages, etc.