Skip to content

Commit

Permalink
Merge pull request #9762 from gem/gh
Browse files Browse the repository at this point in the history
Added more debugging utilities
  • Loading branch information
micheles authored Jun 7, 2024
2 parents 6feb688 + ccb7a13 commit 87397b4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[Michele Simionato]
* Internal: added utility `oq info geohash:<lon>,<lat>`
* Changed the scenario calculators to discard the sites far away from
the rupture, with the effect of generating different GMFs
* Cached `get_realizations` and optimized the memory occupation; now
Expand Down
10 changes: 0 additions & 10 deletions openquake/calculators/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1678,16 +1678,6 @@ def compare_disagg_rates(token, dstore):
).sort_values(['imt', 'src'])



@view.add('geohash')
def view_geohash(token, dstore):
lon_lat = token.split(':')[1]
lon, lat = valid.lon_lat(lon_lat)
arr = geo.utils.CODE32[geo.utils.geohash(F32([lon]), F32([lat]), U8(8))]
gh = b''.join([row.tobytes() for row in arr])
return gh.decode('ascii')


@view.add('gh3')
def view_gh3(token, dstore):
sitecol = dstore['sitecol']
Expand Down
26 changes: 21 additions & 5 deletions openquake/commands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@
from openquake.baselib import config
from openquake.baselib.general import groupby, gen_subclasses, humansize
from openquake.baselib.performance import Monitor
from openquake.hazardlib import gsim, nrml, imt, logictree, site
from openquake.hazardlib import nrml, imt, logictree, site, geo
from openquake.hazardlib.gsim.base import registry
from openquake.hazardlib.mfd.base import BaseMFD
from openquake.hazardlib.scalerel.base import BaseMSR
from openquake.hazardlib.source.base import BaseSeismicSource
from openquake.hazardlib.valid import pmf_map
from openquake.hazardlib.valid import pmf_map, lon_lat
from openquake.commonlib.oqvalidation import OqParam
from openquake.commonlib import readinput, logs
from openquake.risklib import scientific
from openquake.risklib import asset, scientific
from openquake.calculators.export import export
from openquake.calculators.extract import extract
from openquake.calculators import base, reportwriter
from openquake.calculators.views import view, text_table
from openquake.calculators.export import DISPLAY_NAME

F32 = numpy.float32
U8 = numpy.uint8

def print_features(fiona_file):
rows = []
Expand Down Expand Up @@ -121,6 +123,13 @@ def print_gsim(what):
print('Unknown GSIM %s' % split[1])


def print_geohash(what):
lon, lat = lon_lat(what.split(':')[1])
arr = geo.utils.CODE32[geo.utils.geohash(F32([lon]), F32([lat]), U8(8))]
gh = b''.join([row.tobytes() for row in arr])
print(gh.decode('ascii'))


def source_model_info(sm_nodes):
"""
Extract information about source models. Returns a table
Expand Down Expand Up @@ -237,6 +246,8 @@ def main(what, report=False):
print_subclass(what, BaseMFD)
elif what.startswith('msr'):
print_subclass(what, BaseMSR)
elif what.startswith('geohash'):
print_geohash(what)
elif what == 'venv':
print(sys.prefix)
elif what == 'cfg':
Expand Down Expand Up @@ -274,9 +285,14 @@ def main(what, report=False):
print(mon)
elif what.endswith('.xml'):
node = nrml.read(what)
if node[0].tag.endswith('sourceModel'):
tag = node[0].tag
if tag.endswith('sourceModel'):
print(source_model_info([node]))
elif node[0].tag.endswith('logicTree'):
elif tag.endswith('exposureModel'):
exp, df = asset.read_exp_df(what)
print(node.to_str())
print(df.set_index('id')[['lon', 'lat', 'taxonomy', 'value-structural']])
elif tag.endswith('logicTree'):
bset = node[0][0]
if bset.tag.endswith("logicTreeBranchingLevel"):
bset = bset[0]
Expand Down
5 changes: 2 additions & 3 deletions openquake/commonlib/readinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ def get_site_model(oqparam, h5=None):

fnames = oqparam.inputs['site_model']
if oqparam.aristotle:
# read the site model close to the rupture
rup = get_rupture(oqparam)
# global site model close to the rupture
dist = oqparam.maximum_distance('*')(rup.mag)
return get_site_model_around(fnames[0], rup, dist)

Expand Down Expand Up @@ -1025,8 +1025,7 @@ def get_exposure(oqparam, h5=None):
fnames = oq.inputs['exposure']
with Monitor('reading exposure', measuremem=True, h5=h5):
if oqparam.aristotle:
# reading the assets around a rupture
sm = get_site_model(oq)
sm = get_site_model(oq) # the site model around the rupture
gh3 = numpy.array(sorted(set(geohash3(sm['lon'], sm['lat']))))
exposure = asset.Exposure.read_around(
fnames[0], gh3, oqparam.countries)
Expand Down
5 changes: 5 additions & 0 deletions openquake/risklib/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,11 @@ def _read_csv(self, errors=None):
for fname in self.datafiles:
t0 = time.time()
df = hdf5.read_csv(fname, conv, rename, errors=errors, index='id')
asset = os.environ.get('OQ_DEBUG_ASSET')
if asset:
df = df[df.index == asset]
if len(df) == 0:
continue
add_dupl_fields(df, oqfields)
df['lon'] = numpy.round(df.lon, 5)
df['lat'] = numpy.round(df.lat, 5)
Expand Down

0 comments on commit 87397b4

Please sign in to comment.