Repository navigation
Integrate ARS spatialnc library elements - #86
Conversation
There was a problem hiding this comment.
🟡 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
spatialncfrom 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
| 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 |
There was a problem hiding this comment.
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.
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
There was a problem hiding this comment.
Is this basically a copy of what's in the spatialnc package?
There was a problem hiding this comment.
Yes. To be exact - this one
https://github.com/USDA-ARS-NWRC/spatialnc/blob/main/spatialnc/proj.py
and one helper method.

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.