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

each dimension and 1D variable must have the same name: not documented, no warning #10

Open
Thomas-Ulrich opened this issue Oct 13, 2020 · 2 comments

Comments

@Thomas-Ulrich
Copy link
Collaborator

This is the file I try to parse:

!Switch
[d_c]: !AffineMap
    matrix:
      x: [1.0, 0.0, 0.0]
      y: [0.0, 0.0, -1.0]
    translation:
      x: 20e3
      y: 0.0
    components: 
      -  !ASAGI
          file: test.nc
          parameters: [d_c]
          var: h

And this is how I create the example netcdf

import numpy as np
dx=5e3
x=np.arange(0,40e3+dx, dx)
y=np.arange(0,20e3+dx, dx)
nx=x.shape[0]
ny=y.shape[0]
from netCDF4 import Dataset
rootgrp = Dataset("test.nc", "w", format="NETCDF4")
rootgrp.createDimension("a", nx)
rootgrp.createDimension("b", ny)
vx = rootgrp.createVariable("a","f4",("a",))
vx[:]=x
vy = rootgrp.createVariable("b","f4",("b",))
vy[:]=y
vplastCo =  rootgrp.createVariable("h","f4",("b","a"))
vplastCo[:,:] = np.ones((ny, nx))
rootgrp.close()

structure of the netcdf

ncdump -h test.nc 
netcdf test {
dimensions:
	a = 9 ;
	b = 5 ;
variables:
	float a(a) ;
	float b(b) ;
	float h(b, a) ;
}

I try then to parse the yaml file use a cpp program, and I get the expected value:

../EvaluateVpVs/EvaluateDc test2.yaml -15000. 0 -5000.
1

On the other hand, when using a netcdf file with this structure:

ncdump -h test.nc 
netcdf test {
dimensions:
	na = 9 ;
	nb = 5 ;
variables:
	float a(na) ;
	float b(nb) ;
	float h(nb, na) ;
}

I get the following error:

../EvaluateVpVs/EvaluateDc test2.yaml -15000. 0 -5000.
terminate called after throwing an instance of 'std::runtime_error'
  what():  test2.yaml@9: Could not find model for point [ 5000 5000 ] in group 1.
Aborted (core dumped)

Which means that asagi only works when each dimension and 1D variable have the same name.
This should be Documented, or a warning should be raised when not the case.

@rettenbs
Copy link

This is part of the COARDS Convention for netCDF files: https://ferret.pmel.noaa.gov/Ferret/documentation/coards-netcdf-conventions

Coordinate Variables:
1-dimensional netCDF variables whose dimension names are identical to their variable names are regarded as "coordinate variables" (axes of the underlying grid structure of other variables defined on this dimension).

Probably everything is working fine but the your arrays a and b are no longer considered as coordinate variables and the point 5000, 5000 is out of bounds.

@Thomas-Ulrich
Copy link
Collaborator Author

Thomas-Ulrich commented Oct 19, 2020 via email

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

2 participants