Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions openquake/calculators/classical.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,15 @@ def classical(sources, tilegetters, cmaker, dstore, monitor):
yield result
return

for tileget in tilegetters:
for tileno, tileget in enumerate(tilegetters):
result = hazclassical(sources, tileget(sitecol), cmaker)
if tileno:
# source_data has keys src_id, grp_id, nsites, esites, nrupts,
# weight, ctimes, taskno
for key, lst in result['source_data'].items():
if key in ('weight', 'nrupts'):
# avoid bogus weights in `oq show task:classical`
lst[:] = [0. for _ in range(len(lst))]
if cmaker.disagg_by_src:
# do not remove zeros, otherwise AELO for JPN will break
# since there are 4 sites out of 18 with zeros
Expand All @@ -179,8 +186,6 @@ def classical(sources, tilegetters, cmaker, dstore, monitor):
# print(f"{monitor.task_no=} {rmap=}")

if rmap.size_mb and cmaker.blocks == 1 and not cmaker.disagg_by_src:
if len(tilegetters) > 1:
del result['source_data']
if config.directory.custom_tmp:
rates = rmap.to_array(cmaker.gid)
_store(rates, cmaker.num_chunks, None, monitor)
Expand Down
36 changes: 13 additions & 23 deletions openquake/calculators/preclassical.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def preclassical(srcs, sites, cmaker, secparams, monitor):
Weight the sources. Also split them if split_sources is true. If
ps_grid_spacing is set, grid the point sources before weighting them.
"""
spacing = cmaker.ps_grid_spacing
grp_id = srcs[0].grp_id
if sites:
N = len(sites)
Expand Down Expand Up @@ -137,24 +136,12 @@ def preclassical(srcs, sites, cmaker, secparams, monitor):
splits = _filter(splits, cmaker.oq.minimum_magnitude)
if splits:
mon = monitor('weighting sources', measuremem=False)
if sites is None or spacing == 0:
with mon:
cmaker.set_weight(splits, sf, multiplier)
dic = {grp_id: splits}
dic['before'] = len(srcs)
dic['after'] = len(splits)
yield dic
else:
dic = grid_point_sources(splits, spacing, monitor)
for src in dic[grp_id]:
src.num_ruptures = src.count_ruptures()
# this is also prefiltering the split sources
with mon:
cmaker.set_weight(dic[grp_id], sf, multiplier)
# print(f'{mon.task_no=}, {mon.duration=}')
dic['before'] = len(splits)
dic['after'] = len(dic[grp_id])
yield dic
with mon:
cmaker.set_weight(splits, sf, multiplier)
dic = {grp_id: splits}
dic['before'] = len(srcs)
dic['after'] = len(splits)
yield dic


def store_tiles(dstore, csm, sitecol, cmakers):
Expand Down Expand Up @@ -315,10 +302,13 @@ def _process(self, atomic_sources, normal_sources, sites, secparams):
others.append(src)
check_maxmag(pointlike)
if pointsources or pointlike:
if self.oqparam.ps_grid_spacing:
# do not split the pointsources
smap.submit((pointsources + pointlike,
sites, cmaker, secparams))
spacing = self.oqparam.ps_grid_spacing
if spacing:
for plike in pointlike:
pointsources.extend(split_source(plike))
cpsources = grid_point_sources(pointsources, spacing)
for block in block_splitter(cpsources, 200):
smap.submit((block, sites, cmaker, secparams))
else:
for block in block_splitter(pointsources, 2000):
smap.submit((block, sites, cmaker, secparams))
Expand Down
14 changes: 6 additions & 8 deletions openquake/hazardlib/source/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import copy
import numpy
from openquake.baselib.general import AccumDict, groupby_grid, Deduplicate
from openquake.baselib.performance import Monitor
from openquake.hazardlib.geo import Point, geodetic
from openquake.hazardlib.geo.nodalplane import NodalPlane
from openquake.hazardlib.geo.surface.planar import (
Expand Down Expand Up @@ -498,7 +497,7 @@ def count_ruptures(self):
for src in pdata_to_psources(self.pdata))


def grid_point_sources(sources, ps_grid_spacing, monitor=Monitor()):
def grid_point_sources(sources, ps_grid_spacing):
"""
:param sources:
a list of sources with the same grp_id (point sources and not)
Expand All @@ -511,11 +510,11 @@ def grid_point_sources(sources, ps_grid_spacing, monitor=Monitor()):
for src in sources[1:]:
assert src.grp_id == grp_id, (src.grp_id, grp_id)
if not ps_grid_spacing:
return {grp_id: sources}
return sources
out = [src for src in sources if not hasattr(src, 'location')]
ps = numpy.array([src for src in sources if hasattr(src, 'location')])
if len(ps) < 2: # nothing to collapse
return {grp_id: out + list(ps)}
return out + list(ps)
coords = numpy.zeros((len(ps), 3))
for p, psource in enumerate(ps):
coords[p, 0] = psource.location.x
Expand All @@ -524,24 +523,23 @@ def grid_point_sources(sources, ps_grid_spacing, monitor=Monitor()):
if (len(numpy.unique(coords[:, 0])) == 1 or
len(numpy.unique(coords[:, 1])) == 1):
# degenerated rectangle, there is no grid, do not collapse
return {grp_id: out + list(ps)}
return out + list(ps)
deltax = angular_distance(ps_grid_spacing, lat=coords[:, 1].mean())
deltay = angular_distance(ps_grid_spacing)
grid = groupby_grid(coords[:, 0], coords[:, 1], deltax, deltay)
task_no = getattr(monitor, 'task_no', 0)
cnt = 0
for idxs in grid.values():
if len(idxs) > 1:
cnt += 1
name = 'cps-%03d-%04d' % (task_no, cnt)
name = 'cps-%03d-%04d' % (grp_id, cnt)
cps = CollapsedPointSource(name, ps[idxs])
cps.grp_id = ps[0].grp_id
cps.trt_smr = ps[0].trt_smr
cps.ps_grid_spacing = ps_grid_spacing
out.append(cps)
else: # there is a single source
out.append(ps[idxs[0]])
return {grp_id: out}
return out


