ghammad / pyactigraphy Goto Github PK
View Code? Open in Web Editor NEWPython-based open source package for actigraphy data analysis
Home Page: https://ghammad.github.io/pyActigraphy
License: GNU General Public License v3.0
Python-based open source package for actigraphy data analysis
Home Page: https://ghammad.github.io/pyActigraphy
License: GNU General Public License v3.0
Dear Grégory,
I am a new Ph.D. student working on a project involving MotionWatch as the Actigraphy for measuring sleep diaries and physical activities. I followed your codes and successfully perform many of the feature examples listed in the Tutorials. However, when I tried to analyze the sleep diaries. I faced some difficulties. Specifically, when I typed the following codes,
fpath = os.path.join(os.path.dirname(pyActigraphy._file), 'C:\\pyActigraphy\\Re_Working_on_WITHIN_Project') raw = pyActigraphy.io.read_raw_mtn(fpath + '\\ID_488.mtn') sleep_diary = raw.read_sleep_diary(fpath + '\\actiwatch data_488.csv')
The following error messages occurred in my Python IDE (Pycharm),
Traceback (most recent call last): File "C:\pyActigraphy\SleepDiary\main.py", line 8, in <module> sleep_diary = raw.read_sleep_diary(fpath + '\\actiwatch data_488.csv') File "C:\pyActigraphy\SleepDiary\venv\lib\site-packages\pyActigraphy\io\base.py", line 312, in read_sleep_diary self.__sleep_diary = SleepDiary( File "C:\pyActigraphy\SleepDiary\venv\lib\site-packages\pyActigraphy\sleep\diary.py", line 31, in _init_ columns=sd_array[header_size]).astype({ File "C:\pyActigraphy\SleepDiary\venv\lib\site-packages\pandas\core\generic.py", line 6212, in astype raise KeyError( KeyError: "Only a column name can be used for the key in a dtype mappings argument. 'TYPE' not found in columns."
Also, while I could successfully plot the individual's distribution of number of step counts throughout the assessment period and Daily activity profile, I cannot compute the individual's total count every day (e.g., 8 assessment days with 8 output in an arrayList). May I know if there is any suggested codes as the solution to my issues raised? Thanks a lot and I look forward to your reply.
New function "estimate_start_time()" would return an estimate of the start time. Would be useful when the recording starts before the participant actually wears the device.
Companion function from the RawReader class: create_sst_log(). Would create a SST log file filled with the start time estimates for all the raw files.
Issue with the sleep bout detection (SleepBoutMixin.sleep_bouts in sleep.py) performed by the Roenneberg algo when the recording starts with a long stretch of inactivity; the first transition between inactivity and activity is an "activity onset" and thus the onsets&offsets time returned by Roenneberg_AoT are uneven and misaligned. Bout durations are negative.
Change mask length from number of epochs to time delta.
This modification will make sure that the length of the default masking period (120 epochs) does not depend on the underlying sampling frequency.
Default will be "2H".
Greetings, hope you're doing well.
I've been running a few tests with your implementation of the Crespo algorithm confronting it with my own implementation and I've come across a few divergences, some are bugs and cause inaccuracies. On a previous issue, I told you about a bug in the inactivity mask, the ones I'm going to discuss now are newly discovered.
I hope this will help to improve the library.
Keep up the good work.
Julius
New feature: develop a reader for the OpenMovement AX device.
Documentation about the data format:
https://github.com/digitalinteraction/openmovement
Steps:
BaseRaw
)Hello Gregory,
I'm trying to open a .mtn file using the code:
import pyActigraphy
import matplotlib.pyplot as plt
act = pyActigraphy.read_mtn('C://Users//Jeffrey Pagaduan//Downloads//FTRAW.mtn')
fig, ax = plt.subplots()
ax.plot(act['Time'], act['Activity'])
ax.set(xlabel='Time', ylabel='Activity', title='Actigraphy Data')
plt.show()
sleep_params = pyActigraphy.get_sleep_params(act, interval=30, window=5)
print(sleep_params)
But I get this error:
Traceback (most recent call last):
File "C:\Users\Jeffrey Pagaduan\Downloads\mtn.py", line 5, in
act = pyActigraphy.read_mtn('C://Users//Jeffrey Pagaduan//Downloads//FTRAW.mtn')
AttributeError: module 'pyActigraphy' has no attribute 'read_mtn'
Thanks for the help.
Dear Grégory,
as discussed yesterday, here is the reminder to double check the Roenneberg (MASDA) default settings in the paper with your implemented code and whether the MASDA is always binned into 10 min.
Additionally, it would be good to i) match the description of the settings in Chrono sapiens / the Roenneberg paper with your setting names (3 bins above/below threshold and so on) so the reader is sure to match the two settings accordingly, and ii) write a note about the bin size and that you specify minutes instead.
Thanks! Anna
Bonjour Gregory!
I just stumbled upon your package and it looks absolutely fantastic -- congrats on all the great work! The only thing preventing me from using it right now is that my actigraphy data is not in any of the supported format and is instead typically processed into a pandas.DataFrame with a DatetimeIndex, e.g:
Datetime | Activity | Light | Non-wear |
---|---|---|---|
01-01-2020 22:00:00 | 0 | 100 | 0 |
01-01-2020 22:00:30 | 10 | 120 | 0 |
01-01-2020 22:01:00 | 400 | 122 | 0 |
01-01-2020 22:01:30 | 0 | 130 | 0 |
I wonder if it would be possible and desirable to add a function to create a pyActigraphy.io.BaseRaw object directly from a raw dataframe like the one above? The frequency and start time attributes could be directly extracted from the DatetimeIndex. Other required attributes would have to be manually specified by the user as input parameters of the function.
Let me know what you think,
Thanks!
Raphael
import pyActigraphy
ImportError: Numba needs NumPy 1.20 or less
OS: Windows 10
Please consider including
import plotly.graph_objects as go
in your introduction tutorial https://ghammad.github.io/pyActigraphy/pyActigraphy-Intro.html.
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
Dear @ghammad,
Thank you for making this package, it is really helpful.
I was wondering whether a specific stop time can be selected for individual files? In the tutorials it looks like stop times are selected with the 'period' keyword, although this does not allow you to select a specific stop time. I see this can be done with the start/stop time logs but I only have a small number of files so do not think this is necessary.
Another unrelated question about future features of the package. I think calculating M10/L5 variables with dynamic time parameters (e.g. M1, M30_mins_, L1) would be a helpful addition. These parameters are useful for measuring different patterns of physical activity across 24 hours, whereas the traditional M10/L5 are quite broad. Here's a paper discussing the benefits of this approach - https://sportsmedicine-open.springeropen.com/articles/10.1186/s40798-019-0225-9.
Let me know what you think.
Thanks,
Rory
Hi! I am trying to read Actical files (AWC) but the script does not support them
I would really appreciate your help!
Dear Grégory
I feel a little bit silly for this small remark, but I was just working through the introduction here:
https://ghammad.github.io/pyActigraphy/pyActigraphy-Intro.html
and was not familiar with plotly. So the
title="Actigraphy data",
xaxis=dict(title="Date time"),
yaxis=dict(title="Counts/period"),
showlegend=False)
didn't work at first for me.
Would it be possible, to add
import plotly.graph_objects as go
to the imports?
Best regards!
Hi Gregory,
I'd suggest you change the readme instruction for installing the developer version to simply read:
pip install https://github.com/ghammad/pyActigraphy/archive/develop.zip
This worked better for me!
Hi!
Hope you can help - I have my actigraphy files which are in .txt format, but they read in just fine individually using read_raw_atr. However, when I try and use the batch function I'm getting the error :
63 # Check requested sampling mode is available:
---> 64 if mode not in header['MODE'][0].split('/'):
65 raise ValueError(
66 "The requested mode ({}) is not available".format(mode) +
KeyError: 'MODE'
Looking in my files the mode is: PIM/TAT/ZCM. Is it kicking back because of this? Would really appreciate guidance.
Thanks,
Katie
Hi @ghammad,
Just a couple of questions about the M10 and file cleaning.
I am aware that the binarized M10 data shows the average proportion of time spent active per hour (during the M10 hours), however I was wondering what the non-binarized M10 data might indicate? Is there somewhere I can access the formula you used to calculate the variable?
On another note, I have been playing around with the following code used to set start times and periods of data collection:
raw_cropped = pyActigraphy.io.read_raw_awd(
fpath+'example_01.AWD',
start_time='1918-01-24 08:00:00',
period='9 days')
I have found that when data collection runs from one month into the next (as in the example above, 24th Jan + 9 day period = 1st Feb), I receive a keyerror highlighting last day of data collection (KeyError: Timestamp('1918-02-01 12:00:00'), for example above). This has happened across a couple of data files. Thought this might be worth bringing to your attention, unless I'm somehow using this incorrectly.
Greetings!
I've been running a few tests with your Crespo algorithm implementation and I've come across a bug.
Notice that there are invalid transitions (duration is less than zeta) both at the beginning and the end of the rest period. These are a result of your program not being able to recognize that there is a time gap between those transitions, it actually processes it as if it was one single wake period. Another point you should review is that, according to the article by Crespo at al, sequences of zeros with length greater than zeta are considered invalid. In the code sequences with length equal to zeta are also considered invalid. I can provide you with the data I've been probing so you can confirm my findings. Hope this will help, you've been doing a great job, keep it up!
Hi Gregory,
I stopped by your demo at OHBM and was so impressed by your work on this! Unfortunately I don't think it's compatible with the files we have. We use Actiware 6.0 which exports individual files as csv files and I haven't been able to get the files to read in. I attached an example of one of our data files (GitHub won't let me upload csv files). Could you let me know if I'm missing something? If not, would you consider adding compatibility with this file type?
The current BaseLog class does not allow child classes to read additional columns, besides start and stop times.
Should be made more generic and port SST-oriented features to SSTLog class.
I was very excited to stumble across this API. However, I am using Actigraph (WGT3X) data to measure movement and need to pull the raw data of whether the individual is lying down, standing up, or sitting. This information is currently coded into the .agd file, but I cannot access it. Any help here would be great!
I've been trying to use pyActigraphy, but a bunch of my files are in .dat or .wac format. Do you know how to get around this in a way that I could use them for input?
Also, I read the tutorials on how to use pyActigraphy, but didn't find any instructions about calculating SRI. Reading the original article, If I'm not wrong, I can obtain SRI by multiplying kRA x kAR. But it doesn't seem logical.
Thank you!
The language used in the header of the Respironics files are country-specific. Reader functions need to be adapted to support new languages.
Request from Anna Biller (https://www.imp.med.uni-muenchen.de/members/mitarbeiter/anna-biller/index.html)
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
Dear Grégory,
I found myself testing how comparable are the outputs generated by two different ways: raw data analyzed with your package and the native Condor program for reading the data of ActTrust accelerometers. But I bumped into a wall, the data don't match. Both the outputs are totally different. I tried to change some parameters using the functions related to IS and IV, even so I couldn't manage to achieve the results from original Condor program. Do you know how to solve this problem? What changes or functions should I run to parse the raw data?
Thank you!
Move sleep profiles from sleep/scoring_base.py to Viz module.
Hello,
In the current tutorials/implementations, all the days are visualized in one diagram.
Could I visualize one day per diagram?
I mean something like this: https://s3.amazonaws.com/actigraphcorp.com/wp-content/uploads/2018/02/19210723/screenshot-al-inclineview-v5.png
Thank you.
Best regards,
Loukas
Hello,
Can I use PyActigraphy for reading ACTILIFE data?
Thank you!
Hi Grègory,
I've been in touch with a collaborator who has met with you to understand the light functionalities of the package, and I was just wondering if they have been adapted to run on batch files? I've only managed to get them to work on single files. I managed to write a loop - but this doesn't allow me to apply the start/stop times log.
TLDR: I am interested in the L5i, M10i and raw ambient light, ran as a batch with the SST log applied. You sent my collaborator a script for reports (which has a light label), which seem to have batch functionalities but I cannot get those to work, the error message says it doesn't work on batch files. Any guidance?
Thanks,
Katie
ADAT (total average daily activity: https://ghammad.github.io/pyActigraphy/_autosummary/pyActigraphy.metrics.MetricsMixin.ADAT.html#pyActigraphy.metrics.MetricsMixin.ADAT) is calculated per day and then averaged. However, the first and last days might be incomplete. If so, the mean is biased.
There are two patterns for the UUID recorded with the Actiwatch-L - one with a lowercase 'l' and one with a capital 'L'. Currently, pyActigraphy only supports files with the capital 'L' in the UUID.
Thank you,
Debora.
Hello,
When attempting to read in a sleep diary .ods file, the suggested format provided on the github tutorial page -
https://ghammad.github.io/pyActigraphy/pyActigraphy-Sleep-Diary.html - does not read in the file correctly, unless the following 3 things are corrected:
Thank you!
Alex Washburn
Hi! The actical solution worked amazing, but I am having some issues with some of the actigraph files
It is saying this:
DatabaseError: Execution failed on sql 'SELECT state, timeStamp FROM capsense': no such table: capsense
Thanks!
Ale
Hello Grégory,
We are a couple of BSc students working with ActTrust and ActTrust 2 wristbands for a research. We noticed a mismatch in the documentation and the code. For example, in the documentation the Cole-Kripke (CK) function can take the parameters "settings" but the code does not have that parameter. Is it possible to update the documentation?
Thanks!
Alexandra
For all the metrics (kAR, kRA, fSoD, etc),
allow users to specify, either:
Hi Grégory,
I was at your software demonstration at the OHBM in Rome last week.
There you showed us an awesome Jupyter Notebook with even more features than described in your repository (e.g. signal filtering).
Would it be possible to make these notebooks you used at the demonstration public available?
This would be very helpful!
Thanks for your efforts and best regards,
Marco
Hi,
It says in the readme that this package is compatible with Actiwatch Spectrum plus, but how can I use the code to read AW5 files?
Thanks!
This algorithm is used by default for sleep/wake scoring performed by the Actiware software (Philips Respironics)
Reference:
N. Oakley, “Validation with Polysomnography of the Sleepwatch
Sleep/Wake Scoring Algorithm used by the Actiwatch Activity Monitoring System,” Technical Report, 1997
Hi
I'm trying to compare activity signals coming from Fitbit and Actiwatch devices. To create identical conditions for both, I create the PyActigraphy object using activity timeseries.
Now, I'd like to auto-create the inactivity mask. However, since the activity for the fitbit device has a different amplitude (somewhere between 1 and 15), I need to be able to define the threshold used differently.
Therefore, I suggest the following change to the method interface of create_inactivity_mask()
:
https://github.com/ghammad/pyActigraphy/blob/master/pyActigraphy/filters/filters.py#L71
# old
def create_inactivity_mask(self, duration)
# new
def create_inactivity_mask(self, duration, threshold=1)
And consequently the method call to _create_inactivity_mask()
:
https://github.com/ghammad/pyActigraphy/blob/master/pyActigraphy/filters/filters.py#L104
# old
self.mask = _create_inactivity_mask(self.raw_data, nepochs, 1)
# new
self.mask = _create_inactivity_mask(self.raw_data, nepochs, threshold)
If this sounds reasonable, I'll gladly make the adaption and create a corresponding PR.
Cheers
Hi @ghammad,
I have seen this issue has already been posted but just wanted to make sure you had seen. I was wondering whether pyActigraphy is able to calculate M10/L5 onset times. I cannot see this function in: [https://ghammad.github.io/pyActigraphy/MetricsMixin.html#pyActigraphy.metrics.MetricsMixin]. Since 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, and sorry for double-posting this issue.
Rory
Dear Grégory,
as discussed today, reading raw Actitwtach Spectrum Pro files into pyActi only allows to view the white light data (command raw.light) even though the device collected other light colours, too. Could you add them so they're also accessible through the "raw.light" command or similar?
Thank you!
Best
Anna
Hello Grégory,
I have a number of .gt3x files that I'm working with. I can see from your API and documentation that this package requires .agd files. Are there any plans to add .gt3x file support? Or is there something missing from these files that makes them unsuitable?
In a publication (preprint PDF here) in Sleep, Hand and colleagues recently proposed the Light Regularity Index.
From their paper:
Inspired by the formulation of the SRI, we devised an equivalent metric for light. First, we converted the light time series into a binary signal (similar to sleep vs. wake), based on whether the light level was above or below an absolute threshold (i.e., 10, 20, 50, 100, 300 and 500 lux). The LRI was then calculated by determining the probability that an individual was in the same state (above vs. below a threshold) at any two time points, 24 hours apart. The index was scaled so that an individual who records light exposure greater than their median light level at exactly the same times each day would score 100, whereas an individual who records random light exposure patterns would score 0. Participants whose LRI value was calculated using less than 5 days of overlapping valid epochs were considered missing for that period (school = 0.00%; vacation = 2.00%).
It would be a great addition to pyActigraphy.
Add the possibility to:
weekends when calculating any metric (ex: RAR variables, sleep characteristics, etc).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.