.jp2 error in load_earth_relief

I’m attempting to download an DEM with the following command:

grd = pygmt.datasets.load_earth_relief('01m', region= [-125, -120, 40, 49.5], registration="gridline")

and I get the following error:

ERROR 4: `/Users/wthelen/.gmt/server/earth/earth_relief/earth_relief_01m_g/N30W150.earth_relief_01m_g.jp2' not recognized as being in a supported file format. It could have been recognized by driver JP2OpenJPEG, but plugin gdal_JP2OpenJPEG.dylib is not available in your installation. You may install it with 'conda install -c conda-forge libgdal-jp2openjpeg'

However, libgdal-jp2openjpeg is already installed via conda. Within the GDAL_DRIVER_PATH environmental variable, there exists the correct library, gdal_JP2OpenJPEG.dylib.

gdalinfo also shows compatibility:

gdalinfo --formats | grep JPEG
  JPEG -raster- (rwv): JPEG JFIF (*.jpg, *.jpeg)
  JP2OpenJPEG -raster,vector- (rwv): JPEG-2000 driver based on JP2OpenJPEG library (*.jp2, *.j2k)

pygmt (and gdal and GMT) were installed via conda. Here is the output of pygmt.show_version():

PyGMT information:
  version: v0.13.0
System information:
  python: 3.11.10 | packaged by conda-forge | (main, Oct 16 2024, 01:29:22) [Clang 17.0.6 ]
  executable: /opt/miniconda3/envs/pygmt-posit/bin/python
  machine: macOS-13.7-x86_64-i386-64bit
Dependency information:
  numpy: 1.26.4
  pandas: 1.5.3
  xarray: 2024.3.0
  netCDF4: 1.7.1
  packaging: 24.1
  contextily: None
  geopandas: 1.0.1
  IPython: None
  rioxarray: None
  gdal: 3.9.2
  ghostscript: 10.04.0
GMT library information:
  version: 6.5.0
  padding: 2
  share dir: /opt/miniconda3/envs/pygmt-posit/share/gmt
  plugin dir: /opt/miniconda3/envs/pygmt-posit/lib/gmt/plugins
  library path: /opt/miniconda3/envs/pygmt-posit/lib/libgmt.dylib
  cores: 32
  grid layout: rows
  image layout: 
  binary version: 6.5.0

Interestingly, I have a older environment that the command DOES work in. The output of pygmt.show_version() for that environment is below:

PyGMT information:
  version: v0.11.0
System information:
  python: 3.9.16 | packaged by conda-forge | (main, Feb  1 2023, 21:42:20)  [Clang 14.0.6 ]
  executable: /opt/miniconda3/envs/pygmt/bin/python
  machine: macOS-13.7-x86_64-i386-64bit
Dependency information:
  numpy: 1.24.2
  pandas: 2.2.1
  xarray: 2022.11.0
  netCDF4: 1.6.3
  packaging: 23.0
  contextily: None
  geopandas: 0.14.3
  ipython: None
  rioxarray: None
  ghostscript: 9.54.0
GMT library information:
  binary version: 6.4.0
  cores: 32
  grid layout: rows
  image layout: 
  library path: /opt/miniconda3/envs/pygmt/lib/libgmt.dylib
  padding: 2
  plugin dir: /opt/miniconda3/envs/pygmt/lib/gmt/plugins
  share dir: /opt/miniconda3/envs/pygmt/share/gmt
  version: 6.4.0

Thanks in advance for any tips or additional checks to make.

I have pygmt 0.13.0 and have no problem calling grd = pygmt.datasets.load_earth_relief(... as in the topic.

ERROR 4: `/Users/wthelen/.gmt/server/earth/earth_relief/earth_relief_01m_g/N30W150.earth_relief_01m_g.jp2'

Sounds like a corrupt file. Not clear if your two pygmt environments share gmt cache folder, I assume they do not. Try erasing this file and calling pygmt.datasets.load_earth_relief(... again. It should try to download the file again. Or run gmt clear cache, this should wipe the whole gmt cache for the global remote data.