aggregation_calc
Primary functions for calculating an aggregation for a single, site, IMT, etc.
calc_aggregation() does one task: it converts the probabilities of the component branches to rates, calculates the aggregates of the composite branches with calculate_aggs_from_components(), converts them back to probabilities and saves them. The rates of the composite branches are never stored, see calculators.composite_rate_aggs() and docs/aggregate_calculation.md for how the aggregates are calculated without them.
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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
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. |
probs |
NDArray
|
the realization probabilities with shape (n component branches, n IMTL), where row i is for the component branch at position i of the branch index table. |
Source code in toshi_hazard_post/aggregation_calc.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
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
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
calculate_aggs_from_components(branch_index_table, component_rates, weights, agg_types, columns)
¶
Calculate weighted aggregate statistics of the composite realizations from the component realizations.
The rate of a composite realization is the sum of the rates of its component realizations. The aggregates are calculated without building the array of composite rates (see calculators.composite_rate_aggs()).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branch_index_table
|
NDArray
|
composite branches represented as rows of indices into component_rates |
required |
component_rates
|
NDArray
|
component realization rates with shape (n component branches, n 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 |
columns
|
Sequence[NDArray]
|
the component branches in each column of the branch index table (see logic_tree.branch_index_columns()) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
hazard |
NDArray
|
aggregate rates array with dimension (agg_type, IMTL) |
Raises:
| Type | Description |
|---|---|
IndexError
|
if the branch index table refers to a component branch not in component_rates. |
Source code in toshi_hazard_post/aggregation_calc.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |