Compare commits
4 Commits
v2.64
...
cce0cd258d
Author | SHA1 | Date | |
---|---|---|---|
cce0cd258d | |||
c20f7c06a7 | |||
22fc9f7c07 | |||
8f1ab5518a |
@@ -468,6 +468,16 @@ 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)
|
||||||
@@ -495,10 +505,48 @@ verbose: {verbose}")
|
|||||||
|
|
||||||
# Save the figure
|
# Save the figure
|
||||||
fig.canvas.draw()
|
fig.canvas.draw()
|
||||||
plt.savefig("overlay_" + str(j) + ".svg", bbox_inches="tight", pad_inches=0, transparent=True)
|
svg_path = f"overlay_{j}.svg"
|
||||||
|
plt.savefig(svg_path, bbox_inches="tight", pad_inches=0, transparent=True)
|
||||||
plt.close(fig)
|
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()
|
||||||
|
|
||||||
|
# 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
|
||||||
|
Reference in New Issue
Block a user