GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
747 stars 216 forks source link

pygmt.load_dataarray #3270

Closed kjz1997 closed 4 months ago

kjz1997 commented 4 months ago

Description of the problem

When I used pygmt. load_dataarray to read the grd file, the code reported the following error: Value Error: did not find a match in any of the current installed IO backups ['netcdf4 ','scipy'] Advisor clearly selects one of the installed engines via the engine parameter, or installing additional IO dependencies ,but it is possible to not add an engine before

Minimal Complete Verifiable Example

import pygmt
import xarray as xr
import numpy as np

radem = r"F:\2018009_2018021\topo_ra.grd"
fdem = r"F:\topo\dem.grd"
phase = r"F:\2018009_2018021\phasefilt.grd"

data1 = pygmt.load_dataarray(radem)

Full error message

Traceback (most recent call last):
  File "d:\python\PyFile\gmtsar2aps\grdRead.py", line 9, in <module>
    data1 = pygmt.load_dataarray(radem)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kjzha\.conda\envs\pygmt\Lib\site-packages\pygmt\io.py", line 42, in load_dataarray
    with xr.open_dataarray(filename_or_obj, **kwargs) as dataarray:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kjzha\.conda\envs\pygmt\Lib\site-packages\xarray\backends\api.py", line 748, in open_dataarray
    dataset = open_dataset(
              ^^^^^^^^^^^^^
  File "C:\Users\kjzha\.conda\envs\pygmt\Lib\site-packages\xarray\backends\api.py", line 553, in open_dataset
    engine = plugins.guess_engine(filename_or_obj)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kjzha\.conda\envs\pygmt\Lib\site-packages\xarray\backends\plugins.py", line 197, in guess_engine
    raise ValueError(error_msg)
ValueError: did not find a match in any of xarray's currently installed IO backends ['netcdf4', 'scipy']. Consider explicitly selecting one of the installed engines via the ``engine`` parameter, or installing additional IO dependencies, see:
https://docs.xarray.dev/en/stable/getting-started-guide/installing.html
https://docs.xarray.dev/en/stable/user-guide/io.html

System information

PyGMT information:
  version: v0.10.0
System information:
  python: 3.11.7 | packaged by conda-forge | (main, Dec 23 2023, 14:27:59) [MSC v.1937 64 bit (AMD64)]
  executable: C:\Users\kjzha\.conda\envs\pygmt\python.exe
  machine: Windows-10-10.0.19045-SP0
Dependency information:
  numpy: 1.26.3
  pandas: 2.1.4
  xarray: 2023.12.0
  netCDF4: 1.6.5
  packaging: 23.2
  contextily: None
  geopandas: 0.14.4
  IPython: None
  rioxarray: None
  ghostscript: 10.02.0
GMT library information:
  binary version: 6.5.0
  cores: 16
  grid layout: rows
  image layout:
  library path: C:/Users/kjzha/.conda/envs/pygmt/Library/bin/gmt.dll
  padding: 2
  plugin dir: C:/Users/kjzha/.conda/envs/pygmt/Library/bin/gmt_plugins
  share dir: C:/Users/kjzha/.conda/envs/pygmt/Library/share/gmt
  version: 6.5.0
welcome[bot] commented 4 months ago

👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.

weiji14 commented 4 months ago

Could you provide the output of pygmt.grdinfo(radem)? You could also try pygmt.load_dataarray(radem, engine="netcdf4") to see if it works.

Note that pygmt.load_dataarray is basically just a wrapper around xarray.load_dataarray, which is intended to load NetCDF files. So depending on whether your .grd file is actually a NetCDF-4 file internally (see https://docs.generic-mapping-tools.org/6.5/reference/file-formats.html#grid-files), it may or may not be possible to read the file into an xarray.DataArray using the netcdf4 driver.

kjz1997 commented 4 months ago

thanks for your reply,it works,there was an error in my file

在 2024年5月23日,下午4:44,Wei Ji @.***> 写道:

 Could you provide the output of pygmt.grdinfo(radem)? You could also try pygmt.load_dataarray(radem, engine="netcdf4") to see if it works.

Note that pygmt.load_dataarray is basically just a wrapper around xarray.load_dataarray, which is intended to load NetCDF files.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.