-
Notifications
You must be signed in to change notification settings - Fork 229
Remove the dependency of netCDF4 #3643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
pygmt/helpers/testing.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Not sure if removing a required dependency counts as a breaking change (i.e. if we should should we put |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
grid.to_netcdf(tmpfile.name) |
because .to_netcdf()
still relies on the netCDF4 engine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: