aggregation_calc
Primary functions for calculating an aggregation for a single, site, IMT, etc.
AggSharedArgs
dataclass
¶
A class to store arguments shared by multiple aggregation jobs (used for parallelization).
Attribues
Source code in toshi_hazard_post/aggregation_calc.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
AggTaskArgs
dataclass
¶
The arguments for a specific aggregation task.
A aggregation task is for a single location, vs30, imt, etc.
Attributes:
Name | Type | Description |
---|---|---|
location |
CodedLocation
|
the site locaiton. |
vs30 |
int
|
the site vs30. |
imt |
str
|
the intensity measure type. |
table_filepath |
Path
|
the location of the realization data ORC format file. |
Source code in toshi_hazard_post/aggregation_calc.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
build_branch_rates(branch_hash_table, component_rates)
¶
Calculate the rate for the composite branches in the logic tree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
branch_hash_table
|
NDArray
|
composite branches represented as a list of hashes of the component branches |
required |
component_rates
|
Dict[str, NDArray]
|
component realization rates keyed by component branch hash |
required |
Returns:
Type | Description |
---|---|
NDArray
|
The rates array with shape (n branches, n IMTL) |
Source code in toshi_hazard_post/aggregation_calc.py
193 194 195 196 197 198 199 200 201 202 203 204 |
|
calc_aggregation(task_args, shared_args)
¶
Calculate hazard aggregation for a single site and imt and save result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_args
|
AggTaskArgs
|
The arguments fot the specific aggregation calculation. |
required |
shared_args
|
AggSharedArgs
|
The arguments shared among all workers. |
required |
Source code in toshi_hazard_post/aggregation_calc.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
calc_composite_rates(branch_hashes, component_rates, nlevels)
¶
Calculate the rate for a single composite branch of the logic tree.
The rate for a composite branch is the sum of rates of the component branches.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
branch_hashes
|
list[str]
|
the branch hashes for the component branches that comprise the composite branch |
required |
component_rates
|
Dict[str, NDArray]
|
component realization rates keyed by component branch hash |
required |
nlevels
|
int
|
the number of levels (IMTLs) in the rate array |
required |
Returns:
Name | Type | Description |
---|---|---|
rates |
NDArray
|
hazard rates for the composite realization D(nlevels,) |
Source code in toshi_hazard_post/aggregation_calc.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
calculate_aggs(branch_rates, weights, agg_types)
¶
Calculate weighted aggregate statistics of the composite realizations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
branch_rates
|
NDArray
|
hazard rates for every composite realization of the model with dimensions (branch, IMTL) |
required |
weights
|
NDArray
|
one dimensional array of weights for composite branches with dimensions (branch,) |
required |
agg_types
|
Sequence[str]
|
the aggregate statistics to be calculated (e.g., "mean", "0.5") with dimension (agg_type,) |
required |
Returns:
Name | Type | Description |
---|---|---|
hazard |
NDArray
|
aggregate rates array with dimension (agg_type, IMTL) |
Source code in toshi_hazard_post/aggregation_calc.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
convert_probs_to_rates(probs)
¶
Convert probabilies to rates assuming probabilies are Poissonian.
The 'values' column in the input dataframe will be used to calculate rates assuming they are probabilities in one year. The output dataframe will have a 'rates' column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
probs
|
DataFrame
|
the probabilities dataframe. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
the rates dataframe. |
Source code in toshi_hazard_post/aggregation_calc.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
create_component_dict(component_rates)
¶
Convert component branch rates DataFrame to dict.
The 'digest' is constructed by concatenating sources digest and gmms digest. The source and gmm digests are then dropped.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component_rates
|
DataFrame
|
data frame with the component branch rates. |
required |
Returns:
Type | Description |
---|---|
Dict[str, NDArray]
|
The dictionary of rates keyed by the branch digest. |
Source code in toshi_hazard_post/aggregation_calc.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
load_realizations(filepath)
¶
Load the realizations from an Appache ORC format file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
Path
|
the path of the ORC file. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
The realization data. |
Source code in toshi_hazard_post/aggregation_calc.py
82 83 84 85 86 87 88 89 90 91 92 |
|