Compare commits
8 Commits
cce0cd258d
...
ISEPOS-237
Author | SHA1 | Date | |
---|---|---|---|
86fb03c792 | |||
846078352b | |||
f1472bf250 | |||
d12e91d951 | |||
7c484e3974 | |||
7a39d5a07e | |||
9c58664770 | |||
17cbcc8e79 |
@@ -70,6 +70,8 @@ def main(catalog_file, mc_file, pdf_file, m_file, m_select, mag_label, mc, m_max
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from matplotlib.ticker import MultipleLocator
|
from matplotlib.ticker import MultipleLocator
|
||||||
from matplotlib.contour import ContourSet
|
from matplotlib.contour import ContourSet
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
import json
|
||||||
|
|
||||||
logger = getDefaultLogger('igfash')
|
logger = getDefaultLogger('igfash')
|
||||||
|
|
||||||
@@ -239,6 +241,9 @@ verbose: {verbose}")
|
|||||||
grid_y_max = int(ceil(y_max / grid_dim) * grid_dim)
|
grid_y_max = int(ceil(y_max / grid_dim) * grid_dim)
|
||||||
grid_y_min = int(floor(y_min / grid_dim) * grid_dim)
|
grid_y_min = int(floor(y_min / grid_dim) * grid_dim)
|
||||||
|
|
||||||
|
grid_lat_max, grid_lon_max = utm.to_latlon(grid_x_max, grid_y_max, utm_zone_number, utm_zone_letter)
|
||||||
|
grid_lat_min, grid_lon_min = utm.to_latlon(grid_x_min, grid_y_min, utm_zone_number, utm_zone_letter)
|
||||||
|
|
||||||
# rectangular grid
|
# rectangular grid
|
||||||
nx = int((grid_x_max - grid_x_min) / grid_dim) + 1
|
nx = int((grid_x_max - grid_x_min) / grid_dim) + 1
|
||||||
ny = int((grid_y_max - grid_y_min) / grid_dim) + 1
|
ny = int((grid_y_max - grid_y_min) / grid_dim) + 1
|
||||||
@@ -468,16 +473,6 @@ verbose: {verbose}")
|
|||||||
else:
|
else:
|
||||||
iml_grid_prep = iml_grid_raw
|
iml_grid_prep = iml_grid_raw
|
||||||
|
|
||||||
# TODO Remove. Saving coordinates to
|
|
||||||
# north, south = lat.max(), lat.min()
|
|
||||||
# east, west = lon.max(), lon.min()
|
|
||||||
# bbox_json = {"south": float(south), "west": float(west),
|
|
||||||
# "north": float(north), "east": float(east)}
|
|
||||||
# with open("overlay_bounds.json", "w", encoding="utf‑8") as fh:
|
|
||||||
# json.dump(bbox_json, fh, indent=2)
|
|
||||||
#
|
|
||||||
# logger.info(f"Saved bbox to overlay_bounds.json → {bbox_json}")
|
|
||||||
|
|
||||||
for j in range(0, len(products)):
|
for j in range(0, len(products)):
|
||||||
vmin = min(x for x in iml_grid_prep[j] if x is not np.nan)
|
vmin = min(x for x in iml_grid_prep[j] if x is not np.nan)
|
||||||
vmax = max(x for x in iml_grid_prep[j] if x is not np.nan)
|
vmax = max(x for x in iml_grid_prep[j] if x is not np.nan)
|
||||||
@@ -505,48 +500,19 @@ verbose: {verbose}")
|
|||||||
|
|
||||||
# Save the figure
|
# Save the figure
|
||||||
fig.canvas.draw()
|
fig.canvas.draw()
|
||||||
svg_path = f"overlay_{j}.svg"
|
overlay_filename = f"overlay_{j}.svg"
|
||||||
plt.savefig(svg_path, bbox_inches="tight", pad_inches=0, transparent=True)
|
plt.savefig(overlay_filename, bbox_inches="tight", pad_inches=0, transparent=True)
|
||||||
plt.close(fig)
|
plt.close(fig)
|
||||||
|
|
||||||
|
# Embed geographic bounding box into the SVG
|
||||||
import xml.etree.ElementTree as ET # <-- TODO place this with other imports
|
map_bounds = dict(zip(("south", "west", "north", "east"),
|
||||||
import json
|
map(float, (grid_lat_min, grid_lon_min, grid_lat_max, grid_lon_max))))
|
||||||
|
tree = ET.parse(overlay_filename)
|
||||||
# -----------------------------------------
|
tree.getroot().set("data-map-bounds", json.dumps(map_bounds))
|
||||||
# Inject bounding box (BBOX) metadata into the SVG
|
tree.write(overlay_filename, encoding="utf-8", xml_declaration=True)
|
||||||
# -----------------------------------------
|
logger.info(f"Saved geographic bounds to SVG metadata (data-map-bounds): {overlay_filename} → {map_bounds}")
|
||||||
north, south = lat.max(), lat.min()
|
|
||||||
east, west = lon.max(), lon.min()
|
|
||||||
bbox_dict = {
|
|
||||||
"south": float(south),
|
|
||||||
"west": float(west),
|
|
||||||
"north": float(north),
|
|
||||||
"east": float(east)
|
|
||||||
}
|
|
||||||
tree = ET.parse(svg_path)
|
|
||||||
|
|
||||||
root = tree.getroot()
|
|
||||||
|
|
||||||
# Remove any existing <metadata> tags
|
|
||||||
for old_meta in root.findall("{http://www.w3.org/2000/svg}metadata"):
|
|
||||||
root.remove(old_meta)
|
|
||||||
|
|
||||||
# Add new <metadata> element with the bounding box JSON
|
|
||||||
meta_elem = ET.SubElement(root, "metadata")
|
|
||||||
meta_elem.text = json.dumps(bbox_dict)
|
|
||||||
|
|
||||||
# (Optional) Also store the bounding box as a data attribute for quick access
|
|
||||||
root.set("data-bbox", json.dumps(bbox_dict))
|
|
||||||
tree.write(svg_path, encoding="utf-8", xml_declaration=True)
|
|
||||||
logger.info(f"Embedded bbox into {svg_path} → {bbox_dict}")
|
|
||||||
|
|
||||||
# -----------------------------------------
|
|
||||||
# END Inject bounding box (BBOX) metadata into the SVG
|
|
||||||
# -----------------------------------------
|
|
||||||
|
|
||||||
# Make the color bar
|
# Make the color bar
|
||||||
|
|
||||||
cmap_name = 'viridis'
|
cmap_name = 'viridis'
|
||||||
width = 50
|
width = 50
|
||||||
height = 500
|
height = 500
|
||||||
|
@@ -23,6 +23,15 @@ from seismic_hazard_forecasting import main as shf
|
|||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
|
|
||||||
|
def str2bool(v):
|
||||||
|
if v.lower() in ("True", "TRUE", "yes", "true", "t", "y", "1"):
|
||||||
|
return True
|
||||||
|
elif v.lower() in ("False", "FALSE", "no", "false", "f", "n", "0"):
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
raise argparse.ArgumentTypeError("Boolean value expected.")
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
parser.add_argument("catalog_file", help="Path to input file of type 'catalog'")
|
parser.add_argument("catalog_file", help="Path to input file of type 'catalog'")
|
||||||
@@ -30,23 +39,23 @@ def main(argv):
|
|||||||
parser.add_argument("--pdf_file", help="Path to input file of type 'PDF'", type=str, default=None, required=False)
|
parser.add_argument("--pdf_file", help="Path to input file of type 'PDF'", type=str, default=None, required=False)
|
||||||
parser.add_argument("--m_file", help="Path to input file of type 'm'", type=str, default=None, required=False)
|
parser.add_argument("--m_file", help="Path to input file of type 'm'", type=str, default=None, required=False)
|
||||||
|
|
||||||
parser.add_argument("--m_select", type=bool)
|
parser.add_argument("--m_select", type=str2bool)
|
||||||
parser.add_argument("--mag_label", type=str, default=None, required=False)
|
parser.add_argument("--mag_label", type=str, default=None, required=False)
|
||||||
parser.add_argument("--mc", type=float, default=None, required=False)
|
parser.add_argument("--mc", type=float, default=None, required=False)
|
||||||
parser.add_argument("--m_max", type=float, default=None, required=False)
|
parser.add_argument("--m_max", type=float, default=None, required=False)
|
||||||
parser.add_argument("--m_kde_method", type=str)
|
parser.add_argument("--m_kde_method", type=str)
|
||||||
parser.add_argument("--xy_select", type=bool)
|
parser.add_argument("--xy_select", type=str2bool)
|
||||||
parser.add_argument("--grid_dim", type=int)
|
parser.add_argument("--grid_dim", type=int)
|
||||||
parser.add_argument("--xy_win_method", type=bool)
|
parser.add_argument("--xy_win_method", type=str2bool)
|
||||||
parser.add_argument("--rate_select", type=bool)
|
parser.add_argument("--rate_select", type=str2bool)
|
||||||
parser.add_argument("--time_win_duration", type=float)
|
parser.add_argument("--time_win_duration", type=float)
|
||||||
parser.add_argument("--forecast_select", type=bool)
|
parser.add_argument("--forecast_select", type=str2bool)
|
||||||
parser.add_argument("--custom_rate", type=float, default=None, required=False)
|
parser.add_argument("--custom_rate", type=float, default=None, required=False)
|
||||||
parser.add_argument("--forecast_len", type=float)
|
parser.add_argument("--forecast_len", type=float)
|
||||||
parser.add_argument("--time_unit", type=str)
|
parser.add_argument("--time_unit", type=str)
|
||||||
parser.add_argument("--model", type=str)
|
parser.add_argument("--model", type=str)
|
||||||
parser.add_argument("--products_string", type=str)
|
parser.add_argument("--products_string", type=str)
|
||||||
parser.add_argument("--verbose", type=bool)
|
parser.add_argument("--verbose", type=str2bool)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
shf(**vars(args))
|
shf(**vars(args))
|
||||||
|
Reference in New Issue
Block a user