Sens
labda.parsers.Sens
from_csv
from_csv(
path: str | Path,
*,
subject_id: str | None = None,
start: datetime | None = None,
end: datetime | None = None,
sampling_frequency: float | None = None,
timezone: str | None = None,
sensor_id: str | None = None,
vendor: Vendor = Vendor.SENS,
model: str | None = None,
serial_number: str | None = None,
firmware_version: str | None = None
) -> Subject
This function is designed to process data activity CSV files generated by Sens sensors. Optionally, you can define a date and time range to download data for a specific timeframe. If no date range is provided (from/to), all data for the chosen device will be parsed.
It infers certain information using Sens' classification algorithms; more details are available here.
Wear is determined by checking the "nodata" column. A value of 0 indicates that the sensor was worn, while a value of 1 indicates that it wasn't.
Position is determined by looking for values (not NA) in multiple data columns. Here's the logic it follows:
sitting-lying
if values are in columns lying_sitting_rest or lying_sitting_movement,sitting
if cycling,standing
if upright_stand, upright_sporadic_walk, upright_walk, upright_moderate or upright_run.
Number of steps is calculated by summing the values in columns steps, steps2 and steps3.
Activity intensity is calculated based on the vendor's activity value (metric). The values are binned into the following categories: sedentary, light, moderate, vigorous, very_vigorous based on the following thresholds: 0, 2, 50, 75, 100.
Activity is determined by looking for values (not NA) in multiple data columns. Here's the logic it follows:
bicycling
if values are in column cycling,resting
if lying_sitting_rest,sporadic_walking
if upright_sporadic_walk,walking
if upright_walk,jogging
if upright_moderate,running
if upright_run.
The data will be parsed and validated according to the schema defined in the structure module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str | Path
|
The path to the CSV file. |
required |
subject_id |
str
|
The ID of the subject. If not provided, it will be set to the file name. |
None
|
start |
datetime
|
The start time of the data to fetch. If not provided, it will fetch all available data. |
None
|
end |
datetime
|
The end time of the data to fetch. If not provided, it will fetch all available data. |
None
|
sampling_frequency |
float
|
The sampling frequency of the data. If not provided, it will be infered from data. |
None
|
timezone |
str
|
The timezone of the data. If None it will be set to the local timezone. Otherwise, it will be set to the provided timezone. |
None
|
sensor_id |
str
|
The ID of the sensor. If not provided, it will be set to the file name. |
None
|
vendor |
Vendor
|
The vendor of the sensor. Defaults to "Sens". |
SENS
|
model |
str
|
The model of the sensor. |
None
|
serial_number |
str
|
The serial number of the sensor. |
None
|
firmware_version |
str
|
The firmware version of the sensor. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Subject |
Subject
|
A Subject object containing the fetched and processed dataframe containing information: datetime, wear, position, steps, activity_intensity, activity_value and activity. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
File not found. |
ValueError
|
File format not CSV. |
Examples:
Here's how to call the function with just the minimum required parameters.