Update get_grid_mapping_variables(nc)#1165
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
| :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.
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.
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.
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.
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.