Exemplo n.º 1
0
def load_experiment(data_path, diary_path, start_hour):

    # Configure an Experiment
    exp = Experiment()

    # Iterates over a set of files in a directory.
    # Unfortunately, we have to do it manually with RawProcessing because we are modifying the annotations
    print("Running %s" % data_path)
    for file in glob(data_path):
        print("FILE", file)
        pp = RawProcessing(file,
                           cols_for_activity=["stdMET_highIC_Branch"],
                           is_act_count=False,
                           col_for_datetime="REALTIME",
                           strftime="%d-%b-%Y %H:%M:%S",
                           col_for_pid="id",
                           col_for_hr="mean_hr",
                           device_location="dw")
        pp.data["hyp_act_x"] = pp.data[
            "hyp_act_x"] - 1.0  # adjust for the BBVA dataset

        w = Wearable(pp)  # Creates a wearable from a pp object
        exp.add_wearable(w)

    # Set frequency for every wearable in the collection
    exp.set_freq_in_secs(60)

    # Changing the hour the experiment starts from midnight (0) to 3pm (15)
    exp.change_start_hour_for_experiment_day(start_hour)

    diary = Diary().from_file(diary_path)
    exp.add_diary(diary)

    return exp
Exemplo n.º 2
0
 def setUp(self):
     # Loads some file
     pp1 = RawProcessing()
     pp1.load_file("../data/examples_mesa/mesa-sample-day5-invalid5hours.csv",
                   # activitiy information
                   cols_for_activity=["activity"],
                   is_act_count=True,
                   # Datatime information
                   col_for_datatime="linetime",
                   device_location="dw",
                   start_of_week="dayofweek",
                   # Participant information
                   col_for_pid="mesaid")
     self.w_5day_invalid5hours = Wearable(pp1)
Exemplo n.º 3
0
def load_experiment(data_path, diary_path, start_hour):
    # Configure an Experiment
    exp = Experiment()

    # 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(data_path):
        pp = RawProcessing(
            file,
            # HR information
            col_for_hr="HR",
            # Activity information
            cols_for_activity=["Axis1", "Axis2", "Axis3"],
            is_act_count=False,
            # Datetime information
            col_for_datetime="time",
            strftime="%Y-%b-%d %H:%M:%S",
            # Participant information
            col_for_pid="pid")

        w = Wearable(pp)  # Creates a wearable from a pp object
        exp.add_wearable(w)

    # Set frequency for every wearable in the collection
    # exp.set_freq_in_secs(5)

    # Changing the hour the experiment starts from midnight (0) to 3pm (15)
    exp.change_start_hour_for_experiment_day(start_hour)

    diary = Diary().from_file(diary_path)
    exp.add_diary(diary)

    return exp
def load_experiment(data_path, start_hour):
    # Configure an Experiment
    exp = Experiment()

    # 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(data_path):
        pp = RawProcessing(file,
                     # HR information
                     col_for_hr="hr",
                     # Activity information
                     cols_for_activity=["x", "y", "z"],
                     is_act_count=True,
                     # Datetime information
                     col_for_datetime="faketime",
                     strftime="%Y-%m-%d %H:%M:%S",
                     # Participant information
                     col_for_pid="pid")

        w = Wearable(pp)  # Creates a wearable from a pp object
        w.data["hyp_annotation"] = (w.data["label"] > 0)
        exp.add_wearable(w)

    # Set frequency for every wearable in the collection
    exp.set_freq_in_secs(15)

    # Changing the hour the experiment starts from midnight (0) to 3pm (15)
    exp.change_start_hour_for_experiment_day(start_hour)

    return exp
Exemplo n.º 5
0
def setup_experiment(file_path, diary_path, start_hour):
    # Configure an Experiment
    exp = Experiment()

    # 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 = RawProcessing(file,
                           device_location="dw",
                           # HR information
                           col_for_hr="mean_hr",
                           # Activity information
                           cols_for_activity=["activity"],
                           is_act_count=True,
                           # Datetime information
                           col_for_datetime="linetime",
                           strftime="%Y-%m-%d %H:%M:%S",
                           # Participant information
                           col_for_pid="mesaid")

        w = Wearable(pp)  # Creates a wearable from a pp object
        # Invert the two_stages flag. Now True means sleeping and False means awake
        w.data["hyp_annotation"] = (w.data["stages"] > 0)
        exp.add_wearable(w)
        exp.set_freq_in_secs(30)
        w.change_start_hour_for_experiment_day(start_hour)

    diary = Diary().from_file(diary_path)
    exp.add_diary(diary)

    return exp
Exemplo n.º 6
0
    def configure_experiment(self, datapath: str, device_location: str, cols_for_activity, col_for_mets: str = None,
                             is_emno: bool = False, is_act_count: bool = False, col_for_datetime: str = "time",
                             start_of_week: int = -1, strftime: str = None, col_for_pid: str = None, pid: int = -1,
                             additional_data: object = None, col_for_hr: str = None):

        # TODO: Missing a check to see if datapath exists.
        if os.path.isdir(datapath):
            if not datapath.endswith("*"):
                datapath = os.path.join(datapath, "*")
        else:
            if '*' not in datapath:
                datapath = datapath + "*"

        for file in glob(datapath):
            pp = RawProcessing(file,
                               device_location=device_location,
                               # activitiy information
                               cols_for_activity=cols_for_activity,
                               is_act_count=is_act_count,
                               is_emno=is_emno,
                               # Datatime information
                               col_for_datetime=col_for_datetime,
                               col_for_mets=col_for_mets,
                               start_of_week=start_of_week,
                               strftime=strftime,
                               # Participant information
                               col_for_pid=col_for_pid,
                               pid=pid,
                               additional_data=additional_data,
                               # HR information
                               col_for_hr=col_for_hr, )
            w = Wearable(pp)
            self.wearables[w.get_pid()] = w
Exemplo n.º 7
0
    def test_load_file(self):

        pp1 = RawProcessing()
        pp1.load_file("../data/examples_mesa/mesa-sample.csv",
                      collection_name="mesa",
                      col_for_datatime="linetime",
                      device_location="dw",
                      start_of_week="dayofweek",
                      col_for_pid="mesaid")
        nrows = pp1.data.shape[0]
        self.assertEqual(nrows, 23003)
        self.assertIn("linetime", pp1.data.keys())

        pp2 = RawProcessing()
        pp2.load_file("../data/examples_mesa/mesa-sample.csv",
                      collection_name="mesa",
                      col_for_datatime="linetime",
                      device_location="dw",
                      start_of_week=4,
                      pid=1)

        nrows = pp2.data.shape[0]
        self.assertEqual(nrows, 23003)
        self.assertIn("hyp_time", pp2.data.keys())
Exemplo n.º 8
0
    def configure_experiment(self,
                             datapath: str,
                             device_location: str,
                             cols_for_activity,
                             col_for_mets: str = None,
                             is_emno: bool = False,
                             is_act_count: bool = False,
                             col_for_datetime: str = "time",
                             start_of_week: int = -1,
                             strftime: str = None,
                             col_for_pid: str = None,
                             pid: int = -1,
                             additional_data: object = None,
                             col_for_hr: str = None):
        """
        

        Parameters
        ----------
        datapath : str
            DESCRIPTION. Path to the dat folder
        device_location : str, optional
            DESCRIPTION. The default is None. Where this device was located (options are: "bw", "hip", "dw", "ndw", "chest", "hp_ch", "hp_bw", "all")
        # Configuration for activity                 
        cols_for_activity : list / str
            DESCRIPTION. Which columns record activity
        col_for_mets : object, optional
            DESCRIPTION. Column that records METs.
        is_emno : bool, optional
            DESCRIPTION. True if the cols_for_activity are already computed as the ENMO (Euclidean Norm Minus One)
        is_act_count : bool, optional
            DESCRIPTION. The default is False. True us cols_for_activity are already computed as counts
        # Datetime parameters                 
        col_for_datetime : str, optional
            DESCRIPTION. The default is "time". Name of timestamp column.
        start_of_week : int, optional
            DESCRIPTION. The default is -1. Integer that represents the day at the start of the week
        strftime : str, optional
            DESCRIPTION. The default is None. Format to parse col_for_datetime
        # PID parameters                 
        col_for_pid : str, optional
            DESCRIPTION. The default is None. Participant ID columns
        pid : int, optional
            DESCRIPTION. The default is -1.
        # HR parameters                 
        col_for_hr : str, optional
            DESCRIPTION. The default is None. Column with heart rate data
        # Any additional data?                 
        additional_data : object, optional
            DESCRIPTION. The default is None.
       

        Returns
        -------
        None.

        """

        # TODO: Missing a check to see if datapath exists.
        if os.path.isdir(datapath):
            if not datapath.endswith("*"):
                datapath = os.path.join(datapath, "*")
        else:
            if '*' not in datapath:
                datapath = datapath + "*"

        for file in glob(datapath):
            pp = RawProcessing(
                file,
                device_location=device_location,
                # activitiy information
                cols_for_activity=cols_for_activity,
                is_act_count=is_act_count,
                is_emno=is_emno,
                # Datatime information
                col_for_datetime=col_for_datetime,
                col_for_mets=col_for_mets,
                start_of_week=start_of_week,
                strftime=strftime,
                # Participant information
                col_for_pid=col_for_pid,
                pid=pid,
                additional_data=additional_data,
                # HR information
                col_for_hr=col_for_hr,
            )
            w = Wearable(pp)
            self.wearables[w.get_pid()] = w
Exemplo n.º 9
0
# Shiftworker analysis

from hypnospy import Wearable
from hypnospy.data import RawProcessing
from hypnospy.analysis import Viewer, NonWearingDetector, SleepBoudaryDetector, SleepWakeAnalysis
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

pp = RawProcessing(
    "./data/shiftworker/Shiftworker.csv",
    # HR information
    col_for_hr="mean_hr",
    # Activity information
    cols_for_activity=["ACC"],
    is_act_count=True,
    # Datetime information
    col_for_datetime="real_time",
    strftime="%d/%m/%Y %H:%M",
    # Participant information
    col_for_pid="id")

w = Wearable(pp)

#Check out data columns
#print(w.data.head(10))

#Define parameters fo HR-based sleep algorithm
hr_quantile = 0.4
hr_min_window_length = 60
hr_merge_blocks = 180