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

Added the possibility to read variables in NetCDF-4 groups #4527

Merged
merged 2 commits into from Dec 7, 2020

Conversation

remkos
Copy link
Contributor

@remkos remkos commented Dec 1, 2020

Description of proposed changes

This is to introduce the possibility to read variables from netCDF-4 files that contain variables in groups.
For example, a group "ku" with variables "time", "latitude", and "longitude".

This required introducing "," as an optional separator for variables on the command line. Because, otherwise, the "/'" separator for the variables on the command line would be seen as part of the group/variable naming convention.

Example 1: In case of a traditional file without groups (NetCDF-3 or NetCDF-4): file.nc?time/latitude/longitude and file.nc?time,latitude,longitude are equivalent, and will both work.

Example 2: In case we have a group "ku".

  • file.nc?ku/time will first check if the group 'ku' exists; if so, then open group 'ku' to find 'time'.
  • file.nc?ku/time,ku/latitude,ku/longitude will automatically assume that there is a group 'ku'.

This has been tested with success on both files with and without groups, reading either single or multiple variables, in one group or spread over multiple groups.

Fixes #

Reminders

  • Make sure that your code follows our style. Use the other functions/files as a basis.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Describe changes to function behavior and arguments in a comment below the function declaration.
  • If adding new functionality, add a detailed description to the documentation and/or an example.

If approved, I will add examples to documentation and tests.

@remkos remkos requested review from joa-quim, leouieda, PaulWessel and a team December 1, 2020 20:46
Copy link
Member

@PaulWessel PaulWessel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @remkos, I first thought this had to do with grids but I see this is netcdf tables. I installed the branch and ran the tests and it fails to pass gaps_time.sh which deals with netcdf tables:

gmtmath (gmtio_nc_fopen): NetCDF: No group found. [gtec_tx_daily.nc]
gmtmath [ERROR]: Cannot open file gtec_tx_daily.nc?time/gtec
gmtmath (gmtio_nc_fopen): NetCDF: No group found. [gtec_tx_daily.nc]
gmtmath [ERROR]: Cannot open file gtec_tx_daily.nc?time/gtec
psxy [WARNING]: File <stdin> is empty!

Perhaps you can sort out what goes wrong there since there are no groups I think.
Also, there probably needs to be some updated in the docs.

@remkos
Copy link
Contributor Author

remkos commented Dec 6, 2020

Indeed. This applies (for the time being) only to tables. I will look into grids later, though I do not expect groups to be that common there.
The above commit should fix the bug. Somehow I did not test it properly.

Copy link
Member

@PaulWessel PaulWessel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests pass for me, nice. Please add docs and example as you see fit.

@remkos remkos merged commit e164b68 into master Dec 7, 2020
@remkos remkos deleted the netcdf-groups branch December 7, 2020 07:54
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

Successfully merging this pull request may close these issues.

None yet

2 participants