reader

polar_format

add_events(csv_dir)[source]

Adds an ‘events’ column to the synchronized signal file.

Parameters:

csv_dir (str) – Directory of the csv files for a specific record.

add_record_time(csv_dir, file_types=['HR', 'PPI', 'ACC', 'PPG', 'MAGN', 'GYRO'], marker=False, start_time=None)[source]

Adds a column to the selected csv files representing relative time in milliseconds. The timepoints are calculated referenced to the start_time.

Parameters:
  • csv_dir (str) – Directory of the csv files for a specific record.

  • file_types (list, optional) – File types to be included. Defaults to [‘HR’,’PPI’,’ACC’,’PPG’,’MAGN’,’GYRO’].

  • marker (bool, optional) – True if marker file exists. Defaults to False.

  • start_time (datetime.datetime, optional) – Reference start time. Defaults to None. If None, it is calculated as the earliest timestamp of the selected files.

calculate_sync_time(csv_dir, time_step=1, file_types=['HR', 'PPI', 'ACC', 'PPG', 'MAGN', 'GYRO'], save_file=False, marker=False)[source]

Generates an array of time points for synchronization.

Parameters:
  • csv_dir (str) – Directory of the csv files for a specific record.

  • time_step (float) – Time step in milliseconds. Defaults to 1.

  • file_types (list, optional) – File types to be included. Defaults to [‘HR’,’PPI’,’ACC’,’PPG’,’MAGN’,’GYRO’].

  • save_file (bool, optional) – If True, the generated time list is saved as a txt file. Defaults to False.

  • marker (bool, optional) – True if marker file exists. Defaults to False.

Raises:

ValueError – If the directory is empty.

Returns:

Dataframe of generated time list.

Return type:

pd.DataFrame

csv_to_pkl(csv_dir, file_types=['HR', 'PPI', 'ACC', 'PPG', 'MAGN', 'GYRO'])[source]

Reads csv files and saves as pkl files.

Parameters:
  • csv_dir (str) – Directory of the csv files.

  • file_types (list, optional) – File types to be included. Defaults to [‘HR’,’PPI’,’ACC’,’PPG’,’MAGN’,’GYRO’].

  • record_id (str, optional) – Record id of the file. It is used to rename the file. Defaults to None.

get_start_time(csv_dir, file_types=['HR', 'PPI', 'ACC', 'PPG', 'MAGN', 'GYRO'], marker=False)[source]

Returns the earliest timestamp in selected file types which is required for synchronization.

Parameters:
  • csv_dir (str) – Directory of the csv files for a specific record.

  • file_types (list, optional) – File types to be included. Defaults to [‘HR’,’PPI’,’ACC’,’PPG’,’MAGN’,’GYRO’].

  • marker (bool, optional) – True if marker file exists. Defaults to False.

Returns:

Datetime object for start time.

Return type:

datetime.datetime

marker_to_events(filepath, markerpath, events, out_path=None, save_file=False)[source]

Segments signals for events using the marker file.

Parameters:
  • filepath (str) – Full path for the csv file to be segmented.

  • markerpath (str) – Full path for the marker file.

  • events (list) – List of events

  • out_path (str) – Full path for the output file.

  • save_file (bool, optional) – If True, saves the array of events. Defaults to False.

Returns:

Dataframe of signals and corresponding events.

Return type:

pd.DataFrame

rename_csv(csv_dir, file_types=['HR', 'PPI', 'ACC', 'PPG', 'MAGN', 'GYRO'])[source]

Renames the csv files using the record id (name of the subdirectory) given by the user.

Parameters:
  • csv_dir (str) – Directory of the csv files

  • file_types (list, optional) – File types to be renamed. Defaults to [‘HR’,’PPI’,’ACC’,’PPG’,’MAGN’,’GYRO’].

synchronize_signals(csv_dir, time_step=1, time_list=None, interp_method='linear', resampling_rate=None, file_types=['ACC', 'PPG', 'MAGN', 'GYRO'], save_files=False)[source]

Synchronizes the signals by interpolating for the time_list.

Parameters:
  • csv_dir (str) – Directory of the csv files.

  • time_step (float) – Time step in milliseconds. Defaults to 1.

  • time_list (pd.DataFrame, optional) – Time array to be used for synchronization. If it is not given, it is read from the file. Defaults to None.

  • interp_method (str, optional) – Interpolation method. Defaults to ‘Linear’.

  • resampling_rate (int, optional) – Resampling rate. Defaults to None.

  • file_types (list, optional) – Signal types to be synchronized. Defaults to [‘ACC’,’PPG’,’MAGN’,’GYRO’].

  • save_files (bool, optional) – If True, the synchronized signals are saved as a csv file. Defaults to False.

Raises:

ValueError – If no file for the given file_type.

Returns:

DataFrame including synchronized signals and time points.

Return type:

pd.DataFrame

timestamp_to_msec(timestamp_df, start_time=None)[source]

Converts timestamp to time in milliseconds.

Parameters:
  • timestamp_df (pd.DataFrame) – Timestamps to be converted.

  • start_time (datetime.datetime, optional) – Reference starting time. Defaults to None. If a specific value is given, all time points are calculated referenced to it.

Returns:

Array of timepoints in msec.

Return type:

ArrayLike

txt_to_csv(txt_dir, file_types=['HR', 'PPI', 'ACC', 'PPG', 'MAGN', 'GYRO'])[source]

Reads txt files and saves as csv files.

Parameters:
  • txt_dir (str) – Directory of the text files.

  • file_types (list, optional) – File types. Defaults to [‘HR’,’PPI’,’ACC’,’PPG’,’MAGN’,’GYRO’].

polar_reader

polar_csv_reader(filepath, signal_type)[source]

Reads a csv file and returns a dictionary.

Parameters:
  • filepath (str) – Directory of the csv file.

  • signal_type (str) – Signal type to be processed.

Raises:

ValueError – If signal_type is not one of “valid_types”.

Returns:

Dictionary of signals.

Return type:

dict