ISEPOS-2373 Add coordinates to SVG overlay files #10
@ -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')
|
||||
|
||||
@ -239,6 +241,9 @@ verbose: {verbose}")
|
||||
grid_y_max = int(ceil(y_max / 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
|
||||
nx = int((grid_x_max - grid_x_min) / grid_dim) + 1
|
||||
ny = int((grid_y_max - grid_y_min) / grid_dim) + 1
|
||||
@ -495,9 +500,18 @@ verbose: {verbose}")
|
||||
|
||||
# Save the figure
|
||||
fig.canvas.draw()
|
||||
plt.savefig("overlay_" + str(j) + ".svg", 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)
|
||||
|
||||
# Embed geographic bounding box into the SVG
|
||||
map_bounds = dict(zip(("south", "west", "north", "east"),
|
||||
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))
|
||||
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'
|
||||
width = 50
|
||||
|
Loading…
Reference in New Issue
Block a user