source_modelling.scripts.plot_rise

Plot multi-segment rupture with rise.

  1"""Plot multi-segment rupture with rise."""
  2
  3from pathlib import Path
  4from typing import Annotated, Optional
  5
  6import typer
  7
  8from pygmt_helper import plotting
  9from source_modelling import srf
 10
 11app = typer.Typer()
 12
 13
 14@app.command(help="Plot multi-segment rupture with rise.")
 15def plot_rise(
 16    srf_ffp: Annotated[
 17        Path, typer.Argument(help="Path to SRF file to plot.", exists=True)
 18    ],
 19    output_ffp: Annotated[
 20        Path, typer.Argument(help="Output plot image.", dir_okay=False)
 21    ],
 22    dpi: Annotated[
 23        float, typer.Option(help="Plot output DPI (higher is better)")
 24    ] = 300,
 25    title: Annotated[Optional[str], typer.Option(help="Plot title to use")] = None,
 26) -> None:
 27    """Plot multi-segment drupture with rise.
 28
 29    Parameters
 30    ----------
 31    srf_ffp : Path
 32        Path to SRF file to plot.
 33    output_ffp : Path
 34        Output plot image.
 35    dpi : float, default 300
 36        Plot output DPI (higher is better).
 37    title : Optional[str], default None
 38        Plot title to use.
 39    """
 40    srf_data = srf.read_srf(srf_ffp)
 41    region = (
 42        srf_data.points["lon"].min() - 0.5,
 43        srf_data.points["lon"].max() + 0.5,
 44        srf_data.points["lat"].min() - 0.25,
 45        srf_data.points["lat"].max() + 0.25,
 46    )
 47    srf_slip = srf_data.slip
 48
 49    srf_data.points["trise"] = (
 50        srf_slip.indptr[1:] - srf_slip.indptr[:-1]
 51    ) * srf_data.points["dt"]
 52    trise_cb_max = srf_data.points["trise"].max()
 53    cmap_limits = (0, trise_cb_max, trise_cb_max / 10)
 54
 55    fig = plotting.gen_region_fig(title, region=region, map_data=None)
 56    for i, segment_points in enumerate(srf_data.segments):
 57        cur_grid = plotting.create_grid(
 58            segment_points,
 59            "trise",
 60            grid_spacing="5e/5e",
 61            region=(
 62                segment_points["lon"].min(),
 63                segment_points["lon"].max(),
 64                segment_points["lat"].min(),
 65                segment_points["lat"].max(),
 66            ),
 67            set_water_to_nan=False,
 68        )
 69        plotting.plot_grid(
 70            fig,
 71            cur_grid,
 72            "hot",
 73            cmap_limits,
 74            ("white", "black"),
 75            transparency=0,
 76            reverse_cmap=True,
 77            plot_contours=False,
 78            cb_label="trise",
 79            continuous_cmap=True,
 80        )
 81        time_grid = plotting.create_grid(
 82            segment_points,
 83            "tinit",
 84            grid_spacing="5e/5e",
 85            region=(
 86                segment_points["lon"].min(),
 87                segment_points["lon"].max(),
 88                segment_points["lat"].min(),
 89                segment_points["lat"].max(),
 90            ),
 91            set_water_to_nan=False,
 92        )
 93        fig.grdcontour(
 94            levels=0.5,
 95            annotation=1,
 96            grid=time_grid,
 97            pen="0.1p",
 98        )
 99        nstk = srf_data.header["nstk"].iloc[i]
