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

Support for CDL #5

Closed
martinjuckes opened this issue Sep 20, 2019 · 6 comments · Fixed by #7
Closed

Support for CDL #5

martinjuckes opened this issue Sep 20, 2019 · 6 comments · Fixed by #7
Assignees
Labels
enhancement New feature or request netCDF read Relating to reading netCDF datasets

Comments

@martinjuckes
Copy link

It would be really useful to be able to read CDL files directly into cfdm, rather than having to first convert to binary netCDF files. Can this be added?

@davidhassell
Copy link
Contributor

Good idea, thanks. This will be ready in the next version, which should be ready in a few days.

@cofinoa
Copy link

cofinoa commented Oct 3, 2019

This would be a interesting feature.

@davidhassell
Copy link
Contributor

All ready in v1.7.8 (https://pypi.org/project/cfdm). See the documentation at https://ncas-cms.github.io/cfdm/function/cfdm.read.html

Try it with test_file.zip

$ unzip test_file.zip
Archive:  test_file.zip
  inflating: test_file.nc          
$ ncdump test_file.nc > test_file.cdl
$ ncdump -h test_file.nc > test_file_h.cdl
$ ncdump -c test_file.nc > test_file_c.cdl
In [10]: import cfdm                                                                                                  

In [11]: f = cfdm.read('test_file.nc')[0]                                                                                                    

In [12]: g = cfdm.read('test_file.cdl')[0]                                                                                                   

In [13]: f.equals(g)                                                                                                                         
Out[13]: True

In [14]: cfdm.read('test_file_h.cdl')[0]                                                                                                     
Out[14]: <Field: eastward_wind(atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) m s-1>

In [15]: cfdm.read('test_file_c.cdl')[0]                                                                                                     
Out[15]: <Field: eastward_wind(atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) m s-1>

@davidhassell
Copy link
Contributor

I am aware that this doesn't work for Python 2. I will gladly fix this if anyone needs it ...

@davidhassell davidhassell reopened this Nov 7, 2019
@martinjuckes
Copy link
Author

Hi David,

thanks for adding this, it will be very useful.

Trying it out, I found that it fails when a file starts with a comment line (// ........), which I think should still be valid cdl. The error given is raise IOError("Can't determine format of file {}".format(filename)).

Here is the file which triggers the error:

// https://www.unidata.ucar.edu/software/netcdf/examples/sresa1b_ncar_ccsm3-example.cdl
netcdf cal01 {
dimensions:
        time = UNLIMITED ; // (1 currently)
variables:
        double time(time) ;
                time:calendar = "gregorian" ;
                time:standard_name = "time" ;
                time:axis = "T" ;
                time:units = "days since 1980-24-33 12:00:00" ;
                time:long_name = "time" ;
        float mydata(time) ;
                mydata:standard_name = "air_temperature" ;
                mydata:units = "K" ;
// global attributes:
                :Conventions = "CF-1.7" ;

data:

 time = 730135.5 ;

 mydata = 280.;
}

It works when the first line is deleted.

@davidhassell
Copy link
Contributor

Hi Martin, thanks for spotting this - I was only allowing files whose first line started netcdf . I shall update the code to accept leading comment lines, too.

davidhassell added a commit that referenced this issue Nov 11, 2019
@davidhassell davidhassell added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Nov 11, 2019
davidhassell added a commit that referenced this issue Nov 13, 2019
@davidhassell davidhassell self-assigned this Jan 7, 2020
@davidhassell davidhassell added netCDF read Relating to reading netCDF datasets and removed bug Something isn't working labels Nov 15, 2023
@davidhassell davidhassell linked a pull request Nov 15, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request netCDF read Relating to reading netCDF datasets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants