Reading netCDF in Python: Issue within analysis3?

Hi all,

I’m having recent trouble trying to read netCDF files in Python using xarray on my ARE gadi session (Jupyter Notebook). I think it’s an environment/package issue. The line that it struggles with is:

ds = xr.open_mfdataset(yearly_list, engine="netcdf4", chunks={"time": 1200, "realization": -1, "lon": -1, "lat": -1}, combine="by_coords", parallel=True)

Here is the error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[6], line 2
      1 # Near-surface air temperature
----> 2 tas = readData(year_start, "tas", model_code, year_end)['tas']
      3 # Downwelling shortwave radiation
      4 rsds = readData(year_start, "rsds", model_code, year_end)['rsds']

Cell In[3], line 16, in readData(year_start, var, model_code, year_end)
     11 yearly_list = [
     12     file for file in yearly_list
     13     if (match := re.search(r'(\d{4})', file)) and year_start <= int(match.group(1)) <= year_end
     14 ]
     15 # Chunking with Dask
---> 16 ds = xr.open_mfdataset(yearly_list, engine="netcdf4", chunks={"time": 1200, "realization": -1, "lon": -1, "lat": -1}, combine="by_coords", parallel=True)
     18 print(full_path)
     19 return ds[['lon', 'lat', var]]

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.03/lib/python3.11/site-packages/xarray/backends/api.py:1642, in open_mfdataset(paths, chunks, concat_dim, compat, preprocess, engine, data_vars, coords, combine, parallel, join, attrs_file, combine_attrs, **kwargs)
   1637     datasets = [preprocess(ds) for ds in datasets]
   1639 if parallel:
   1640     # calling compute here will return the datasets/file_objs lists,
   1641     # the underlying datasets will still be stored as dask arrays
-> 1642     datasets, closers = dask.compute(datasets, closers)
   1644 # Combine all datasets, closing them in case of a ValueError
   1645 try:

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.03/lib/python3.11/site-packages/dask/base.py:662, in compute(traverse, optimize_graph, scheduler, get, *args, **kwargs)
    659     postcomputes.append(x.__dask_postcompute__())
    661 with shorten_traceback():
--> 662     results = schedule(dsk, keys, **kwargs)
    664 return repack([f(r, *a) for r, (f, a) in zip(results, postcomputes)])

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.03/lib/python3.11/site-packages/xarray/backends/api.py:686, in open_dataset()
    674 decoders = _resolve_decoders_kwargs(
    675     decode_cf,
    676     open_backend_dataset_parameters=backend.open_dataset_parameters,
   (...)
    682     decode_coords=decode_coords,
    683 )
    685 overwrite_encoded_chunks = kwargs.pop("overwrite_encoded_chunks", None)
--> 686 backend_ds = backend.open_dataset(
    687     filename_or_obj,
    688     drop_variables=drop_variables,
    689     **decoders,
    690     **kwargs,
    691 )
    692 ds = _dataset_from_backend_dataset(
    693     backend_ds,
    694     filename_or_obj,
   (...)
    704     **kwargs,
    705 )
    706 return ds

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.03/lib/python3.11/site-packages/xarray/backends/netCDF4_.py:666, in open_dataset()
    644 def open_dataset(
    645     self,
    646     filename_or_obj: str | os.PathLike[Any] | ReadBuffer | AbstractDataStore,
   (...)
    663     autoclose=False,
    664 ) -> Dataset:
    665     filename_or_obj = _normalize_path(filename_or_obj)
--> 666     store = NetCDF4DataStore.open(
    667         filename_or_obj,
    668         mode=mode,
    669         format=format,
    670         group=group,
    671         clobber=clobber,
    672         diskless=diskless,
    673         persist=persist,
    674         auto_complex=auto_complex,
    675         lock=lock,
    676         autoclose=autoclose,
    677     )
    679     store_entrypoint = StoreBackendEntrypoint()
    680     with close_on_error(store):

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.03/lib/python3.11/site-packages/xarray/backends/netCDF4_.py:414, in open()
    399 @classmethod
    400 def open(
    401     cls,
   (...)
    412     autoclose=False,
    413 ):
