From db3e1916c314a9dc0b33fa8943cc67988ca7a6a5 Mon Sep 17 00:00:00 2001 From: wanghaoyu Date: Wed, 30 Jul 2025 16:25:04 +0800 Subject: [PATCH] fix column name error --- scripts/run_event_association.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/run_event_association.py b/scripts/run_event_association.py index e788f88..d02336a 100644 --- a/scripts/run_event_association.py +++ b/scripts/run_event_association.py @@ -189,7 +189,7 @@ def process_group(group): event = group.copy() event = event[event['event_index'] != -1] # Filter out events with event_index == -1 if len(event) == 0: - return pd.DataFrame(columns=phase_picks.columns) + return phase_picks.iloc[0:0] # Return empty DataFrame if no valid events station_id = event['station_id'].iloc[0] # The station_id for this group # travel time tt = (tp + ts) / 2 = (1 + ps_ratio)/2 * tp => tp = tt * 2 / (1 + ps_ratio) @@ -207,8 +207,8 @@ def process_group(group): picks_for_station = phase_picks.loc[station_id].copy() # or picks.loc[station_id].copy() #picks.loc[station_id].copy() except KeyError: - # If no picks for this station, just return empty or do nothing - return pd.DataFrame(columns=phase_picks.columns) + # If no picks for this station, just return empty DataFrame + return phase_picks.iloc[0:0] # Return empty DataFrame if no picks for this station # We have shape (n_events, ) and picks_for_station has shape (n_picks_for_station, ...). # Let's match them up by broadcast. @@ -232,6 +232,9 @@ def process_group(group): updated_picks_list = event_picks.groupby("station_id").parallel_apply(process_group) updated_picks_list.index = updated_picks_list.index.droplevel(0) updated_picks_list = updated_picks_list.reset_index() + if 'index' in updated_picks_list.columns: + # rename the 'index' column to 'station_id' + updated_picks_list.rename(columns={'index': 'station_id'}, inplace=True) return updated_picks_list