vitabel.utils.helpers¶
Collection of various auxiliary and helper functions.
Classes¶
Special json encoder for numpy types |
Functions¶
|
Calculates the central point first derivative of x=time,y=data, |
|
Integrates data after time with trapezoidal rule |
|
|
|
Calculate a centered average mean of data over k elements. |
|
|
|
Calculates the area and duration where the signal falls |
|
|
|
|
|
|
Aligns two or more Channel objects by their time indices, ensuring |
|
|
|
|
|
|
Module Contents¶
- class vitabel.utils.helpers.NumpyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)¶
Bases:
json.JSONEncoderSpecial json encoder for numpy types
- default(obj)¶
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return super().default(o)
- vitabel.utils.helpers.deriv(time, data)¶
Calculates the central point first derivative of x=time,y=data, and take forward/backward step derivative at the boundaries
- Parameters:
- timenp.array()
equidistantly spaced x values.
- datanp.array()
corresponding y values.
- Returns:
- ddatnp.array()
array with the derivative values.
- vitabel.utils.helpers.integrate(time, data)¶
Integrates data after time with trapezoidal rule
- Parameters:
- timepd.Series
Timestamps in seconds.
- datapd.Series
Datapoints.
- Returns:
- velpd.Series
Integrated data. vel[0]=0
- vitabel.utils.helpers.construct_snippets(acctime, acc, ecgtime, ecg, CC_starts, CC_stops)¶
- vitabel.utils.helpers.av_mean(k: int, data: numpy.typing.ArrayLike) numpy.typing.NDArray¶
Calculate a centered average mean of data over k elements.
The data is zero-padded at the boundaries.
- vitabel.utils.helpers.predict_circulation(erg)¶
- vitabel.utils.helpers.area_under_threshold(timeseries: pandas.Series, start_time: vitabel.typing.Timestamp | vitabel.typing.Timedelta | None = None, stop_time: vitabel.typing.Timestamp | vitabel.typing.Timedelta | None = None, threshold: int = 0, time_unit: vitabel.typing.TimeUnitChoices = 'minutes') vitabel.typing.ThresholdMetrics¶
Calculates the area and duration where the signal falls below a threshold.
This function operates on a given timeseries, subtracts a threshold, detects zero-crossings (sign changes), interpolates crossing points, and integrates the area under the threshold using the trapezoidal rule.
- Parameters:
- timeseries
A
pandas.Seriesholding numerical data indexed by a timeseries.- start_time
Start time for truncating the timeseries (passed to meth:.Vitals.truncate).
- stop_time
End time for truncating the timeseries (passed to meth:.Vitals.truncate).
- threshold
The threshold of the signal under which the area is calcuated.
- time_unit
The time unit according to which the result is scaled. Defaults to
"minutes", accepts the same arguments aspandas.to_timedelta.
- Returns:
- vitabel.utils.helpers.rename_channels(dats, new_name_dict)¶
- vitabel.utils.helpers.determine_gaps_in_recording(time: numpy.typing.ArrayLike, data: numpy.typing.ArrayLike)¶
- vitabel.utils.helpers.linear_interpolate_gaps_in_recording(time: numpy.typing.ArrayLike, data: numpy.typing.ArrayLike)¶
- vitabel.utils.helpers.resample_to_common_index(*channels: vitabel.timeseries.Channel) tuple[vitabel.typing.DataSlice, Ellipsis]¶
Aligns two or more Channel objects by their time indices, ensuring all are sampled at the same time points, including zero-crossings. Data are interpolated to a common time base within their overlapping range.
- Parameters:
- *channels
Two or more
Channelobjects to be aligned and interpolated.
- Returns:
- tuple[DataSlice, …]
A tuple of
DataSliceobjects representing the aligned channels.
- Raises:
- ValueError
If there is no overlapping time range between the two channels.
Notes
Zero-crossings are inserted to improve alignment, especially for strongly oscillating signals.
- vitabel.utils.helpers.convert_two_alternating_list(df)¶
- vitabel.utils.helpers.find_ROSC_2(rosctime, roscdata, CC_starts, CC_stops)¶
- vitabel.utils.helpers.CCF_minute(t_start, t_stop, CC_starts, CC_stops)¶
- vitabel.utils.helpers.gaussian_kernel_regression_point(x0, x, y, sigma=1, max_width_factor=2)¶