Skip to content

Move projection-based axis labels and aspect ratio onto geometry - #991

Open
ecomodeller wants to merge 2 commits into
mainfrom
axis-labels-on-geometry
Open

Move projection-based axis labels and aspect ratio onto geometry#991
ecomodeller wants to merge 2 commits into
mainfrom
axis-labels-on-geometry

Conversation

@ecomodeller

Copy link
Copy Markdown
Member

Axis labels for spatial plots and the plot aspect ratio were decided by if/elif branches living inside the plotting code, duplicated across _FM_plot, _grid_geometry and _data_plot (the latter two byte-for-byte identical). The branches keyed entirely off geometry properties — is_geo, is_local_coordinates, is_spectral, _is_rotated — so the decision belongs on the geometry, not the plotter.

Geometries now expose two properties, _axis_labels and _plot_aspect, and every plotter just reads them. This removes the duplication, takes the branching out of the plotting classes, and makes the labelling consistent across the structured-grid and flexible-mesh plot paths.

One intentional behaviour change: NON-UTM (local-coordinate) grids now label x [m] / y [m], where the structured-grid path previously used [m] / [m]. This unifies on the convention the flexible-mesh path already used.

The axis labels for spatial plots (Easting/Northing, Longitude/Latitude,
etc.) and the plot aspect ratio were decided by if/elif branches inside the
plotting code, duplicated across _FM_plot, _grid_geometry and _data_plot.
The discriminators (is_geo, is_local_coordinates, is_spectral, _is_rotated)
are all geometry properties, so the decision belongs on the geometry.

Geometries now expose `_axis_labels` and `_plot_aspect`; every plotter just
reads them. This removes the duplication and the branching from the plotters.

NON-UTM grids now label "x [m]" / "y [m]" consistently (previously "[m]" in
the grid path), matching the FM convention.
@ecomodeller
ecomodeller requested a review from Copilot June 29, 2026 06:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors spatial plotting so axis labels and plot aspect ratio are derived from geometry properties instead of duplicated if/elif logic inside multiple plotters, aiming to centralize and standardize projection-dependent plotting behavior.

Changes:

  • Added _Geometry._axis_labels and a shared _geographic_aspect() helper to compute projection-based axis labeling and geographic aspect correction.
  • Updated Grid2D/Flexible Mesh geometries to expose _plot_aspect and (where needed) override _axis_labels, and updated plotters to consume these properties.
  • Removed now-duplicated projection/aspect branching helpers from the flexible-mesh plotting code.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/mikeio/spatial/_grid_geometry.py Uses geometry-provided labels/aspect in plotting; adds Grid2D _axis_labels override and _plot_aspect property.
src/mikeio/spatial/_geometry.py Introduces _geographic_aspect() and base _Geometry._axis_labels to centralize projection-based axis labels.
src/mikeio/spatial/_FM_plot.py Removes projection branching helpers and reads _axis_labels/_plot_aspect from FM geometry directly.
src/mikeio/spatial/_FM_geometry.py Moves FM aspect calculation onto geometry via _plot_aspect and updates plotting methods to use geometry labels/aspect.
src/mikeio/dataset/_data_plot.py Removes duplicated projection/aspect branching for Grid2D plotting and consumes geometry _axis_labels/_plot_aspect.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +505 to +511
@property
def _plot_aspect(self) -> Literal["equal"] | float | None:
if self.is_spectral or self._is_rotated or self.is_local_coordinates:
return None
if self.is_geo:
return _geographic_aspect(self.y)
return "equal"
Comment on lines +92 to +96
if self.is_geo:
return "Longitude [degrees]", "Latitude [degrees]"
if self.is_local_coordinates: # NON-UTM
return "x [m]", "y [m]"
return "Easting [m]", "Northing [m]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants