skdh.io.ReadBin#

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

Read a binary .bin file from a GeneActiv sensor into memory. Acceleration values are returned in units of g. If providing a base and period value, included in the output will be the indices to create windows starting at the base time, with a length of period.

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).

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

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

Methods

convert_timestamps(t)

Convert a timestamp/array of timestamps to a datetime object

predict(*, file)

Read the data from the GeneActiv 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 = ReadBin()
>>> reader.predict('example.bin')
{'accel': ..., 'time': ...}
predict(*, file)#

Read the data from the GeneActiv 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

Notes

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

  • accel: acceleration [g]

  • time: timestamps [s]

  • light: light values [unknown]

  • temperature: temperature [deg C]