Commit 96de041b authored by Javier Vegas-Regidor's avatar Javier Vegas-Regidor
Browse files

Add variable filtering to MMA cmorization

parent c32c4f27
......@@ -318,7 +318,25 @@ class Cmorizer(object):
options="-O", input=filename, output=temp
)
shutil.move(temp, filename)
Utils.cdo().mergetime(input=files, output=merged)
cmorize_vars = set()
var_manager = self.config.var_manager
for filename in files:
handler = Utils.open_cdf(filename)
for variable in handler.variables.keys():
_, var_cmor = var_manager.get_variable_and_alias(
variable, silent=True,
)
if self.cmor.cmorize(var_cmor):
cmorize_vars.add(variable)
handler.close()
if not cmorize_vars:
continue
var_str = ",".join([str(var) for var in cmorize_vars])
Utils.cdo().mergetime(
input=[f"-selvar,{var_str} {filepath}" for filepath in files],
output=merged
)
for filename in files:
self._remove(filename)
tar_startdate = (
......
......@@ -21,7 +21,7 @@ import calendar
class TestCmorizer(TestCase):
"""Tests for Cmorizer class"""
def _get_variable_and_alias(self, variable):
def _get_variable_and_alias(self, variable, silent=False):
mock_alias = Mock()
mock_alias.basin = None
mock_alias.grid = None
......@@ -349,22 +349,26 @@ class TestCmorizer(TestCase):
log.Log.WARNING: warnings,
}
):
if value:
self.assertTrue(
[
record
for record in cmd.records
if record.levelno == level
]
)
else:
self.assertFalse(
[
record
for record in cmd.records
if record.levelno == level
]
)
try:
if value:
self.assertTrue(
[
record
for record in cmd.records
if record.levelno == level
]
)
else:
self.assertFalse(
[
record
for record in cmd.records
if record.levelno == level
]
)
except AssertionError:
print(cmd.records)
raise
else:
cmorizer = Cmorizer(self.data_manager, "19900101", 0)
if ocean:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment