Scripts to create intensity plots from 24/7 accelerometer data
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.0 KiB

# -*- coding: utf-8 -*-
Created on Wed Jun 16 13:03:03 2021
@author: -
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
os.chdir('D:\AcA Mike Dijkhof\Scripts') # set path to folder of
import formules
rootdir = 'D:\AcA Mike Dijkhof\cwa files\Pt204_csv\Pt204_csv35694_0000020406.resampled' # provide path to .csv files of the cut weekdays
d = {}
for subdir, dirs, files in os.walk(rootdir):
for file in files:
d[file] = pd.read_csv(file, infer_datetime_format=True)
Keys = d.keys()
Check = formules.SlopeWeeker(Keys, d)
Worklist = Check
Length = pd.DataFrame(np.zeros(((1,int(len(Check)/7)))))
# Create PtName, this depends on subdir string so has to be changed for each patient
PtName = subdir.replace('35694_00000', '')
PtName = PtName.replace('D:\AcA Mike Dijkhof\cwa files\Pt204_csv\Pt204_','')
PtName = PtName.replace('resampled-','')
PtName = PtName.replace('.resampled','')
PtName = PtName.replace('.csv','')
for i in Length:
CheckWeek = Worklist[:7]
Worklist = Worklist.drop(CheckWeek.index, axis=0)
CheckWeek.loc['Mean','a'] = CheckWeek['a'].median()
CheckWeek.loc['Mean','b'] = CheckWeek['b'].median()
CheckWeek.loc['Mean','c'] = CheckWeek['c'].median()
Xscale = np.arange(0,CheckWeek['ENMOmax'].max(), 5)
plt.title('All weekdays and average plotted ' + PtName)
plt.xlabel('Movement intensity [bins of 5 mg]')
plt.ylabel('Amount of time spend at intensity [min]')
for i, r in CheckWeek.iterrows():
Y = formules.func(Xscale, CheckWeek.loc[i,'a'],CheckWeek.loc[i,'b'], CheckWeek.loc[i,'c'] )
if i != 'Mean':
plt.plot(Xscale, Y, 'grey')
plt.plot(Xscale, Y, 'k--')
plt.savefig(fname=('Weekplot ' + PtName+ '.png'))