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

datetime64 considered non numeric #101

Open
BorjaEst opened this issue Dec 16, 2021 · 2 comments
Open

datetime64 considered non numeric #101

BorjaEst opened this issue Dec 16, 2021 · 2 comments
Assignees

Comments

@BorjaEst
Copy link

The following dataset:

Dataset:
- Dimensions: bounds(2), time(n), ...
- Coordinates:
  - time (time) datetime64[ns] 2004-01-16
  - ...
 - Data variables:
  - time_bnds (time, bounds2) datetime64[ns] ...
  - ...
- Attributes:
  - Conventions : CF-1.8
  - ...

raises the following error:

ERROR: (7.1): boundary variable with non-numeric data type

See the following code:
https://github.com/cedadev/cf-checker/blob/master/src/cfchecker/cfchecks.py#L1159
checks for:

not self.isNumeric(bounds)

it looks "datetime64" is considered "nonNumeric".

How to reproduce (a bit long):

import cf
import numpy as np

# field: specific_humidity
f = cf.Field()
f.set_properties({'standard_name': 'specific_humidity', 'units': '1'})
d = cf.Data([0.007, 0.034])
f.nc_set_variable('q')

# domain_axis: ncdim%time
c = cf.DomainAxis()
c.set_size(2)
c.nc_set_dimension('time')
f.set_construct(c, key='domainaxis0', copy=False)

# field data axes
f.set_data_axes(('domainaxis0'))

# dimension_coordinate: time
c = cf.DimensionCoordinate()
c.set_properties({'units': 'days since 2004-01-01', 'standard_name': 'time'})
d = cf.Data(cf.dt_vector(['2004-01-15', '2004-02-15']))
c.set_data(d)
c.nc_set_variable('time')
b = cf.Bounds()
b.set_properties({})
d = cf.Data([cf.dt_vector(['2004-01-01', '2004-01-31']), 
             cf.dt_vector(['2004-02-01', '2004-02-28'])])
b.set_data(d)
b.nc_set_variable('time_bnds')
c.set_bounds(b)
f.set_construct(c, axes=('domainaxis0',), key='dimensioncoordinate0', copy=False)

# Create file
cf.write(f, filename, Conventions='CF-1.8') #Bug, it creates CF-1.9

# Dirtycode: cfchecks does not support CF-1.9
import netCDF4 as nc4
ncfid = nc4.Dataset(filename, mode='a', format='NETCDF4')
ncfid.Conventions = "CF-1.8"
ncfid.close()

and then run

cfchecks test.nc
CHECKING NetCDF FILE: test.nc
=====================
Using CF Checker Version 4.1.0
Checking against CF Version CF-1.8
Using Standard Name Table Version 78 (2021-09-21T11:55:06Z)
Using Area Type Table Version 10 (23 June 2020)
Using Standardized Region Name Table Version 4 (18 December 2018)

ERROR: (7.1): boundary variable with non-numeric data type

------------------
Checking variable: time_bnds
------------------

------------------
Checking variable: time
------------------
WARN: (4.4.1): Use of the calendar and/or month_lengths attributes is recommended for time coordinate variables

------------------
Checking variable: q
------------------

ERRORS detected: 1
WARNINGS given: 1
INFORMATION messages: 0
@BorjaEst
Copy link
Author

It also applies to int64 see: xarray-contrib/cf-xarray#310

@DanHollis
Copy link

I am seeing the same problem.

ERROR: (7.1): boundary variable with non-numeric data type

My file contains three boundary variables:

	int64 time_bnds(time, bnds) ;
	double projection_y_coordinate_bnds(projection_y_coordinate, bnds) ;
	double projection_x_coordinate_bnds(projection_x_coordinate, bnds) ;

Based on the previous comment I assume it must be the time bounds that it is complaining about.

@RosalynHatcher RosalynHatcher self-assigned this Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants