Download scripts/utils.py from sammlapp/Alberta_SBT_2016_REVI_Localized: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/datasets/sammlapp/Alberta_SBT_2016_REVI_Localized/resolve/main/scripts/utils.py
- Command line
-
hf download hf://datasets/sammlapp/Alberta_SBT_2016_REVI_Localized/scripts/utils.py
-
curl -L -o utils.py https://huggingface.co/datasets/sammlapp/Alberta_SBT_2016_REVI_Localized/resolve/main/scripts/utils.py
1.23 kB
| import re | |
| import ast | |
| import pandas as pd | |
| import numpy as np | |
| def parse_list_of_lists(cell): | |
| # Replace newline characters and convert the cell string to a list of lists | |
| cell = ( | |
| re.sub(r"\s+", ",", cell.replace("\n", "")) | |
| .replace("[,", "[") | |
| .replace(",,", ",") | |
| ) | |
| # cell = cell.strip(', ') | |
| return ast.literal_eval(cell) | |
| def load_event_df(path): | |
| """load CSV containing localized events, parsing columns that contain lists""" | |
| df = pd.read_csv( | |
| path, | |
| index_col=0, | |
| converters={ | |
| "receiver_files": parse_list_of_lists, | |
| "receiver_locations": parse_list_of_lists, | |
| "tdoas": parse_list_of_lists, | |
| "cc_maxs": parse_list_of_lists, | |
| "receiver_start_time_offsets": parse_list_of_lists, | |
| "distance_residuals": parse_list_of_lists, | |
| "location_estimate": parse_list_of_lists, | |
| }, | |
| parse_dates=["start_timestamp"], | |
| ) | |
| df["residual_rms"] = np.sqrt( | |
| df["distance_residuals"].apply(lambda x: np.mean(np.square(x))) | |
| ) | |
| df["x"] = np.array(list(df.location_estimate.values))[:, 0] | |
| df["y"] = np.array(list(df.location_estimate.values))[:, 1] | |
| return df | |