--> 414     import netCDF4
    416     if isinstance(filename, os.PathLike):
    417         filename = os.fspath(filename)

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.03/lib/python3.11/site-packages/netCDF4/__init__.py:3
      1 # init for netCDF4. package
      2 # Docstring comes from extension module _netCDF4.
----> 3 from ._netCDF4 import *
      4 # Need explicit imports for names beginning with underscores
      5 from ._netCDF4 import __doc__

ImportError: /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.03/lib/python3.11/site-packages/netCDF4/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop

I’ve tried loading conda/analysis3-25.03 and conda/analysis3-25.11 and I get the same issue. I also get the same issue if I use h5netcdf instead of netcdf4 to read the netCDF file. Has the conda environment changed perhaps? Please let me know if there’s more information I can provide.

The loaded modules in my ARE session are:

Currently Loaded Modulefiles:
 1) singularity   2) conda/analysis3-25.03   3) pbs

Cheers,

Joel

Hey Joel,

It looks like for some reason the _edge environment is getting dragged in there. I’m not sure what’s going on with the 25.03 environment at this point, can you reproduce the error in the analysis3-stable environment (just module load conda/analysis3 should get you the one I’m after) and then paste in the stack trace (the error you posted above) here for me?

If it’s the exact same issue then something weird is going on…

Cheers!

2 Likes

Hi Charles,

Thanks so much for the reply. I’ve loaded the stable analysis3 environment (analysis3-25.11) and it has the same issue unfortunately. The error looks slightly longer but looks to be the same problem.

Cheers,

Joel

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[8], line 2
      1 # Near-surface air temperature
----> 2 tas = readData(year_start, "tas", model_code, year_end)['tas']
      3 # Downwelling shortwave radiation
      4 rsds = readData(year_start, "rsds", model_code, year_end)['rsds']

Cell In[5], line 16, in readData(year_start, var, model_code, year_end)
     11     yearly_list = [
     12         file for file in yearly_list
     13         if (match := re.search(r'(\d{4})', file)) and year_start <= int(match.group(1)) <= year_end
     14     ]
     15     # Chunking with Dask
---> 16     ds = xr.open_mfdataset(yearly_list, engine="h5netcdf", chunks={"time": 1200, "realization": -1, "lon": -1, "lat": -1}, combine="by_coords", parallel=True)
     17 #netcdf4
     19     print(full_path)

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/api.py:1648, in open_mfdataset(paths, chunks, concat_dim, compat, preprocess, engine, data_vars, coords, combine, parallel, join, attrs_file, combine_attrs, errors, **kwargs)
   1643     datasets = [preprocess(ds) for ds in datasets]
   1645 if parallel:
   1646     # calling compute here will return the datasets/file_objs lists,
   1647     # the underlying datasets will still be stored as dask arrays
-> 1648     datasets, closers = dask.compute(datasets, closers)
   1650 # Combine all datasets, closing them in case of a ValueError
   1651 try:

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/dask/base.py:681, in compute(traverse, optimize_graph, scheduler, get, *args, **kwargs)
    678     expr = expr.optimize()
    679     keys = list(flatten(expr.__dask_keys__()))
--> 681     results = schedule(expr, keys, **kwargs)
    683 return repack(results)

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/api.py:596, in open_dataset()
    584 decoders = _resolve_decoders_kwargs(
    585     decode_cf,
    586     open_backend_dataset_parameters=backend.open_dataset_parameters,
   (...)
    592     decode_coords=decode_coords,
    593 )
    595 overwrite_encoded_chunks = kwargs.pop("overwrite_encoded_chunks", None)
--> 596 backend_ds = backend.open_dataset(
    597     filename_or_obj,
    598     drop_variables=drop_variables,
    599     **decoders,
    600     **kwargs,
    601 )
    602 ds = _dataset_from_backend_dataset(
    603     backend_ds,
    604     filename_or_obj,
   (...)
    615     **kwargs,
    616 )
    617 return ds

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/h5netcdf_.py:502, in open_dataset()
    499 emit_phony_dims_warning, phony_dims = _check_phony_dims(phony_dims)
    501 filename_or_obj = _normalize_filename_or_obj(filename_or_obj)
