Merge pull request 'ISEPOS-2373 Add coordinates to SVG overlay files' (#10) from ISEPOS-2373-add-coordinates-for-svg-overlay into master
Reviewed-on: #10 Reviewed-by: ftong <ftong@noreply.example.org>
This commit is contained in:
		@@ -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
 | 
				
			||||||
@@ -495,9 +500,18 @@ 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)
 | 
					            overlay_filename = f"overlay_{j}.svg"
 | 
				
			||||||
 | 
					            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
 | 
				
			||||||
 | 
					            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
 | 
					            # Make the color bar
 | 
				
			||||||
            cmap_name = 'viridis'
 | 
					            cmap_name = 'viridis'
 | 
				
			||||||
            width = 50
 | 
					            width = 50
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user