<jupyter_start><jupyter_text>Imports<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import seaborn as sns

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import seaborn as sns

from glob import glob
from hypnospy import Wearable
from hypnospy.data import ActiwatchSleepData
from hypnospy.analysis import SleepWakeAnalysis
from hypnospy.analysis import NonWearingDetector
from hypnospy.analysis import SleepBoudaryDetector
from hypnospy.analysis import CircadianAnalysis
from hypnospy.analysis import PhysicalActivity
from hypnospy import Experiment
from hypnospy.analysis import Viewer

from tqdm import trange, tqdm
import pickle<jupyter_output><empty_output><jupyter_text>Read dataset - HCHS<jupyter_code># Configure an Experiment
exp = Experiment()

file_path = "HypnosPy-master/data/small_collection_hchs/*"

# Iterates over a set of files in a directory.
# Unfortunately, we have to do it manually with RawProcessing because we are modifying the annotations
for file in glob(file_path):
    pp = ActiwatchSleepData(file, col_for_datetime="time", col_for_pid="pid")
    w = Wearable(pp)  # Creates a wearable from a pp object
    exp.add_wearable(w)
    print(w.pid)

freq = 30
exp.set_freq_in_secs(freq)


# tsp = NonWearingDetector(exp)
# tsp.fill_no_activity(-0.0001)
# tsp.detect_non_wear(strategy="choi")
# tsp.detect_non_wear(strategy="choi2011")

# tsp.check_consecutive_days(5)
# # print("Valid days:", tsp.get_valid_days())
# # print("Invalid days:", tsp.get_invalid_days())

# # strategy: "annotation", "hr", "angle"
# # sbd = SleepBoudaryDetector(exp)
# # sbd.detect_sleep_boundaries(strategy="annotation", 
# #                             annotation_hour_to_start_search=0,
# #                             annotation_col='hyp_annotation',
# #                             output_col='hyp_sleep_period',
# #                             annotation_only_largest_sleep_period=False)
# tsp.invalidate_day_if_no_sleep(sleep_period_col='hyp_sleep_period')
# print("Valid days:", tsp.get_valid_days())

# tsp.check_valid_days(max_non_wear_minutes_per_day=180, min_activity_threshold=0)
# print("Valid days:", tsp.get_valid_days())
# print("Invalid days:", tsp.get_invalid_days())<jupyter_output>29881087
29883363
29909542
29915385
29950301<jupyter_text>Use PhysicalActivity<jupyter_code>pa = PhysicalActivity(exp, cutoffs=[399, 1404], names=['lpa', 'mvpa', 'vpa'])
pa.generate_pa_columns(based_on='activity')

print('cutoffs:', exp.get_all_wearables()[0].pa_cutoffs)
print('cutoffs region names:', exp.get_all_wearables()[0].pa_names)<jupyter_output>cutoffs: [399, 1404]
cutoffs region names: ['lpa', 'mvpa', 'vpa']<jupyter_text>Find count of bouts per day per wearable<jupyter_code>pa.get_bouts(pa_col='mvpa', length_in_minutes=10, decomposite_bouts=True)<jupyter_output><empty_output><jupyter_text>Find stats of activity per hour per day per wearable<jupyter_code>pa.get_stats_pa_representation()<jupyter_output><empty_output><jupyter_text>draw physical activity within using Viewer module<jupyter_code>Viewer(exp).view_signals(signal_categories=['activity'], signal_as_area=['mvpa'], 
               colors ={"area": ["orange"]}, alphas ={"area": 0.8},
              resample_to='5T')<jupyter_output><empty_output><jupyter_text>draw MVPA boxplotEach row represents the wearable MVPA boxplotX-axis = 24 hourY-axis = MVPA box plot for 7 days<jupyter_code>data = pa.get_binned_pa_representation()
data = data.reset_index()
# data = data[data['pid'] == '29881087']

g = sns.catplot(x="hyp_time_col", y="MVPA", data=data, 
                kind="box", color='white',
                row='pid',
                height=4, aspect=2.5)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11070110701107011, 'fraction_numerical': 0.024248813916710597, 'mean_word_length': 5.487179487179487, 'pattern_counts': {'":': 2, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '13234', 'license': 'MIT', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1287, 'n_words': 266, 'path': 'mdpi_sensors/hypnospy_physicalActivity_example.ipynb', 'repo_name': 'HypnosPy/HypnosPy', 'size': '3794'}