oq-wrapper 2025.12.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ Empirical Engine - Empirical IM calculation
2
+
3
+ (Based on https://wiki.canterbury.ac.nz/download/attachments/58458136/CodeVersioning_v18p2.pdf?version=1&modificationDate=1519269238437&api=v2 )
4
+
5
+ ## Unreleased
6
+ ### Fixed
7
+ ### Changed
8
+ ### Added
9
+
10
+ ## [23.7.11] - 2023-07-11
11
+ ### Changed
12
+ - Removed most of the code, except for the OpenQuake vectorised wrapper
13
+ - Old code is recoverable from the `backup_20230707` branch
14
+
15
+
16
+ ## [21.1.1] - 2021-01-21
17
+ ### Added
18
+ - Added OpenQuake compatibility layer
19
+ - Added OpenQuake models for ver component
20
+ - Added component selection to command line arguments
21
+
22
+ ## [19.9.3] - 2020-02-11 -
23
+ ### Added
24
+ - Added RotD100/50 (rotd100_50) and inelastic to elastic spectral displacement ratio (IESDR) empiricals
25
+ ### Changed
26
+ - Added 16 pSA periods to the default
27
+
28
+ ## [19.9.2] - 2019-12-10 -
29
+ ### Added
30
+ - Permutation aggregation script to generate all combinations of intensity measure models for a given event or fault from the available intensity measure files
31
+ - Abrahamson A18 model added and verification script created
32
+ ### Changed
33
+ - Empirical calculation and aggregation scripts refactored to allow easier access to their functionality
34
+
35
+ ## [19.9.1] - 2019-09-11
36
+ ### Added
37
+ Additional Empirical Models. (and unit tests)
38
+
39
+ ## [18.7.2] - 2018-08-16
40
+ ### Added
41
+ Interpolation for Zhao beyond the period of 5.0s
42
+ Config file to select which model is used for each tect_type / im
43
+ Empirical IM_csv creation
44
+ IM_aggregation (aggregating an individual IM_csv into a larger file containing more than one IM_type)
45
+ ### Changed
46
+ Verification changes (Z1p0 units and rock_site estimation for CB)
47
+
48
+ ## [18.7.1] - 2018-07-13
49
+ ### Added
50
+ Empirical calculations from site (rrup + vs30) and fault for Zhao_06, Bradley_13, Afshari_Stewart_16,
51
+ Campbell_Bozorgina_2010, Campbell_Bozorgina_2012
52
+ Output IM into individual csv files
53
+ Estimation of parameters unspecified
@@ -0,0 +1 @@
1
+ prune tests
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.4
2
+ Name: oq-wrapper
3
+ Version: 2025.12.3
4
+ Summary: Wrapper for OpenQuake engine to run empirical GMMs
5
+ Author: ucgmsim
6
+ Requires-Python: <3.14,>=3.11
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: numpy<2
9
+ Requires-Dist: openquake.engine
10
+ Requires-Dist: pandas
11
+ Requires-Dist: pytest-black
12
+ Requires-Dist: pytest>=3.5.0
13
+ Requires-Dist: pyyaml
14
+ Requires-Dist: scipy>=1.7.2
15
+ Requires-Dist: source-modelling
16
+ Requires-Dist: pyarrow
17
+
18
+ [![Build Status](https://quakecoresoft.canterbury.ac.nz/jenkins/job/Empirical_Engine/badge/icon?build=last:${params.ghprbActualCommit=master})](https://quakecoresoft.canterbury.ac.nz/jenkins/job/Empirical_Engine)
19
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
20
+
21
+ # Empirical_Engine
22
+ Contains codes to calculate Empirical IMs using the openquake engine
23
+
24
+ ## To calculate empirical IMs
25
+
26
+ calculate_empirical.py is the main script to calculate empirical IMs.
27
+ It uses the openquake engine to calculate the IMs. The script takes the following parameters:
28
+
29
+ ```
30
+ positional arguments:
31
+ output output directory
32
+
33
+ options:
34
+ -h, --help show this help message and exit
35
+ --ll_ffp LL_FFP Path to the .ll file
36
+ --vs30_ffp VS30_FFP Path to the .vs30 file
37
+ --z_ffp Z_FFP Path to the .z file that contains Z1.0 and Z2.5. If not available, estimate from vs30
38
+ utilizing relations in z_model_calculations.py. (eg. chiou_young_08_calc_z1p0). The file
39
+ should have columns: station, z1p0, z2p5, sigma
40
+ --srf_ffp SRF_FFP Path to the SRF file
41
+ --nhm_ffp NHM_FFP Path to the NHM file. If srf_ffp is not provided, this is used to get the fault data. Get
42
+ one from https://github.com/ucgmsim/Empirical_Engine/files/15256612/NZ_FLTmodel_2010_v18p6.txt
43
+ --srfdata_ffp SRFDATA_FFP
44
+ Path to the SRF .info or .csv file
45
+ -rm MAX_RUPTURE_DISTANCE, --max_rupture_distance MAX_RUPTURE_DISTANCE
46
+ Only calculate empiricals for stations that are within X distance to rupture
47
+ --nz_gmdb_source_ffp NZ_GMDB_SOURCE_FFP
48
+ NZ GMDB source CSV. Required for historical events when srfdata is missing. Use
49
+ earthquake_source_table.csv contained in GMDB.zip from https://osf.io/q9yrg/?view_only=05337ba1ebc744fc96b9924de633ca0e
50
+ --model_config_ffp MODEL_CONFIG_FFP
51
+ Path to the model_config file. Found in Empirical util.
52
+ --meta_config_ffp META_CONFIG_FFP
53
+ Path to the meta_config weight file. Found in Empirical util.
54
+ -e, --extended_period
55
+ Indicate the use of extended(100) pSA periods
56
+ -p PERIODS [PERIODS ...], --periods PERIODS [PERIODS ...]
57
+ pSA period(s) separated by a " " space. eg: 0.02 0.05 0.1.
58
+ -m IM [IM ...], --im IM [IM ...]
59
+ Intensity measure(s) separated by a " " space(if more than one). eg: PGV PGA CAV.
60
+ -comp {090,000,ver,H1,H2,geom,rotd50,rotd100,rotd100_50,norm,EAS}, --component {090,000,ver,H1,H2,geom,rotd50,rotd100,rotd100_50,norm,EAS}
61
+ The component you want to calculate.
62
+
63
+ ```
64
+ This is designed to accommodate fairly flexible situations. In practice, we often find .srf, .info and some .csv files missing.
65
+ - If srf_ffp is not supplied, and it is a known fault in NHM, it will extract the srf data directly from NHM.
66
+ - srfdata_ffp can be either .csv or .info.
67
+ - If neither .csv nor .info is supplied, and if it is a historical event (found in NZ_GMDB) , it will find the event info from NZ_GMDB and carry on.
68
+
69
+ Data files can be downloaded from the following links:
70
+ - earthquake_source_table.csv can be found in the [GMDB.zip](https://osf.io/q9yrg/?view_only=05337ba1ebc744fc96b9924de633ca0e)
71
+ - NHM file : [NZ_FLTmodel_2010_v18p6.txt](https://github.com/ucgmsim/Empirical_Engine/files/15256612/NZ_FLTmodel_2010_v18p6.txt) (Credit: [GNS Science](https://www.gns.cri.nz/data-and-resources/2010-national-seismic-hazard-model/))
72
+
73
+ Note that
74
+ - Z-values must be supplied. Z1.0 and Z2.5 can be estimated from vs30 using the relations in z_model_calculations.py.
75
+ - If the model_config_ffp is not supplied, it will use the default model_config found in Empirical util.
76
+ - If the meta_config_ffp is not supplied, it will use the default meta_config found in Empirical util.
77
+
78
+
79
+ Internally, it calls the function oq_run in util.openquake_wrapper_vectorised.py with the following parameters:
80
+
81
+ model_type: GMM
82
+ OQ model
83
+ tect_type: TectType
84
+ One of the tectonic types from
85
+ ACTIVE_SHALLOW, SUBDUCTION_SLAB and SUBDUCTION_INTERFACE
86
+ rupture_df: Rupture DF
87
+ Columns for properties. E.g., vs30, z1pt0, rrup, rjb, mag, rake, dip....
88
+ Rows be the separate site-fault pairs
89
+ im: string
90
+ intensity measure
91
+ periods: Sequence[Union[int, float]]
92
+ for spectral acceleration, openquake tables automatically
93
+ interpolate values between specified values, fails if outside range
94
+ meta_config: Dict
95
+ A dictionary contains models and its weight
96
+ kwargs: pass extra (model specific) parameters to models
97
+
@@ -0,0 +1,80 @@
1
+ [![Build Status](https://quakecoresoft.canterbury.ac.nz/jenkins/job/Empirical_Engine/badge/icon?build=last:${params.ghprbActualCommit=master})](https://quakecoresoft.canterbury.ac.nz/jenkins/job/Empirical_Engine)
2
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3
+
4
+ # Empirical_Engine
5
+ Contains codes to calculate Empirical IMs using the openquake engine
6
+
7
+ ## To calculate empirical IMs
8
+
9
+ calculate_empirical.py is the main script to calculate empirical IMs.
10
+ It uses the openquake engine to calculate the IMs. The script takes the following parameters:
11
+
12
+ ```
13
+ positional arguments:
14
+ output output directory
15
+
16
+ options:
17
+ -h, --help show this help message and exit
18
+ --ll_ffp LL_FFP Path to the .ll file
19
+ --vs30_ffp VS30_FFP Path to the .vs30 file
20
+ --z_ffp Z_FFP Path to the .z file that contains Z1.0 and Z2.5. If not available, estimate from vs30
21
+ utilizing relations in z_model_calculations.py. (eg. chiou_young_08_calc_z1p0). The file
22
+ should have columns: station, z1p0, z2p5, sigma
23
+ --srf_ffp SRF_FFP Path to the SRF file
24
+ --nhm_ffp NHM_FFP Path to the NHM file. If srf_ffp is not provided, this is used to get the fault data. Get
25
+ one from https://github.com/ucgmsim/Empirical_Engine/files/15256612/NZ_FLTmodel_2010_v18p6.txt
26
+ --srfdata_ffp SRFDATA_FFP
27
+ Path to the SRF .info or .csv file
28
+ -rm MAX_RUPTURE_DISTANCE, --max_rupture_distance MAX_RUPTURE_DISTANCE
29
+ Only calculate empiricals for stations that are within X distance to rupture
30
+ --nz_gmdb_source_ffp NZ_GMDB_SOURCE_FFP
31
+ NZ GMDB source CSV. Required for historical events when srfdata is missing. Use
32
+ earthquake_source_table.csv contained in GMDB.zip from https://osf.io/q9yrg/?view_only=05337ba1ebc744fc96b9924de633ca0e
33
+ --model_config_ffp MODEL_CONFIG_FFP
34
+ Path to the model_config file. Found in Empirical util.
35
+ --meta_config_ffp META_CONFIG_FFP
36
+ Path to the meta_config weight file. Found in Empirical util.
37
+ -e, --extended_period
38
+ Indicate the use of extended(100) pSA periods
39
+ -p PERIODS [PERIODS ...], --periods PERIODS [PERIODS ...]
40
+ pSA period(s) separated by a " " space. eg: 0.02 0.05 0.1.
41
+ -m IM [IM ...], --im IM [IM ...]
42
+ Intensity measure(s) separated by a " " space(if more than one). eg: PGV PGA CAV.
43
+ -comp {090,000,ver,H1,H2,geom,rotd50,rotd100,rotd100_50,norm,EAS}, --component {090,000,ver,H1,H2,geom,rotd50,rotd100,rotd100_50,norm,EAS}
44
+ The component you want to calculate.
45
+
46
+ ```
47
+ This is designed to accommodate fairly flexible situations. In practice, we often find .srf, .info and some .csv files missing.
48
+ - If srf_ffp is not supplied, and it is a known fault in NHM, it will extract the srf data directly from NHM.
49
+ - srfdata_ffp can be either .csv or .info.
50
+ - If neither .csv nor .info is supplied, and if it is a historical event (found in NZ_GMDB) , it will find the event info from NZ_GMDB and carry on.
51
+
52
+ Data files can be downloaded from the following links:
53
+ - earthquake_source_table.csv can be found in the [GMDB.zip](https://osf.io/q9yrg/?view_only=05337ba1ebc744fc96b9924de633ca0e)
54
+ - NHM file : [NZ_FLTmodel_2010_v18p6.txt](https://github.com/ucgmsim/Empirical_Engine/files/15256612/NZ_FLTmodel_2010_v18p6.txt) (Credit: [GNS Science](https://www.gns.cri.nz/data-and-resources/2010-national-seismic-hazard-model/))
55
+
56
+ Note that
57
+ - Z-values must be supplied. Z1.0 and Z2.5 can be estimated from vs30 using the relations in z_model_calculations.py.
58
+ - If the model_config_ffp is not supplied, it will use the default model_config found in Empirical util.
59
+ - If the meta_config_ffp is not supplied, it will use the default meta_config found in Empirical util.
60
+
61
+
62
+ Internally, it calls the function oq_run in util.openquake_wrapper_vectorised.py with the following parameters:
63
+
64
+ model_type: GMM
65
+ OQ model
66
+ tect_type: TectType
67
+ One of the tectonic types from
68
+ ACTIVE_SHALLOW, SUBDUCTION_SLAB and SUBDUCTION_INTERFACE
69
+ rupture_df: Rupture DF
70
+ Columns for properties. E.g., vs30, z1pt0, rrup, rjb, mag, rake, dip....
71
+ Rows be the separate site-fault pairs
72
+ im: string
73
+ intensity measure
74
+ periods: Sequence[Union[int, float]]
75
+ for spectral acceleration, openquake tables automatically
76
+ interpolate values between specified values, fails if outside range
77
+ meta_config: Dict
78
+ A dictionary contains models and its weight
79
+ kwargs: pass extra (model specific) parameters to models
80
+
@@ -0,0 +1,18 @@
1
+ from . import constants, estimations
2
+ from .wrapper import (
3
+ OQ_MODEL_MAPPING,
4
+ get_model_from_str,
5
+ load_gmm_logic_tree_config,
6
+ run_gmm,
7
+ run_gmm_logic_tree,
8
+ )
9
+
10
+ __all__ = [
11
+ "estimations",
12
+ "constants",
13
+ "run_gmm",
14
+ "run_gmm_logic_tree",
15
+ "load_gmm_logic_tree_config",
16
+ "OQ_MODEL_MAPPING",
17
+ "get_model_from_str",
18
+ ]
@@ -0,0 +1,163 @@
1
+ """Constants used in the OpenQuake wrapper package."""
2
+
3
+ from enum import StrEnum, auto
4
+ from pathlib import Path
5
+
6
+ from openquake.hazardlib import const as oq_const
7
+
8
+ # Different OQ GMM model standard deviation types of interest
9
+ SPT_STD_DEVS = [
10
+ oq_const.StdDev.TOTAL,
11
+ oq_const.StdDev.INTER_EVENT,
12
+ oq_const.StdDev.INTRA_EVENT,
13
+ ]
14
+
15
+
16
+ class TectType(StrEnum):
17
+ """Fault tectonic type."""
18
+
19
+ ACTIVE_SHALLOW = auto()
20
+ VOLCANIC = auto()
21
+ SUBDUCTION_INTERFACE = auto()
22
+ SUBDUCTION_SLAB = auto()
23
+
24
+
25
+ OQ_TECT_TYPE_MAPPING = {
26
+ oq_const.TRT.ACTIVE_SHALLOW_CRUST: TectType.ACTIVE_SHALLOW,
27
+ oq_const.TRT.SUBDUCTION_INTERFACE: TectType.SUBDUCTION_INTERFACE,
28
+ oq_const.TRT.SUBDUCTION_INTRASLAB: TectType.SUBDUCTION_SLAB,
29
+ oq_const.TRT.VOLCANIC: TectType.VOLCANIC,
30
+ }
31
+
32
+
33
+ class GMM(StrEnum):
34
+ """Ground motion models."""
35
+
36
+ ZA_06 = "ZA_06"
37
+ AS_16 = "AS_16"
38
+ BSSA_14 = "BSSA_14"
39
+ ASK_14 = "ASK_14"
40
+ BCH_16 = "BCH_16"
41
+ CB_14 = "CB_14"
42
+ CY_14 = "CY_14"
43
+ CB_10 = "CB_10"
44
+ A_18 = "A_18"
45
+ P_20 = "P_20"
46
+ AG_20 = "AG_20" # (global)
47
+ K_20 = "K_20" # (global)
48
+ K_20_NZ = "K_20_NZ" # (NZ)
49
+ AG_20_NZ = "AG_20_NZ" # (NZ)
50
+ S_22 = "S_22"
51
+ A_22 = "A_22"
52
+ Br_13 = "Br_13"
53
+ P_21 = "P_21"
54
+ GA_11 = "GA_11"
55
+ BA_18 = "BA_18"
56
+
57
+
58
+ class GMMLogicTree(StrEnum):
59
+ """Logic tree for GMMs."""
60
+
61
+ NHM2010_BB = "NHM2010_BB"
62
+ NSHM2022 = "NSHM2022"
63
+
64
+
65
+ class EpistemicBranch(StrEnum):
66
+ """Epistemic uncertainty for GMMs"""
67
+
68
+ LOWER = "LOWER"
69
+ CENTRAL = "CENTRAL"
70
+ UPPER = "UPPER"
71
+
72
+
73
+ GMM_EPISTEMIC_BRANCH_KWARGS_MAPPING = {
74
+ GMM.S_22: {
75
+ EpistemicBranch.LOWER: {"mu_branch": "Lower", "sigma_branch": "Lower"},
76
+ EpistemicBranch.UPPER: {"mu_branch": "Upper", "sigma_branch": "Upper"},
77
+ }
78
+ }
79
+
80
+ GMM_EPISTEMIC_BRANCH_SIGMA_FACTOR_MAPPING = {
81
+ GMM.Br_13: {
82
+ EpistemicBranch.LOWER: -1.2815,
83
+ EpistemicBranch.UPPER: 1.2815,
84
+ },
85
+ GMM.ASK_14: {
86
+ EpistemicBranch.LOWER: -1.2815,
87
+ EpistemicBranch.UPPER: 1.2815,
88
+ },
89
+ GMM.CY_14: {
90
+ EpistemicBranch.LOWER: -1.2815,
91
+ EpistemicBranch.UPPER: 1.2815,
92
+ },
93
+ GMM.CB_14: {
94
+ EpistemicBranch.LOWER: -1.2815,
95
+ EpistemicBranch.UPPER: 1.2815,
96
+ },
97
+ GMM.BSSA_14: {
98
+ EpistemicBranch.LOWER: -1.2815,
99
+ EpistemicBranch.UPPER: 1.2815,
100
+ },
101
+ }
102
+
103
+
104
+ GMM_LT_CONFIG_DIR = Path(__file__).parent / "gmm_logic_tree_configs"
105
+
106
+ GMM_LT_CONFIG_MAPPING = {
107
+ GMMLogicTree.NHM2010_BB: GMM_LT_CONFIG_DIR / "nhm_2010_bb_config.yaml",
108
+ GMMLogicTree.NSHM2022: GMM_LT_CONFIG_DIR / "nshm_2022_config.yaml",
109
+ }
110
+
111
+
112
+ NZGMDB_SITE_COLUMNS = [
113
+ "Vs30",
114
+ "Z1.0",
115
+ "Z2.5",
116
+ ]
117
+ OQ_SITE_COLUMNS = [
118
+ "vs30",
119
+ "z1pt0",
120
+ "z2pt5",
121
+ ]
122
+
123
+ NZGMDB_SITE_TO_SOURCE_COLUMNS = [
124
+ "r_rup",
125
+ "r_jb",
126
+ "r_x",
127
+ "r_y",
128
+ "r_hyp",
129
+ ]
130
+ OQ_SITE_TO_SOURCE_COLUMNS = [
131
+ "rrup",
132
+ "rjb",
133
+ "rx",
134
+ "ry",
135
+ "rhypo",
136
+ ]
137
+
138
+ NZ_GMDB_SOURCE_COLUMNS = [
139
+ "mag",
140
+ "tect_class",
141
+ "z_tor",
142
+ "z_bor",
143
+ "rake",
144
+ "dip",
145
+ "ev_depth",
146
+ ]
147
+ OQ_SOURCE_COLUMNS = [
148
+ "mag",
149
+ "tect_class",
150
+ "ztor",
151
+ "zbot",
152
+ "rake",
153
+ "dip",
154
+ "hypo_depth",
155
+ ]
156
+
157
+
158
+ NZGMDB_COLUMNS = (
159
+ NZGMDB_SITE_COLUMNS + NZGMDB_SITE_TO_SOURCE_COLUMNS + NZ_GMDB_SOURCE_COLUMNS
160
+ )
161
+ OQ_RUPTURE_COLUMNS = OQ_SITE_COLUMNS + OQ_SITE_TO_SOURCE_COLUMNS + OQ_SOURCE_COLUMNS
162
+
163
+ NZGMDB_OQ_COL_MAPPING = dict(zip(NZGMDB_COLUMNS, OQ_RUPTURE_COLUMNS))