Parsers
labda.parsers.Actigraph
dataclass
Parses ActiGraph accelerometer data from binary and CSV formats.
This parser supports two distinct ActiGraph file types:
- .gt3x (Binary): High-frequency raw acceleration data.
- .csv (Export): Aggregated "epoch" data (counts), often containing derived metrics like steps or lux.
The parser automatically handles the manufacturer's proprietary header formats, timestamp decoding, and timezone conversion to UTC.
from_gt3x
from_gt3x(
path: Path | str,
idle: Literal["ffill", "zero"] = "ffill",
timezone: str | None = None,
) -> pd.DataFrame
Parses a raw binary .gt3x file.
Extracts x, y, z acceleration data. If the file contains timezone information, the datetime index is converted to UTC.
The file's TimeZone field is not always the recording offset
ActiGraph devices store timestamps on the clock set at initialisation and
never adjust it mid-recording. Some devices populate TimeZone with the
locale's standard (winter) offset rather than the offset in force when
the device was started. A device initialised during daylight saving time
then yields an index shifted by one hour, silently, for the whole file.
Pass timezone with the IANA zone of the deployment to resolve the offset
from the recording's start date instead of trusting the field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Path to the .gt3x file. |
required |
idle
|
Literal['ffill', 'zero']
|
Strategy for handling samples flagged as "Idle Sleep Mode" by the device. |
'ffill'
|
`'ffill'`
|
default
|
Preserves the raw values recorded by the device (often the last known value repeated). |
required |
`'zero'`
|
Overwrites acceleration values with |
required | |
timezone
|
str | None
|
IANA zone of the deployment, e.g. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Standardized raw accelerometer data. |
from_csv
from_csv(
path: str | Path,
datetime_format: str = "ISO8601",
header_rows: int = 10,
) -> pd.DataFrame
Parses an ActiGraph CSV export (Epoch/Count data).
ActiGraph CSVs typically contain aggregated "counts" rather than raw acceleration. This method parses the metadata header to reconstruct the correct datetime index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the .csv file. |
required |
datetime_format
|
str
|
Format string for parsing the header date/time. Defaults to "ISO8601". |
'ISO8601'
|
header_rows
|
int
|
Number of header lines to skip before data begins. Defaults to 10 (standard ActiGraph export). |
10
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing epoch-level data. |
labda.parsers.Axivity
dataclass
Parses Axivity .cwa files into a standardized DataFrame format.
This parser handles the binary reading of Axivity files (.cwa), extracting
tri-axial acceleration and temperature data. It ensures the resulting data
is properly indexed with datetimes and validated against corruption.
Attributes:
| Name | Type | Description |
|---|---|---|
timezone |
ZoneInfo | str | None
|
The timezone to which the resulting datetime
index will be localized. If |
from_cwa
from_cwa(path: Path | str) -> pd.DataFrame
Parses a .cwa file and returns a standardized accelerometer DataFrame.
This method wraps the skdh reader logic, adding specific validation
checks for data corruption (negative timestamps) and normalizing column
names to the package standard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The file system path to the .cwa file. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Standardized accelerometer data. |
labda.parsers.Sens
dataclass
Parses proprietary 'Sens' binary accelerometer files.
This parser handles custom binary files containing 48-bit timestamps (milliseconds) and 16-bit Big-Endian accelerometer readings. It supports loading data from both physical files on disk and in-memory byte buffers.
Attributes:
| Name | Type | Description |
|---|---|---|
normalize |
bool
|
Controls data normalization.
If |
from_bin
from_bin(path: str | Path) -> pd.DataFrame
Parses a Sens binary file from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
The system path to the binary file. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Standardized accelerometer data.
Note: If |
from_buffer
from_buffer(buffer: bytes | bytearray) -> pd.DataFrame
Parses Sens binary data directly from an in-memory buffer.
Useful for processing data received over network streams or extracted from larger container files without writing to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buffer
|
bytes | bytearray
|
The raw binary data. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Standardized accelerometer data. See [FileParser][labda.parsers.sens.file.Sens.from_buffer.parser.FileParser] for column specification. |