ghammad / pyActigraphy

Python-based open source package for actigraphy data analysis

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

yeelapto opened this issue · comments

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.

Hello @yeelapto

Happy to help. Could you provide me with the sleep diary you try to read?

As mentioned in the corresponding tutorial on sleep diaries, there is, within the pyActigraphy package, an example file:

# Retrieve path to example sleep diary
path_to_sd = os.path.join(os.path.dirname(pyActigraphy.__file__),'tests',data','example_01_sleepdiary.ods')

Make sure that your file is identically formatted.

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.

You can use the ADAT variable to compute the daily average of the total activity count.
If now, you want a daily evaluation, you can use the ADATp and set the period parameter to 1D.

Hope that helps.

Greg

Hello @yeelapto

Could you provide me with the file you mentioned? Unless I missed it, I don't see any attached to your message.

I just checked the code and ran it over a sample file and I do see the expected daily values.

A few general comments:

  • check the documentation for ADAT/ADATp if you haven't done so. With the default input parameter, those functions used binarised data. So your daily average cannot exceed the number of epochs per day (ex: 1440 for a 1-min epochs). And, for the ADATp with a '1D' periods, your daily average is simply the total amount of epochs whose counts are above the threshold. To get an average of the activity counts, turn the input parameter binarize=False.
  • For the ADATp, the first period starts at the beginning of your recording and has the requested length. If you want the average activity to be computed from midnight to midnight, make your recording start at midnight (using the start_time parameter in the reader function).

Do not hesitate if you have questions.

Happy to help and happy to see that the package is useful for others!

Thank you.

Greg

Hi Greg,

Due to the limit on the type of files that can be uploaded on Github, I have sent you an email for further inquiry. But I think that the issue of physical activity has been basically solved.

Thanks a lot for your prompt response and help!

Regards,
Peter

Hello @yeelapto

Thanks for sharing the files.

First, as you can see on the attached screenshot, the recording is longer than the actual wear period. Most likely, the device was worn for a week or so, and then removed and put aside while the recording continues. Those 'non-wear' periods must be removed before analysing the recording.
Unknown-4

Please, check the dedicated tutorial.

For your sleep diary, if you compare it to the example file provided within the package, you will see that it misses a header with the columns 'TYPE', 'START' and 'END'. See this tutorial.

Once those issues are solved, you are on the right track for your analysis.

Good luck.

Let me know if this helps and don't hesitate to come back to me if you have questions or face another issue.

Happy actigraphing.

Greg

Hi Greg,

Thanks so much for the very detailed advice on how I shall handle those raw files. I will try to read these documents and will let you know if my issues have been solved (may take a few days because of other work).

Regards,
Peter

Hello @yeelapto

Closing this issue now. Feel free to re-open this issue if needed.