Skip to content

plot

plot_hazard_curve(axes: Axes, data: HazardCurves, hazard_model_id: str, location: CodedLocation, imt: str, vs30: int, aggs: list[str], **kwargs: Any) -> list[Line2D]

Plot hazard curves with optional error bound estimates.

If more than one item is passed to aggs they will be treated as error bound estimates. The area between the inner values will be shaded and outer values will be plotted with a thin line. If an odd number of aggs is provided, the centre value will be plotted as a thick line; this is usually a central value such as the mean or 50th percentile aggregate. See example.

Parameters:

Name Type Description Default
axes Axes

Handle of axes to plot to.

required
data HazardCurves

The hazard curve data.

required
hazard_model_id str

The id of the hazard model to plot.

required
location CodedLocation

The site location.

required
imt str

The intensity measure type to plot (e.g. "PGA", SA(1.0)")

required
vs30 int

The site vs30 to plot.

required
aggs list[str]

The aggregate statistics to plot (e.g. "mean", "0.1")

required
kwargs Any

Any additional arguments to pass to the matplotlib plot function.

{}

Returns:

Type Description
list[Line2D]

The handles of the plotted lines.

Example

This will plot the mean hazard curve along with 60% and 80% confidence intervals as dashed lines and label the curve "PGA vs30=400".

>>> from nzshm_hazlab.data.data_loaders import THSHazardLoader
>>> from nzshm_hazlab.data.hazard_curves import HazardCurves
>>> from nzshm_hazlab.plot import plot_hazard_curve
>>> from nzshm_common import CodedLocation
>>> import matplotlib.pyplot as plt

>>> hazard_model_id = "NSHM_v1.0.4"
>>> loader = THSHazardLoader()
>>> hazard_curves = HazardCurves(loader=loader)
>>> location_id = "WLG"
>>> location = CodedLocation(-41.3, 174.78, 0.001)

>>> aggs = ["0.1", "0.2", "mean", "0.8", "0.9"]

>>> fig, ax = plt.subplots(1,1)
>>> line_handles = plot_hazard_curve(
        ax, hazard_curves, hazard_model_id, location, "PGA", 400, aggs, label="PGA vs30=400", linestyle="--"
    )

plot_uhs(axes: Axes, data: HazardCurves, hazard_model_id: str, location: CodedLocation, imts: list[str], poe: float, inv_time: float, vs30: int, aggs: list[str], **kwargs: Any) -> list[Line2D]

Plot uniform hazard spectra curves with optional error bound estimates.

If more than one item is passed to aggs they will be treated as error bound estimates. The area between the inner values will be shaded and outer values will be plotted with a thin line. If an odd number of aggs is provided, the centre value will be plotted as a thick line; this is usually a central value such as the mean or 50th percentile aggregate. See example.

Parameters:

Name Type Description Default
axes Axes

Handle of axes to plot to.

required
data HazardCurves

The hazard curve data.

required
hazard_model_id str

The id of the hazard model to plot.

required
location CodedLocation

The site location.

required
imts list[str]

The periods as IMTs (e.g. ["PGA", SA(1.0)", "SA(2.0)"])

required
poe float

The proability of exceedance at which to calculate the UHS.

required
inv_time float

The investigation time for the poe.

required
vs30 int

The site vs30 to plot.

required
aggs list[str]

The aggregate statistics to plot (e.g. "mean", "0.1")

required
kwargs Any

Any additional arguments to pass to the matplotlib plot function.

{}

Returns:

Type Description
list[Line2D]

The handles of the plotted lines.

Example

This will plot the mean UHS curve along with 60% and 80% confidence intervals as dashed lines and label the curve "vs30=400".

>>> from nzshm_hazlab.data.data_loaders import THSHazardLoader
>>> from nzshm_hazlab.data.hazard_curves import HazardCurves
>>> from nzshm_hazlab.plot import plot_uhs
>>> from nzshm_common import CodedLocation
>>> import matplotlib.pyplot as plt

>>> hazard_model_id = "NSHM_v1.0.4"
>>> loader = THSHazardLoader()
>>> hazard_curves = HazardCurves(loader=loader)
>>> location_id = "WLG"
>>> location = CodedLocation(-41.3, 174.78, 0.001)

>>> aggs = ["0.1", "0.2", "mean", "0.8", "0.9"]
>>> imts = ["PGA", "SA(0.2)", "SA(0.5)", "SA(1.0)", "SA(2.0)", "SA(3.0)", "SA(5.0)", "SA(10.0)"]

>>> fig, ax = plt.subplots(1,1)
>>> line_handles = plot_uhs(
        ax, hazard_curves, hazard_model_id, location, imts, 400, aggs, label="vs30=400", linestyle="--"
    )

plot_disagg_1d(axes: Axes, data: Disaggregations, hazard_model_id: str, location: CodedLocation, imt: str, vs30: int, poe: ProbabilityEnum, agg: str, dimension: str, **kwargs: Any) -> Axes

Make a bar plot of percent contribution to hazard along a given dimension.

Parameters:

Name Type Description Default
axes Axes

Axes on which to create the bar plot.

required
data Disaggregations

The disaggregation data.

required
hazard_model_id str

The d of the hazard model to plot.

required
location CodedLocation

The site location.

required
imt str

The intensity measure type to plot (e.g. "PGA", SA(1.0)")

required
vs30 int

The site vs30 to plot.

required
poe ProbabilityEnum

The probabilty of exceedance on the mean hazard curve at which the disggregation is calcualted.

required
agg str

The aggregate statistic (e.g. 'mean' would plot the mean disaggregation and '0.5' would plot the median disaggregation)

required
dimension str

The disaggregation dimension (also known as the projection) to plot as the independent variable.

required
kwargs Any

Any additional arguments to pass to the matplotlib plot function.

{}

Returns:

Type Description
Axes

The axes on which the bar plot was created.

plot_disagg_2d(axes: Union[Axes, Sequence[Axes]], data: Disaggregations, hazard_model_id: str, location: CodedLocation, imt: str, vs30: int, poe: ProbabilityEnum, agg: str, dimensions: list[str], pct_lim: list[float] | None = None, split_by_trt: bool = False, **kwargs: Any) -> tuple[Axes, ...]

Make a 2D pseudocolor plot of percent contribution to hazard along two dimensions.

Parameters:

Name Type Description Default
axes Union[Axes, Sequence[Axes]]

Axes on which to create the bar plot. If split_by_trt is true, this must be a list of Axes objects with the number of elements equal to the number of tectonic tregion types.

required
data Disaggregations

The disaggregation data.

required
hazard_model_id str

The d of the hazard model to plot.

required
location CodedLocation

The site location.

required
imt str

The intensity measure type to plot (e.g. "PGA", SA(1.0)")

required
vs30 int

The site vs30 to plot.

required
poe ProbabilityEnum

The probabilty of exceedance on the mean hazard curve at which the disggregation is calcualted.

required
agg str

The aggregate statistic (e.g. 'mean' would plot the mean disaggregation and '0.5' would plot the median disaggregation)

required
dimensions list[str]

The disaggregation dimensions (also known as the projection) to use.

required
pct_lim list[float] | None

The percent contribution limits for the colormap. Colormap will autoscale if not given.

None
split_by_trt bool

If True, split the plots into seperate TRT (tectonic retion type) plots.

False
kwargs Any

Any additional arguments to pass to the matplotlib plot function.

{}

Returns:

Type Description
tuple[Axes, ...]

Tuple of axes on which the plot(s) were created.

Raises:

Type Description
ValueError

If demensions does not have len 2.

ValueError

If pct_lim does not have len 2.

ValueError

If split_by_trt and len(axes) does not match the number of TRTs

TypeError

If split_by_trt and axes is not a Sequence.

KeyError

If shading is given as a keword argument. Shading is always set to 'nearest'.

plot_disagg_3d(fig: Figure, data: Disaggregations, hazard_model_id: str, location: CodedLocation, imt: str, vs30: int, poe: ProbabilityEnum, agg: str, dist_lim: list[float] | None = None, mag_lim: list[float] | None = None) -> Axes

Make a 3D bar plot of percent contribution to hazard.

The disaggregation will be plotted as a function of distance and magnitude colored by epislon.

Parameters:

Name Type Description Default
fig Figure

Figure on which to create the bar plot.

required
data Disaggregations

The disaggregation data.

required
hazard_model_id str

The d of the hazard model to plot.

required
location CodedLocation

The site location.

required
imt str

The intensity measure type to plot (e.g. "PGA", SA(1.0)")

required
vs30 int

The site vs30 to plot.

required
poe ProbabilityEnum

The probabilty of exceedance on the mean hazard curve at which the disggregation is calcualted.

required
agg str

The aggregate statistic (e.g. 'mean' would plot the mean disaggregation and '0.5' would plot the median disaggregation)

required
dist_lim list[float] | None

The distance plot limits.

None
mag_lim list[float] | None

The magnitude plot limits.

None

Returns:

Type Description
Axes

The axes on which the plot was created.

plot_hazard_map(hazard_grids: HazardGrids, hazard_model_id: str, grid_name: str, imt: str, vs30: int, poe: ProbabilityEnum, agg: str, cmap: str = 'inferno', clim: list[float] | None = None, ll_lim: list[float] | None = None) -> tuple[Figure, GeoAxes]

Create a hazard map.

This function will plot the hazard level (imtl) at a particular probability for all locations in a grid of geographic points.

Parameters:

Name Type Description Default
hazard_grids HazardGrids

The HazardGrids object that retrieves/stores the hazard data.

required
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

A grid name from nzshm_common. Use nzshm_common.grids.get_location_grid_names() to find a list of valid grid names.

required
vs30 int

The vs30 of the sites.

required
poe ProbabilityEnum

Probability of exceedance

required
agg str

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

required
cmap str

The colormap. See the matplotlib documentation on available colormaps.

'inferno'
clim list[float] | None

The limits of the color map. Default is [0, max(imtl)].

None
ll_lim list[float] | None

The longitude and latitude plot limtis. Default is [165, 180, -48, -34].

None

Returns:

Type Description
tuple[Figure, GeoAxes]

Tuple of figure and axes objects on which the plot is created.

plot_hazard_diff_map(hazard_grids: Sequence[HazardGrids], hazard_model_ids: Sequence[str], grid_name: str, imts: Sequence[str], vs30s: Sequence[int], poes: Sequence[ProbabilityEnum], aggs: Sequence[str], diff_type: Diff, cmap: str = 'inferno', clim: list[float] | None = None, ll_lim: list[float] | None = None) -> tuple[Figure, GeoAxes]

Create a hazard difference map.

This function will plot the difference or ratio of hazard levels (imtl). The map will be the ratio of the 1st to the 0th or difference between the 1st and the 0th elements of the arguments passed. The 0th grid is retrieved using the 0th element of the Sequence type arguments and the 1st grid is retrieved using the 1st element.

Parameters:

Name Type Description Default
hazard_grids Sequence[HazardGrids]

The HazardGrids objects that retrieves/stores the hazard data.

required
hazard_model_ids Sequence[str]

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

required
imts Sequence[str]

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

required
grid_name str

A grid name from nzshm_common. Use nzshm_common.grids.get_location_grid_names() to find a list of valid grid names.

required
vs30s Sequence[int]

The vs30s of the sites.

required
poes Sequence[ProbabilityEnum]

Probabilities of exceedance

required
aggs Sequence[str]

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

required
diff_type Diff

Plot the difference ("sub") or ratio ("ratio") of the hazard grids.

required
cmap str

The colormap. See the matplotlib documentation on available colormaps.

'inferno'
clim list[float] | None

The limits of the color map. Default is [0, max(imtl)].

None
ll_lim list[float] | None

The longitude and latitude plot limtis. Default is [165, 180, -48, -34].

None

Returns:

Type Description
tuple[Figure, GeoAxes]

Tuple of figure and axes objects on which the plot is created.