def get_rup_maxlen(src):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#,,,,,,,,,,,,,,,,,,,,,,"generated_by='OpenQuake engine 3.20.0-git6a5db97d59', start_date='2024-06-03T09:36:02', checksum=3887009167, kind='mean', investigation_time=50.0, imt='PGA'"
#,,,,,,,,,,,,,,,,,,,,,,"generated_by='OpenQuake engine 3.23.0-gitaf0024471b', start_date='2025-01-28T04:26:32', checksum=2765880070, kind='mean', investigation_time=50.0, imt='PGA'"
lon,lat,depth,poe-0.0050000,poe-0.0070015,poe-0.0098041,poe-0.0137286,poe-0.0192240,poe-0.0269192,poe-0.0376948,poe-0.0527836,poe-0.0739125,poe-0.1034991,poe-0.1449289,poe-0.2029427,poe-0.2841789,poe-0.3979333,poe-0.5572227,poe-0.7802743,poe-1.0926116,poe-1.5299748,poe-2.1424109,poe-3.0000000
112.10000,22.30000,0.00000,5.379706E-02,4.118577E-02,2.768623E-02,1.618356E-02,8.170117E-03,3.517656E-03,1.269163E-03,3.727899E-04,8.385302E-05,1.334312E-05,1.255226E-06,4.479167E-08,0.000000E+00,0.000000E+00,0.000000E+00,0.000000E+00,0.000000E+00,0.000000E+00,0.000000E+00,0.000000E+00
112.10000,22.30000,0.00000,5.379705E-02,4.118577E-02,2.768623E-02,1.618356E-02,8.170118E-03,3.517655E-03,1.269162E-03,3.727898E-04,8.385300E-05,1.334312E-05,1.255226E-06,4.479167E-08,0.000000E+00,0.000000E+00,0.000000E+00,0.000000E+00,0.000000E+00,0.000000E+00,0.000000E+00,0.000000E+00
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#,,"generated_by='OpenQuake engine 3.20.0-git6a5db97d59', start_date='2024-06-03T09:36:02', checksum=3887009167, kind='mean', investigation_time=50.0"
#,,"generated_by='OpenQuake engine 3.23.0-gitaf0024471b', start_date='2025-01-28T04:26:32', checksum=2765880070, kind='mean', investigation_time=50.0"
lon,lat,PGA-0.002105
112.10000,22.30000,3.189415E-02
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#,,,,,,,"generated_by='OpenQuake engine 3.20.0-git6a5db97d59', start_date='2024-06-03T09:36:06', checksum=3727907911, kind='mean', investigation_time=1.0, imt='SA(0.2)'"
#,,,,,,,"generated_by='OpenQuake engine 3.23.0-gitaf0024471b', start_date='2025-01-28T04:26:47', checksum=3727907911, kind='mean', investigation_time=1.0, imt='SA(0.2)'"
lon,lat,depth,poe-0.0010000,poe-0.0056234,poe-0.0316228,poe-0.1778279,poe-1.0000000
-160.78075,59.28785,0.00000,3.794203E-03,7.911166E-04,7.141627E-05,2.784793E-07,0.000000E+00
-152.68536,64.36898,0.00000,9.397284E-02,1.783666E-02,1.809431E-03,2.580792E-05,1.094629E-08
-160.78075,59.28785,0.00000,3.794119E-03,7.910071E-04,7.138622E-05,2.799880E-07,0.000000E+00
-152.68536,64.36898,0.00000,9.397200E-02,1.783198E-02,1.809473E-03,2.579189E-05,1.112215E-08