GithubHelp home page GithubHelp logo

ghammad / pyactigraphy Goto Github PK

View Code? Open in Web Editor NEW
130.0 5.0 25.0 78.21 MB

Python-based open source package for actigraphy data analysis

Home Page: https://ghammad.github.io/pyActigraphy

License: GNU General Public License v3.0

Python 100.00%
python open-source actigraphy actimetry sleep rest-activity-rhythms circadian physical-activity

pyactigraphy's People

Contributors

ghammad avatar reytmathilde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pyactigraphy's Issues

Analysis of sleep diary and physical activity with pyActigraphy (MotionWatch 8)

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.

Automatic start time detection

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.

Sleep bout detection with the Roenneberg algo

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.

Masking period

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".

Bugs in adaptive median filter implementation (Crespo algorithm)

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.

  1. In line 1130 of your /sleep/scoring_base.py script you use the rolling class from pandas with parameter min_periods. You should check that because min_periods may produce unexpected results when applied to series containing NaNs.
  2. Starting at line 1136 you use the expanding class from pandas with parameter center=True and it produces "unexpected" results. Please refer to expanding-git-issue.
  3. In line 1141 you apply an index reversion using "[::-1]". You should check that because it leads to indexing problems in subsequent pandas-related operations.

I hope this will help to improve the library.
Keep up the good work.

Julius

AX3 Reader

New feature: develop a reader for the OpenMovement AX device.

Documentation about the data format:
https://github.com/digitalinteraction/openmovement

Steps:

  • write a class for parsing the CWA binary file header
  • write a class for parsing the CWA binary file block
  • write a class CWA that reads binary file and creates a pyActigraphy object (base class: BaseRaw)

.mtn error

Hello Gregory,

I'm trying to open a .mtn file using the code:

import pyActigraphy
import matplotlib.pyplot as plt

read in .mtn file

act = pyActigraphy.read_mtn('C://Users//Jeffrey Pagaduan//Downloads//FTRAW.mtn')

plot actigraphy data

fig, ax = plt.subplots()
ax.plot(act['Time'], act['Activity'])
ax.set(xlabel='Time', ylabel='Activity', title='Actigraphy Data')
plt.show()

compute sleep parameters

sleep_params = pyActigraphy.get_sleep_params(act, interval=30, window=5)

print sleep parameters

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.

Roenneberg Algorithm (MASDA) default settings check

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

Support for raw pandas data?

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

How to get the L5 and M10 start times?

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

Stop times and dynamic variables

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

Add "import plotly.graph_objects as go" to Introduction section of documentation

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!

Easier install developer version

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!

Batch processing txt files from Condor

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

M10 and file cleaning

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.

Bug in inactivity mask filter (Crespo algorithm)

Greetings!

I've been running a few tests with your Crespo algorithm implementation and I've come across a bug.
filter_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!

Request for Actiware 6.0 csv file compatibility

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?

csv_ex

Improve BaseLog class

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.

Pulling Activity Counts from Actigraph Data

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!

Other file formats and calculating SRI

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!

L5 and M10 Sampling frequency

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

Comparing raw data analyzed with PyActigraphy versus data through native program

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!

Sleep profile

Move sleep profiles from sleep/scoring_base.py to Viz module.

Batch function for extracting light data?

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

Viz module

Create a module for vizualisation:

  • double plot (day by day)
  • #98
  • #99
  • detected rest periods
  • daily profile (with single or multiple traces)
  • #100

Add support for different model of Actiwatch-L

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.

Sleep diary file format bug

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:

  1. The 'Type', 'Start', and 'End' columns must be capitalized to 'TYPE', 'START', and 'END'.
  2. For the 'TYPE' column, values 'Night/Nap/NoWear' all must be capitalized as well.
  3. A blank line (on row 2) needed to be inserted between the header line describing the subjectID and the line with the column names ('TYPE', 'START', and 'END').

Thank you!
Alex Washburn

Issue with the reading of some actigraph

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

Mismatch in code vs documentation

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

OHBM Jupyter Notebooks

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

using AW5 files

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!

Implement Oakley's sleep/wake scoring algorithm

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

Define Threshold as Parameter in create_inactivity_mask()

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

M10/L5 onset

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

Actiwatch Spectrum Pro: Add other than just white light information

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

Support for .gt3x files?

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?

Implementation of the Light Regularity Index in the pyLight submodule

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.