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

cfdm.write fails for a vertical CRS with no coordinates #164

Closed
davidhassell opened this issue Nov 3, 2021 · 1 comment · Fixed by #165
Closed

cfdm.write fails for a vertical CRS with no coordinates #164

davidhassell opened this issue Nov 3, 2021 · 1 comment · Fixed by #165
Assignees
Labels
bug Something isn't working netCDF write Relating to writing netCDF datasets
Milestone

Comments

@davidhassell
Copy link
Contributor

We get an untrapped TypeError: 'NoneType object is not subscriptable error when writing some fields that have vertical coordinate reference systems:

>>> f.dump()
-------------------------------------------------------------------------
Field: eastward_wind (ncvar%UM_m01s00i002_vn1107_true_latitude_longitude)
-------------------------------------------------------------------------
Conventions = 'CF-1.9'
_FillValue = -1073741824.0
history = 'Converted from UM/PP by cf-python v3.11.0'
lbproc = '0'
lbtim = '12'
long_name = 'U COMPNT OF WIND AFTER TIMESTEP'
runid = 'aaaaa'
source = 'UM vn1107'
standard_name = 'eastward_wind'
stash_code = '2'
submodel = '1'
um_stash_source = 'm01s00i002'
units = 'm s-1'

Data(time(3), atmosphere_hybrid_height_coordinate(85), latitude(144), longitude(192)) = [[[[-1.71728515625, ..., 3.736572265625]]]] m s-1

Cell Method: time(3): point

Domain Axis: atmosphere_hybrid_height_coordinate(85)
Domain Axis: latitude(144)
Domain Axis: longitude(192)
Domain Axis: time(3)

Dimension coordinate: time
    axis = 'T'
    calendar = '360_day'
    standard_name = 'time'
    units = 'days since 1988-1-1'
    Data(time(3)) = [1988-09-01 00:20:00, 1988-09-01 00:40:00, 1988-09-01 01:00:00] 360_day

Dimension coordinate: atmosphere_hybrid_height_coordinate
    axis = 'Z'
    positive = 'up'
    standard_name = 'atmosphere_hybrid_height_coordinate'
    units = ''
    Data(atmosphere_hybrid_height_coordinate(85)) = [0.00011764710370232077, ..., 0.9652942095588235]
    Bounds:units = ''
    Bounds:Data(atmosphere_hybrid_height_coordinate(85), 2) = [[0.0, ..., 85000.0]]

Dimension coordinate: latitude
    axis = 'Y'
    standard_name = 'latitude'
    units = 'degrees_north'
    Data(latitude(144)) = [-89.375, ..., 89.375] degrees_north
    Bounds:units = 'degrees_north'
    Bounds:Data(latitude(144), 2) = [[-90.0, ..., 90.0]] degrees_north

Dimension coordinate: longitude
    axis = 'X'
    standard_name = 'longitude'
    units = 'degrees_east'
    Data(longitude(192)) = [0.0, ..., 358.125] degrees_east
    Bounds:units = 'degrees_east'
    Bounds:Data(longitude(192), 2) = [[-0.9375, ..., 359.0625]] degrees_east

Auxiliary coordinate: model_level_number
    standard_name = 'model_level_number'
    units = '1'
    Data(atmosphere_hybrid_height_coordinate(85)) = [1, ..., 85] 1

Domain ancillary: id%UM_atmosphere_hybrid_height_coordinate_a
    long_name = 'height based hybrid coeffient a'
    units = 'm'
    Data(atmosphere_hybrid_height_coordinate(85)) = [10.000003814697266, ..., 82050.0078125] m
    Bounds:units = 'm'
    Bounds:Data(atmosphere_hybrid_height_coordinate(85), 2) = [[0.0, ..., 85000.0]] m

Domain ancillary: id%UM_atmosphere_hybrid_height_coordinate_b
    long_name = 'height based hybrid coeffient b'
    units = '1'
    Data(atmosphere_hybrid_height_coordinate(85)) = [0.998870313167572, ..., 0.0] 1
    Bounds:units = '1'
    Bounds:Data(atmosphere_hybrid_height_coordinate(85), 2) = [[1.0, ..., 0.0]] 1

