datasets
query interfaces for pyarrow datasets
Datasets objects are cached to reduce overhead in future queries.
https://arrow.apache.org/docs/python/parquet.html#reading-and-writing-the-apache-parquet-format
AggregatedHazard
dataclass
¶
Represents an aggregated hazard dataset.
Attributes:
Name | Type | Description |
---|---|---|
compatible_calc_id |
str
|
the ID of a compatible calculation for PSHA engines interoperability. |
hazard_model_id |
str
|
the model that these curves represent. |
nloc_001 |
str
|
the location string to three places e.g. "-38.330~17.550". |
nloc_0 |
str
|
the location string to zero places e.g. "-38.0~17.0" (used for partitioning). |
imt |
str
|
the intensity measure type label e.g. 'PGA', 'SA(5.0)'. |
vs30 |
int
|
the VS30 integer. |
agg |
str
|
the aggregation type. |
values |
list[Union[float, IMTValue]]
|
a list of 44 IMTL values. |
Notes
This class is designed to match the table schema for aggregated hazard datasets.
Source code in toshi_hazard_store/query/datasets.py
87 88 89 90 91 92 93 94 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 |
|
to_imt_values()
¶
Converts the IMTL values in this object's values
attribute from a list of floats to a list of IMTValue
objects.
Returns:
AggregatedHazard: this object itself.
Source code in toshi_hazard_store/query/datasets.py
115 116 117 118 119 120 121 122 123 124 |
|
IMTValue
dataclass
¶
Represents an intensity measure type (IMT) value.
Attributes:
Name | Type | Description |
---|---|---|
lvl |
float
|
The level of the IMT value. |
val |
float
|
The value of the IMT at that level. |
Source code in toshi_hazard_store/query/datasets.py
74 75 76 77 78 79 80 81 82 83 84 |
|
get_dataset()
cached
¶
Cache the dataset.
Returns:
Type | Description |
---|---|
Dataset
|
A pyarrow.dataset.Dataset object. |
Source code in toshi_hazard_store/query/datasets.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
get_dataset_vs30(vs30)
cached
¶
Cache the dataset for a given vs30.
Returns:
Type | Description |
---|---|
Dataset
|
A pyarrow.dataset.Dataset object. |
Source code in toshi_hazard_store/query/datasets.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
get_dataset_vs30_nloc0(vs30, nloc)
cached
¶
Cache the dataset for a given vs30 and nloc_0.
Returns:
Type | Description |
---|---|
Dataset
|
A pyarrow.dataset.Dataset object. |
Source code in toshi_hazard_store/query/datasets.py
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 |
|
get_hazard_curves(location_codes, vs30s, hazard_model, imts, aggs, strategy='naive')
¶
Retrieves aggregated hazard curves from the dataset.
The optional strategy
argument can be used to control how the query behaves:
- 'naive' (the default) lets pyarrow do its normal thing.
- 'd1' assumes the dataset is partitioned on vs30
, generating multiple pyarrow queries from the user args.
- 'd2' assumes the dataset is partitioned on vs30, nloc_0
and acts accordingly.
These overriding strategies alow the user to tune the query to suit the size of the datasets and the
compute resources available. e.g. for the full NSHM, with an AWS lambda function, the d2
option is optimal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location_codes
|
list
|
List of location codes. |
required |
vs30s
|
list
|
List of VS30 values. |
required |
hazard_model
|
str
|
the hazard model id. |
required |
aggs
|
list
|
List of aggregation types. |
required |
strategy
|
str
|
which query strategy to use (options are |
'naive'
|
Yields:
Name | Type | Description |
---|---|---|
AggregatedHazard |
AggregatedHazard
|
An object containing the aggregated hazard curve data. |
Source code in toshi_hazard_store/query/datasets.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|
get_hazard_curves_by_vs30(location_codes, vs30s, hazard_model, imts, aggs)
¶
Retrieves aggregated hazard curves from the dataset.
Subdivides the dataset using partitioning to reduce IO and memory demand.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location_codes
|
list
|
List of location codes. |
required |
vs30s
|
list
|
List of VS30 values. |
required |
hazard_model
|
str
|
the hazard model id. |
required |
imts
|
list
|
List of intensity measure types (e.g. 'PGA', 'SA(5.0)'). |
required |
aggs
|
list
|
List of aggregation types. |
required |
Yields:
Name | Type | Description |
---|---|---|
AggregatedHazard |
AggregatedHazard
|
An object containing the aggregated hazard curve data. |
Raises:
Type | Description |
---|---|
RuntimeWarning
|
describing any dataset partitions that could not be opened. |
Source code in toshi_hazard_store/query/datasets.py
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 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
get_hazard_curves_by_vs30_nloc0(location_codes, vs30s, hazard_model, imts, aggs)
¶
Retrieves aggregated hazard curves from the dataset.
Subdivides the dataset using partitioning to reduce IO and memory demand.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location_codes
|
list
|
List of location codes. |
required |
vs30s
|
list
|
List of VS30 values. |
required |
hazard_model
|
str
|
the hazard model id. |
required |
imts
|
list
|
List of intensity measure types (e.g. 'PGA', 'SA(5.0)'). |
required |
aggs
|
list
|
List of aggregation types. |
required |
Yields:
Name | Type | Description |
---|---|---|
AggregatedHazard |
AggregatedHazard
|
An object containing the aggregated hazard curve data. |
Raises:
Type | Description |
---|---|
RuntimeWarning
|
describing any dataset partitions that could not be opened. |
Source code in toshi_hazard_store/query/datasets.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
|
get_hazard_curves_naive(location_codes, vs30s, hazard_model, imts, aggs)
¶
Retrieves aggregated hazard curves from the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location_codes
|
list
|
List of location codes. |
required |
vs30s
|
list
|
List of VS30 values. |
required |
hazard_model
|
str
|
the hazard model id. |
required |
imts
|
list
|
List of intensity measure types (e.g. 'PGA', 'SA(5.0)'). |
required |
aggs
|
list
|
List of aggregation types. |
required |
Yields:
Name | Type | Description |
---|---|---|
AggregatedHazard |
AggregatedHazard
|
An object containing the aggregated hazard curve data. |
Source code in toshi_hazard_store/query/datasets.py
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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
options: filters: public