Skip to content

Boolean attributes cause problems when converting to netCDF4/HDF5 #10

@davidhassell

Description

@davidhassell

Some created attributes have Boolean values

>>> a =  ppfive.File('/home/david/test2.pp')
>>> a['m01s15i201'].attrs
{'stash_model': 1,
 'stash_code': 15201,
 'lbtim': 121,
 'lbproc': 128,
 'packing_modes': [0],
 'compression_modes': [0],
 'is_packed': False,                         # BOOLEAN
 'is_wgdos_packed': False,                   # BOOLEAN
 'um_version': 405,
 'um_identity': 'UM_m01s15i201_vn405',
 'lbrel': 2,
 'lbfc': 56,
 'lbvc': 8,
 'lbuser5': 0,
 'um_stash_source': 'm01s15i201',
 'standard_name': 'eastward_wind',
 'long_name': 'U COMPNT OF WIND ON PRESSURE LEVELS',
 'units': 'm s-1',
 'source': 'UM vn405',
 'DIMENSION_LIST': (('time',),
  ('air_pressure',),
  ('grid_latitude',),
  ('grid_longitude',)),
 'cell_methods': 'time: mean',
 'coordinates': 'latitude longitude',
 'grid_mapping': 'rotated_latitude_longitude'}

but these are not support by h5netcdf when writing the PP/UM field out to a netCDF file via cfdm.write:

>>> cfdm.write(u, 'delme.nc')
<snip>
CompatibilityError: boolean dtypes are not a supported NetCDF feature, and are not allowed by h5netcdf unless invalid_netcdf=True.

and also with netCDF4:

>>> cfdm.write(u, 'delme.nc', netcdf_backend='netCDF4')
<snip>
TypeError: illegal data type for attribute b'is_packed', must be one of dict_keys(['S1', 'i1', 'u1', 'i2', 'u2', 'i4', 'u4', 'i8', 'u8', 'f4', 'f8']), got b1

We should follow h5netcdf and netCDF4, and not store Boolean-valued attributes, I think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions