Uh oh!
There was an error while loading. Please reload this page.
Remove the dependency of netCDF4 - #3643
Conversation
| return load_dataarray(fname) | ||
| with Session() as lib: | ||
| with lib.virtualfile_out(kind="grid") as voutgrd: | ||
| lib.call_module( | ||
| module="read", args=["@static_earth_relief.nc", voutgrd, "-Tg"] | ||
| ) | ||
| grid = lib.virtualfile_to_raster(vfname=voutgrd, kind="grid") |
There was a problem hiding this comment.
You know what? Maybe we could think of refactoring pygmt.io.load_dataarray to use this with block? It would be a breaking change, but that could mean we can use GMT's I/O directly.
There was a problem hiding this comment.
Yes, actually, I'm thinking if we should provide a wrapper for the special read module, which can read a table, grid, or image, and return pd.DataFrame or xarray.DataArray. The function looks like:
def read(file, kind=None, **kwargs):
if kind == None:
# Try our best to decide the data kind. Or make 'kind' a required parameter
pass code = {"dataset": "d", "grid": "g", "image": "i"}[kind]
func = with Session() as lib:
with lib.virtualfile_out(kind=kind) as voutfile:
lib.call_module(
module="read", args=[file, voutfile, f"-T{code}"]
)
if kind == "dataset":
return lib.virtualfile_to_dataset(vfname=voutfile, **kwargs)
elif kind in {"grid", "image"}
return lib.virtualfile_to_raster(vfname=voutgrd, kind=kind)
For comparison, GMT.jl provides the gmtread/gmtwrite functions, but As I understand it, the functions return the GMT_DATASET/GMT_GRID/GMT_IMAGE containers, rather than data structures in the Julia world.
weiji14
commented
Apr 29, 2025
Not sure if removing a required dependency counts as a breaking change (i.e. if we should should we put |
weiji14
left a comment
There was a problem hiding this comment.
There's a test failing on ubuntu latest - Python 3.12. Need to add a @pytest.mark.skipif(condition=not _HAS_NETCDF4, reason="netCDF4 is not installed") marker for this line:
pygmt/pygmt/tests/test_xarray_backend.py
Line 27 in ae82fd6
because .to_netcdf() still relies on the netCDF4 engine.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
weiji14
left a comment
There was a problem hiding this comment.
Nice, glad to have one less dependency to handle! Remember to remove netCDF4 from the conda-forge feedstock for the next release 🔥
Description of proposed changes
Inspired by #3639 (comment), now it's possible to remove the netCDF4 package from PyGMT's dependency list.
TODO: