File size: 1,230 Bytes
524a318 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 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
|