Skip to content

Preserve LLC grid metadata for area weights - #864

Open
fomo-bot wants to merge 3 commits into
mainfrom
fomo/801-llc-grid-metadata-post-823
Open

Preserve LLC grid metadata for area weights#864
fomo-bot wants to merge 3 commits into
mainfrom
fomo/801-llc-grid-metadata-post-823

Conversation

@fomo-bot

@fomo-bot fomo-bot commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve LLC XC/YC/rA through canonicalization as lon_2d/lat_2d/areacello coordinates.
  • Prefer finite non-negative areacello for canonical and standalone area weights, with cosine-latitude fallback only when no cell area exists.
  • Document the tensor-axis versus geographic-coordinate convention for curvilinear sources.

Closes #801

Validation

  • Focused LLC, config, writer, and dataset pytest selections passed.
  • Fresh-cache CPU-hidden suite passed: 465 passed, 2 skipped, 68 deselected, 10 xfailed.
  • uvx pre-commit run --all-files passed.

Note: the first broad CPU-hidden run against the existing local .data_cache failed only in two compact fixture tests because that cache was stale; rerunning those failures and the full suite with a fresh SAMUDRA_TEST_DATA_CACHE passed.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 73c1626834

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/samudra/utils/llc.py
Comment on lines +9 to +10
_LLC_CENTER_LON_CANDIDATES = ("XC", "longitude", "lon")
_LLC_CENTER_LAT_CANDIDATES = ("YC", "latitude", "lat")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve lon/lat metadata before renaming axes

When an LLC source uses the advertised lon/lat candidate names for its 2-D geographic coordinates instead of XC/YC, canonicalize_llc_datasets later attempts to rename the existing i/j dimensions to those same names. Xarray rejects that name collision before _assign_llc_grid_metadata can consume the coordinates, so these fallback candidates cannot actually be loaded. Rename or extract the 2-D metadata before renaming the model-space axes.

Useful? React with 👍 / 👎.

@alxmrs

alxmrs commented Sep 2, 2026

Copy link
Copy Markdown
Member

@fomo-bot will you address the issues that Codex raised in its review?

@alxmrs alxmrs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PR LGTM so far.

@fomo-bot

fomo-bot commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed and pushed in 66860615 on PR #864.

I changed LLC canonicalization to extract the fallback lon/lat/areacello metadata before renaming model-space i/j axes, then added a regression test for that exact collision path.

Validation:

  • 10 passed: tests/test_utils_data.py -k "llc or spherical_area_weights"
  • 6 passed: tests/test_config.py -k llc
  • ruff check, ruff format --check, and git diff --check passed

Fresh GitHub checks on 66860615c4db have data tests, pre-commit, and test-cpu passing. test-gpu and build-and-smoke are still in progress, so I’m scheduling a follow-up to verify the final CI state.

Debug info

@fomo-bot

fomo-bot commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

The remaining external checks have completed on 66860615c4db: test-gpu passed and build-and-smoke passed. The PR is now APPROVED with mergeStateStatus: CLEAN, and the branch is synced with origin.

Debug info

@alxmrs

alxmrs commented Sep 2, 2026

Copy link
Copy Markdown
Member

@codex will you review this PR once more?

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 66860615c4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/samudra/utils/llc.py
Comment on lines +132 to +136
raw_metadata_vars = [
source
for source in {lon_source, lat_source, area_source}
if source not in coords and source in out.variables
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove all raw LLC axis aliases before renaming

When an input exposes both the preferred metadata name and its fallback alias—for example, XC together with a 2-D lon, or YC together with lat—this cleanup drops only the selected XC/YC source. The unused lon/lat variable therefore remains, and the subsequent i -> lon or j -> lat rename still fails with a name collision. The new pre-rename extraction fixes single-alias inputs, but inputs carrying redundant aliases require dropping every raw candidate after the canonical coordinates have been assigned.

Useful? React with 👍 / 👎.

@alxmrs

alxmrs commented Sep 3, 2026

Copy link
Copy Markdown
Member

@codex, will you review this PR once more?

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 7e7660cf33

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Untangle i/j/x/y/lat/lon given LLC datasets too

2 participants