Skip to content

data_loaders

DynamoHazardLoader

A class for loading hazard curves from toshi-hazard-store DynamoDB.

The use of DynamoDB for storing hazard curves is depricated and will be removed with v2 of toshi-hazard-store.

__init__() -> None

Initialize a DynamoHazardLoader object.

get_levels(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, agg: str) -> npt.NDArray

Get the intensity measure levels for a hazard curve.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

The vs30 of the site.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
npt.NDArray

The intensity measure values.

get_probabilities(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, agg: str) -> npt.NDArray

Get the probablity values for a hazard curve.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

The vs30 of the site.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
npt.NDArray

The probability values.

DynamoDisaggLoader

A class for loading disaggregation matricies from toshi-hazard-store DynamoDB.

get_bin_centers(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, poe: ProbabilityEnum, agg: str) -> dict[str, npt.NDArray]

Get the disaggregation bin centers.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model. Specific use will depend on the DataLoader type.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

The vs30 of the site.

required
poe ProbabilityEnum

The probability of exceedance.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
dict[str, npt.NDArray]

Array of probability contributions from each disaggregation bin. Array has demensionallity matching the number of disaggregation dimensions with the length along each dimension matching the number of bins. The order of dimensions matches the order of the bins from the get_bin_centers method.

Raises:

Type Description
KeyError

If no records or more than one record is found in the database.

get_bin_edges(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, poe: ProbabilityEnum, agg: str) -> dict[str, npt.NDArray]

Get the disaggregation bin centers.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model. Specific use will depend on the DataLoader type.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

The vs30 of the site.

required
poe ProbabilityEnum

The probability of exceedance.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Raises:

Type Description
NotImplementedError

Dynamo database does not provide bin edges.

get_disagg(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, poe: ProbabilityEnum, agg: str) -> npt.NDArray

Get the disaggregation values.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model. Specific use will depend on the DataLoader type.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

The vs30 of the site.

required
poe ProbabilityEnum

The probability of exceedance.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
npt.NDArray

Array of probability contributions from each disaggregation bin. Array has demensionallity matching the number of disaggregation dimensions with the length along each dimension matching the number of bins. The order of dimensions matches the order of the bins from the get_bin_centers method. Indexing order is 'matrix' indexing.

Raises:

Type Description
KeyError

If no records or more than one record is found in the database.

DynamoGridLoader

A class for loading hazard grid data from toshi-hazard-store DynamoDB.

get_grid(hazard_model_id: str, imt: str, grid_name: str, vs30: int, poe: ProbabilityEnum, agg: str) -> npt.NDArray

Get the hazard grid IMTL values.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model. Specific use will depend on the DataLoader type.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
grid_name str

The site location for the hazard curve.

required
vs30 int

The vs30 of the site.

required
poe ProbabilityEnum

The probability of exceedance.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
npt.NDArray

The intensity measure levels (IMTLs) at the poe of interest over the grid. The array is 1D and its entries are in the same order as the locations retrieved from nzshm_common.grids.get_location_grid.

OQCSVHazardLoader

A class for loading hazard curves from OpenQuake csv output.

__init__(output_dir: Path | str)

Initialize a new OQCSVHazardLoader object.

Parameters:

Name Type Description Default
output_dir Path | str

The path to the folder where the output csv files are stored.

required

get_levels(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, agg: str) -> npt.NDArray

Get the intensity measure levels for a hazard curve.

Note that because the OpenQuake csv file does not store the site conditions, the vs30 argument is a dummy value. It is the responsibility of the user to check that the OpenQuake calculation was performed with the desired site conditions.

Parameters:

Name Type Description Default
hazard_model_id str

The calculation ID of the OpenQuake run.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

Not used.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
npt.NDArray

The intensity measure values.

get_probabilities(hazard_model_id: str | int, imt: str, location: CodedLocation, vs30: int, agg: str) -> npt.NDArray

Get the probablity values for a hazard curve.

Note that because the OpenQuake csv file does not store the site conditions, the vs30 argument is a dummy value. It is the responsibility of the user to check that the OpenQuake calculation was performed with the desired site conditions.

Parameters:

Name Type Description Default
hazard_model_id str | int

The calculation ID of the OpenQuake run.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

Not used.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
npt.NDArray

The probability values.

Raises:

Type Description
KeyError

If no records or more than one record is found in the database.

THSHazardLoader

A class for loading hazard curves from toshi-hazard-store.

Specify the location of the dataset with environment variable 'THS_DATASET_AGGR_URI'.

__init__() -> None

Initialize a THSHazardLoader object.

get_levels(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, agg: str) -> npt.NDArray

Get the intensity measure levels for a hazard curve.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

The vs30 of the site.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
npt.NDArray

The intensity measure values.

get_probabilities(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, agg: str) -> npt.NDArray

Get the probablity values for a hazard curve.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

The vs30 of the site.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
npt.NDArray

The probability values.

Raises:

Type Description
KeyError

If no records are found.

OQCSVDisaggLoader

A class for loading disaggregations from OpenQuake csv output.

__init__(output_dir: Path | str)

Initialize a new OQCSVDisaggLoader object.

Parameters:

Name Type Description Default
output_dir Path | str

The path to the folder where the output csv files are stored.

required

get_bin_centers(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, poe: ProbabilityEnum, agg: str) -> dict[str, npt.NDArray]

Get the disaggregation bin centers.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model. Specific use will depend on the DataLoader type.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

Not used.

required
poe ProbabilityEnum

The probability of exceedance.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
dict[str, npt.NDArray]

Array of probability contributions from each disaggregation bin. Array has demensionallity matching the number of disaggregation dimensions with the length along each dimension matching the number of bins. The order of dimensions matches the order of the bins from the get_bin_centers method.

Raises:

Type Description
KeyError

If no records or more than one record is found in the database.

get_bin_edges(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, poe: ProbabilityEnum, agg: str) -> dict[str, npt.NDArray] cached

Get the disaggregation bin centers.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model. Specific use will depend on the DataLoader type.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

The vs30 of the site.

required
poe ProbabilityEnum

The probability of exceedance.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
dict[str, npt.NDArray]

The disaggregation bin centers with the keys being the disaggregation dimension names (e.g. "TRT", "dist") and the values being the bin centers.

get_disagg(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, poe: ProbabilityEnum, agg: str) -> npt.NDArray

Get the disaggregation values.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model. Specific use will depend on the DataLoader type.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

Not used.

required
poe ProbabilityEnum

The probability of exceedance.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
npt.NDArray

Array of probability contributions from each disaggregation bin. Array has demensionallity matching the number of disaggregation dimensions with the length along each dimension matching the number of bins. The order of dimensions matches the order of the bins from the get_bin_centers method. Indexing order is 'matrix' indexing.

Raises:

Type Description
KeyError

If no records or more than one record is found in the database.

THPHazardLoader

A class for creating hazard curves from user-defined hazard models.

This class allows a user to calculate hazard curves from a hazard model comprised of user-defined source and ground motion logic trees. The logic trees are comprised of branches for which realizations have been pre-computed and stored in a Arrow dataset by toshi-hazard-store. See the nzshm-model documentation for how to build the logic tree objects needed to define the hazard model.

The location of the realizations database is set with the environment variable THP_RLZ_DIR, in a .env file or by passing the location on initilaization. The location can be a local file path or an s3 bucket URI.

Examples:

from nzshm_hazlab.data.data_loaders import THPHazardLoader
from nzshm_hazlab.data import HazardCurves
from nzshm_model.logic_tree import SourceLogicTree, GMCMLogicTree

hazard_model_ths = "NSHM_v1.0.4"
slt = SourceLogicTree.from_json("srm_logic_tree.json")
gmcm = GMCMLogicTree.from_json("gmcm_logic_tree.json")
thp_loader = THPHazardLoader("NZSHM22", slt, gmcm)

branch_index_table = build_branch_index_table(logic_tree.branch_hash_table, self.component_digests) instance-attribute

compatible_calc_id = compatible_calc_id instance-attribute

component_digests = [branch.hash_digest for branch in component_branches] instance-attribute

dataset = data.get_realizations_dataset(rlz_dir=rlz_dir) instance-attribute

gmms_digests = [branch.gmcm_hash_digest for branch in component_branches] instance-attribute

sources_digests = [branch.source_hash_digest for branch in component_branches] instance-attribute

weights = logic_tree.weights instance-attribute

__init__(compatible_calc_id: str, srm_logic_tree: SourceLogicTree, gmcm_logic_tree: GMCMLogicTree, rlz_dir: str | Path | None = None)

Initialize a new THPHazardLoader object.

Parameters:

Name Type Description Default
compatible_calc_id str

The ID of a compatible calculation for PSHA engines interoperability. See the toshi-hazard-store documentation for details.

required
srm_logic_tree SourceLogicTree

The seismicity rate model (aka source model) logic tree.

required
gmcm_logic_tree GMCMLogicTree

The ground motion model logic tree.

required
rlz_dir str | Path | None

Location of realization dataset. If not passed, function will use env var.

None

get_levels(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, agg: str) -> npt.NDArray

Get the intensity measure levels for a hazard curve.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model. This is not used for the THP loader and can take on any value.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

The vs30 of the site.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
npt.NDArray

The intensity measure values.

get_probabilities(hazard_model_id: str, imt: str, location: CodedLocation, vs30: int, agg: str) -> npt.NDArray

Get the probablity values for a hazard curve.

Parameters:

Name Type Description Default
hazard_model_id str

The identifier of the hazard model. This is not used for the THP loader and can take on any value.

required
imt str

The intesity measure type (e.g. "PGA", "SA(1.0)").

required
location CodedLocation

The site location for the hazard curve.

required
vs30 int

The vs30 of the site.

required
agg str

The statistical aggregate curve (e.g. "mean", "0.1") where fractions represent fractile curves.

required

Returns:

Type Description
npt.NDArray

The probability values.