Skip to content

Commit

Permalink
Fix nans (#512)
Browse files Browse the repository at this point in the history
* change index for start and stop task timestamp

* bug fix

* change delimter type

* increase end index by 2_This change was for Eric to fix the issue he encountered during interpolation._ 

Updates:
1. Made sure all exports use ";" as seperator.
2. Changed index of event markers by -2 before event start and +2 after event ended. 

* update v2 script
  • Loading branch information
CalebUAz authored Jul 10, 2023
1 parent 40ee113 commit d5c174b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def check_cv(
list(zip(channels, cv_vals, channel_good_or_bad)),
columns=["Channels", "coeff_of_var", "status"],
)
df.to_csv(new_csv_file_path + "/" + "NIRS_channel_quality.csv", index=False)
df.to_csv(new_csv_file_path + "/" + "NIRS_channel_quality.csv", sep=";",index=False)


def filter_NIRS(data):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def utc_time_ns(seconds):


def create_time_distribution(data):
time_distribution_unix_list.append(temp)
# time_distribution_unix_list.append(temp)
time_distribution_unix_list = data["time_stamps"]

ctime_list = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def get_timestamps_from_dict(
state_end = df_temp.index[
iloc_idx_end
] # reduce index by 1 as the index sometimes overflows
range_ = list(range(state_start, state_end))
state_start, state_end = state_start-1, state_end+2 # Increase start and stop state by 1 to avoid NaNs for data extrapolation script.
range_ = list(range(state_start, state_end))
state = [state] * len(range_)
state = {i: x for i, x in enumerate(state, state_start)}

Expand Down Expand Up @@ -542,7 +543,7 @@ def dataframe_to_csv(

# Save as CSV file
if extract_csv == True:
df_original.to_csv(new_csv_file_path + ".csv", sep="\t", encoding="utf-8")
df_original.to_csv(new_csv_file_path + ".csv", sep=";", encoding="utf-8")
print(
colored("[INFO]", "green", attrs=["bold"]),
colored("Sucessfully generated csv file at", "green", attrs=["bold"]),
Expand All @@ -552,7 +553,7 @@ def dataframe_to_csv(
if bool(filter) == True and stream_type == "NIRS":
df_final_filtered = filter_NIRS(df_final)
df_final_filtered.to_csv(
new_csv_file_path + "_filtered" + ".csv", sep="\t", encoding="utf-8"
new_csv_file_path + "_filtered" + ".csv", sep=";", encoding="utf-8"
)
print(
colored("[INFO]", "green", attrs=["bold"]),
Expand All @@ -567,7 +568,7 @@ def dataframe_to_csv(
if bool(filter) == True and stream_type == "EEG":
df_final_filtered = filter_EEG(df_final)
df_final_filtered.to_csv(
new_csv_file_path + "_filtered" + ".csv", sep="\t", encoding="utf-8"
new_csv_file_path + "_filtered" + ".csv", sep=";", encoding="utf-8"
)
print(
colored("[INFO]", "green", attrs=["bold"]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ def update_state(block, state, start_time, end_time):
try:
start_index = block["unix_time"].searchsorted(start_time)
end_index = block["unix_time"].searchsorted(end_time)
start_index, end_index = start_index-2, end_index+2
block.loc[start_index:end_index, "event_type"] = state
except KeyError as e:
print(f"KeyError: {e} in update_state function")
Expand Down

0 comments on commit d5c174b

Please sign in to comment.