Skip to content

Update get_grid_mapping_variables(nc)#1165

Open
leilabbb wants to merge 6 commits into
mainfrom
grid-mappings
Open

Update get_grid_mapping_variables(nc)#1165
leilabbb wants to merge 6 commits into
mainfrom
grid-mappings

Conversation

@leilabbb
Copy link
Copy Markdown
Contributor

@leilabbb leilabbb commented Apr 28, 2025

  • Added a function extract_grid_mapping_names(grid_mapping_string) to extracts all grid mapping variable names from the grid_mapping variable's attribute.
  • 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.

- 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.
@benjwadams
Copy link
Copy Markdown
Contributor

pre-commit.ci autofix

Comment thread 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)
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor Author

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.
@leilabbb leilabbb marked this pull request as ready for review May 1, 2025 00:08
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"
@leilabbb
Copy link
Copy Markdown
Contributor Author

leilabbb commented May 1, 2025

pre-commit.ci autofix

else grid_mapping_string.split()
)


Copy link
Copy Markdown
Contributor Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve CF Conformance: 5.6 Grid Mappings and Projections

2 participants