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

Should fix more but now all "Error in sys.excepthook:" #1069

Merged
merged 5 commits into from
May 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions compliance_checker/cf/cf_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,12 @@
:return: List of variable names (str) that are defined to be auxiliary
coordinate variables.
"""
ds_str = ds.__str__()
Copy link
Member Author

@ocefpaf ocefpaf May 14, 2024

Choose a reason for hiding this comment

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

@benjwadams this is not elegant but using the actual netCDF4.Dataset object here was leading to odd behaviors. I guess that the str representation of the dataset is unique and "safe" enough for this use. Maybe a hash would be more appropriated, but it tuns hashing netCDF objects is not easy!

if self._aux_coords.get(ds, None) and refresh is False:
return self._aux_coords[ds]
return self._aux_coords[ds_str]

Check warning on line 500 in compliance_checker/cf/cf_base.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/cf/cf_base.py#L500

Added line #L500 was not covered by tests

self._aux_coords[ds] = cfutil.get_auxiliary_coordinate_variables(ds)
return self._aux_coords[ds]
self._aux_coords[ds_str] = cfutil.get_auxiliary_coordinate_variables(ds)
return self._aux_coords[ds_str]

def _find_boundary_vars(self, ds, refresh=False):
"""
Expand All @@ -512,12 +513,13 @@
:rtype: list
:return: A list containing strings with boundary variable names.
"""
ds_str = ds.__str__()
if self._boundary_vars.get(ds, None) and refresh is False:
return self._boundary_vars[ds]
return self._boundary_vars[ds_str]

Check warning on line 518 in compliance_checker/cf/cf_base.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/cf/cf_base.py#L518

Added line #L518 was not covered by tests

self._boundary_vars[ds] = cfutil.get_cell_boundary_variables(ds)
self._boundary_vars[ds_str] = cfutil.get_cell_boundary_variables(ds)

return self._boundary_vars[ds]
return self._boundary_vars[ds_str]

def _find_ancillary_vars(self, ds, refresh=False):
"""
Expand All @@ -541,26 +543,26 @@
:return: List of variable names (str) that are defined as ancillary
variables in the dataset ds.
"""

ds_str = ds.__str__()
# Used the cached version if it exists and is not empty
if self._ancillary_vars.get(ds, None) and refresh is False:
return self._ancillary_vars[ds]
return self._ancillary_vars[ds_str]

Check warning on line 549 in compliance_checker/cf/cf_base.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/cf/cf_base.py#L549

Added line #L549 was not covered by tests

# Invalidate the cache at all costs
self._ancillary_vars[ds] = []
self._ancillary_vars[ds_str] = []

for var in ds.variables.values():
if hasattr(var, "ancillary_variables"):
for anc_name in var.ancillary_variables.split(" "):
if anc_name in ds.variables:
self._ancillary_vars[ds].append(anc_name)
self._ancillary_vars[ds_str].append(anc_name)

if hasattr(var, "grid_mapping"):
gm_name = var.grid_mapping
if gm_name in ds.variables:
self._ancillary_vars[ds].append(gm_name)
self._ancillary_vars[ds_str].append(gm_name)

return self._ancillary_vars[ds]
return self._ancillary_vars[ds_str]

def _find_clim_vars(self, ds, refresh=False):
"""
Expand All @@ -573,15 +575,15 @@
:return: A list containing strings with geophysical variable
names.
"""

ds_str = ds.__str__()
if self._clim_vars.get(ds, None) and refresh is False:
return self._clim_vars[ds]
return self._clim_vars[ds_str]

Check warning on line 580 in compliance_checker/cf/cf_base.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/cf/cf_base.py#L580

Added line #L580 was not covered by tests

climatology_variable = cfutil.get_climatology_variable(ds)
if climatology_variable:
self._clim_vars[ds].append(climatology_variable)
self._clim_vars[ds_str].append(climatology_variable)

Check warning on line 584 in compliance_checker/cf/cf_base.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/cf/cf_base.py#L584

Added line #L584 was not covered by tests

return self._clim_vars[ds]
return self._clim_vars[ds_str]

def _find_cf_standard_name_table(self, ds):
"""
Expand Down Expand Up @@ -693,12 +695,13 @@
:return: A list of variables names (str) that are defined as coordinate
variables in the dataset ds.
"""
if ds in self._coord_vars and refresh is False:
return self._coord_vars[ds]
ds_str = ds.__str__()
if ds_str in self._coord_vars and refresh is False:
return self._coord_vars[ds_str]

self._coord_vars[ds] = cfutil.get_coordinate_variables(ds)
self._coord_vars[ds_str] = cfutil.get_coordinate_variables(ds)

return self._coord_vars[ds]
return self._coord_vars[ds_str]

def _find_geophysical_vars(self, ds, refresh=False):
"""
Expand All @@ -712,12 +715,13 @@
:return: A list containing strings with geophysical variable
names.
"""
ds_str = ds.__str__()
if self._geophysical_vars.get(ds, None) and refresh is False:
return self._geophysical_vars[ds]
return self._geophysical_vars[ds_str]

Check warning on line 720 in compliance_checker/cf/cf_base.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/cf/cf_base.py#L720

Added line #L720 was not covered by tests

self._geophysical_vars[ds] = cfutil.get_geophysical_variables(ds)
self._geophysical_vars[ds_str] = cfutil.get_geophysical_variables(ds)

return self._geophysical_vars[ds]
return self._geophysical_vars[ds_str]

def _find_metadata_vars(self, ds, refresh=False):
"""
Expand All @@ -731,10 +735,11 @@
variable candidates.

"""
ds_str = ds.__str__()
if self._metadata_vars.get(ds, None) and refresh is False:
return self._metadata_vars[ds]
return self._metadata_vars[ds_str]

Check warning on line 740 in compliance_checker/cf/cf_base.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/cf/cf_base.py#L740

Added line #L740 was not covered by tests

self._metadata_vars[ds] = []
self._metadata_vars[ds_str] = []
for name, var in ds.variables.items():
if name in self._find_ancillary_vars(ds) or name in self._find_coord_vars(
ds,
Expand All @@ -749,17 +754,17 @@
"platform_id",
"surface_altitude",
):
self._metadata_vars[ds].append(name)
self._metadata_vars[ds_str].append(name)

Check warning on line 757 in compliance_checker/cf/cf_base.py

View check run for this annotation

Codecov / codecov/patch

compliance_checker/cf/cf_base.py#L757

Added line #L757 was not covered by tests

elif getattr(var, "cf_role", "") != "":
self._metadata_vars[ds].append(name)
self._metadata_vars[ds_str].append(name)

elif (
getattr(var, "standard_name", None) is None and len(var.dimensions) == 0
):
self._metadata_vars[ds].append(name)
self._metadata_vars[ds_str].append(name)

return self._metadata_vars[ds]
return self._metadata_vars[ds_str]

def _get_coord_axis_map(self, ds):
"""
Expand Down
Loading