Skip to content
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

Cannot save regridder when providing precomputed_weights #433

Open
rhyspoulton opened this issue Nov 11, 2024 · 0 comments
Open

Cannot save regridder when providing precomputed_weights #433

rhyspoulton opened this issue Nov 11, 2024 · 0 comments
Labels
New: Issue Highlight a new community raised "generic" issue Type: Bug

Comments

@rhyspoulton
Copy link

🐛 Bug Report

I am attempting to save a regridder created using the ESMFBilinearRegridder and providing precomputed_weights, but I am enountering the following error when calling save_regridder(regridder, 'saved_regridder.nc'):

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[226], line 2
      1 regridder = esmf_regrid.schemes.ESMFBilinearRegridder(src_gl_cube, tar_gl_cube, precomputed_weights = combined_weights, mdtol=1)
----> 2 save_regridder(regridder, "saved_comb_regridder.nc")
      3 print(regridder.regridder.esmf_version)

File ~/.conda/envs/iris-esmf-regrid/lib/python3.12/site-packages/esmf_regrid/experimental/io.py:270, in save_regridder(rg, filename)
    267 for cube in cube_list:
    268     cube.attributes = attributes
--> 270 iris.fileformats.netcdf.save(cube_list, filename)
...
File ~/.conda/envs/iris-esmf-regrid/lib/python3.12/site-packages/iris/fileformats/netcdf/saver.py:271, in _setncattr(variable, name, attribute)
    269 assert hasattr(variable, "THREAD_SAFE_FLAG")
    270 attribute = _bytes_if_ascii(attribute)
--> 271 return variable.setncattr(name, attribute)

File src/netCDF4/_netCDF4.pyx:3087, in netCDF4._netCDF4.Dataset.setncattr()

File src/netCDF4/_netCDF4.pyx:1888, in netCDF4._netCDF4._set_att()

TypeError: illegal data type for attribute b'ESMF_version', must be one of dict_keys(['S1', 'i1', 'u1', 'i2', 'u2', 'i4', 'u4', 'i8', 'u8', 'f4', 'f8']), got O

And if print out the I print out the emsf_version from the regridder, I can see that is None which is causing the issue with saving:

In  [1]: regridder = esmf_regrid.schemes.ESMFBilinearRegridder(src_cube, tar_cube, precomputed_weights = weights)

In  [2]: regridder.regridder.esmf_version
Out [2]: None

How To Reproduce

Steps to reproduce the behaviour:

Call the save_regridder with a regridder that has precomputed_weight supplied e.g.:

# Create the regridder
regridder = esmf_regrid.schemes.ESMFBilinearRegridder(src_cube, tar_cube, precomputed_weights = weights)

# save the regridder
save_regridder(regridder, 'saved_regridder.nc')

Expected behaviour

No error encountered

Environment

  • OS: Linux
  • esmf_regrid version: 0.11.0
@rhyspoulton rhyspoulton added New: Issue Highlight a new community raised "generic" issue Type: Bug labels Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New: Issue Highlight a new community raised "generic" issue Type: Bug
Projects
None yet
Development

No branches or pull requests

1 participant