-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get the L5 and M10 start times? #84
Comments
Hi @ghammad, I also wanted to ask this question. The code can already calculate the average activity in the L5/M10 periods, would it be possible to identify the time corresponding to the first activity data point included in the L5/M10? Although I appreciate this may be easier said than done. Thanks, Rory |
Sorry for the late reply. Feedback and requests are always appreciated. Indeed, the code is there and actually the L5/M10 times are calculated. I just did not think about exposing these variables via a convenient function. I'll make one asap but for the time being, here is a simple workaround: import pyActigraphy
from pyActigraphy.metrics.metrics import _lmx
import os
fpath = os.path.join(os.path.dirname(pyActigraphy.__file__),'tests/data/')
raw = pyActigraphy.io.read_raw_awd(fpath+'example_01.AWD')
# The _lmx function returns the start time of the LX or MX period (depending on the value of the "lowest" switch variable)
# as well as the mean activity during this period.
l5_ts, l5 = _lmx(raw.resampled_data('15min'), '5h', lowest=True)
m10_ts, m10 = _lmx(raw.resampled_data('15min'), '10h', lowest=False) Be aware that 'l5_ts' or 'm10_ts' are of type 'pd.Timedelta'. It is easy to use them for further computation (such as average or differences). However, if you want to manipulate them as strings, you can the following function: from pyActigraphy.sleep.scoring_base import _td_format
l5_ts_as_str = _td_format(l5_ts)
print(l5_ts_as_str) Hope that helps. Cheers, Greg |
Hi @ghammad, Thank you so much for this response, it's been a great help for my PhD. I understand that the _lmx function retrieves the start times of the LX and MX period, however I was wondering whether there was a function that could return the start times for L5p and M10p? Best wishes, |
Hello @roryos1 Unfortunately, no. But that would be a nice addition. For the time being, I suggest to use a plain python trick. Group your data by the required amount of time (ex: '3 days') and then apply the _lmx function to each chunk. This can easily done: raw.data.groupby(pd.Grouper(freq='3D')).apply(_lmx, period='5h', lowest=True) To be tested of course. But that should do the trick. Hope that helps. Grégory |
Hi @ghammad, Thank you very much for taking the time to respond. I've tried to use the trick you provided, adjusted for daily M10 onset values:
Like you said, this is subject to testing. I keep being presented with the following error:
The code works fine when grouping the data by 2 days or 3 days, just not for 1 day. I have done nothing with the data besides import it. There may be a very simple answer to this that I am overlooking... If you have any insights into what is going on, it would be massively appreciated. Best wishes, |
Hello @roryos1 Without having access to the data or a way to reproduce the pb, difficult for me to make a precise diagnosis but I suspect the following:
So, my advice is to use more than a day and reflect on the variability of a L5/M10 variable calculated on a short time range. Side remark: having a clear error message when there is less than 24h of data would be nice. Hope that helps. Greg |
Hi! I can see in the paper that you got the L5 and M10 start times, but I only see in the tutorials how to get the mean activity but not their start time.
Is it possible to get this?
Thanks!
Ale
The text was updated successfully, but these errors were encountered: