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

Setting a vertical coordinate reference system #2

Closed
martinjuckes opened this issue May 8, 2019 · 6 comments
Closed

Setting a vertical coordinate reference system #2

martinjuckes opened this issue May 8, 2019 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@martinjuckes
Copy link

I've just started using cfdm ... still finding my way around the many classes. I'm trying to implement a vertical coordinate reference system for an atmosphere_hybrid_height_coordinate .. using the "more complete" example in the tutorial (https://ncas-cms.github.io/cfdm/1.7.1/tutorial.html ) .. which shows all the structures I need. In my code I get an error message (copied below) about an unexpected argument. I can reproduce the error if I take your script from the tutorial (which works as it is) and comment out the line "tas.set_construct(horizontal_crs)". Then, as in the script I want to create, you only have a vertical coordinate reference. The script still executes fine. tas.dump() also works as expected, but cfdm.write( "tas.nc", tas ) produces the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/cfdm/read_write/write.py", line 357, in write
    verbose=verbose)
  File "/usr/local/lib/python3.5/dist-packages/cfdm/read_write/netcdf/netcdfwrite.py", line 3402, in write
    self._write_field(f)
  File "/usr/local/lib/python3.5/dist-packages/cfdm/read_write/netcdf/netcdfwrite.py", line 2699, in _write_field
    self._create_vertical_datum(ref, owning_coord_key)
  File "/usr/local/lib/python3.5/dist-packages/cfdm/read_write/netcdf/netcdfwrite.py", line 2853, in _create_vertical_datum
    datum=self.implementation.get_datum(ref))
TypeError: initialise_CoordinateReference() got an unexpected keyword argument 'coordinates'
@davidhassell
Copy link
Contributor

Hi Martin,

I'm afraid that I can't replicate this, either at v1.7.1, or the latest version. That said, the line of code that you are causing problems was incorrect, and I have hopefully fixed it in the master branch.

I am not sure how you came to be running it with this example test_write.txt - could you try this?

Thanks,
David

@martinjuckes
Copy link
Author

Hello David,

I get the same problem: it runs OK as it is, but if I comment out the tas.set_construct(horizontal_crs) line (because I want a file with a vertical CRS and no horizontal one -- which should be possible, shouldn't it?) the program crashes while trying to write the file as above. I have cfdm package version 1.7.3 and python netCDF4 version 1.5.1.1 running in python 3.5.2 (the exception occurs in the netCDF4 package, so it may depend on the version of that library).

Do I need to do something else to get a file which only has a vertical CRS?

regards,
Martin

@davidhassell
Copy link
Contributor

Thanks for the extra info. You should indeed be able to do what you want to. The vertical CRS has a datum, which is fine, which needs to be written as a grid mapping netCDF variable - and that bit code appears faulty. I'll investigate ...

@martinjuckes
Copy link
Author

Thanks. I wasn't expecting a grid mapping variable for the vertical coordinates ... because CMOR doesn't generate one for this type of coordinate (just formula_terms).

@davidhassell
Copy link
Contributor

The latest code (v1.7.4 https://pypi.org/project/cfdm/) all seems to work fine for me - could you upgrade and give it a go?

The "new" grid mapping appears bcause the vertical CRS has a datum, but there is no appropriate horizontal CRS in which to store it.

If we don't set a datum on the vertical CRS , by removing in our test file the datum=datum line from

# Create the vertical coordinate reference construct
vertical_crs = cfdm.CoordinateReference(
                 datum=datum,
                 coordinate_conversion=coordinate_conversion_v,
                 coordinates=[dim_Z])

then you do not get the extra grid mapping variable.The connection of vertical CRSs to datums was, of course, new in CF-1.7

Thanks,
David

@martinjuckes
Copy link
Author

Thanks, that works now.

I see what you mean with the datum ... but there appears to be some ambiguity about whether it is really needed. The CF convention says "A grid mapping variable if, in addition, it is desired to .....". At the moment, my impression is that the CMIP community are not possessed by such a desire ... though I would agree that it would be a good thing -- perhaps in CMIP7. I'm aiming to use cfdm to create some sample files. Now that I've update to 1.7.4 it looks as though it might work very nicely.

PS: there is still an issue (unrelated) with the cf-checker crashing when it finds a scalar coordinate used as an NetCDF4 dimension. This may not be your problem ... but your examples would be easier to work with if you avoided scalar coordinates used as dimensions.

@davidhassell davidhassell self-assigned this Jan 7, 2020
@davidhassell davidhassell added the bug Something isn't working label Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants