Skip to content
Snippets Groups Projects
Commit 9dc048b5 authored by Marius Kriegerowski's avatar Marius Kriegerowski
Browse files

update

parent 340b1dae
Branches feature/docker
No related tags found
No related merge requests found
Pipeline #51726 failed
......@@ -17,12 +17,13 @@ RUN wget https://earthquake.usgs.gov/static/lfs/data/global_vs30_grd.zip && unzi
WORKDIR /src/
COPY requirements.txt /src/
RUN pip3 install numpy==1.18
RUN pip3 install -r /src/requirements.txt
COPY . /src/
# This will pull in a newer version of numpy. Pip will complain but accept this.
RUN pip3 install --upgrade numpy
#RUN pip3 install --upgrade numpy
ENV VS30PATH="/data/global_vs30.grd"
......
......@@ -25,8 +25,7 @@ async def request_api():
# localhost, port 8082. You can request the available IMTs and GMPEs
# with a GET request against: <hostname>:<port>/[imts|gmpes]
url = "http://localhost:8082/shakemap"
async with session.post(url, data=str(data_quakeml),
params=params) as resp:
async with session.post(url, data=str(data_quakeml), params=params) as resp:
data = await resp.json()
......
obspy~=1.2
pandas
obspy==1.2.2
pandas==1.0
aiopg==1.3.3
postgis==1.0.4
psycopg2==2.9.2
......@@ -19,7 +19,7 @@ docutils==0.14
filelock==3.0.12
idna==2.8
kiwisolver==1.1.0
matplotlib
matplotlib<3.2
multidict==4.5.2
openquake.engine~=3.10.1
pipenv==2021.5.29
......@@ -28,7 +28,7 @@ psutil==5.6.5
pyparsing==2.4.5
pyshp==1.2.3
python-dateutil==2.8.1
pytz==2019.3
pytz==2020.1
six==1.16.0
virtualenv==20.7.2
virtualenv-clone==0.5.7
......@@ -11,7 +11,7 @@ import shakemap_lite as sml
import json
import logging
import inspect
import numpy as num
logger = logging.getLogger("API")
......@@ -65,10 +65,30 @@ async def handle_shakemap(request):
kwargs = ensure_type(sm_process.process, query)
loop = asyncio.get_event_loop()
geojson = await loop.run_in_executor(
return_format = kwargs.pop("return_format", "contour")
logger.info(f"want return_format: {return_format}")
lats, lons, shakemap_data = await loop.run_in_executor(
None, sm_process.process, *tuple(kwargs.values())
)
if return_format == "grid":
geojson = {
"lats": lats.tolist(),
"lons": lons.tolist(),
"values": shakemap_data.tolist(),
}
elif return_format == "contour":
geojson = sm_process.to_contour(
shakemap_data,
num.unique(lats),
num.unique(lons),
)
geojson = sm_process.polygons_to_geojson(geojson)
else:
raise Exception(f"Unknown return_format {return_format}")
# try:
# building_shaking = await sm_process.building_count(geojson)
# except Exception as e:
......
......@@ -67,11 +67,9 @@ def to_contour(data, lats, lons):
def process(
event: sml.Event, gmpe: str, imt: str, margin: float = 3, format: str = "contour"
event: sml.Event, gmpe: str, imt: str, margin: float = 3
):
assert format in ("contour", "grid"), "format has to be either contour or grid"
lon_min = event.lon - margin
lat_min = event.lat - margin
lon_max = event.lon + margin
......@@ -102,20 +100,7 @@ def process(
lons = sites["lon"]
lats = sites["lat"]
if format == "grid":
return {
"lats": lats.tolist(),
"lons": lons.tolist(),
"values": shakemap_data.tolist(),
}
elif format == "contour":
polygons = to_contour(
shakemap_data,
num.unique(lats),
num.unique(lons),
)
return polygons_to_geojson(polygons)
return lats, lons, shakemap_data
async def building_count(geojson, dbname="obm_cologne"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment