skdh.io.ReadCwa#

class skdh.io.ReadCwa(*, trim_keys=None, trim_start_factor=None, ext_error='warn')#

Read a binary CWA file from an axivity sensor into memory. Acceleration is return in units of ‘g’ while angular velocity (if available) is returned in units of deg/s.

Parameters:
trim_keys{None, tuple}, optional

Trim keys provided in the predict method. Default (None) will not do any trimming. Trimming of either start or end can be accomplished by providing None in the place of the key you do not want to trim. If provided, the tuple should be of the form (start_key, end_key). When provided, trim datetimes will be assumed to be in the same timezone as the data (ie naive if naive, or in the timezone provided).

trim_start_factorint, optional

Factor of seconds to trim start time to. For example, if trim_start_factor=15, then the start time will be trimmed to the next multiple of 15 seconds. Default is None (no trimming).

ext_error{“warn”, “raise”, “skip”}, optional

What to do if the file extension does not match the expected extension (.cwa). Default is “warn”. “raise” raises a ValueError. “skip” skips the file reading altogether and attempts to continue with the pipeline.

.. deprecated:: 0.14.0

bases Removed in favor of having windowing be its own class, skdh.preprocessing.GetDayWindowIndices. periods Removed in favor of having windowing be its own class.

Methods

convert_timestamps(t)

Convert a timestamp/array of timestamps to a datetime object

predict(*, file)

Read the data from the axivity file

save_results(results, file_name)

Save the results of the processing pipeline to a csv file

trim_data(trim_start_factor, start_key, ...)

Trim data based on either a start factor or start/end keys

trim_data_factor(trim_start_factor, *, time, ...)

Trim raw data based on a factor of seconds.

trim_data_time(start_key, end_key, tz_name, ...)

Trim raw data based on provided date-times

Examples

Setup a reader:

>>> reader = ReadCwa()
>>> reader.predict('example.cwa')
{'accel': ..., 'time': ..., ...}
predict(*, file)#

Read the data from the axivity file

Parameters:
file{str, Path}

Path to the file to read. Must either be a string, or be able to be converted by str(file).

tz_name{None, str}, optional

IANA time-zone name for the recording location. If not provided, timestamps will represent local time naively. This means they will not account for any time changes due to Daylight Saving Time.

Returns:
datadict

Dictionary of the data contained in the file.

Raises:
ValueError

If the file name is not provided

UnexpectedAxesError

If the number of axes returned is not 3, 6 or 9

Notes

The keys in data depend on which data the file contained. Potential keys are:

  • accel: acceleration [g]

  • gyro: angular velocity [deg/s]

  • magnet: magnetic field readings [uT]

  • time: timestamps [s]

  • day_ends: window indices