Skip to content

Commit

Permalink
fix(AxivityReader): add freq == 0 error check
Browse files Browse the repository at this point in the history
Found 2 out of >100k files (UK Biobank) where this data error occurs.
  • Loading branch information
chanshing committed Dec 7, 2024
1 parent 83d7f7d commit 32fe82f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/actipy/AxivityReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ public void parse(ByteBuffer block) {
if (rateCode == 0) {
// Old format, where pos26 = freq
freq = (float) block.getShort(26);
// Check that sample rate is valid, otherwise skip block
if (freq == 0) { throw new Exception("Found zero sample rate is zero. Skipping data block..."); }
offsetStart = 0;
} else {
// New format
Expand All @@ -247,7 +249,7 @@ public void parse(ByteBuffer block) {
offsetStart = (float) -timestampOffset / freq;
// Checksum
for (int i = 0; i < BLOCKSIZE / 2; i++) { checkSum += block.getShort(i * 2); }
if (checkSum != 0) { throw new Exception("Found checksum error. Skipping data block"); }
if (checkSum != 0) { throw new Exception("Found checksum error. Skipping data block..."); }
}
sampleRate = freq;

Expand Down

0 comments on commit 32fe82f

Please sign in to comment.