Skip to content

Commit

Permalink
Added check for table_id
Browse files Browse the repository at this point in the history
  • Loading branch information
sol1105 committed Jul 12, 2024
1 parent 043bf9a commit 2e3e918
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
40 changes: 35 additions & 5 deletions cc_plugin_cc6/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,16 @@ def setup(self, dataset):
self.filepath, decode_coords=True, decode_times=False
)
# Options
self.options = self.options
if "debug" in self.options:
self.debug = True
else:
self.debug = False
# Input options
# - Output for consistency checks across files
self.consistency_output = self.inputs.get("consistency_output", False)
self.consistency_output = self.options.get("consistency_output", False)
# - Get path to the tables and initialize
if self.inputs.get("tables", False):
tables_path = self.inputs["tables"]
if self.options.get("tables", False):
tables_path = self.options["tables"]
self._initialize_CV_info(tables_path)
self._initialize_time_info()
self._initialize_coords_info()
Expand Down Expand Up @@ -145,7 +144,11 @@ def _initialize_CV_info(self, tables_path):
var_ids = [v for v in varlist if v in list(self.dataset.variables.keys())]
self.varname = var_ids
# Identify table_id, requested frequency and cell_methods
self.table_id = self._get_attr("table_id")
self.table_id_raw = self._get_attr("table_id")
if self.table_id_raw in self.CT:
self.table_id = self.table_id_raw
else:
self.table_id = "unknown"
self.frequency = self._get_var_attr(self.varname, "frequency", False)
if not self.frequency:
self.frequency = self._get_attr("frequency")
Expand Down Expand Up @@ -500,6 +503,33 @@ def _map_drs_blocks(self):
except AttributeError:
self.drs_gatts[gatt] = False

def check_table_id(self, ds):
"""Table ID (CV)"""
desc = "Table ID"
level = BaseCheck.HIGH
out_of = 1
score = 0
messages = []

# Check if table_id is defined, and if it is valid
# (and if not, if it could be inferred)
if self.table_id == "unknown":
if self.table_id_raw == "unknown":
messages.append("The global attribute 'table_id' is not defined.")
else:
messages.append(
f"The CMOR table denoted by the global attribute 'table_id' could not be found: '{self.table_id_raw}'."
)
elif self.table_id != self.table_id_raw:
messages.append(
"The CMOR table denoted by the global attribute 'table_id' "
f"is not the expected one ('{self.table_id}'): '{self.table_id_raw}'."
)
else:
score += 1

return self.make_result(level, score, out_of, desc, messages)

def check_drs_CV(self, ds):
"""DRS building blocks in filename and path checked against CV."""
desc = "DRS (CV)"
Expand Down
2 changes: 1 addition & 1 deletion cc_plugin_cc6/cc6.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CORDEXCMIP6(MIPCVCheck):

def setup(self, dataset):
super().setup(dataset)
if not self.inputs.get("tables", False):
if not self.options.get("tables", False):
if self.debug:
print("Downloading CV and CMOR tables.")
tables_path = "~/.cc6_metadata/cordex-cmip6-cmor-tables"
Expand Down

0 comments on commit 2e3e918

Please sign in to comment.