ISEPOS-2373 Simplify code
This commit is contained in:
parent
17cbcc8e79
commit
9c58664770
@ -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
|
||||
from matplotlib.ticker import MultipleLocator
|
||||
from matplotlib.contour import ContourSet
|
||||
import xml.etree.ElementTree as ET
|
||||
import json
|
||||
|
||||
logger = getDefaultLogger('igfash')
|
||||
|
||||
@ -495,37 +497,17 @@ verbose: {verbose}")
|
||||
|
||||
# Save the figure
|
||||
fig.canvas.draw()
|
||||
svg_path = f"overlay_{j}.svg"
|
||||
plt.savefig(svg_path, bbox_inches="tight", pad_inches=0, transparent=True)
|
||||
overlay_filename = f"overlay_{j}.svg"
|
||||
plt.savefig(overlay_filename, bbox_inches="tight", pad_inches=0, transparent=True)
|
||||
plt.close(fig)
|
||||
|
||||
|
||||
import xml.etree.ElementTree as ET # <-- TODO place this with other imports
|
||||
import json
|
||||
|
||||
# -----------------------------------------
|
||||
# Inject bounding box (BBOX) metadata into the SVG
|
||||
# -----------------------------------------
|
||||
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()
|
||||
|
||||
# (Optional) Also store the bounding box as a data attribute for quick access
|
||||
root.set("data-map-bounds", 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
|
||||
# -----------------------------------------
|
||||
# Embed geographic bounding box into the SVG
|
||||
map_bounds = dict(zip(("south", "west", "north", "east"),
|
||||
map(float, (lat.min(), lon.min(), lat.max(), lon.max()))))
|
||||
tree = ET.parse(overlay_filename)
|
||||
tree.getroot().set("data-map-bounds", json.dumps(map_bounds))
|
||||
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}")
|
||||
|
||||
# Make the color bar
|
||||
cmap_name = 'viridis'
|
||||
|
Loading…
Reference in New Issue
Block a user