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

Improve cf conformance 5.6 grid mappings and projections #976

Conversation

leilabbb
Copy link
Contributor

@leilabbb leilabbb commented Dec 9, 2022

No description provided.

related to issue#950 [ioos#950]

updated the function get_grid_mapping_variables to parse the attribute variables when it contains more than one string.
related to issue # 950 [ioos#950]

Mocked a new .nc file to test the grid_mapping requirements and recommendations
fixed the for loop of the get_grid_mapping_variables function
in cf_1_7.py
- added "geographic_crs_name" to the function def _check_gmattr_existence_condition_ell_pmerid_hdatum(self, var):

- Modified function def check_grid_mapping(self, ds):

in cfutil.py
- modified the function def grid_mapping_variables(ds)

- added the function def get_grid_mapping_variables_coordinates(ds):

in test_cf.py
- modified the function def test_check_grid_mapping(self):
@codecov
Copy link

codecov bot commented Dec 9, 2022

Codecov Report

Attention: Patch coverage is 73.03371% with 24 lines in your changes are missing coverage. Please review.

Please upload report for BASE (main@640ecb2). Learn more about missing BASE report.

Files Patch % Lines
compliance_checker/cf/cf_1_7.py 68.65% 13 Missing and 8 partials ⚠️
compliance_checker/cfutil.py 86.36% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #976   +/-   ##
=======================================
  Coverage        ?   81.55%           
=======================================
  Files           ?       24           
  Lines           ?     5243           
  Branches        ?     1262           
=======================================
  Hits            ?     4276           
  Misses          ?      655           
  Partials        ?      312           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@benjwadams
Copy link
Contributor

@leilabbb, could you address the test failures?

"§5.6 Horizontal Coordinate Reference Systems, Grid Mappings, Projections"
)
assert all(r.name == expected_name for r in results.values())
# def test_check_grid_mapping(self):
Copy link
Contributor

@benjwadams benjwadams Jan 5, 2023

Choose a reason for hiding this comment

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

Please remove commented function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

commented function deleted.

compliance_checker/cf/cf_1_7.py Outdated Show resolved Hide resolved
@@ -501,6 +504,7 @@ def _check_gmattr_existence_condition_ell_pmerid_hdatum(self, var):
"reference_ellipsoid_name",
"prime_meridian_name",
"horizontal_datum_name",
"geographic_crs_name",
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test coverage for added functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in progress ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do not understand " not covered by test" comment:

there is a test "_check_grid_mapping_attr_condition" that evaluates the 'geographic_crs_name' in the file

removed commented function
compliance_checker/cf/cf_1_7.py Outdated Show resolved Hide resolved
removed "print( )" to suppress output, it is needed only for debugging. 

removed the IF conditional statement and used the tests' results from  _check_gmattr_existence_condition_ell_pmerid_hdatum and _check_gmattr_existence_condition_geoid_name_geoptl_datum_name
@benjwadams
Copy link
Contributor

Can you check the test failures on this PR?

leilabbb added 2 commits May 1, 2023 16:40
using  regex I have replaced an inner loop with:
grid_mapping_variable_list.append(regex.findall(r"(\w+)",item.grid_mapping))
added the "else" clause to the "if not" statement on line 740

# [5/9] The grid mapping variables must have the grid_mapping_name attribute.
# The legal values for the grid_mapping_name attribute are contained in Appendix F.
if "grid_mapping_name" not in var.ncattrs():
Copy link
Contributor

Choose a reason for hiding this comment

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

if not hasattr(var, "grid_mapping_name") would be more Pythonic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed... changed


# [6/9] The data types of the attributes of the
# grid mapping variable must be specified in Table 1 of Appendix F.
type_map = {"S": "str" , "N": "float64"}
Copy link
Contributor

Choose a reason for hiding this comment

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

The typecheck for N is likely too strong. N simply means that the value has a numeric type, not just floating point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed.... changed to:
type_map = {"S": "str", "N": ["float64", "int"]}

test_ctx.score += 1
test_ctx.out_of += 1

test_ctx.out_of += 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about hasattr mentioned above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed ... changed

elif len_vdatum_name_attrs == 1:
vert_datum_attrs = possible_vert_datum_attrs.intersection(var.ncattrs())

if exist_cond_1[0] == True and vert_datum_attrs:
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use if exist_cond_1[0] and vert_datum_attrs if exist_cond[0] is expected to be boolean.

Copy link
Contributor

@benjwadams benjwadams left a comment

Choose a reason for hiding this comment

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

Please also fix and/or change unit tests as necessary.

Copy link
Contributor

@benjwadams benjwadams left a comment

Choose a reason for hiding this comment

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

EDIT: already mentioned

@ocefpaf ocefpaf deleted the branch ioos:main July 16, 2024 17:39
@ocefpaf ocefpaf closed this Jul 16, 2024
Copy link
Contributor Author

@leilabbb leilabbb left a comment

Choose a reason for hiding this comment

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

all comments were resolved except one that i am not sure about "Add test coverage for added functionality."

"§5.6 Horizontal Coordinate Reference Systems, Grid Mappings, Projections"
)
assert all(r.name == expected_name for r in results.values())
# def test_check_grid_mapping(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

commented function deleted.

@@ -501,6 +504,7 @@ def _check_gmattr_existence_condition_ell_pmerid_hdatum(self, var):
"reference_ellipsoid_name",
"prime_meridian_name",
"horizontal_datum_name",
"geographic_crs_name",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

do not understand " not covered by test" comment:

there is a test "_check_grid_mapping_attr_condition" that evaluates the 'geographic_crs_name' in the file


# [5/9] The grid mapping variables must have the grid_mapping_name attribute.
# The legal values for the grid_mapping_name attribute are contained in Appendix F.
if "grid_mapping_name" not in var.ncattrs():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed... changed


# [6/9] The data types of the attributes of the
# grid mapping variable must be specified in Table 1 of Appendix F.
type_map = {"S": "str" , "N": "float64"}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed.... changed to:
type_map = {"S": "str", "N": ["float64", "int"]}

test_ctx.score += 1
test_ctx.out_of += 1

test_ctx.out_of += 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed ... changed

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.

3 participants