Skip to content

Add SGRID metadata to generic datasets#2647

Merged
VeckoTheGecko merged 11 commits into
Parcels-code:mainfrom
VeckoTheGecko:push-tywxqruslnrl
May 29, 2026
Merged

Add SGRID metadata to generic datasets#2647
VeckoTheGecko merged 11 commits into
Parcels-code:mainfrom
VeckoTheGecko:push-tywxqruslnrl

Conversation

@VeckoTheGecko
Copy link
Copy Markdown
Contributor

@VeckoTheGecko VeckoTheGecko commented May 28, 2026

Description

This PR does some refactoring/prep work on datasets ahead of removing the XGrid.from_dataset() code path which is being deprecated. This is in favour of the FieldSet.from_sgrid_conventions() code path which directly constructs the grid.

This is ultimately working towards #2646

This PR:

  • Renames datasets_comodo back to datasets
    • A dataset can adhere both to COMODO and SGRID conventions since they don't conflict. I was thinking that using datasets as the default for most test cases would be great since the COMODO dimension naming is quite nice. It now having SGRID metadata makes ingestion much easier.
  • Attaches SGRID metadata to these datasets
  • Adds datasets['ds_2d_inner'] and datasets['ds_2d_outer']
    • For completeness, and so they can be used as ds_2d_padded_both and ds_2d_padded_none in datasets_sgrid
  • (see commit history for more info)

Checklist

  • Closes None
  • Tests added - NA
  • This PR targets the correct branch (main for normal development, v3-support for v3 support)

AI Disclosure

None used

At the moment XGrid.from_dataset uses xgcm internals to set the time dimension. Once the `from_dataset` code path is dropped, this can be enabled again
Update ds_2d_padded_both and ds_2d_padded_none
Now that the datasets themselves have sgrid metadata, theres no need to have this extra dataset
of the grid.
"""
return ds.drop_vars(ds.data_vars)
return ds.drop_vars(set(ds.data_vars) - {"grid"}) # don't drop sgrid metadata
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This function will be removed in a future PR anyway (once from_dataset is removed)

grid.to_attrs(),
)
ds.attrs["Conventions"] = "SGRID"
# ds.attrs["Conventions"] = "SGRID" # TODO: re-enable once XGrid.from_dataset is gone
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was needed to get around some xgcm internals - will be re-enabled in a future PR.

@VeckoTheGecko VeckoTheGecko mentioned this pull request May 28, 2026
3 tasks
Copy link
Copy Markdown
Member

@erikvansebille erikvansebille left a comment

Choose a reason for hiding this comment

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

Looks good; just one question below

Comment thread src/parcels/_datasets/structured/generic.py
@VeckoTheGecko VeckoTheGecko merged commit 558d2c5 into Parcels-code:main May 29, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Parcels development May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants