diff --git a/pygmt_helper/examples/ds_sources.py b/pygmt_helper/examples/ds_sources.py index d2268db..67f76c7 100644 --- a/pygmt_helper/examples/ds_sources.py +++ b/pygmt_helper/examples/ds_sources.py @@ -1,15 +1,13 @@ from pathlib import Path -import pygmt -import pandas as pd import numpy as np +import pandas as pd +import pygmt from pygmt_helper import plotting - # Config ds_ffp = Path(__file__).parent / "resources" / "NZ_DSmodel_2015.txt" -map_data_ffp = Path("path to qcore/qcore/data") output_dir = Path("path to the output directory") @@ -26,7 +24,7 @@ ds_df["lon"] = split_ids[:, 1] # Plotting data -map_data = plotting.NZMapData.load(map_data_ffp) if map_data_ffp is not None else None +map_data = plotting.NZMapData.load() if incl_rec_prob: sum_df = ( diff --git a/pygmt_helper/examples/event_stations.py b/pygmt_helper/examples/event_stations.py index 36c90c8..4097a3b 100644 --- a/pygmt_helper/examples/event_stations.py +++ b/pygmt_helper/examples/event_stations.py @@ -22,14 +22,11 @@ inset_region = [172.60, 172.69, -43.545, -43.495] # Output file name output_ffp = Path("path to the output file") -# Path to the map data -# Is part of the qcore package, once installed it -# can be found under qcore/qcore/data -# Set to None for lower quality map, but much faster plotting time -map_data_ffp = None +# If true, then use New Zealand specific map data +use_map_data = True # If true, then use the high resolution topography # This will further increase plot time, and only has an -# effect if map_data_ffp is set +# effect if use_map_data is set use_high_res_topo = True # List of events to highlight events_to_highlight = None @@ -66,11 +63,7 @@ # Load map data -map_data = ( - None - if map_data_ffp is None - else plotting.NZMapData.load(map_data_ffp, high_res_topo=use_high_res_topo) -) +map_data = plotting.NZMapData.load(high_res_topo=use_high_res_topo) if use_map_data else None # Generate the figure fig = plotting.gen_region_fig( diff --git a/pygmt_helper/examples/fault_traces.py b/pygmt_helper/examples/fault_traces.py index 226387d..2afbf1c 100644 --- a/pygmt_helper/examples/fault_traces.py +++ b/pygmt_helper/examples/fault_traces.py @@ -1,15 +1,13 @@ from pathlib import Path -import pandas as pd import numpy as np - +import pandas as pd from qcore import nhm -from pygmt_helper import plots -from pygmt_helper import plotting + +from pygmt_helper import plots, plotting # Config nhm_ffp = Path("path to nhm file") -map_data_ffp = Path("path to qcore/qcore/data") output_dir = Path("path to the output directory") # If true, then for each CS fault @@ -20,7 +18,7 @@ nhm_data = nhm.load_nhm(str(nhm_ffp)) # Load plotting data -map_data = plotting.NZMapData.load(map_data_ffp) +map_data = plotting.NZMapData.load() # Load the source information cybershake_df = pd.read_csv( diff --git a/pygmt_helper/examples/ratio.py b/pygmt_helper/examples/ratio.py index 8916fd3..325d9a8 100644 --- a/pygmt_helper/examples/ratio.py +++ b/pygmt_helper/examples/ratio.py @@ -2,16 +2,14 @@ from pathlib import Path -import pandas as pd import numpy as np +import pandas as pd from pygmt_helper import plotting site_ffp = Path(__file__).parent / "resources" # Config -# map_data_ffp = Path("path to qcore/qcore/data") -map_data_ffp = Path("/Users/claudy/dev/work/code/qcore/qcore/data") site_locations = ( Path(__file__).parent / "resources" @@ -30,7 +28,7 @@ ) # Load plotting data -map_data = plotting.NZMapData.load(map_data_ffp) +map_data = plotting.NZMapData.load() # Add some fake data df["ratio"] = np.random.uniform(-0.5, 0.5, df.shape[0]) diff --git a/pygmt_helper/examples/srf.py b/pygmt_helper/examples/srf.py index e9fc8f5..f5b6704 100644 --- a/pygmt_helper/examples/srf.py +++ b/pygmt_helper/examples/srf.py @@ -7,11 +7,10 @@ import numpy as np import pandas as pd +from qcore import srf from pygmt_helper import plotting -from qcore import srf -map_data_ffp = Path("/path/to/qcore/qcore/data") output_dir = Path("/path/to/output_dir") srf_ffp = Path(__file__).parent / "resources" / "Akatarawa.srf" @@ -23,7 +22,7 @@ slip_values = srf.srf2llv_py(str(srf_ffp), value="slip") # Set map_data to None for faster plotting without topography -map_data = plotting.NZMapData.load(map_data_ffp, high_res_topo=False) +map_data = plotting.NZMapData.load(high_res_topo=False) # map_data = None # Compute colormap limits diff --git a/pygmt_helper/plots.py b/pygmt_helper/plots.py index c8f2c0d..a9db9d7 100644 --- a/pygmt_helper/plots.py +++ b/pygmt_helper/plots.py @@ -212,7 +212,7 @@ def im_plots( output_dir: Path, rel_name: Optional[str] = None, nhm_ffp: Optional[Path] = None, - qcore_data_dir: Optional[Path] = None, + nz_map_data: Optional[plotting.NZMapData] = None, cb_limits_dict: Optional[dict[str, tuple[float, float]]] = None, n_procs: int = 1, ) -> None: @@ -233,8 +233,8 @@ def im_plots( If provided, the function will generate plots for a specific realization (run) identified by this name. nhm_ffp : Path, optional Path to the NHM file, which can provide fault trace information. - qcore_data_dir : Path, optional - Path to the directory containing QCore data used for NZ map generation. + nz_map_data: Optional[NZMapData], default=None + The NZMapData object to supply topographic data. cb_limits_dict : dict, optional A dictionary specifying the color bar limits for each intensity measure (IM). If None, limits will be automatically computed. n_procs : int, optional @@ -245,9 +245,6 @@ def im_plots( None This function saves the generated plots to the specified output directory and does not return any values. """ - nz_map_data = ( - None if qcore_data_dir is None else plotting.NZMapData.load(qcore_data_dir) - ) # Load the trace if possible fault_trace = ( diff --git a/pygmt_helper/plotting.py b/pygmt_helper/plotting.py index 5ee9caa..b22a02b 100644 --- a/pygmt_helper/plotting.py +++ b/pygmt_helper/plotting.py @@ -10,6 +10,7 @@ import pandas as pd import pygmt import xarray as xr +from qcore import gmt from scipy import interpolate from shapely import geometry @@ -25,13 +26,11 @@ class NZMapData(NamedTuple): topo_shading_grid: xr.DataArray = None @classmethod - def load(cls, qcore_data_dir: Path, high_res_topo: bool = False) -> Self: + def load(cls, high_res_topo: bool = False) -> Self: """Load NZMapData from qcore resources. Parameters ---------- - qcore_data_dir : Path - Path to qcore data directory. high_res_topo : bool If True, load high resolution topographic data. @@ -40,17 +39,17 @@ def load(cls, qcore_data_dir: Path, high_res_topo: bool = False) -> Self: NZMapData A map data object containing the paths to the map data. """ - road_ffp = qcore_data_dir / "Paths/road/NZ.gmt" - highway_ffp = qcore_data_dir / "Paths/highway/NZ.gmt" - coastline_ffp = qcore_data_dir / "Paths/coastline/NZ.gmt" - water_ffp = qcore_data_dir / "Paths/water/NZ.gmt" + road_ffp = gmt.GMT_DATA.fetch("data/Paths/road/NZ.gmt") + highway_ffp = gmt.GMT_DATA.fetch("data/Paths/highway/NZ.gmt") + coastline_ffp = gmt.GMT_DATA.fetch("data/Paths/coastline/NZ.gmt") + water_ffp = gmt.GMT_DATA.fetch("data/Paths/water/NZ.gmt") if high_res_topo: - topo_ffp = qcore_data_dir / "Topo/srtm_NZ_1s.grd" - topo_shading_ffp = qcore_data_dir / "Topo/srtm_NZ_1s_i5.grd" + topo_ffp = gmt.GMT_DATA.fetch("data/Topo/srtm_NZ_1s.grd") + topo_shading_ffp = gmt.GMT_DATA.fetch("data/Topo/srtm_NZ_1s_i5.grd") else: - topo_ffp = qcore_data_dir / "Topo/srtm_NZ.grd" - topo_shading_ffp = qcore_data_dir / "Topo/srtm_NZ_i5.grd" + topo_ffp = gmt.GMT_DATA.fetch("data/Topo/srtm_NZ.grd") + topo_shading_ffp = gmt.GMT_DATA.fetch("data/Topo/srtm_NZ_i5.grd") return cls( road_df=geopandas.read_file(road_ffp), @@ -372,7 +371,7 @@ def plot_grid( phase = f"+{cmap_limits[0]}" if cmap_limits[0] > 0 else f"+{cmap_limits[1]}" cb_frame = [f"a+{cmap_limits[2] * 2}{phase}f+{cmap_limits[2]}"] if cb_label is not None: - cb_frame.append(f'x+l"{cb_label}"') + cb_frame.append(f"x+l{cb_label.replace(' ', r'\040')}") fig.colorbar( cmap=cpt_ffp, frame=cb_frame,