--> 502 store = H5NetCDFStore.open(
    503     filename_or_obj,
    504     format=format,
    505     group=group,
    506     lock=lock,
    507     invalid_netcdf=invalid_netcdf,
    508     phony_dims=phony_dims,
    509     decode_vlen_strings=decode_vlen_strings,
    510     driver=driver,
    511     driver_kwds=driver_kwds,
    512     storage_options=storage_options,
    513 )
    515 store_entrypoint = StoreBackendEntrypoint()
    517 ds = store_entrypoint.open_dataset(
    518     store,
    519     mask_and_scale=mask_and_scale,
   (...)
    525     decode_timedelta=decode_timedelta,
    526 )

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/h5netcdf_.py:181, in open()
    165 @classmethod
    166 def open(
    167     cls,
   (...)
    179     storage_options: dict[str, Any] | None = None,
    180 ):
--> 181     import h5netcdf
    183     if isinstance(filename, str) and is_remote_uri(filename) and driver is None:
    184         mode_ = "rb" if mode == "r" else mode

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5netcdf/__init__.py:16
     11 except Exception:
     12     # Local copy or not installed with setuptools.
     13     # Disable minimum version checks on downstream libraries.
     14     __version__ = "999"
---> 16 from .core import CompatibilityError, Dimension, File, Group, Variable  # noqa

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5netcdf/core.py:9
      6 from collections import ChainMap, Counter, OrderedDict, defaultdict
      7 from collections.abc import Mapping
----> 9 import h5py
     10 import numpy as np
     11 from packaging import version

File /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/__init__.py:25
     19 # --- Library setup -----------------------------------------------------------
     20 
     21 # When importing from the root of the unpacked tarball or git checkout,
     22 # Python sees the "h5py" source directory and tries to load it, which fails.
     23 # We tried working around this by using "package_dir" but that breaks Cython.
     24 try:
---> 25     from . import _errors
     26 except ImportError:
     27     import os.path as _op

ImportError: /g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'uf' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'uf' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'radolan' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'rainbow' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'uf' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'radolan' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'rainbow' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'uf' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'radolan' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'rainbow' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'uf' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'radolan' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'rainbow' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/xarray/backends/plugins.py:109: RuntimeWarning: Engine 'uf' loading failed:
/g/data/xp65/public/apps/med_conda/envs/analysis3_edge-25.11/lib/python3.11/site-packages/h5py/../../../././libucc.so.1: undefined symbol: ucs_config_doc_nop
  external_backend_entrypoints = backends_dict_from_pkg(entrypoints_unique)

Yeah, that’s very weird, and definitely not what I was hoping to see.

Please could you post a screencap of your ARE session setup for me? I’m hoping maybe there’ll be some clues in there…

FWIW, I’m able to open datasets using xarray without any issues, so I’m hoping this is a config issue sneaking in somehow and not an environment problem.

I’ve uploaded a screenshot of my config - hopefully you can spot someting in there which looks meaningfully different to yours? (Ignoring all the projects, I have a bunch by default to work on the intake catalog).

Hi Charles,

Thanks for verifying that it works on your end - makes the issue even more odd. I can’t see anything that’s overly different except for you loading openmpi. Here is my setup:

I’m curious does your Jupyter lab show the same directory for the environment?

These are the loaded modules

Currently Loaded Modulefiles:
 1) singularity   2) conda/analysis3-25.11(analysis3:esmvaltool:ilamb)   3) pbs 

The error you’re getting is related to xarray handling parallel worker communication (dask stuff), which makes me wonder if explicitly loading openmpi is stopping me seeing the issue.

Can you try loading openmpi like I have and let me know if that fixes it?

Hi Charles,

Thanks for your reply! Unfortunately it doesn’t seem to change the issue if I load the openmpi directly. But I found a fix - if I use analysis3-25.12 it seems to work now! It may be an issue with older versions or analsysi3-edge? I had to explicity change it to this version

Thanks so much for helping out,

Joel

Weird - the edge environments are more likely to have this sort of issue, but I wouldn’t expect to see it in the regular analysis3-25.11 environment.

Glad you’ve found a fix - I’ll see if I can reproduce the error when I get the chance.

1 Like