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

Support yearly and remove auto data fix from regmean

parent 638eed7d
...@@ -812,8 +812,16 @@ class Cmor3Convention(DataConvention): ...@@ -812,8 +812,16 @@ class Cmor3Convention(DataConvention):
"month", "month",
self.config.experiment.calendar, self.config.experiment.calendar,
) )
if frequency == Frequencies.yearly:
if frequency == Frequencies.monthly: chunk_end = previous_day(
chunk_end, self.config.experiment.calendar
)
time_bound = "{0:04}{2}{1:04}".format(
chunk_start.year,
chunk_end.year,
self.time_separator,
)
elif frequency == Frequencies.monthly:
chunk_end = previous_day( chunk_end = previous_day(
chunk_end, self.config.experiment.calendar chunk_end, self.config.experiment.calendar
) )
......
...@@ -474,6 +474,7 @@ class DataFile(Publisher): ...@@ -474,6 +474,7 @@ class DataFile(Publisher):
if len(cube_list) == 1: if len(cube_list) == 1:
return return
iris.experimental.equalise_cubes.equalise_attributes(cube_list) iris.experimental.equalise_cubes.equalise_attributes(cube_list)
iris.util.unify_time_units(cube_list)
final_cube = cube_list.merge_cube() final_cube = cube_list.merge_cube()
temp = TempFile.get() temp = TempFile.get()
iris.save(final_cube, temp, zlib=True) iris.save(final_cube, temp, zlib=True)
......
...@@ -12,6 +12,7 @@ from earthdiagnostics.diagnostic import ( ...@@ -12,6 +12,7 @@ from earthdiagnostics.diagnostic import (
DiagnosticChoiceOption, DiagnosticChoiceOption,
DiagnosticBoolOption, DiagnosticBoolOption,
DiagnosticOption, DiagnosticOption,
DiagnosticFrequencyOption,
) )
from earthdiagnostics.modelingrealm import ModelingRealms from earthdiagnostics.modelingrealm import ModelingRealms
from earthdiagnostics.utils import Utils, TempFile from earthdiagnostics.utils import Utils, TempFile
...@@ -66,6 +67,7 @@ class InterpolateCDO(Diagnostic): ...@@ -66,6 +67,7 @@ class InterpolateCDO(Diagnostic):
mask_oceans, mask_oceans,
original_grid, original_grid,
weights, weights,
frequency,
): ):
Diagnostic.__init__(self, data_manager) Diagnostic.__init__(self, data_manager)
self.startdate = startdate self.startdate = startdate
...@@ -81,6 +83,7 @@ class InterpolateCDO(Diagnostic): ...@@ -81,6 +83,7 @@ class InterpolateCDO(Diagnostic):
self.mask_oceans = mask_oceans self.mask_oceans = mask_oceans
self.original_grid = original_grid self.original_grid = original_grid
self.weights = weights self.weights = weights
self.frequency = frequency
def __eq__(self, other): def __eq__(self, other):
if self._different_type(other): if self._different_type(other):
...@@ -96,6 +99,7 @@ class InterpolateCDO(Diagnostic): ...@@ -96,6 +99,7 @@ class InterpolateCDO(Diagnostic):
and self.mask_oceans == other.mask_oceans and self.mask_oceans == other.mask_oceans
and self.grid == other.grid and self.grid == other.grid
and self.original_grid == other.original_grid and self.original_grid == other.original_grid
and self.frequency == other.frequency
) )
def __hash__(self): def __hash__(self):
...@@ -105,6 +109,7 @@ class InterpolateCDO(Diagnostic): ...@@ -105,6 +109,7 @@ class InterpolateCDO(Diagnostic):
return ( return (
"Interpolate with CDO Startdate: {0.startdate} Member: {0.member} " "Interpolate with CDO Startdate: {0.startdate} Member: {0.member} "
"Chunk: {0.chunk} Variable: {0.domain}:{0.variable} " "Chunk: {0.chunk} Variable: {0.domain}:{0.variable} "
"Frequency: {0.frequency} "
"Target grid: {0.grid} Original grid: {0.original_grid} " "Target grid: {0.grid} Original grid: {0.original_grid} "
"Mask ocean: {0.mask_oceans} Model: {0.model_version}".format(self) "Mask ocean: {0.mask_oceans} Model: {0.model_version}".format(self)
) )
...@@ -134,6 +139,8 @@ class InterpolateCDO(Diagnostic): ...@@ -134,6 +139,8 @@ class InterpolateCDO(Diagnostic):
DiagnosticBoolOption("mask_oceans", True), DiagnosticBoolOption("mask_oceans", True),
DiagnosticOption("original_grid", ""), DiagnosticOption("original_grid", ""),
DiagnosticBoolOption("weights_from_mask", True), DiagnosticBoolOption("weights_from_mask", True),
DiagnosticFrequencyOption(
default_value=diags.config.frequency),
) )
options = cls.process_options(options, options_available) options = cls.process_options(options, options_available)
target_grid = cls._translate_ifs_grids_to_cdo_names( target_grid = cls._translate_ifs_grids_to_cdo_names(
...@@ -166,6 +173,7 @@ class InterpolateCDO(Diagnostic): ...@@ -166,6 +173,7 @@ class InterpolateCDO(Diagnostic):
options["original_grid"], options["original_grid"],
weights, weights,
options["method"], options["method"],
options["frequency"],
) )
for var in options["variables"]: for var in options["variables"]:
...@@ -186,6 +194,7 @@ class InterpolateCDO(Diagnostic): ...@@ -186,6 +194,7 @@ class InterpolateCDO(Diagnostic):
options["mask_oceans"], options["mask_oceans"],
options["original_grid"], options["original_grid"],
weights, weights,
options["frequency"]
) )
if weights_job is not None: if weights_job is not None:
job.add_subjob(weights_job) job.add_subjob(weights_job)
...@@ -326,6 +335,7 @@ class InterpolateCDO(Diagnostic): ...@@ -326,6 +335,7 @@ class InterpolateCDO(Diagnostic):
self.member, self.member,
self.chunk, self.chunk,
grid=self.original_grid, grid=self.original_grid,
frequency=self.frequency,
) )
def declare_data_generated(self): def declare_data_generated(self):
...@@ -337,6 +347,7 @@ class InterpolateCDO(Diagnostic): ...@@ -337,6 +347,7 @@ class InterpolateCDO(Diagnostic):
self.member, self.member,
self.chunk, self.chunk,
grid=self.grid, grid=self.grid,
frequency=self.frequency,
) )
def compute(self): def compute(self):
...@@ -451,6 +462,7 @@ class ComputeWeights(Diagnostic): ...@@ -451,6 +462,7 @@ class ComputeWeights(Diagnostic):
original_grid, original_grid,
weights_file, weights_file,
method, method,
frequency
): ):
Diagnostic.__init__(self, data_manager) Diagnostic.__init__(self, data_manager)
self.startdate = startdate self.startdate = startdate
...@@ -462,6 +474,7 @@ class ComputeWeights(Diagnostic): ...@@ -462,6 +474,7 @@ class ComputeWeights(Diagnostic):
self.original_grid = original_grid self.original_grid = original_grid
self.weights_file = weights_file self.weights_file = weights_file
self.method = method self.method = method
self.frequency = frequency
def __str__(self): def __str__(self):
return ( return (
...@@ -487,6 +500,7 @@ class ComputeWeights(Diagnostic): ...@@ -487,6 +500,7 @@ class ComputeWeights(Diagnostic):
self.member, self.member,
self.chunk, self.chunk,
grid=self.original_grid, grid=self.original_grid,
frequency=self.frequency,
) )
def declare_data_generated(self): def declare_data_generated(self):
......
...@@ -45,6 +45,7 @@ class Moc(Diagnostic): ...@@ -45,6 +45,7 @@ class Moc(Diagnostic):
def __init__(self, data_manager, startdate, member, chunk, basins): def __init__(self, data_manager, startdate, member, chunk, basins):
Diagnostic.__init__(self, data_manager) Diagnostic.__init__(self, data_manager)
self.data_convention = data_manager.convention
self.startdate = startdate self.startdate = startdate
self.member = member self.member = member
self.chunk = chunk self.chunk = chunk
...@@ -161,21 +162,25 @@ class Moc(Diagnostic): ...@@ -161,21 +162,25 @@ class Moc(Diagnostic):
"region", "S1", ("region", "region_length") "region", "S1", ("region", "region_length")
) )
lat = handler_temp.createVariable("lat", float, ("j", "i")) lat = handler_temp.createVariable(
self.data_convention.lat_name, float, ("j", "i"))
lat[...] = gphiv[:, max_gphiv] lat[...] = gphiv[:, max_gphiv]
lat.units = "degrees_north" lat.units = "degrees_north"
lat.long_name = "Latitude" lat.long_name = "Latitude"
lat.standard_name = "latitude"
lon = handler_temp.createVariable("lon", float, ("j", "i")) lon = handler_temp.createVariable(
self.data_convention.lon_name, float, ("j", "i"))
lon[...] = 0 lon[...] = 0
lon.units = "degrees_east" lon.units = "degrees_east"
lon.long_name = "Longitude" lon.long_name = "Longitude"
lon.standard_name = "longitude"
var = handler_temp.createVariable( var = handler_temp.createVariable(
"vsftmyz", float, ("time", "lev", "i", "j", "region") "vsftmyz", float, ("time", "lev", "i", "j", "region")
) )
var.units = "Sverdrup" var.units = "Sverdrup"
var.coordinates = "lev time" var.coordinates = "lev time latitude longitude"
var.long_name = "Ocean meridional overturning volume streamfunction" var.long_name = "Ocean meridional overturning volume streamfunction"
var.missing_value = 1e20 var.missing_value = 1e20
var.fill_value = 1e20 var.fill_value = 1e20
......
...@@ -253,25 +253,25 @@ class RegionMean(Diagnostic): ...@@ -253,25 +253,25 @@ class RegionMean(Diagnostic):
return cube return cube
def _load_data(self): def _load_data(self):
coords = [] # handler = Utils.open_cdf(self.variable_file.local_file)
handler = Utils.open_cdf(self.variable_file.local_file) # coords = set(handler.variables[self.variable].coordinates.split(' '))
for variable in handler.variables: # for variable in handler.variables:
if variable in ( # if variable in (
"time", # "time",
"lev", # "lev",
"lat", # "lat",
"lon", # "lon",
"latitude", # "latitude",
"longitude", # "longitude",
"leadtime", # "leadtime",
"time_centered", # "time_centered",
): # ):
coords.append(variable) # coords.add(variable)
if variable == "time_centered": # if variable == "time_centered":
handler.variables[variable].standard_name = "" # handler.variables[variable].standard_name = ""
handler.variables[self.variable].coordinates = " ".join(coords) # handler.variables[self.variable].coordinates = " ".join(coords)
handler.close() # handler.close()
data = iris.load_cube(self.variable_file.local_file) data = iris.load_cube(self.variable_file.local_file)
return self._rename_depth(data) return self._rename_depth(data)
...@@ -287,24 +287,10 @@ class RegionMean(Diagnostic): ...@@ -287,24 +287,10 @@ class RegionMean(Diagnostic):
def _fix_file_metadata(self): def _fix_file_metadata(self):
handler = Utils.open_cdf(self.variable_file.local_file) handler = Utils.open_cdf(self.variable_file.local_file)
var = handler.variables[self.variable]
coordinates = ""
has_levels = False has_levels = False
for dimension in handler.variables.keys(): for dimension in handler.variables.keys():
if dimension in [
"time",
"lev",
"lat",
"latitude",
"lon",
"longitude",
"i",
"j",
]:
coordinates += " {0}".format(dimension)
if dimension == "lev": if dimension == "lev":
has_levels = True has_levels = True
var.coordinates = coordinates
handler.close() handler.close()
return has_levels return has_levels
......
...@@ -5,6 +5,7 @@ from earthdiagnostics.ocean.interpolatecdo import InterpolateCDO ...@@ -5,6 +5,7 @@ from earthdiagnostics.ocean.interpolatecdo import InterpolateCDO
from mock import Mock, patch from mock import Mock, patch
from earthdiagnostics.modelingrealm import ModelingRealms from earthdiagnostics.modelingrealm import ModelingRealms
from earthdiagnostics.frequency import Frequencies
from earthdiagnostics.diagnostic import ( from earthdiagnostics.diagnostic import (
DiagnosticVariableListOption, DiagnosticVariableListOption,
DiagnosticOptionError, DiagnosticOptionError,
...@@ -23,6 +24,7 @@ class TestInterpolate(TestCase): ...@@ -23,6 +24,7 @@ class TestInterpolate(TestCase):
) )
self.diags.config.experiment.model_version = "model_version" self.diags.config.experiment.model_version = "model_version"
self.diags.config.experiment.atmos_grid = "atmos_grid" self.diags.config.experiment.atmos_grid = "atmos_grid"
self.diags.config.frequency = Frequencies.daily
def fake_parse(self, value): def fake_parse(self, value):
if not value: if not value:
...@@ -63,6 +65,7 @@ class TestInterpolate(TestCase): ...@@ -63,6 +65,7 @@ class TestInterpolate(TestCase):
True, True,
"", "",
None, None,
Frequencies.daily,
), ),
) )
self.assertEqual( self.assertEqual(
...@@ -79,6 +82,7 @@ class TestInterpolate(TestCase): ...@@ -79,6 +82,7 @@ class TestInterpolate(TestCase):
True, True,
"", "",
None, None,
Frequencies.daily,
), ),
) )
...@@ -100,6 +104,7 @@ class TestInterpolate(TestCase): ...@@ -100,6 +104,7 @@ class TestInterpolate(TestCase):
True, True,
"", "",
None, None,
Frequencies.daily,
), ),
) )
self.assertEqual( self.assertEqual(
...@@ -116,6 +121,7 @@ class TestInterpolate(TestCase): ...@@ -116,6 +121,7 @@ class TestInterpolate(TestCase):
True, True,
"", "",
None, None,
Frequencies.daily,
), ),
) )
...@@ -137,6 +143,7 @@ class TestInterpolate(TestCase): ...@@ -137,6 +143,7 @@ class TestInterpolate(TestCase):
True, True,
"", "",
None, None,
Frequencies.daily,
), ),
) )
self.assertEqual( self.assertEqual(
...@@ -153,6 +160,7 @@ class TestInterpolate(TestCase): ...@@ -153,6 +160,7 @@ class TestInterpolate(TestCase):
True, True,
"", "",
None, None,
Frequencies.daily,
), ),
) )
...@@ -175,6 +183,7 @@ class TestInterpolate(TestCase): ...@@ -175,6 +183,7 @@ class TestInterpolate(TestCase):
False, False,
"", "",
None, None,
Frequencies.daily,
), ),
) )
self.assertEqual( self.assertEqual(
...@@ -191,6 +200,7 @@ class TestInterpolate(TestCase): ...@@ -191,6 +200,7 @@ class TestInterpolate(TestCase):
False, False,
"", "",
None, None,
Frequencies.daily,
), ),
) )
...@@ -221,6 +231,7 @@ class TestInterpolate(TestCase): ...@@ -221,6 +231,7 @@ class TestInterpolate(TestCase):
False, False,
"orig", "orig",
None, None,
Frequencies.daily,
), ),
) )
self.assertEqual( self.assertEqual(
...@@ -237,6 +248,7 @@ class TestInterpolate(TestCase): ...@@ -237,6 +248,7 @@ class TestInterpolate(TestCase):
False, False,
"orig", "orig",
None, None,
Frequencies.daily,
), ),
) )
...@@ -268,6 +280,7 @@ class TestInterpolate(TestCase): ...@@ -268,6 +280,7 @@ class TestInterpolate(TestCase):
False, False,
"orig", "orig",
None, None,
Frequencies.daily,
), ),
) )
self.assertEqual( self.assertEqual(
...@@ -284,6 +297,57 @@ class TestInterpolate(TestCase): ...@@ -284,6 +297,57 @@ class TestInterpolate(TestCase):
False, False,
"orig", "orig",
None, None,
Frequencies.daily,
),
)
jobs = InterpolateCDO.generate_jobs(
self.diags,
[
"interpcdo",
"ocean",
"var",
"target_grid",
"bicubic",
"false",
"orig",
"false",
"mon"
],
)
self.assertEqual(len(jobs), 2)
self.assertEqual(
jobs[0],
InterpolateCDO(
self.data_manager,
"20010101",
0,
0,
ModelingRealms.ocean,
"var",
"target_grid",
"model_version",
False,
"orig",
None,
Frequencies.monthly,
),
)
self.assertEqual(
jobs[1],
InterpolateCDO(
self.data_manager,
"20010101",
0,
1,
ModelingRealms.ocean,
"var",
"target_grid",
"model_version",
False,
"orig",
None,
Frequencies.monthly,
), ),
) )
...@@ -301,6 +365,7 @@ class TestInterpolate(TestCase): ...@@ -301,6 +365,7 @@ class TestInterpolate(TestCase):
"false", "false",
"orig", "orig",
"false", "false",
"daily,"
"extra", "extra",
], ],
) )
...@@ -318,11 +383,12 @@ class TestInterpolate(TestCase): ...@@ -318,11 +383,12 @@ class TestInterpolate(TestCase):
False, False,
"orig", "orig",
None, None,
Frequencies.monthly,
) )
self.assertEqual( self.assertEqual(
str(diag), str(diag),
"Interpolate with CDO Startdate: 20010101 Member: 0 Chunk: 0 " "Interpolate with CDO Startdate: 20010101 Member: 0 Chunk: 0 "
"Variable: ocean:var " "Variable: ocean:var Frequency: mon "
"Target grid: atmos_grid Original grid: orig Mask ocean: False " "Target grid: atmos_grid Original grid: orig Mask ocean: False "
"Model: model_version", "Model: model_version",
) )
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