Skip to content

Error in cf.write when writing UM data fields #838

@ellgil82

Description

@ellgil82

Hi folks. I'm encountering issues again with processing UM data. It's a related task to ticket #817 but a different error so I figured I'd start a new topic.

I can load in a single file (either on a surface level, UM tiles, or pressure levels) with no problem and perform usual cf-python tasks like amending and adding attributes, but when it comes to writing the file I get an unhashable type error as follows:

>>> cf.write(f[0], 'test.nc')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.11/mf3-23.11.0-0/envs/jaspy3.11-mf3-23.11.0-0-v20240815/lib/python3.11/site-packages/cfdm/decorators.py", line 171, in verbose_override_wrapper
    return method_with_verbose_kwarg(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.11/mf3-23.11.0-0/envs/jaspy3.11-mf3-23.11.0-0-v20240815/lib/python3.11/site-packages/cf/read_write/write.py", line 808, in write
    netcdf.write(
  File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.11/mf3-23.11.0-0/envs/jaspy3.11-mf3-23.11.0-0-v20240815/lib/python3.11/site-packages/cfdm/decorators.py", line 171, in verbose_override_wrapper
    return method_with_verbose_kwarg(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.11/mf3-23.11.0-0/envs/jaspy3.11-mf3-23.11.0-0-v20240815/lib/python3.11/site-packages/cfdm/read_write/netcdf/netcdfwrite.py", line 4911, in write
    self._file_io_iteration(
  File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.11/mf3-23.11.0-0/envs/jaspy3.11-mf3-23.11.0-0-v20240815/lib/python3.11/site-packages/cfdm/read_write/netcdf/netcdfwrite.py", line 5153, in _file_io_iteration
    self._write_global_attributes(fields)
  File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.11/mf3-23.11.0-0/envs/jaspy3.11-mf3-23.11.0-0-v20240815/lib/python3.11/site-packages/cfdm/read_write/netcdf/netcdfwrite.py", line 4289, in _write_global_attributes
    force_global = {
                   ^
  File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.11/mf3-23.11.0-0/envs/jaspy3.11-mf3-23.11.0-0-v20240815/lib/python3.11/site-packages/cfdm/read_write/netcdf/netcdfwrite.py", line 4292, in <dictcomp>
    if len(v) == len(fields) and len(set(v)) == 1
                                     ^^^^^^
TypeError: unhashable type: 'dict'

I've managed to process hourly and daily files with this workflow and v similar code with no problem so far. I've also double-checked that all the files I'm currently trying to process here are fully formed and compliant, so that's not the issue (I think this was the main problem in my previous ticket).

I have also tested this behaviour with a MWE, where I load a UM file and then try to write it to netcdf, and the same occurs, i.e.

f = cf.read('/path/to/file/UM_file')
cf.write(f[0], 'test.nc')

Can you help me understand what's going on here? I am able to save the fields in iris without a problem, so it doesn't seem to be packing or underlying file problem, but I'd like to use cf-python to maintain consistency with the other files I've post-processed with this method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionGeneral questionum/ppRelating to UM or PP format files

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions