Skip to content

Integrate ARS spatialnc library elements - #86

Merged
jomey merged 3 commits into
mainfrom
spatial_nc
Oct 22, 2026
Merged

jomey merged 3 commits into
mainfrom
spatial_nc

Conversation

@jomey

@jomey jomey commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Remove the last dependency on a non-maintained spatialnc package. One step towards a Python version upgrade. This is a blunt copy and stripping it down to the essentials that SMRF needs.

Follow up

Remove the package from the environment.yaml files in model setup.

@jomey
jomey requested review from a team and a lite review from Copilot October 21, 2026 23:08
@jomey jomey added maintenance Technical updates to code base, dependent libraries, package install, or software architecture Cleanup Remove unused, untested, or complex model logic labels Oct 21, 2026

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.

🟡 Changes recommended

The documented support for already-open NetCDF objects must be restored or the API contract narrowed before approval.

1 open issue
What changed in this PR

This pull request removes SMRF’s dependency on the unmaintained spatialnc package by integrating the required projection and NetCDF helpers locally.

Changes:

  • Adds local projection metadata parsing and NetCDF projection utilities.
  • Updates NetCDF output handling to use the local utilities.
  • Removes spatialnc from the project dependencies.
  • Requires preserving support for already-open NetCDF objects in the metadata-copying function.
File Description
smrf/​utils/​spatialnc.py Adds local projection parsing and NetCDF projection helpers; open Dataset inputs are not currently handled as documented.
smrf/​output/​output_netcdf.py Switches NetCDF output handling to the local projection utilities.
pyproject.toml Removes the obsolete spatialnc dependency and reformats project metadata.

Review effort: Lite

Comment thread smrf/utils/spatialnc.py
Comment on lines +48 to +57
with Dataset(nc_to_copy) as ds:
# Sometimes the projection is called transverse_mercator
if "transverse_mercator" in ds.variables:
map_meta = parse_wkt(ds["transverse_mercator"].getncattr("spatial_ref"))
elif "projection" in ds.variables:
map_meta = parse_wkt(ds["projection"].getncattr("spatial_ref"))
else:
raise Exception("No projection information found in the nc_to_copy")

return map_meta

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not sure we need to support netCDF objects. A future revision of the way that information is copied over is overdue. Then also comply more with CF metadata conventions.

jomey added 3 commits October 21, 2026 17:16
Reduce the external package dependecies and copy the few methods over. The ARS package is no longer
maintained and it is one less library that was only tested with old Python versions.

Closes #12
Comment thread smrf/utils/spatialnc.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this basically a copy of what's in the spatialnc package?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. To be exact - this one
https://github.com/USDA-ARS-NWRC/spatialnc/blob/main/spatialnc/proj.py

and one helper method.

@jomey
jomey merged commit 7a91aa8 into main Oct 22, 2026
6 checks passed
@jomey
jomey deleted the spatial_nc branch October 22, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cleanup Remove unused, untested, or complex model logic maintenance Technical updates to code base, dependent libraries, package install, or software architecture

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants