nilspodlib.datastream.Datastream#
- class nilspodlib.datastream.Datastream(data: ndarray, sampling_rate: float = 1.0, columns: Optional[Iterable] = None, calibrated_unit: Optional[str] = None, sensor_type: Optional[str] = None)[source]#
Object representing a single set of data of one sensor_type.
Usually it is not required to directly interact with the datastream object (besides accessing the data attribute). Most important functionality can/should be used via a dataset or session object to manage multiple datasets at once.
- Attributes:
- data
The actual data of the sensor_type as
np.array
. Can have multiple dimensions depending on the sensor_type.- sensor_type
The name of the sensor_type
- is_calibrated
If the sensor_type is in a raw format or the expected final output units
- is_factory_calibrated
If the datastream was factory calibrated and hence, provided in physical meaningful units. This should be True if the datastream was loaded using the methods to load datasets and sessions provided in this library.
- sampling_rate_hz
The sampling rate of the datastream
Methods
cut
([start, stop, step, inplace])Cut the datastream.
data_as_df
([index_as_time, include_units])Export the datastream as pandas DataFrame using
self.columns
as colummns.downsample
(factor[, inplace])Downsample the datastreams by a factor.
norm
()Calculate the norm of the data along the last axis.
Get the normalized data.
- __init__(data: ndarray, sampling_rate: float = 1.0, columns: Optional[Iterable] = None, calibrated_unit: Optional[str] = None, sensor_type: Optional[str] = None)[source]#
Get new datastream instance.
- Parameters:
- data
The actual data to be stored in the datastream. Should be 2D (even if only 1D data is stored). First dimension should be the time axis and second dimension the different data vector entries (e.g. acc_x, acc_y, acc_z).
- sampling_rate
The sampling rate of the datastream. Is used for all calculations that require sampling info.
- columns
Optional list of names for the data vector entries. Only used to make it easier to understand the content of a datastream.
- calibrated_unit
The expected unit of the datastream after calibration.
- sensor_type
Type of sensor_type the data is produced from. This allows to automatically get default values for columns and units from
nilspodlib.consts
.
- cut(start: Optional[int] = None, stop: Optional[int] = None, step: Optional[int] = None, inplace: bool = False) Self [source]#
Cut the datastream.
This is equivalent to applying the following slicing to the data of the datastream:
array[start:stop:step]
- Parameters:
- start
Start index
- stop
Stop index
- step
Step size of the cut
- inplace
If True this methods modifies the current datastream object. If False, a copy of the datastream is returned.
- data_as_df(index_as_time: bool = True, include_units=False) DataFrame [source]#
Export the datastream as pandas DataFrame using
self.columns
as colummns.- Parameters:
- index_as_time
If True the index will be divided by the sampling rate to represent time since start of the measurement
- include_units
If True the column names will have the unit of the datastream concatenated with an
- Returns:
- DataFrame
- downsample(factor: int, inplace: bool = False) Self [source]#
Downsample the datastreams by a factor.
- Parameters:
- factor
Factor by which the datastream should be downsampled.
- inplace
If True this methods modifies the current datastream object. If False, a copy of the datastream is returned.