1

I am following a particular Machine Learning exercise using jupyter notebooks. The link to the exercise is here. I have managed to install all the necessary packages such as netCDF4, rioxarray, xarray and tensorflow. However, I am having trouble reading the netCDF4 datasets using the open_mfdataset function of xarray. This is the error I get if I try to run the following code:

z500 = xr.open_mfdataset('geopotential_500*.nc', combine='by_coords').isel(time=slice(None, None, 12))
z500

The error:

...
ImportError: DLL load failed while importing defs: The specified procedure could not be found.

I also loaded other dependancies of xarray as explained here. However, I cannot proceed to the next step because of the above issue.

Here is my full code:

# Import packages
import xarray as xr
import numpy as np

# Load in the necessary python packages to train in the neural network
import tensorflow.keras as keras
import tensorflow as tf

# Unzip the data
import os
from zipfile import ZipFile

path = "C:/Users/gachuhi/gis800"
filepath = os.path.join(path, 'geopotential_500_5.625deg.zip')
with ZipFile(filepath, 'r') as zObject:
              zObject.extractall(path=os.path.join(path, 'geopotential'))

z500 = xr.open_mfdataset('C:/Users/gachuhi/gis800/geopotential/geopotential_500*.nc', combine='by_coords').isel(time=slice(None, None, 12))
z500

The error ---------

C:\Users\gachuhi\anaconda3\envs\python-gis\lib\site-packages\xarray\backends\plugins.py:71: RuntimeWarning: Engine 'rasterio' loading failed:
DLL load failed while importing _version: The specified procedure could not be found.
  warnings.warn(f"Engine {name!r} loading failed:\n{ex}", RuntimeWarning)
.....
--snip, too long--
.....
File h5py\h5.pyx:1, in init h5py.h5()

ImportError: DLL load failed while importing defs: The specified procedure could not be found.

I tried importing rasterio, netCDF4 as import netCDF4, but whatever attempt was used, it was impossible to open the dataset as intended. I think the end goal of xr.mf_dataset is to combine the netCDF4 files into one file for further analysis but I have been unable to proceed any further with the exercise from this particular point. How do I solve this?

Full path to zip file is here

  • It looks to me like you have a problem with your environment. How did you install the packages? Conda? Pip? Anaconda? A mix? – Michael Delgado Jan 26 '23 at 21:26
  • I installed the packages using conda. I used the anaconda cmd to do this. For example `conda install -c anaconda xarray` for `xarray` and all the rest followed likewise. Due to frustrations I reinstalled the `xarray` with pip, but then when this did not work, I resorted to reinstalling with conda again. I think the problem here is with `xarray` since `tensorflow` seems to just work fine – Samuel Gachuhi Jan 27 '23 at 06:09
  • It’s not a problem with xarray but with the non-python binaries underlying h5py, which is being called to read the files. If you are mixing and matching channels this can get you into this kind of trouble. I’d try deleting anaconda and reinstalling your environment with miniforge or mambaforge - see [this answer](https://stackoverflow.com/a/74248405/3888719) for an explanation – Michael Delgado Jan 27 '23 at 11:46

0 Answers0