zhuwq0 commited on
Commit
a51c4e8
·
1 Parent(s): 47e65a0
Files changed (1) hide show
  1. app.py +15 -25
app.py CHANGED
@@ -12,7 +12,7 @@ from pyproj import Proj
12
  app = FastAPI()
13
 
14
  PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
15
- STATION_CSV = os.path.join(PROJECT_ROOT, "tests/stations_hawaii.csv")
16
  # STATION_CSV = os.path.join(PROJECT_ROOT, "tests/stations.csv") ## ridgecrest
17
 
18
 
@@ -57,14 +57,14 @@ config["bfgs_bounds"] = [list(config[x]) for x in config["dims"]] + [[None, None
57
  for k, v in config.items():
58
  print(f"{k}: {v}")
59
 
60
- ## read stations
61
- stations = pd.read_csv(STATION_CSV, delimiter="\t")
62
- stations = stations.rename(columns={"station": "id"})
63
- stations["x(km)"] = stations["longitude"].apply(lambda x: (x - config["center"][0]) * config["degree2km"])
64
- stations["y(km)"] = stations["latitude"].apply(lambda x: (x - config["center"][1]) * config["degree2km"])
65
- stations["z(km)"] = stations["elevation(m)"].apply(lambda x: -x / 1e3)
66
 
67
- print(stations)
68
 
69
 
70
  class Data(BaseModel):
@@ -105,21 +105,16 @@ def run_gamma(picks, config, stations):
105
  return catalogs, picks_gamma
106
 
107
 
108
- @app.post("/predict_stream")
109
- def predict(data: Pick):
110
 
111
- picks = pd.DataFrame(data.picks)
112
- if len(picks) == 0:
113
- return {"catalog": [], "picks": []}
114
 
115
- catalogs, picks_gamma = run_gamma(data, config, stations)
116
 
117
- if use_kafka:
118
- print("Push events to kafka...")
119
- for event in catalogs.to_dict(orient="records"):
120
- producer.send("gmma_events", key=event["time"], value=event)
121
-
122
- return {"catalog": catalogs.to_dict(orient="records"), "picks": picks_gamma.to_dict(orient="records")}
123
 
124
 
125
  @app.post("/predict")
@@ -161,11 +156,6 @@ def predict(data: Data):
161
 
162
  catalogs, picks_gamma = run_gamma(picks, config, stations)
163
 
164
- if use_kafka:
165
- print("Push events to kafka...")
166
- for event in catalogs.to_dict(orient="records"):
167
- producer.send("gamma_events", key=event["time"], value=event)
168
-
169
  return {"catalog": catalogs.to_dict(orient="records"), "picks": picks_gamma.to_dict(orient="records")}
170
 
171
 
 
12
  app = FastAPI()
13
 
14
  PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
15
+ # STATION_CSV = os.path.join(PROJECT_ROOT, "tests/stations_hawaii.csv")
16
  # STATION_CSV = os.path.join(PROJECT_ROOT, "tests/stations.csv") ## ridgecrest
17
 
18
 
 
57
  for k, v in config.items():
58
  print(f"{k}: {v}")
59
 
60
+ # ## read stations
61
+ # stations = pd.read_csv(STATION_CSV, delimiter="\t")
62
+ # stations = stations.rename(columns={"station": "id"})
63
+ # stations["x(km)"] = stations["longitude"].apply(lambda x: (x - config["center"][0]) * config["degree2km"])
64
+ # stations["y(km)"] = stations["latitude"].apply(lambda x: (x - config["center"][1]) * config["degree2km"])
65
+ # stations["z(km)"] = stations["elevation(m)"].apply(lambda x: -x / 1e3)
66
 
67
+ # print(stations)
68
 
69
 
70
  class Data(BaseModel):
 
105
  return catalogs, picks_gamma
106
 
107
 
108
+ # @app.post("/predict_stream")
109
+ # def predict(data: Pick):
110
 
111
+ # picks = pd.DataFrame(data.picks)
112
+ # if len(picks) == 0:
113
+ # return {"catalog": [], "picks": []}
114
 
115
+ # catalogs, picks_gamma = run_gamma(data, config, stations)
116
 
117
+ # return {"catalog": catalogs.to_dict(orient="records"), "picks": picks_gamma.to_dict(orient="records")}
 
 
 
 
 
118
 
119
 
120
  @app.post("/predict")
 
156
 
157
  catalogs, picks_gamma = run_gamma(picks, config, stations)
158
 
 
 
 
 
 
159
  return {"catalog": catalogs.to_dict(orient="records"), "picks": picks_gamma.to_dict(orient="records")}
160
 
161