From 2ff3f3c8086b061746719a81fb36a44332b63bf0 Mon Sep 17 00:00:00 2001 From: ftong <95+ftong@noreply.example.org> Date: Wed, 8 Jul 2026 16:42:22 +0200 Subject: [PATCH] Update src/seismic_hazard_forecasting.py use dataframe total_bounds as the bounding box of SVG file --- src/seismic_hazard_forecasting.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/seismic_hazard_forecasting.py b/src/seismic_hazard_forecasting.py index 95af87a..ef965e9 100644 --- a/src/seismic_hazard_forecasting.py +++ b/src/seismic_hazard_forecasting.py @@ -723,15 +723,13 @@ verbose: {verbose}") grid_gdf_latlon['AOI'] = ( (centroids_latlon.x >= AOI_lon[0]) & (centroids_latlon.x <= AOI_lon[1]) & (centroids_latlon.y >= AOI_lat[0]) & (centroids_latlon.y <= AOI_lat[1]) - ) - - distances_sel = grid_gdf_latlon.loc[grid_gdf_latlon['AOI']]['distance_matrix'].to_numpy() - centroids_sel = grid_gdf_latlon.loc[grid_gdf_latlon['AOI']].centroid + ) else: grid_gdf_latlon['AOI']=True #set entire grid to be the area of interest - distances_sel = grid_gdf_latlon['distance_matrix'].to_numpy() - centroids_sel = grid_gdf_latlon.centroid + distances_sel = grid_gdf_latlon.loc[grid_gdf_latlon['AOI']]['distance_matrix'].to_numpy() + centroids_sel = grid_gdf_latlon.loc[grid_gdf_latlon['AOI']].centroid + loc_pdf = grid_gdf_latlon['location_PDF'].to_numpy() # extract the previously created location PDF from the GDF # convert distances from m to km because openquake ground motion models take input distances in kilometres @@ -821,16 +819,10 @@ verbose: {verbose}") plt.close(fig) # set image map extent in geographic coordinates - if use_AOI: - north = AOI_lat[1] - south = AOI_lat[0] - east = AOI_lon[1] - west = AOI_lon[0] - else: - north = grid_gdf_latlon.total_bounds[3] - south = grid_gdf_latlon.total_bounds[1] - east = grid_gdf_latlon.total_bounds[2] - west = grid_gdf_latlon.total_bounds[0] + north = grid_gdf_latlon[grid_gdf_latlon['AOI']].total_bounds[3] + south = grid_gdf_latlon[grid_gdf_latlon['AOI']].total_bounds[1] + east = grid_gdf_latlon[grid_gdf_latlon['AOI']].total_bounds[2] + west = grid_gdf_latlon[grid_gdf_latlon['AOI']].total_bounds[0] # Embed geographic bounding box into the SVG map_bounds = dict(zip(("south", "west", "north", "east"), @@ -858,7 +850,7 @@ verbose: {verbose}") extent=[0, 1, vmin, vmax]) # Note: extent order is different for vertical ax.set_xticks([]) # Remove x-ticks for vertical colorbar num_ticks = 11 # Show more ticks - tick_positions = np.linspace(vmin, vmax_hd, num_ticks) + tick_positions = np.linspace(vmin, vmax, num_ticks) ax.set_yticks(tick_positions) ax.set_yticklabels([f"{tick:.2f}" for tick in tick_positions]) # format tick labels ax.set_title(colorbar_title, loc='right', pad=15)