wristpy.io.readers.readers

Function to read accelerometer data from a file.

Functions

read_watch_data(file_name, *[, allow_duplicates])

Read watch data from a file.

unix_epoch_time_to_polars_datetime(time[, units])

Convert unix epoch time to polars Series of datetime.

wristpy.io.readers.readers._extract_dynamic_range(metadata: dict, file_type: Literal['.gt3x', '.bin']) tuple[float, float][source]

Extract the dynamic range from metadata.

Parameters:
  • metadata – Metadata subdictionary where accelerometer range values can be found.

  • file_type – Accelerometer data file type. Supports .gt3x and .bin.

Returns:

A tuple containing the accelerometer range.

Raises:

ValueError – If file type is not supported.

wristpy.io.readers.readers.read_watch_data(file_name: Path | str, *, allow_duplicates: bool = False) WatchData[source]

Read watch data from a file.

Currently supported watch types are Actigraph .gt3x and GeneActiv .bin. Assigns the idle_sleep_mode_flag to false unless the watchtype is .gt3x and sleep_mode is enabled (based on watch metadata).

If requested, removes duplicate timestamps from the data, keeping only unique timestamps and their corresponding sensor values.

Parameters:
  • file_name – The filename to read the watch data from.

  • allow_duplicates – Whether to allow duplicate timestamps in the data. If False, duplicate timestamps will raise a ValueError in the Measurement validation phase. If set to True, we will keep only the unique timestamps and the associated sensor values. The first occurrence of each timestamp is kept. Default is False.

Returns:

WatchData class

Raises:
  • ValueError if the file extension is not supported.

  • IOError if the file cannot be read using actfast.

wristpy.io.readers.readers.unix_epoch_time_to_polars_datetime(time: ndarray, units: Literal['ns', 'us', 'ms', 's', 'd'] = 'ns') Series[source]

Convert unix epoch time to polars Series of datetime.

Parameters:
  • time – The unix epoch timestamps to convert.

  • units – The units to convert the time to (‘s’, ‘ms’, ‘us’, or ‘ns’). Default value is ‘ns’.