100        ndip = srf_data.header["ndip"].iloc[i]
101        corners = segment_points.iloc[[0, nstk - 1, -1, (ndip - 1) * nstk]]
102        fig.plot(
103            x=corners["lon"].iloc[list(range(len(corners))) + [0]].to_list(),
104            y=corners["lat"].iloc[list(range(len(corners))) + [0]].to_list(),
105            pen="0.5p,black,-",
106        )
107
108    fig.savefig(
109        output_ffp,
110        dpi=dpi,
111        anti_alias=True,
112    )
113
114
115if __name__ == "__main__":
116    app()
app = <typer.main.Typer object>
@app.command(help='Plot multi-segment rupture with rise.')
def plot_rise( srf_ffp: Annotated[pathlib.Path, <typer.models.ArgumentInfo object>], output_ffp: Annotated[pathlib.Path, <typer.models.ArgumentInfo object>], dpi: Annotated[float, <typer.models.OptionInfo object>] = 300, title: Annotated[Optional[str], <typer.models.OptionInfo object>] = None) -> None:
 15@app.command(help="Plot multi-segment rupture with rise.")
 16def plot_rise(
 17    srf_ffp: Annotated[
 18        Path, typer.Argument(help="Path to SRF file to plot.", exists=True)
 19    ],
 20    output_ffp: Annotated[
 21        Path, typer.Argument(help="Output plot image.", dir_okay=False)
 22    ],
 23    dpi: Annotated[
 24        float, typer.Option(help="Plot output DPI (higher is better)")
 25    ] = 300,
 26    title: Annotated[Optional[str], typer.Option(help="Plot title to use")] = None,
 27) -> None:
 28    """Plot multi-segment drupture with rise.
 29
 30    Parameters
 31    ----------
 32    srf_ffp : Path
 33        Path to SRF file to plot.
 34    output_ffp : Path
 35        Output plot image.
 36    dpi : float, default 300
 37        Plot output DPI (higher is better).
 38    title : Optional[str], default None
 39        Plot title to use.
 40    """
 41    srf_data = srf.read_srf(srf_ffp)
 42    region = (
 43        srf_data.points["lon"].min() - 0.5,
 44        srf_data.points["lon"].max() + 0.5,
 45        srf_data.points["lat"].min() - 0.25,
 46        srf_data.points["lat"].max() + 0.25,
 47    )
 48    srf_slip = srf_data.slip
 49
 50    srf_data.points["trise"] = (
 51        srf_slip.indptr[1:] - srf_slip.indptr[:-1]
 52    ) * srf_data.points["dt"]
 53    trise_cb_max = srf_data.points["trise"].max()
 54    cmap_limits = (0, trise_cb_max, trise_cb_max / 10)
 55
 56    fig = plotting.gen_region_fig(title, region=region, map_data=None)
 57    for i, segment_points in enumerate(srf_data.segments):
 58        cur_grid = plotting.create_grid(
 59            segment_points,
 60            "trise",
 61            grid_spacing="5e/5e",
 62            region=(
 63                segment_points["lon"].min(),
 64                segment_points["lon"].max(),
 65                segment_points["lat"].min(),
 66                segment_points["lat"].max(),
 67            ),
 68            set_water_to_nan=False,
 69        )
 70        plotting.plot_grid(
 71            fig,
 72            cur_grid,
 73            "hot",
 74            cmap_limits,
 75            ("white", "black"),
 76            transparency=0,
 77            reverse_cmap=True,
 78            plot_contours=False,
 79            cb_label="trise",
 80            continuous_cmap=True,
 81        )
 82        time_grid = plotting.create_grid(
 83            segment_points,
 84            "tinit",
 85            grid_spacing="5e/5e",
 86            region=(
 87                segment_points["lon"].min(),
 88                segment_points["lon"].max(),
 89                segment_points["lat"].min(),
 90                segment_points["lat"].max(),
 91            ),
 92            set_water_to_nan=False,
 93        )
 94        fig.grdcontour(
 95            levels=0.5,
 96            annotation=1,
 97            grid=time_grid,
 98            pen="0.1p",
 99        )
100        nstk = srf_data.header["nstk"].iloc[i]
101        ndip = srf_data.header["ndip"].iloc[i]
102        corners = segment_points.iloc[[0, nstk - 1, -1, (ndip - 1) * nstk]]
103        fig.plot(
104            x=corners["lon"].iloc[list(range(len(corners))) + [0]].to_list(),
105            y=corners["lat"].iloc[list(range(len(corners))) + [0]].to_list(),
106            pen="0.5p,black,-",
107        )
108
109    fig.savefig(
110        output_ffp,
111        dpi=dpi,
112        anti_alias=True,
113    )

Plot multi-segment drupture with rise.

Parameters
  • srf_ffp (Path): Path to SRF file to plot.
  • output_ffp (Path): Output plot image.
  • dpi (float, default 300): Plot output DPI (higher is better).
  • title (Optional[str], default None): Plot title to use.