Commit 0199da2d authored by Marius Kriegerowski's avatar Marius Kriegerowski
Browse files

Merge branch 'feature/example' into dev

parents ecc30236 d6a5e477
......@@ -11,7 +11,7 @@ RUN wget https://earthquake.usgs.gov/static/lfs/data/global_vs30_grd.zip && unzi
WORKDIR /src/
COPY . /src/
RUN pip3 install -r /src/requirements.txt --use-feature=2020-resolver
RUN pip3 install -r /src/requirements.txt --use-feature=2020-resolver
ENV VS30PATH="/data/global_vs30.grd"
......
import asyncio
import aiohttp
import matplotlib.pyplot as plt
import numpy as num
import json
import os
async def request_api():
# Read the event data from a quakeml formatted file.
with open("event.quakeml", "r") as f:
data_quakeml = f.read()
params = {
"gmpe": "BindiEtAl2014Rjb", # Ground motion prediction equation
"imt": "PGA", # Intensity measure type
"format": "grid" # select 'grid' for regular spaced data
# or 'contour' for contour data in GeoJSON format.
}
session = aiohttp.ClientSession()
# Post the data and the params against the api, assuming it runs on
# 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:
data = await resp.json()
data = json.loads(data)
# Plotting the data
plt.figure()
lats = data["lats"]
lons = data["lons"]
values = num.array(data["values"])
plt.scatter(lats, lons, values)
plt.show()
if __name__ == "__main__":
asyncio.run(request_api())
......@@ -19,10 +19,12 @@ from openquake.hazardlib.contexts import (ContextMaker, get_distances,
SitesContext, DistancesContext)
from openquake.hazardlib.source.rupture import ParametricProbabilisticRupture
from openquake.hazardlib import const
import synthetic_rupture_generator as srg
from obspy.io import quakeml
from obspy.io.quakeml.core import Unpickler
from openquake.hazardlib.geo import NodalPlane
import synthetic_rupture_generator as srg
GSIM_SET = get_available_gsims()
# IMT_SET = ['ASH', 'AvgSA', 'CAV', 'IA', 'IMT', 'LAHAR', 'LAVA',
......@@ -98,8 +100,9 @@ def vs30_to_z1pt0_cy14(vs30, japan=False):
if japan:
c1 = 412. ** 2.
c2 = 1360.0 ** 2.
return np.exp((-5.23 / 2.0) *
np.log((np.power(vs30, 2.) + c1) / (c2 + c1)))
return np.exp((-5.23 / 2.0) * np.log(
(np.power(vs30, 2.) + c1) / (c2 + c1)))
else:
c1 = 571 ** 4.
c2 = 1360.0 ** 4.
......@@ -200,14 +203,14 @@ class Event(object):
mag = mt.magnitude
strike, dip, rake = (mt.strike1, mt.dip1, mt.rake1)
return cls(id=pyrocko_event.name, lon=pyrocko_event.lon, lat=pyrocko_event.lat,
return cls(id=pyrocko_event.name,
lon=pyrocko_event.lon, lat=pyrocko_event.lat,
hypo_depth=pyrocko_event.depth / 1000.,
mag=mag, strike=strike, dip=dip, rake=rake)
@classmethod
def parse_quakeml(cls, data):
events = quakeml.core.Unpickler().loads(data.encode()).events
events = Unpickler().loads(data.encode()).events
assert len(events) == 1
event = events[0]
......@@ -230,7 +233,7 @@ class Event(object):
lon=origin.longitude,
hypo_depth=origin.depth / 1000.,
mag=mag,
**extra_kwargs,
**extra_kwargs
)
def get_rupture(self):
......@@ -239,7 +242,7 @@ class Event(object):
use a synthetic rupture generator
"""
if self.rupture is not None:
return self.rupture
return self.rupture
npd = NodalPlane(self.strike, self.dip, self.rake)
weight = 1
......
......@@ -31,7 +31,7 @@ async def request_api():
queries = [{'imt': imt, 'gmpe': gmpe}
for imt in imts['imts'] for gmpe in gmpes['gmpes']]
with open('example2.quakeml', 'r') as f:
with open('../examples/event.quakeml', 'r') as f:
data_quakeml = f.read()
tasks = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment