Beispiel #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
Beispiel #2
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
Beispiel #4
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
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 = MESAPreProcessing(file)
        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["interval_sleep"] = w.data["interval"].isin(["REST-S", "REST"])

        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
Beispiel #6
0
 def get_valid_data_for_experiment(self,
                                   experiment: Experiment) -> pd.DataFrame:
     pids = [
         wearable.get_pid() for wearable in experiment.get_all_wearables()
     ]
     return self.data[self.data.index.isin(pids)]
Beispiel #7
0
    def add_to_experiment(self, experiment: Experiment) -> None:

        for wearable in experiment.get_all_wearables():
            self.add_to_wearable(wearable)
        df_acc.append(df_res)

    df_acc = pd.concat(df_acc)
    df_acc["exp_id"] = exp_id
    df_acc["quantile"] = quantile
    df_acc["window_lengths"] = min_window_length
    df_acc["time_merge_blocks"] = merge_blocks

    df_acc.to_csv(os.path.join(output_path, "exp_%d.csv" % (exp_id)), index=False)


if __name__ == "__main__":

    # Configure an Experiment
    exp = Experiment()

    data_path = "./data/collection_apple_watch/*.csv"
    start_hour = 15
    end_hour = start_hour - 1

    quantiles = [0.025, 0.05, 0.075, 0.10, 0.125, 0.15, 0.175, 0.20, 0.225, 0.25, 0.275,
                 0.30, 0.325, 0.35, 0.375, 0.4, 0.425, 0.45, 0.475, 0.5, 0.525, 0.55, 0.575, 0.6, 0.625, 0.65, 0.675,
                 0.7, 0.725, 0.75, 0.775, 0.8, 0.825, 0.85, 0.875, 0.9, 0.925, 0.95, 0.975, 1.0]
    window_lengths = [25, 27.5, 30, 32.5, 35, 37.5, 40, 42.5, 45, 47.5, 50]
    time_merge_blocks = [30, 60, 120, 240, 360, 420]

    hparam_list = []
    exp_id = 0
    for quantile in quantiles:
        for merge_blocks in time_merge_blocks:
Beispiel #9
0
from glob import glob
from hypnospy import Wearable
from hypnospy.data import ActiwatchSleepData
from hypnospy.analysis import SleepWakeAnalysis
from hypnospy.analysis import TimeSeriesProcessing
from hypnospy.analysis import PhysicalActivity
from hypnospy import Experiment

if __name__ == "__main__":

    # Configure an Experiment
    exp = Experiment()

    file_path = "./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)

    tsp = TimeSeriesProcessing(exp)

    tsp.fill_no_activity(-0.0001)
    tsp.detect_non_wear(strategy="choi")

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