Calculating HRV features with IBI.csv.
parent
8c8fe1fec7
commit
66451160e9
|
@ -576,7 +576,7 @@ EMPATICA_INTER_BEAT_INTERVAL:
|
||||||
'VLF', 'LF', 'LFnorm', 'HF', 'HFnorm', 'LF/HF', 'fullIntegral'] # Freq features
|
'VLF', 'LF', 'LFnorm', 'HF', 'HFnorm', 'LF/HF', 'fullIntegral'] # Freq features
|
||||||
WINDOWS:
|
WINDOWS:
|
||||||
COMPUTE: True
|
COMPUTE: True
|
||||||
WINDOW_LENGTH: 4 # specify window length in seconds
|
WINDOW_LENGTH: 120 # specify window length in seconds
|
||||||
SRC_SCRIPT: src/features/empatica_inter_beat_interval/cr/main.py
|
SRC_SCRIPT: src/features/empatica_inter_beat_interval/cr/main.py
|
||||||
|
|
||||||
# See https://www.rapids.science/latest/features/empatica-tags/
|
# See https://www.rapids.science/latest/features/empatica-tags/
|
||||||
|
|
|
@ -62,13 +62,15 @@ def extract_empatica_data(data, sensor):
|
||||||
df.index.name = 'timestamp'
|
df.index.name = 'timestamp'
|
||||||
|
|
||||||
elif sensor == 'EMPATICA_INTER_BEAT_INTERVAL':
|
elif sensor == 'EMPATICA_INTER_BEAT_INTERVAL':
|
||||||
|
|
||||||
df = pd.read_csv(sensor_data_file, names=['timestamp', column], header=None)
|
df = pd.read_csv(sensor_data_file, names=['timestamp', column], header=None)
|
||||||
|
df['timings'] = df['timestamp']
|
||||||
timestampstart = float(df['timestamp'][0])
|
timestampstart = float(df['timestamp'][0])
|
||||||
df['timestamp'] = (df['timestamp'][1:len(df)]).astype(float) + timestampstart
|
df['timestamp'] = (df['timestamp'][1:len(df)]).astype(float) + timestampstart
|
||||||
df = df.drop([0])
|
df = df.drop([0])
|
||||||
df[column] = df[column].astype(float)
|
df[column] = df[column].astype(float)
|
||||||
df = df.set_index('timestamp')
|
df = df.set_index('timestamp')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"sensor has an invalid name: {}".format(sensor))
|
"sensor has an invalid name: {}".format(sensor))
|
||||||
|
|
|
@ -50,6 +50,7 @@ EMPATICA_INTER_BEAT_INTERVAL:
|
||||||
TIMESTAMP: timestamp
|
TIMESTAMP: timestamp
|
||||||
DEVICE_ID: device_id
|
DEVICE_ID: device_id
|
||||||
INTER_BEAT_INTERVAL: inter_beat_interval
|
INTER_BEAT_INTERVAL: inter_beat_interval
|
||||||
|
TIMINGS: timings
|
||||||
MUTATION:
|
MUTATION:
|
||||||
COLUMN_MAPPINGS:
|
COLUMN_MAPPINGS:
|
||||||
SCRIPTS: # List any python or r scripts that mutate your raw data
|
SCRIPTS: # List any python or r scripts that mutate your raw data
|
||||||
|
|
|
@ -217,6 +217,7 @@ EMPATICA_INTER_BEAT_INTERVAL:
|
||||||
- TIMESTAMP
|
- TIMESTAMP
|
||||||
- DEVICE_ID
|
- DEVICE_ID
|
||||||
- INTER_BEAT_INTERVAL
|
- INTER_BEAT_INTERVAL
|
||||||
|
- TIMINGS
|
||||||
|
|
||||||
EMPATICA_TAGS:
|
EMPATICA_TAGS:
|
||||||
- TIMESTAMP
|
- TIMESTAMP
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from scipy.stats import entropy
|
import numpy as np
|
||||||
|
|
||||||
from cr_features.helper_functions import convert_ibi_to2d_time, hrv_features, hrv_freq_features
|
from cr_features.helper_functions import convert_ibi_to2d_time, hrv_features, hrv_freq_features
|
||||||
from cr_features.calculate_features import calculate_features
|
from cr_features.hrv import extract_hrv_features_2d_wrapper
|
||||||
|
|
||||||
|
import math
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
pd.set_option('display.max_rows', 1000)
|
pd.set_option('display.max_rows', 1000)
|
||||||
|
pd.set_option('display.max_columns', None)
|
||||||
|
|
||||||
|
|
||||||
def get_sample_rate(data):
|
def get_sample_rate(data):
|
||||||
|
@ -28,23 +30,32 @@ def extract_ibi_features_from_intraday_data(ibi_intraday_data, features, window_
|
||||||
if not ibi_intraday_data.empty:
|
if not ibi_intraday_data.empty:
|
||||||
|
|
||||||
ibi_intraday_features = pd.DataFrame()
|
ibi_intraday_features = pd.DataFrame()
|
||||||
|
# np.set_printoptions(threshold=sys.maxsize)
|
||||||
|
# print(ibi_intraday_data.groupby('local_segment').apply(lambda x: math.ceil(x['timings'].iloc[-1])))
|
||||||
|
# nekaj = ibi_intraday_data.groupby('local_segment').apply(lambda x: \
|
||||||
|
# convert_ibi_to2d_time(x[['timings', 'inter_beat_interval']], window_length)[1])
|
||||||
|
|
||||||
print(ibi_intraday_data.head(100))
|
# sys.exit()
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
# apply methods from calculate features module
|
# apply methods from calculate features module
|
||||||
if window_length is None:
|
if window_length is None:
|
||||||
ibi_intraday_features = \
|
ibi_intraday_features = \
|
||||||
ibi_intraday_data.groupby('local_segment').apply(\
|
ibi_intraday_data.groupby('local_segment').apply(\
|
||||||
|
lambda x:
|
||||||
extract_hrv_features_2d_wrapper(
|
extract_hrv_features_2d_wrapper(
|
||||||
convert_to2d(x['inter_beat_interval'], window_length*sample_rate),
|
signal_2D = \
|
||||||
sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, feature_names=features))
|
convert_ibi_to2d_time(x[['timings', 'inter_beat_interval']], math.ceil(x['timings'].iloc[-1]))[0],
|
||||||
|
ibi_timings = \
|
||||||
|
convert_ibi_to2d_time(x[['timings', 'inter_beat_interval']], math.ceil(x['timings'].iloc[-1]))[1],
|
||||||
|
sampling=None, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, feature_names=features))
|
||||||
else:
|
else:
|
||||||
ibi_intraday_features = \
|
ibi_intraday_features = \
|
||||||
ibi_intraday_data.groupby('local_segment').apply(\
|
ibi_intraday_data.groupby('local_segment').apply(\
|
||||||
|
lambda x:
|
||||||
extract_hrv_features_2d_wrapper(
|
extract_hrv_features_2d_wrapper(
|
||||||
convert_to2d(x['blood_volume_pulse'], window_length*sample_rate),
|
signal_2D = convert_ibi_to2d_time(x[['timings', 'inter_beat_interval']], window_length)[0],
|
||||||
sampling=sample_rate, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, feature_names=features))
|
ibi_timings = convert_ibi_to2d_time(x[['timings', 'inter_beat_interval']], window_length)[1],
|
||||||
|
sampling=None, hampel_fiter=False, median_filter=False, mod_z_score_filter=True, feature_names=features))
|
||||||
|
|
||||||
ibi_intraday_features.reset_index(inplace=True)
|
ibi_intraday_features.reset_index(inplace=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue