Skip to content

Commit

Permalink
Merge pull request #10238 from gem/export_realizations
Browse files Browse the repository at this point in the history
Fixed a bug while exporting realizations.csv for scenario calculations
  • Loading branch information
micheles authored Dec 20, 2024
2 parents 018b702 + 89be66b commit b0f57d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 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]
* Fixed a bug while exporting realizations.csv for scenario calculations
* Added `webapi.calc_timeout` configuration parameter
* Reduced `conditioned_gmfs_gb` to 8 GB by default
* Parallelized `get_mean_covs` when conditioning the GMFs
Expand Down
19 changes: 11 additions & 8 deletions openquake/calculators/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,24 @@ def extract_realizations(dstore, dummy):
scenario = 'scenario' in oq.calculation_mode
full_lt = dstore['full_lt']
rlzs = full_lt.rlzs
bpaths = encode(rlzs['branch_path'])
if scenario and len(full_lt.trts) == 1: # only one TRT
gsims = encode(dstore.getitem('full_lt/gsim_lt')['uncertainty'])
if 'shakemap' in oq.inputs:
gsims = ["[FromShakeMap]"]
bplen = max(len(gsim) for gsim in gsims) # list of bytes
else:
bpaths = encode(rlzs['branch_path']) # list of bytes
bplen = max(len(bp) for bp in bpaths)

# NB: branch_path cannot be of type hdf5.vstr otherwise the conversion
# to .npz (needed by the plugin) would fail
bplen = max(len(bp) for bp in bpaths)
dt = [('rlz_id', U32), ('branch_path', '<S%d' % bplen), ('weight', F32)]
arr = numpy.zeros(len(rlzs), dt)
arr['rlz_id'] = rlzs['ordinal']
arr['weight'] = rlzs['weight']
if scenario and len(full_lt.trts) == 1: # only one TRT
gsims = dstore.getitem('full_lt/gsim_lt')['uncertainty']
if 'shakemap' in oq.inputs:
gsims = ["[FromShakeMap]"]
# NOTE: repr(gsim) has a form like "b'[ChiouYoungs2008]'"
arr['branch_path'] = ['"%s"' % repr(gsim)[2:-1].replace('"', '""')
for gsim in gsims] # quotes Excel-friendly
# quotes Excel-friendly
arr['branch_path'] = [gsim.replace(b'"', b'""') for gsim in gsims]
else: # use the compact representation for the branch paths
arr['branch_path'] = bpaths
return arr
Expand Down

0 comments on commit b0f57d1

Please sign in to comment.