Skip to content

Commit

Permalink
DEV: function
Browse files Browse the repository at this point in the history
  • Loading branch information
jungheejung committed Jul 11, 2023
1 parent 3c7ad85 commit 1b0dc1a
Showing 1 changed file with 34 additions and 31 deletions.
65 changes: 34 additions & 31 deletions spacetop_prep/physio/p01_grouplevel_01SCL_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,37 +284,7 @@ def main():
if baselinecorrect == True:
baseline_length = source_samplingrate* np.abs(SCL_epoch_start)
physio_df['physio_eda_blcorrect'] = physio_df['physio_eda']
for i in range(len(dict_onset[event_name]['start'])):
if i == 0:
baseline_average = []
baseline_start_ind = dict_onset[event_name]['start'][i] - baseline_length
baseline_stop_ind = dict_onset[event_name]['start'][i]
baseline_average = physio_df.loc[baseline_start_ind:baseline_stop_ind]['physio_eda'].mean()
# print(baseline_average)
start_index = physio_df.index[0]
stop_index = dict_onset[event_name]['start'][i+1] - baseline_length
# print(start_index, stop_index)
physio_df.loc[start_index:stop_index,'physio_eda_blcorrect'] = physio_df.loc[start_index:stop_index]['physio_eda'] - baseline_average
elif i < len(dict_onset[event_name]['start'])-1:
baseline_average = []
baseline_start_ind = dict_onset[event_name]['start'][i] - baseline_length
baseline_stop_ind = dict_onset[event_name]['start'][i]
baseline_average = physio_df.loc[baseline_start_ind:baseline_stop_ind]['physio_eda'].mean()
# print(baseline_average)
start_index = dict_onset[event_name]['start'][i] - baseline_length
stop_index = dict_onset[event_name]['start'][i+1] - baseline_length
# print(start_index, stop_index)
physio_df.loc[start_index:stop_index,'physio_eda_blcorrect'] = physio_df.loc[start_index:stop_index]['physio_eda'] - baseline_average
elif i == len(dict_onset[event_name]['start'])-1:
baseline_average = []
baseline_start_ind = dict_onset[event_name]['start'][i] - baseline_length
baseline_stop_ind = dict_onset[event_name]['start'][i]
baseline_average = physio_df.loc[baseline_start_ind:baseline_stop_ind]['physio_eda'].mean()
# print(baseline_average)
start_index = dict_onset[event_name]['start'][i] - baseline_length
stop_index = physio_df.index[-1]
# print(start_index, stop_index)
physio_df.loc[start_index:stop_index,'physio_eda_blcorrect'] = physio_df.loc[start_index:stop_index]['physio_eda'] - baseline_average
baseline_correct_per_trial(event_name, physio_df, dict_onset, baseline_length)
# also baseline correct the timepoints prior to the first event of interest
# TODO: downsample before saving
resamp = nk.signal_resample(
Expand Down Expand Up @@ -420,6 +390,39 @@ def main():
}
logger.info("__________________ :+: FINISHED :+: __________________\n")

def baseline_correct_per_trial(event_name, physio_df, dict_onset, baseline_length):
for i in range(len(dict_onset[event_name]['start'])):
if i == 0:
baseline_average = []
baseline_start_ind = dict_onset[event_name]['start'][i] - baseline_length
baseline_stop_ind = dict_onset[event_name]['start'][i]
baseline_average = physio_df.loc[baseline_start_ind:baseline_stop_ind]['physio_eda'].mean()
# print(baseline_average)
start_index = physio_df.index[0]
stop_index = dict_onset[event_name]['start'][i+1] - baseline_length
# print(start_index, stop_index)
physio_df.loc[start_index:stop_index,'physio_eda_blcorrect'] = physio_df.loc[start_index:stop_index]['physio_eda'] - baseline_average
elif i < len(dict_onset[event_name]['start'])-1:
baseline_average = []
baseline_start_ind = dict_onset[event_name]['start'][i] - baseline_length
baseline_stop_ind = dict_onset[event_name]['start'][i]
baseline_average = physio_df.loc[baseline_start_ind:baseline_stop_ind]['physio_eda'].mean()
# print(baseline_average)
start_index = dict_onset[event_name]['start'][i] - baseline_length
stop_index = dict_onset[event_name]['start'][i+1] - baseline_length
# print(start_index, stop_index)
physio_df.loc[start_index:stop_index,'physio_eda_blcorrect'] = physio_df.loc[start_index:stop_index]['physio_eda'] - baseline_average
elif i == len(dict_onset[event_name]['start'])-1:
baseline_average = []
baseline_start_ind = dict_onset[event_name]['start'][i] - baseline_length
baseline_stop_ind = dict_onset[event_name]['start'][i]
baseline_average = physio_df.loc[baseline_start_ind:baseline_stop_ind]['physio_eda'].mean()
# print(baseline_average)
start_index = dict_onset[event_name]['start'][i] - baseline_length
stop_index = physio_df.index[-1]
# print(start_index, stop_index)
physio_df.loc[start_index:stop_index,'physio_eda_blcorrect'] = physio_df.loc[start_index:stop_index]['physio_eda'] - baseline_average

# %% -------------------------------------------------------------------
# argparse parameters
# ----------------------------------------------------------------------
Expand Down

0 comments on commit 1b0dc1a

Please sign in to comment.