OxWearables / biobankAccelerometerAnalysis

Extracting meaningful health information from large accelerometer datasets
https://biobankaccanalysis.readthedocs.io/en/latest/index.html
Other
179 stars 61 forks source link

Clipping Issue due to wrong scaling of Raw Data #247

Closed db-2010 closed 7 months ago

db-2010 commented 7 months ago

First of all: thank you for this nice package!

I am running into weird behavior when processing some external files, recorded by Ax6 over 7 days with 100 Hz and ±8g.

Apparently, it occurs while reading the binary data (.cwa) and is related to some wrong scaling of the data. Virtually all values get clipped and are set to ±8g even though they should lay well below the threshold.

With the provided sample.cwa I do not reproduce this error and everything, including the calibration and activity classification works as expected. I also compared my raw data to the sample file loading them externally. The data is very similar (range, mean, std, ...) and has very few to no clipped values, indicating that the error is not hiding there but rather in the de-binarization.

What I noticed is the different .cwa file headers/data_fromats extracted from the binary files using the external software:

for sample.cwa: {'deviceFractional': 55355, 'sessionId': 1, 'sequenceId': 0, 'light': 646, 'temperature': 29.1015625, 'events': 1, 'battery': 4.1953125, 'rateCode': 74, 'numAxesBPS': 48, 'sampleCount': 120, 'frequency': 100.0, 'timestamp': 1399469391.6893005, 'timestampOffset': 125, 'timestampTime': '2014-05-07 13:29:51.689', 'estimatedFirstSampleTime': 1399469390.4393005, 'channels': 3, 'bytesPerAxis': 0, 'bytesPerSample': 4, 'samplesPerSector': 120, 'accelAxis': 0, 'accelRange': 8, 'accelUnit': 256}
for my_file.cwa: {'deviceFractional': 40055, 'sessionId': 12940, 'sequenceId': 0, 'light': 38, 'temperature': 34.375, 'events': 1, 'battery': 4.04296875, 'rateCode': 74, 'numAxesBPS': 50, 'sampleCount': 80, 'frequency': 100.0, 'timestamp': 1660149007.2223816, 'timestampOffset': 80, 'timestampTime': '2022-08-10 16:30:07.222', 'estimatedFirstSampleTime': 1660149006.4223816, 'channels': 3, 'bytesPerAxis': 2, 'bytesPerSample': 6, 'samplesPerSector': 80, 'accelAxis': 0, 'accelRange': 8, 'accelUnit': 4096}

could the error lie in the different accelUnit = 256 and accelUnit = 4096 values? resulting in way too high scaling during de-binarization of the raw data?

Note: I'm using openjdk=11 instead of the suggested openjdk=8, due to apple silicon architecture.

the .json file of produced by accProcess shows the wrong amplitude scaling and thus falsely classified clipped values:

{
    "file-name": "path/to/my_file.cwa",
    "file-size": 390550016,
    "file-deviceID": 55191,
    "calibration-xOffset(g)": 0.0,
    "calibration-yOffset(g)": 0.0,
    "calibration-zOffset(g)": 0.0,
    "calibration-xSlope": 1.0,
    "calibration-ySlope": 1.0,
    "calibration-zSlope": 1.0,
    "calibration-xSlopeTemp": 0.0,
    "calibration-ySlopeTemp": 0.0,
    "calibration-zSlopeTemp": 0.0,
    "calibration-errsBefore(mg)": 12856.130487908302,   <-----------------------
    "calibration-errsAfter(mg)": 12856.130487908302,    <-----------------------
    "calibration-numStaticPoints": 1,
    "quality-calibratedOnOwnData": 1,
    "quality-goodCalibration": 0,
    "file-startTime": "2022-09-20 15:00:07.011000+0100 [Europe/London]",
    "file-endTime": "2022-09-27 14:59:07.011000+0100 [Europe/London]",
    "file-firstDay(0=mon,6=sun)": 1,
    "totalReads": 61061181,
    "quality-daylightSavingsCrossover": 0,
    "clipsBeforeCalibration": 60842031,   <--------------------------------------
    "clipsAfterCalibration": 0,
....
}
chanshing commented 7 months ago

Hi @db-2010 Thank you for the in-depth analysis! Unfortunately, we don't support AX6 devices just yet! I'm pretty sure you are right in that the error is with the parser. I am surprised it worked at all. It is in our pipeline to have it supported though! In the meantime, if you still want to make use of the package for analysis, one way is to extract the AX6 data to a CSV file with the external tool, and then you should be able to run accProcess on that. I'll ping you when the AX6 is natively supported!