Skip to content

Fix: ensure max_num_event a integer to avoid index error#61

Open
Jiaxi-Huang wants to merge 1 commit intoAI4EPS:mainfrom
Jiaxi-Huang:main
Open

Fix: ensure max_num_event a integer to avoid index error#61
Jiaxi-Huang wants to merge 1 commit intoAI4EPS:mainfrom
Jiaxi-Huang:main

Conversation

@Jiaxi-Huang
Copy link

when execute example_fastapi.ipynb in docs folder as tutorial

from app import run_gamma

config["region"] = "Ridgecrest"
config["event_index"] = 1

picks_ = picks.copy()
evengts_, picks_ = run_gamma(picks, stations, config)

meet error like

TypeError Traceback (most recent call last) Cell In[12], line 7 4 config["event_index"] = 1 6 picks_ = picks.copy() ----> 7 evengts_, picks_ = run_gamma(picks, stations, config) 9 plt.figure() 10 mapping_color = lambda x: f"C{x}" if x!= -1 else "black"

File ~/Code/LX/814-918/phase_associator/GaMMA/docs/app.py:134, in run_gamma(picks, stations, config_) 129 stations[["x(km)", "y(km)"]] = stations.apply( 130 lambda x: pd.Series(proj(longitude=x.longitude, latitude=x.latitude)), axis=1 131 ) 132 stations["z(km)"] = stations["elevation_m"].apply(lambda x: -x / 1e3) --> 134 events, assignments = association(picks, stations, config, 0, config["method"]) 136 if events is None: 137 return None, None

File ~/Code/LX/814-918/.venv/lib/python3.9/site-packages/gamma/utils.py:204, in association(picks, stations, config, event_idx0, method, **kwargs) 202 events, assignment = [], [] 203 for unique_label in list(unique_labels): --> 204 events_, assignment_ = associate( 205 unique_label, 206 labels, 207 data, 208 locs, 209 phase_type, 210 phase_weight, 211 pick_idx, 212 pick_station_id, 213 config, 214 timestamp0, 215 vel, 216 method, 217 event_idx, 218 ) 219 event_idx += len(events_) 220 events.extend(events_)

File ~/Code/LX/814-918/.venv/lib/python3.9/site-packages/gamma/utils.py:315, in associate(k, labels, data, locs, phase_type, phase_weight, pick_idx, pick_station_id, config, timestamp0, vel, method, event_idx, lock) 308 return [], [] 310 # time_range = max(data_[:, 0].max() - data_[:, 0].min(), 1) 311 # if config["use_amplitude"]: 312 # amp_range = max(data_[:, 1].max() - data_[:, 1].min(), 1) 313 314 # ## initialization with [1,1,1] horizontal points and N time points --> 315 centers_init = init_centers(config, data_, locs_, phase_type_, phase_weight_, max_num_event) 317 ## run clustering 318 # mean_precision_prior = 0.01 / time_range 319 if "covariance_prior" in config:

File ~/Code/LX/814-918/.venv/lib/python3.9/site-packages/gamma/utils.py:621, in init_centers(config, data_, locs_, type_, weight_, max_num_event) 619 s_index = index[type_ == "s"] 620 if len(p_index) >= max_num_event: --> 621 index = p_index[:: max(len(p_index) // max_num_event, 1)][:max_num_event] 622 else: 623 num = max_num_event - len(p_index)

TypeError: slice indices must be integers or None or have an index method

we notice that it is a error caused by non-integer index, so add one line print(max_num_event) and we got float num 16.0. So I guess it is supposed to transform int(max_num_event) as integer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant