Repository navigation
Write X/Y as degrees in geographic dfsu files - #80
Merged
Merged
Conversation
The X-coord and Y-coord static items of a LONG/LAT dfsu hold degrees, but DfsuBuilder records them as eumIGeographicalCoordinate in metre. The LONG/LAT case fails until that is fixed; the projected cases pin the existing metre quantity. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DfsuBuilder always gave the X-coord and Y-coord static items the eumIGeographicalCoordinate quantity in metre. The check that switches them to eumILatLong in degrees for a geographic projection was left commented out, so LONG/LAT files recorded the wrong unit. Re-enable it using MapProjection, which Projections.py now provides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #47
What and why
A dfsu written by
DfsuBuilderwith a geographic projection such asLONG/LATholds its node coordinates in degrees, but theX-coordandY-coordstatic items were recorded aseumIGeographicalCoordinatein metre. The check that switches them toeumILatLongin degrees was left commented out (# TODO: reenable) whenMapProjectionwasn't available yet.Projections.pynow hasMapProjection.IsValidandIsGeographical, so this PR turns the check back on. Files with a projected coordinate system (UTM,NON-UTM) still get metres.The new output matches the geographic dfsu files that DHI tools produce, for example mikeio's public test file
tests/testdata/wind_north_sea.dfsu(LONG/LAT,X-coord=eumILatLong,eumUdegree; see Evidence).Commits
abd3215Test that DfsuBuilder writes X/Y in degrees for geographic projections: a parametrized test that builds a two-triangle mesh forLONG/LAT,UTM-33andNON-UTMand reads back the X/Y quantities. TheLONG/LATcase fails at this commit.25d5f61Write X/Y as degrees in geographic dfsu files: replaces the commented-out block with live code.47ec11aNote the geographic X/Y quantity fix in the changelog: one entry under Unreleased / Fixed. It says the file output changes.Code Review Guide
Glossary
Node id,X-coord,Y-coord,Z-coord, … each with an EUM quantity (item type and unit).eumIGeographicalCoordinate/eumUmeter: the quantity for projected map coordinates in metres.eumILatLong/eumUdegree: the quantity for longitude/latitude in degrees.MapProjection.IsGeographical(wkt): true when the projection string means lon/lat coordinates (LONG/LAT, aGEOGCS[...]WKT), false for projected ones such asUTM-33.Where the change sits
CreateDfsupicks the X/Y quantity from the projection set earlier and uses it for both coordinate static items.Conventions followed
is not Nonebefore usemikecore/DfsuBuilder.py:489
mikecore/DfsuBuilder.py:707
tmp_pathwith the shared_builder()mesh and assert what reads backtests/test_dfsu_builder.py:91
tests/test_dfsu_builder.py:114
Deviations
DfsFileFactory.DfsGenericOpen, notDfsuFile.Open. Why:DfsuFiledoesn't expose the static items' quantities. Alternative: none through the public API.tests/test_dfsu_builder.py:100
tests/test_dfsu_builder.py:122
Evidence
Before (
abd3215, test only):After (
47ec11a):Reference: a geographic dfsu from mikeio's test data already uses this quantity:
Full suite:
uv run pytest: 173 passed, 8 xfailed.uvx pre-commit run --all-files: passed.uv run pyrefly check: 0 errors, 329 warnings (the same as master).Verify it yourself
xy.py: builds a LONG/LAT and a UTM-33 dfsu and prints their X/Y quantitiesReview
47ec11a): no must-fix findings, no suggestions, no questions. It checked separately that a fullGEOGCS[...]WKT is detected as geographic, that the test fails with master'sDfsuBuilder.py, and that pyrefly stays at 329 warnings. Verdict: clean.Risk
Output changes for geographic dfsu files only: their X/Y static items now say
eumILatLong/degree. The coordinate values are unchanged, and projected files keep the same quantity as before (theUTM-33andNON-UTMtest cases). Readers that look at these quantities see what DHI's own geographic files already carry (the mikeio reference above). MIKE IO's test suite (DHI/mikeiomain, throughtest_mikeio.yml) gives the same result on this branch as on master: 978 passed in every job, with the same two failures that master also has (test_eum.py::test_eum_conversionon all 4 jobs,test_dfs2.py::test_select_area_rotated_UTM_2on Linux). Runs: fix/47, master. Unproven: code outside MIKE IO that relies on the old metre quantity for LONG/LAT files.New import:
DfsuBuildernow importsmikecore.Projections. That module is already imported, and its native library already loaded, bymikecore/__init__.py:34, so the import adds no load-time dependency.Missing projection: the
is not Noneguard can't change behaviour, becauseValidate(called first byCreateFile) already rejects a builder without a projection.CI: all PR checks passed on
47ec11a(tests on Ubuntu and Windows, Python 3.11 and 3.14; ruff; pyrefly; CodeQL).Not in this PR
Nothing.
🤖 Generated with Claude Code