L5 and M10 Sampling frequency
ChronoKatie opened this issue · comments
Hi!
I just wondered if it was possible to alter the data acquisition period when calculating L5 and M10? Due to some actigraph initialisation issues, the sampling frequencies are inconsistent across the files. I.e for some files the epoch lengths are shorter than the others. This seems possible for some of the other non-parametric analyses through setting the sampling frequency. This might be best to achieve by setting a specific sampling frequency when reading files in by batch? Please advise.
Thanks,
Katie
Hello @ChronoKatie
Indeed, that is a common and annoying issue when dealing with large datasets acquired over several months/years.
Since resampling is usually not a costly operation (depending on the sampling frequency and length of the recording, of course), I would advice to resample the data on-the-fly when calculating the variables of interest. There is anyway no way to permanently resample the data to a specific frequency in pyActigraphy as I wanted to keep the calculations of all the metrics dynamic.
However, you can still read all the files by batch and do a loop, as illustrated in this part of the 'batch' tutorial.
When answering to the issue #84 , in addition to the L5/M10 start times, I also provided a way to calculate the L5/M10 with resampled data.
Putting all this together, I can imagine the following solution:
import pyActigraphy
import os
# Define path to test files (to be changed, of course)
fpath = os.path.join(os.path.dirname(pyActigraphy.__file__),'tests/data/')
# Read test files:
raw = pyActigraphy.io.read_raw(fpath+'example_0*.AWD', reader_type='AWD')
# Define dictionary for storing L5/M10 values with filenames as keys:
l5_ts = {}
l5 = {}
m10_ts = {}
m10 = {}
# Now loop over all the test files that have been read:
for iread in raw.readers:
# Resample data to a 5-min period
rs_data = iread.resampled_data('5min')
# Compute L5/M10
l5_ts[iread.name], l5[iread.name] = _lmx(rs_data, '5h', lowest=True)
m10_ts[iread.name], m10[iread.name] = _lmx(rs_data, '10h', lowest=False)
By resampling all your data to a higher period (or equal to) than the highest acquisition period (for example, 5 min if you have actigraphy recording with 30s and 1min sampling period), you ensure that the L5/M10 calculations across recordings have been harmonised. Here I just took 5 min as an example. To be adapted to fit your analysis purposes.
Hope that helps.
Happy actigraphy.
Greg
Amazing! Thank you for your swift response and making my PhD a whole lot easier with this package 😄