Skip to content

Commit

Permalink
update fastapi
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuwq0 committed Aug 18, 2024
1 parent 2c97a93 commit b5fbb6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@app.get("/")
def greet_json():
return {"message": "Hello, World!"}
return {"message": "Hello, GaMMA!"}


@app.post("/predict/")
Expand All @@ -20,10 +20,12 @@ def predict(picks: dict, stations: dict, config: dict):
picks["phase_time"] = pd.to_datetime(picks["phase_time"])
stations = pd.DataFrame(stations)
events_, picks_ = run_gamma(picks, stations, config)
picks_ = picks_.to_dict(orient="records")
if events_ is None:
return {"events": None, "picks": picks_}
events_ = events_.to_dict(orient="records")
picks_ = picks_.to_dict(orient="records")

return {"picks": picks_, "events": events_}
return {"events": events_, "picks": picks_}


def set_config(region="ridgecrest"):
Expand Down Expand Up @@ -123,14 +125,17 @@ def run_gamma(picks, stations, config_):
"phase_amplitude": "amp",
}
)
stations = stations.rename(columns={"station_id": "id"})
stations[["x(km)", "y(km)"]] = stations.apply(
lambda x: pd.Series(proj(longitude=x.longitude, latitude=x.latitude)), axis=1
)
stations["z(km)"] = stations["elevation_m"].apply(lambda x: -x / 1e3)
stations = stations.rename(columns={"station_id": "id"})

events, assignments = association(picks, stations, config, 0, config["method"])

if events is None:
return None, None

events = pd.DataFrame(events)
events[["longitude", "latitude"]] = events.apply(
lambda x: pd.Series(proj(longitude=x["x(km)"], latitude=x["y(km)"], inverse=True)), axis=1
Expand Down
1 change: 1 addition & 0 deletions docs/example_fastapi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,7 @@
"config[\"region\"] = \"Ridgecrest\"\n",
"config[\"event_index\"] = 1\n",
"\n",
"picks_ = picks.copy()\n",
"evengts_, picks_ = run_gamma(picks, stations, config)\n",
"\n",
"plt.figure()\n",
Expand Down

0 comments on commit b5fbb6f

Please sign in to comment.