data
Functions for loading realizations and saving aggregations.
component_row_ids(batch_datatable, component_digests)
¶
Find the component branch of each row of a batch datatable.
A row's component branch digest is its sources digest followed by its gmms digest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_datatable
|
Table
|
the datatable produced by get_batch_table. |
required |
component_digests
|
Sequence[str]
|
the hash digests of the component branches. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
For each row, the index into component_digests of the row's component branch, or -1 if the row is not for a component branch. |
Source code in toshi_hazard_post/data.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
get_batch_table(dataset, compatibility_key, sources_digests, gmms_digests, vs30, nloc_0, imts)
¶
Get the realization datatable for a batch of aggregation jobs.
Filtering is done for comatibility key, branch digests, vs30, nloc_0, and (multiple) imts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
the realization dataset. |
required |
compatibility_key
|
str
|
the toshi-hazard-store compatibility key. |
required |
sources_digests
|
list[str]
|
the digests of the source branches. |
required |
gmms_digests
|
list[str]
|
the digests of the gmcm branches. |
required |
vs30
|
int
|
the vs30 of the sites. |
required |
nloc_0
|
str
|
the nloc_0 (1.0 degree location code). |
required |
imts
|
list[str]
|
the intensity measure types. |
required |
Returns:
| Type | Description |
|---|---|
Table
|
The filtered datatable. |
Source code in toshi_hazard_post/data.py
54 55 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
get_job_probs(batch_datatable, job_rows, component_ids, component_digests, location, imt)
¶
Get the realization probabilities of one aggregation job (one IMT and location), by component branch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_datatable
|
Table
|
the datatable produced by get_batch_table. |
required |
job_rows
|
dict[tuple[str, str], NDArray]
|
the rows of batch_datatable for each job, produced by group_batch_rows. |
required |
component_ids
|
NDArray
|
the component branch of each row of batch_datatable, produced by component_row_ids. |
required |
component_digests
|
Sequence[str]
|
the hash digests of the component branches, in the order wanted for the array. |
required |
location
|
CodedLocation
|
the location of the site. |
required |
imt
|
str
|
the intensity measure type. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
The probabilities with shape (n component branches, n IMTL), where row i is for component_digests[i]. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the job's rows are not exactly one for each component branch. |
ValueError
|
if any of the job's rows or probabilities are null, or the rows differ in length. |
Source code in toshi_hazard_post/data.py
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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
get_realizations_dataset(vs30=None, nloc_0=None, rlz_dir=None)
¶
Get a pyarrow Dataset for realizations.
Optional parameters take advantage of partitioning of dataset for faster retrieval. The partitioning is assumed to be vs30/nloc_0. See toshi-hazard-store documentation for details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vs30
|
int | None
|
the site vs30 |
None
|
nloc_0
|
str | None
|
the 1 degree grid location (e.g. '-41.0~175.0') |
None
|
rlz_dir
|
str | Path | None
|
location of realization dataset. If not passed, function will use env var. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dataset |
Dataset
|
the relization dataset |
Source code in toshi_hazard_post/data.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
group_batch_rows(batch_datatable)
¶
Find the rows of the batch datatable for each aggregation job (one IMT and location).
The whole table is grouped in one pass, so that the table of each job can be taken from it without searching the table again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_datatable
|
Table
|
the datatable produced by get_batch_table. |
required |
Returns:
| Type | Description |
|---|---|
dict[tuple[str, str], NDArray]
|
The row indices of each (location code at 0.001 degree resolution, intensity measure type), in the order the rows have in the table. |
Source code in toshi_hazard_post/data.py
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 | |
resolve_target(target)
¶
Get the path and filesystem of a dataset, as toshi-hazard-store's configure_output does.
Every S3 target shares one S3FileSystem per process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
a local path or an S3 URI. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, FileSystem]
|
The path within the filesystem, and the filesystem. |
Source code in toshi_hazard_post/data.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
save_aggregations(hazard, location, vs30, imt, agg_types, hazard_model_id, compatibility_key)
¶
Save the aggregated hazard to the database.
Converts hazard as rates to proabilities before saving.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hazard
|
NDArray
|
the aggregate hazard rates (not proabilities) |
required |
location
|
CodedLocation
|
the site location |
required |
vs30
|
int
|
the site vs30 |
required |
imt
|
str
|
the intensity measure type (e.g. "PGA", "SA(1.5)") |
required |
agg_types
|
list[str]
|
the statistical aggregate types (e.g. "mean", "0.5") |
required |
hazard_model_id
|
str
|
the model id for storing in the database |
required |
compatibility_key
|
str
|
the toshi-hazard-store compatibility key. |
required |
Source code in toshi_hazard_post/data.py
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 | |