update
Browse files- Dockerfile +4 -0
- app.py +0 -155
Dockerfile
CHANGED
|
@@ -12,5 +12,9 @@ WORKDIR /app
|
|
| 12 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
COPY --chown=user . /app
|
| 16 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 12 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 14 |
|
| 15 |
+
RUN git clone https://github.com/AI4EPS/GaMMA.git
|
| 16 |
+
RUN pip install --no-cache-dir -e GaMMA
|
| 17 |
+
WORKDIR /app/GaMMA
|
| 18 |
+
|
| 19 |
COPY --chown=user . /app
|
| 20 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
DELETED
|
@@ -1,155 +0,0 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
from fastapi import FastAPI
|
| 3 |
-
from pyproj import Proj
|
| 4 |
-
|
| 5 |
-
from gamma.utils import association
|
| 6 |
-
|
| 7 |
-
app = FastAPI()
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
@app.get("/")
|
| 11 |
-
def greet_json():
|
| 12 |
-
return {"message": "Hello, World!"}
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
@app.post("/predict/")
|
| 16 |
-
def predict(picks: dict, stations: dict, config: dict):
|
| 17 |
-
picks = picks["data"]
|
| 18 |
-
stations = stations["data"]
|
| 19 |
-
picks = pd.DataFrame(picks)
|
| 20 |
-
picks["phase_time"] = pd.to_datetime(picks["phase_time"])
|
| 21 |
-
stations = pd.DataFrame(stations)
|
| 22 |
-
print(stations)
|
| 23 |
-
events_, picks_ = run_gamma(picks, stations, config)
|
| 24 |
-
picks_ = picks_.to_dict(orient="records")
|
| 25 |
-
events_ = events_.to_dict(orient="records")
|
| 26 |
-
|
| 27 |
-
return {"picks": picks_, "events": events_}
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
def set_config(region="ridgecrest"):
|
| 31 |
-
|
| 32 |
-
config = {
|
| 33 |
-
"min_picks": 8,
|
| 34 |
-
"min_picks_ratio": 0.2,
|
| 35 |
-
"max_residual_time": 1.0,
|
| 36 |
-
"max_residual_amplitude": 1.0,
|
| 37 |
-
"min_score": 0.6,
|
| 38 |
-
"min_s_picks": 2,
|
| 39 |
-
"min_p_picks": 2,
|
| 40 |
-
"use_amplitude": False,
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
# ## Domain
|
| 44 |
-
if region.lower() == "ridgecrest":
|
| 45 |
-
config.update(
|
| 46 |
-
{
|
| 47 |
-
"region": "ridgecrest",
|
| 48 |
-
"minlongitude": -118.004,
|
| 49 |
-
"maxlongitude": -117.004,
|
| 50 |
-
"minlatitude": 35.205,
|
| 51 |
-
"maxlatitude": 36.205,
|
| 52 |
-
"mindepth_km": 0.0,
|
| 53 |
-
"maxdepth_km": 30.0,
|
| 54 |
-
}
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
lon0 = (config["minlongitude"] + config["maxlongitude"]) / 2
|
| 58 |
-
lat0 = (config["minlatitude"] + config["maxlatitude"]) / 2
|
| 59 |
-
proj = Proj(f"+proj=sterea +lon_0={lon0} +lat_0={lat0} +units=km")
|
| 60 |
-
xmin, ymin = proj(config["minlongitude"], config["minlatitude"])
|
| 61 |
-
xmax, ymax = proj(config["maxlongitude"], config["maxlatitude"])
|
| 62 |
-
zmin, zmax = config["mindepth_km"], config["maxdepth_km"]
|
| 63 |
-
xlim_km = (xmin, xmax)
|
| 64 |
-
ylim_km = (ymin, ymax)
|
| 65 |
-
zlim_km = (zmin, zmax)
|
| 66 |
-
|
| 67 |
-
config.update(
|
| 68 |
-
{
|
| 69 |
-
"xlim_km": xlim_km,
|
| 70 |
-
"ylim_km": ylim_km,
|
| 71 |
-
"zlim_km": zlim_km,
|
| 72 |
-
"proj": proj,
|
| 73 |
-
}
|
| 74 |
-
)
|
| 75 |
-
|
| 76 |
-
config.update(
|
| 77 |
-
{
|
| 78 |
-
"min_picks_per_eq": 5,
|
| 79 |
-
"min_p_picks_per_eq": 0,
|
| 80 |
-
"min_s_picks_per_eq": 0,
|
| 81 |
-
"max_sigma11": 3.0,
|
| 82 |
-
"max_sigma22": 1.0,
|
| 83 |
-
"max_sigma12": 1.0,
|
| 84 |
-
}
|
| 85 |
-
)
|
| 86 |
-
|
| 87 |
-
config["use_dbscan"] = False
|
| 88 |
-
config["use_amplitude"] = True
|
| 89 |
-
config["oversample_factor"] = 8.0
|
| 90 |
-
config["dims"] = ["x(km)", "y(km)", "z(km)"]
|
| 91 |
-
config["method"] = "BGMM"
|
| 92 |
-
config["ncpu"] = 1
|
| 93 |
-
vel = {"p": 6.0, "s": 6.0 / 1.75}
|
| 94 |
-
config["vel"] = vel
|
| 95 |
-
|
| 96 |
-
config["bfgs_bounds"] = (
|
| 97 |
-
(xlim_km[0] - 1, xlim_km[1] + 1), # x
|
| 98 |
-
(ylim_km[0] - 1, ylim_km[1] + 1), # y
|
| 99 |
-
(0, zlim_km[1] + 1), # z
|
| 100 |
-
(None, None), # t
|
| 101 |
-
)
|
| 102 |
-
|
| 103 |
-
config["event_index"] = 0
|
| 104 |
-
|
| 105 |
-
return config
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
config = set_config()
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
def run_gamma(picks, stations, config_):
|
| 112 |
-
|
| 113 |
-
# %%
|
| 114 |
-
config.update(config_)
|
| 115 |
-
|
| 116 |
-
proj = config["proj"]
|
| 117 |
-
|
| 118 |
-
picks = picks.rename(
|
| 119 |
-
columns={
|
| 120 |
-
"station_id": "id",
|
| 121 |
-
"phase_time": "timestamp",
|
| 122 |
-
"phase_type": "type",
|
| 123 |
-
"phase_score": "prob",
|
| 124 |
-
"phase_amplitude": "amp",
|
| 125 |
-
}
|
| 126 |
-
)
|
| 127 |
-
stations[["x(km)", "y(km)"]] = stations.apply(
|
| 128 |
-
lambda x: pd.Series(proj(longitude=x.longitude, latitude=x.latitude)), axis=1
|
| 129 |
-
)
|
| 130 |
-
stations["z(km)"] = stations["elevation_m"].apply(lambda x: -x / 1e3)
|
| 131 |
-
stations = stations.rename(columns={"station_id": "id"})
|
| 132 |
-
|
| 133 |
-
events, assignments = association(picks, stations, config, 0, config["method"])
|
| 134 |
-
|
| 135 |
-
print(events)
|
| 136 |
-
events = pd.DataFrame(events)
|
| 137 |
-
events[["longitude", "latitude"]] = events.apply(
|
| 138 |
-
lambda x: pd.Series(proj(longitude=x["x(km)"], latitude=x["y(km)"], inverse=True)), axis=1
|
| 139 |
-
)
|
| 140 |
-
events["depth_km"] = events["z(km)"]
|
| 141 |
-
events.drop(columns=["x(km)", "y(km)", "z(km)"], inplace=True, errors="ignore")
|
| 142 |
-
picks = picks.rename(
|
| 143 |
-
columns={
|
| 144 |
-
"id": "station_id",
|
| 145 |
-
"timestamp": "phase_time",
|
| 146 |
-
"type": "phase_type",
|
| 147 |
-
"prob": "phase_score",
|
| 148 |
-
"amp": "phase_amplitude",
|
| 149 |
-
}
|
| 150 |
-
)
|
| 151 |
-
|
| 152 |
-
assignments = pd.DataFrame(assignments, columns=["pick_index", "event_index", "gamma_score"])
|
| 153 |
-
picks = picks.join(assignments.set_index("pick_index")).fillna(-1).astype({"event_index": int})
|
| 154 |
-
|
| 155 |
-
return events, picks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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