scenario damage calculation: damage results for each ground motion field?

180 views
Skip to first unread message

Cecilia I. Nievas

unread,
Mar 9, 2022, 12:20:21 PM3/9/22
to openqua...@googlegroups.com

Hi everyone,

When running a scenario damage calculation, is it possible to retrieve the damage results per asset_id and per damage grade for each ground motion field generated for each of the logic tree branches?

I have run a calculation using the OQ engine v 3.13 with:

  • 15 logic tree branches
  • number_of_ground_motion_fields = 100
  • 1037837 asset_ids

I am inferring that the 15 output CSVs avg_damages-rlz-XXX_job_id.csv files I got are one for each of the logic tree branches, and contain each an average of their own 100 ground motion fields. From what I am seeing, this is equivalent to the damages-rlzs array in the HDF5 file. In the HDF5 file I see as well the group risk_by_event, and given that each of dmg_1, ..., dmg4 is a 1500-element 1D array I interpret these as being the damage results per damage grade, for each ground motion field generated for each of the logic tree branch, but condensing all assets together. I am not finding the full results that are not aggregated in at least one of the dimensions (ground motion fields or assets, in the cases I've mentioned), but I am not sure if it is escaping my eyes.

Can anyone please let me know if this exists and where to find it?

Thanks a lot in advance,

Cecilia

anirudh.rao

unread,
Mar 9, 2022, 1:45:14 PM3/9/22
to OpenQuake Users
Hi Cecilia,

The asset-level event damage table is not stored by default since the size of the table can be very large and most users don't need this level of information. To force the engine to store the full table, you'd need to include 
aggregate_by = id
in your job file.

The table will still not be visible in the list of outputs but will be saved to the hdf5 datastore. You can then access it using the code snippet below. The '-1' in the read() function refers to the most recent calculation, but you can provide your calculation id instead. This should also work with the event based damage calculator.


from openquake.commonlib.datastore import read

dstore = read(-1)
agg_keys = dstore.read_df("agg_keys")
damage_df = (
    dstore.read_df("risk_by_event", "event_id")
    .join(agg_keys.id, on="agg_id")
    .dropna(subset=["id"])
    .set_index("id", append=True)
    .drop(columns=["agg_id", "loss_id"])
    .sort_index(level=["event_id", "id"])
)
damage_df.to_csv("Damage_by_Asset_and_Event.csv")


Best wishes,
Anirudh

Marco Baiguera

unread,
Mar 27, 2026, 1:10:35 PM (7 days ago) Mar 27
to OpenQuake Users
Hi everyone,

Further to the response from Anirudh, here is an updated version of the code snippet for accessing the asset-level results.

import pandas as pd

from openquake.commonlib.datastore import read

dstore = read(-1)
risk_df = pd.DataFrame({
    name: ds[()]
    for name, ds in dstore["risk_by_event"].items()
})
agg_arr = dstore["agg_keys"][()]
agg_keys = pd.DataFrame({
    "agg_id": range(len(agg_arr)),
    "id": [x.decode("utf-8") if isinstance(x, bytes) else x for x in agg_arr]
})
damage_df = risk_df.merge(agg_keys, on="agg_id", how="left")
damage_df.to_csv("Damage_by_Asset_and_Event.csv", index=False)

Kind regards,
Marco
Reply all
Reply to author
Forward
0 new messages