-
Notifications
You must be signed in to change notification settings - Fork 67
Update get_grid_mapping_variables(nc) #1165
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
base: main
Are you sure you want to change the base?
Conversation
- added a function extract_crs_names(grid_mapping_string) to extracts all grid mapping variable names from a grid_mapping - updated get_grid_mapping_variables(nc) to include the new function and returns a set of all grid mapping variable names that are present in the dataset.
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
compliance_checker/cf/util.py
Outdated
:param str grid_mapping_string: The grid_mapping attribute string | ||
:return list[str]: List of grid mapping variable names | ||
""" | ||
return re.findall(r"\b\w+(?=:)|\b\w+(?=\s+\w+:)|\b\w+$", grid_mapping_string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would just some_grid_mapping:
be accepted under this regex? Is it a valid grid_mapping
representation in such a case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the documentation text for grid_mapping:
"The attribute takes a string value with two possible formats. In the first format, it is a single word, which names a grid mapping variable. In the second format, it is a blank-separated list of words ": [ …] [: …]" , which identifies one or more grid mapping variables, and with each grid mapping associates one or more coordinatesVariables, i.e. coordinate variables or auxiliary coordinate variables."
the code works for ALL cases:
- Words followed by : are picked up.
- Words not followed by : but separated by spaces (and at the end) are picked up.
- Single isolated words are picked up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre-commit.ci autofix
Added _check_gmattr_existence_condition_crs_name() in cf_1_7.py to satisfy: If projected_crs_name is defined then geographic_crs_name must be also. Fixed _check_gmattr_existence_condition_ell_pmerid_hdatum in cf_1_7.py to satisfy: If any of reference_ellipsoid_name, prime_meridian_name, or horizontal_datum_name or geographic_crs_name are defined, all must be defined. Rewritted and added missing messages in cf_base.py Fixed extract_grid_mapping_names() in util.py to extract the grid mapping variable names from a grid mapping string Changed test_check_grid_mapping() in test_cf.py to mimic netcdf variables and pass them to check_grid_mapping() in cf_base.py to test the grid mapping variable's attributes.
put back "Could not consume entire grid_mapping expression, please check for well-formedness"
reverted to f"Coordinate-related variable {ref_var} referenced by grid_mapping variable {grid_var_name} must exist in this dataset"
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
else grid_mapping_string.split() | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed it to include the only two possible formats:
Key-value-like: "key: value" (key is the grid mapping variables
Space-separated names: "x y z" ( x y z are the grid mapping variables)
Uh oh!
There was an error while loading. Please reload this page.