Coordinate reference: standard_name:atmosphere_hybrid_height_coordinate
    Coordinate conversion:standard_name = atmosphere_hybrid_height_coordinate
    Coordinate conversion:a = Domain Ancillary: id%UM_atmosphere_hybrid_height_coordinate_a
    Coordinate conversion:b = Domain Ancillary: id%UM_atmosphere_hybrid_height_coordinate_b
    Coordinate conversion:orog = 

>>> cfdm.write(f, 'delme.nc')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-512c49024828> in <module>
----> 1 cf.write(f[0], 'delme.nc')

~/cf/lib/python3.8/site-packages/cfdm/decorators.py in verbose_override_wrapper(*args, **kwargs)
    169         # enabling
    170         try:
--> 171             return method_with_verbose_kwarg(*args, **kwargs)
    172         except Exception:
    173             raise

~/cf/lib/python3.8/site-packages/cf/read_write/write.py in write(fields, filename, fmt, mode, overwrite, global_attributes, file_descriptors, external, Conventions, datatype, least_significant_digit, endian, compress, fletcher32, shuffle, reference_datetime, verbose, cfa_options, single, double, variable_attributes, string, warn_valid, group, coordinates, HDF_chunksizes, no_shuffle, unlimited)
    716         # --- End: if
    717 
--> 718         netcdf.write(
    719             fields,
    720             filename,

~/cf/lib/python3.8/site-packages/cfdm/decorators.py in verbose_override_wrapper(*args, **kwargs)
    169         # enabling
    170         try:
--> 171             return method_with_verbose_kwarg(*args, **kwargs)
    172         except Exception:
    173             raise

~/cf/lib/python3.8/site-packages/cfdm/read_write/netcdf/netcdfwrite.py in write(self, fields, filename, fmt, mode, overwrite, global_attributes, variable_attributes, file_descriptors, external, Conventions, datatype, least_significant_digit, endian, compress, fletcher32, shuffle, scalar, string, extra_write_vars, verbose, warn_valid, group, coordinates)
   4810                 )
   4811 
-> 4812         self._file_io_iteration(
   4813             mode=effective_mode,
   4814             overwrite=overwrite,

~/cf/lib/python3.8/site-packages/cfdm/read_write/netcdf/netcdfwrite.py in _file_io_iteration(self, mode, overwrite, fields, filename, fmt, global_attributes, variable_attributes, file_descriptors, external, Conventions, datatype, least_significant_digit, endian, compress, fletcher32, shuffle, scalar, string, extra_write_vars, warn_valid, group)
   5090         # ------------------------------------------------------------
   5091         for f in fields:
-> 5092             self._write_field_or_domain(f)
   5093 
   5094         # ------------------------------------------------------------

~/cf/lib/python3.8/site-packages/cfdm/read_write/netcdf/netcdfwrite.py in _write_field_or_domain(self, f, add_to_seen, allow_data_insert_dimension)
   3726                 f, owning_coord_key
   3727                 )) # DCH
-> 3728                 z_axis = self.implementation.get_construct_data_axes(
   3729                     f, owning_coord_key
   3730                 )[0]

TypeError: 'NoneType' object is not subscriptable
>>>
>>> cfdm.environment(paths=False)
Platform: Linux-4.12.14-197.56_9.1.45-cray_shasta_c-x86_64-with-glibc2.10
HDF5 library: 1.10.6
netcdf library: 4.8.0
Python: 3.8.5
netCDF4: 1.5.6
numpy: 1.20.3
cfdm.core: 1.9.0.1
cftime: 1.5.0
netcdf_flattener: 1.2.0
cfdm: 1.9.0.1
@davidhassell davidhassell added the bug Something isn't working label Nov 3, 2021
@davidhassell davidhassell self-assigned this Nov 3, 2021
davidhassell added a commit to davidhassell/cfdm that referenced this issue Nov 3, 2021
@davidhassell davidhassell changed the title cfdm.write fails for a field with a vertical coordinate reference system cfdm.write fails for a vertical CRS with no coordinates Nov 3, 2021
@sadielbartholomew
Copy link
Member

FYI (not sure by the written context here if you were aware @davidhassell), this bug was probably the underlying cause of NCAS-CMS/cf-python#272 as well (I have asked to get confirmation about that, and if it is I can close that issue too now that this one has since been resolved).

@davidhassell davidhassell added this to the 1.9.0.2 milestone Jan 31, 2022
@davidhassell davidhassell added the netCDF write Relating to writing netCDF datasets label Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working netCDF write Relating to writing netCDF datasets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants