From 5baae488ac2a8bfc0dde6079a6027c793bb1e9e2 Mon Sep 17 00:00:00 2001 From: Javier Vegas-Regidor Date: Thu, 12 Jan 2017 18:05:15 +0100 Subject: [PATCH 1/7] Added region_mean diagnostic --- earthdiagnostics/ocean/regionmean.py | 97 +++++++++++++++++++++ earthdiagnostics/variable_alias/default.csv | 2 +- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 earthdiagnostics/ocean/regionmean.py diff --git a/earthdiagnostics/ocean/regionmean.py b/earthdiagnostics/ocean/regionmean.py new file mode 100644 index 00000000..8d1af638 --- /dev/null +++ b/earthdiagnostics/ocean/regionmean.py @@ -0,0 +1,97 @@ +# coding=utf-8 +from earthdiagnostics import cdftools +from earthdiagnostics.box import Box +from earthdiagnostics.diagnostic import Diagnostic, DiagnosticOption, DiagnosticIntOption, DiagnosticDomainOption +from earthdiagnostics.utils import Utils, TempFile +from earthdiagnostics.modelingrealm import ModelingRealms + + +class RegionMean(Diagnostic): + """ + Chooses vertical level in ocean, or vertically averages between + 2 or more ocean levels + + :original author: Javier Vegas-Regidor + + :created: January 2017 + + :param data_manager: data management object + :type data_manager: DataManager + :param startdate: startdate + :type startdate: str + :param member: member number + :type member: int + :param chunk: chunk's number + :type chunk: int + :param variable: variable to average + :type variable: str + :param box: box used to restrict the vertical mean + :type box: Box + """ + + alias = 'regmean' + "Diagnostic alias for the configuration file" + + def __init__(self, data_manager, startdate, member, chunk, domain, variable, grid, box): + Diagnostic.__init__(self, data_manager) + self.startdate = startdate + self.member = member + self.chunk = chunk + self.domain = domain + self.variable = variable + self.grid = grid.upper() + self.box = box + self.required_vars = [variable] + self.generated_vars = [variable + 'vmean'] + + def __eq__(self, other): + return self.startdate == other.startdate and self.member == other.member and self.chunk == other.chunk and \ + self.box == other.box and self.variable == other.variable + + def __str__(self): + return 'Vertical mean Startdate: {0} Member: {1} Chunk: {2} Variable: {3} ' \ + 'Box: {4}'.format(self.startdate, self.member, self.chunk, self.variable, self.box) + + @classmethod + def generate_jobs(cls, diags, options): + """ + Creates a job for each chunk to compute the diagnostic + + :param diags: Diagnostics manager class + :type diags: Diags + :param options: variable, minimum depth (level), maximum depth (level) + :type options: list[str] + :return: + """ + options_available = (DiagnosticDomainOption('domain'), + DiagnosticOption('variable'), + DiagnosticOption('grid'), + DiagnosticIntOption('min_depth', -1), + DiagnosticIntOption('max_depth', -1)) + options = cls.process_options(options, options_available) + + box = Box() + if options['min_depth'] >= 0: + box.min_depth = options['min_depth'] + if options['max_depth'] >= 0: + box.max_depth = options['max_depth'] + + job_list = list() + for startdate, member, chunk in diags.config.experiment.get_chunk_list(): + job_list.append(RegionMean(diags.data_manager, startdate, member, chunk, + options['domain'], options['variable'], options['grid'], box)) + return job_list + + def compute(self): + """ + Runs the diagnostic + """ + temp = TempFile.get() + variable_file = self.data_manager.get_file(self.domain, self.variable, self.startdate, self.member, self.chunk) + + cdftools.run('cdfmean', input=variable_file, output=temp, options=[self.domain, self.variable, 'T', 0, 0, 0, 0, + self.box.min_depth, self.box.max_depth]) + Utils.setminmax(temp, 'mean_{0}'.format(self.variable)) + self.send_file(temp, ModelingRealms.ocean, self.variable + 'mean', self.startdate, self.member, self.chunk, + box=self.box, rename_var='mean_{0}'.format(self.variable)) + diff --git a/earthdiagnostics/variable_alias/default.csv b/earthdiagnostics/variable_alias/default.csv index 24683fe3..2a4146d0 100644 --- a/earthdiagnostics/variable_alias/default.csv +++ b/earthdiagnostics/variable_alias/default.csv @@ -170,7 +170,7 @@ iice_hsd:snthicat,sndcat,, isnoheco,snheco,, sd,snld,, smlt,snm,, -isnowthi,snthic,, +isnowthi,snld,, sbgvoltot,snvolga,, snvolu,snvolu,, vosaline:mean_3Dsosaline,so,, -- GitLab From 46bf25b49e6105e1c2fc7ca4369e3eb89fcfc9f5 Mon Sep 17 00:00:00 2001 From: Javier Vegas-Regidor Date: Fri, 13 Jan 2017 09:58:10 +0100 Subject: [PATCH 2/7] Added region_mean to diagnostic list --- earthdiagnostics/earthdiags.py | 1 + earthdiagnostics/ocean/__init__.py | 1 + earthdiagnostics/ocean/regionmean.py | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/earthdiagnostics/earthdiags.py b/earthdiagnostics/earthdiags.py index 990b9213..2333f2ba 100755 --- a/earthdiagnostics/earthdiags.py +++ b/earthdiagnostics/earthdiags.py @@ -245,6 +245,7 @@ class EarthDiags(object): Diagnostic.register(MixedLayerHeatContent) Diagnostic.register(HeatContentLayer) Diagnostic.register(HeatContent) + Diagnostic.register(RegionMean) def clean(self): Log.info('Removing scratch folder...') diff --git a/earthdiagnostics/ocean/__init__.py b/earthdiagnostics/ocean/__init__.py index 0628fb68..8443762a 100644 --- a/earthdiagnostics/ocean/__init__.py +++ b/earthdiagnostics/ocean/__init__.py @@ -19,3 +19,4 @@ from earthdiagnostics.ocean.mixedlayersaltcontent import MixedLayerSaltContent from earthdiagnostics.ocean.siasiesiv import Siasiesiv from earthdiagnostics.ocean.heatcontentlayer import HeatContentLayer from earthdiagnostics.ocean.mixedlayerheatcontent import MixedLayerHeatContent +from earthdiagnostics.ocean.regionmean import RegionMean diff --git a/earthdiagnostics/ocean/regionmean.py b/earthdiagnostics/ocean/regionmean.py index 8d1af638..0f819e50 100644 --- a/earthdiagnostics/ocean/regionmean.py +++ b/earthdiagnostics/ocean/regionmean.py @@ -1,7 +1,8 @@ # coding=utf-8 from earthdiagnostics import cdftools from earthdiagnostics.box import Box -from earthdiagnostics.diagnostic import Diagnostic, DiagnosticOption, DiagnosticIntOption, DiagnosticDomainOption +from earthdiagnostics.diagnostic import Diagnostic, DiagnosticOption, DiagnosticIntOption, DiagnosticDomainOption, \ + DiagnosticBoolOption from earthdiagnostics.utils import Utils, TempFile from earthdiagnostics.modelingrealm import ModelingRealms @@ -32,7 +33,7 @@ class RegionMean(Diagnostic): alias = 'regmean' "Diagnostic alias for the configuration file" - def __init__(self, data_manager, startdate, member, chunk, domain, variable, grid, box): + def __init__(self, data_manager, startdate, member, chunk, domain, variable, grid, box, save3d): Diagnostic.__init__(self, data_manager) self.startdate = startdate self.member = member @@ -41,6 +42,7 @@ class RegionMean(Diagnostic): self.variable = variable self.grid = grid.upper() self.box = box + self.save3d = save3d self.required_vars = [variable] self.generated_vars = [variable + 'vmean'] @@ -66,6 +68,7 @@ class RegionMean(Diagnostic): options_available = (DiagnosticDomainOption('domain'), DiagnosticOption('variable'), DiagnosticOption('grid'), + DiagnosticBoolOption('save3D', False), DiagnosticIntOption('min_depth', -1), DiagnosticIntOption('max_depth', -1)) options = cls.process_options(options, options_available) @@ -79,7 +82,7 @@ class RegionMean(Diagnostic): job_list = list() for startdate, member, chunk in diags.config.experiment.get_chunk_list(): job_list.append(RegionMean(diags.data_manager, startdate, member, chunk, - options['domain'], options['variable'], options['grid'], box)) + options['domain'], options['variable'], options['grid'], box, options['save3D'])) return job_list def compute(self): @@ -89,9 +92,14 @@ class RegionMean(Diagnostic): temp = TempFile.get() variable_file = self.data_manager.get_file(self.domain, self.variable, self.startdate, self.member, self.chunk) - cdftools.run('cdfmean', input=variable_file, output=temp, options=[self.domain, self.variable, 'T', 0, 0, 0, 0, + cdftools.run('cdfmean', input=variable_file, output=temp, options=[self.domain, self.variable, self.grid, + 0, 0, 0, 0, self.box.min_depth, self.box.max_depth]) Utils.setminmax(temp, 'mean_{0}'.format(self.variable)) self.send_file(temp, ModelingRealms.ocean, self.variable + 'mean', self.startdate, self.member, self.chunk, box=self.box, rename_var='mean_{0}'.format(self.variable)) + if self.save3d: + Utils.setminmax(temp, 'mean_3D_{0}'.format(self.variable)) + self.send_file(temp, ModelingRealms.ocean, self.variable + '3dmean', self.startdate, self.member, + self.chunk, box=self.box, rename_var='mean_3D_{0}'.format(self.variable)) -- GitLab From 57a368fca9770e94c4faaf5344ab7742c7e0d68e Mon Sep 17 00:00:00 2001 From: Javier Vegas-Regidor Date: Mon, 16 Jan 2017 09:35:12 +0100 Subject: [PATCH 3/7] Added region option for regionmean --- earthdiagnostics/ocean/regionmean.py | 31 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/earthdiagnostics/ocean/regionmean.py b/earthdiagnostics/ocean/regionmean.py index 0f819e50..c1ca2ead 100644 --- a/earthdiagnostics/ocean/regionmean.py +++ b/earthdiagnostics/ocean/regionmean.py @@ -1,8 +1,9 @@ # coding=utf-8 from earthdiagnostics import cdftools from earthdiagnostics.box import Box +from earthdiagnostics.constants import Basins from earthdiagnostics.diagnostic import Diagnostic, DiagnosticOption, DiagnosticIntOption, DiagnosticDomainOption, \ - DiagnosticBoolOption + DiagnosticBoolOption, DiagnosticBasinOption from earthdiagnostics.utils import Utils, TempFile from earthdiagnostics.modelingrealm import ModelingRealms @@ -33,7 +34,7 @@ class RegionMean(Diagnostic): alias = 'regmean' "Diagnostic alias for the configuration file" - def __init__(self, data_manager, startdate, member, chunk, domain, variable, grid, box, save3d): + def __init__(self, data_manager, startdate, member, chunk, domain, variable, grid, box, save3d, variance, basin): Diagnostic.__init__(self, data_manager) self.startdate = startdate self.member = member @@ -43,6 +44,8 @@ class RegionMean(Diagnostic): self.grid = grid.upper() self.box = box self.save3d = save3d + self.variance = variance + self.basin = basin self.required_vars = [variable] self.generated_vars = [variable + 'vmean'] @@ -69,8 +72,10 @@ class RegionMean(Diagnostic): DiagnosticOption('variable'), DiagnosticOption('grid'), DiagnosticBoolOption('save3D', False), + DiagnosticBoolOption('variance', False), DiagnosticIntOption('min_depth', -1), - DiagnosticIntOption('max_depth', -1)) + DiagnosticIntOption('max_depth', -1), + DiagnosticBasinOption('basin', Basins.Global)) options = cls.process_options(options, options_available) box = Box() @@ -82,7 +87,8 @@ class RegionMean(Diagnostic): job_list = list() for startdate, member, chunk in diags.config.experiment.get_chunk_list(): job_list.append(RegionMean(diags.data_manager, startdate, member, chunk, - options['domain'], options['variable'], options['grid'], box, options['save3D'])) + options['domain'], options['variable'], options['grid'], box, options['save3D'], + options['variance'], options['basin'])) return job_list def compute(self): @@ -92,14 +98,19 @@ class RegionMean(Diagnostic): temp = TempFile.get() variable_file = self.data_manager.get_file(self.domain, self.variable, self.startdate, self.member, self.chunk) - cdftools.run('cdfmean', input=variable_file, output=temp, options=[self.domain, self.variable, self.grid, - 0, 0, 0, 0, - self.box.min_depth, self.box.max_depth]) + cdfmean_options = [self.domain, self.variable, self.grid, 0, 0, 0, 0, self.box.min_depth, self.box.max_depth] + if self.basin != Basins.Global: + cdfmean_options.append('-maskfile') + cdfmean_options.append('mask_regions.3d.nc') + cdfmean_options.append('-mask') + cdfmean_options.append(self.basin.shortname) + + cdftools.run('cdfmean', input=variable_file, output=temp, options=cdfmean_options) Utils.setminmax(temp, 'mean_{0}'.format(self.variable)) self.send_file(temp, ModelingRealms.ocean, self.variable + 'mean', self.startdate, self.member, self.chunk, - box=self.box, rename_var='mean_{0}'.format(self.variable)) + box=self.box, rename_var='mean_{0}'.format(self.variable), region=self.basin) if self.save3d: - Utils.setminmax(temp, 'mean_3D_{0}'.format(self.variable)) + Utils.setminmax(temp, 'mean_3D{0}'.format(self.variable)) self.send_file(temp, ModelingRealms.ocean, self.variable + '3dmean', self.startdate, self.member, - self.chunk, box=self.box, rename_var='mean_3D_{0}'.format(self.variable)) + self.chunk, box=self.box, rename_var='mean_3D{0}'.format(self.variable), region=self.basin) -- GitLab From 61c41e8ffb8b3e07af11e20f8e44fa63c1a61862 Mon Sep 17 00:00:00 2001 From: Javier Vegas-Regidor Date: Wed, 25 Jan 2017 14:41:27 +0100 Subject: [PATCH 4/7] Moved list of failed jobs to the end of execution --- earthdiagnostics/earthdiags.py | 16 +++++++++++++--- earthdiagnostics/ocean/areamoc.py | 5 +++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/earthdiagnostics/earthdiags.py b/earthdiagnostics/earthdiags.py index 0daaeb82..a4c40388 100755 --- a/earthdiagnostics/earthdiags.py +++ b/earthdiagnostics/earthdiags.py @@ -151,6 +151,7 @@ class EarthDiags(object): # Run diagnostics Log.info('Running diagnostics') list_jobs = self.prepare_job_list() + self._failed_jobs = [] time = datetime.datetime.now() Log.info("Starting to compute at {0}", time) @@ -170,6 +171,7 @@ class EarthDiags(object): finish_time = datetime.datetime.now() Log.result("Diagnostics finished at {0}", finish_time) Log.result("Elapsed time: {0}\n", finish_time - time) + self.print_errors() self.print_stats() return not self.had_errors @@ -193,6 +195,16 @@ class EarthDiags(object): for diag, time in sorted(total.items(), key=operator.itemgetter(1)): Log.info('{0:23} {1:}', diag.__name__, time) + def print_errors(self): + if len(self._failed_jobs) == 0: + return + self.had_errors = True + Log.error('Failed jobs') + Log.error('-----------') + for job in self._failed_jobs: + Log.error(str(job)) + Log.info('') + def prepare_job_list(self): list_jobs = Queue.Queue() for fulldiag in self.config.get_commands(): @@ -346,9 +358,7 @@ class EarthDiags(object): else: Log.result('Thread {0} finished after running successfully {1} of {2} tasks', numthread, count, count + len(failed_jobs)) - self.had_errors = True - for job in failed_jobs: - Log.error('Job {0} could not be run', job) + self._failed_jobs += failed_jobs return def _prepare_mesh_files(self): diff --git a/earthdiagnostics/ocean/areamoc.py b/earthdiagnostics/ocean/areamoc.py index 5c8464e0..e65fe622 100644 --- a/earthdiagnostics/ocean/areamoc.py +++ b/earthdiagnostics/ocean/areamoc.py @@ -54,8 +54,9 @@ class AreaMoc(Diagnostic): self.basin == other.basin and self.box == other.box def __str__(self): - return 'Area MOC Startdate: {0} Member: {1} Chunk: {2} Box: {3}'.format(self.startdate, self.member, - self.chunk, self.box) + return 'Area MOC Startdate: {0} Member: {1} Chunk: {2} Box: {3} Basin: {4}'.format(self.startdate, self.member, + self.chunk, self.box, + self.basin) @classmethod def generate_jobs(cls, diags, options): -- GitLab From 06a8a41938ed25bade9fd94b4335d073eae7afb2 Mon Sep 17 00:00:00 2001 From: Javier Vegas-Regidor Date: Wed, 25 Jan 2017 15:05:22 +0100 Subject: [PATCH 5/7] Heat content diagnostic is now using the NetCDF output --- earthdiagnostics/cdftools.py | 4 ++- earthdiagnostics/ocean/heatcontent.py | 49 ++++++++++----------------- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/earthdiagnostics/cdftools.py b/earthdiagnostics/cdftools.py index 32eabc34..792853ba 100644 --- a/earthdiagnostics/cdftools.py +++ b/earthdiagnostics/cdftools.py @@ -16,7 +16,7 @@ class CDFTools(object): self.path = path # noinspection PyShadowingBuiltins - def run(self, command, input, output=None, options=None, log_level=Log.INFO): + def run(self, command, input, output=None, options=None, log_level=Log.INFO, input_option=None): """ Runs one of the CDFTools @@ -35,6 +35,8 @@ class CDFTools(object): line = [os.path.join(self.path, command)] self._check_command_existence(line[0]) + if input_option: + line.append(input_option) self._check_input(command, input, line) if options: if isinstance(options, basestring): diff --git a/earthdiagnostics/ocean/heatcontent.py b/earthdiagnostics/ocean/heatcontent.py index acc6334d..07f91ffd 100644 --- a/earthdiagnostics/ocean/heatcontent.py +++ b/earthdiagnostics/ocean/heatcontent.py @@ -98,12 +98,14 @@ class HeatContent(Diagnostic): nco.ncks(input=mlotst_file, output=temperature_file, options='-A -v mlotst') para = list() - para.append('0') - para.append('0') - para.append('0') - para.append('0') - para.append(self.box.min_depth) - para.append(self.box.max_depth) + if self.box.min_depth != 0: + para.append('-zoom') + para.append(0) + para.append(0) + para.append(0) + para.append(0) + para.append(self.box.min_depth) + para.append(self.box.max_depth) if self.mxloption != 0: para.append('-mxloption') para.append(str(self.mxloption)) @@ -113,13 +115,15 @@ class HeatContent(Diagnostic): raise Exception('Basin {0} is not defined on mask_regions.nc'.format(self.basin.fullname)) handler.close() - para.append('-maskfile') + para.append('-M') para.append('mask_regions.3d.nc') - para.append('-mask') para.append(self.basin.fullname) - shell_output = cdftools.run('cdfheatc', options=para, input=temperature_file) + temp2 = TempFile.get() + cdftools.run('cdfheatc', options=para, input=temperature_file, output=temp2, input_option='-f') + + results = Utils.openCdf(temp2) heatcsum_temp = TempFile.get() heatcvmean_temp = TempFile.get() nco.ncks(input=temperature_file, output=heatcsum_temp, options='-O -v time') @@ -130,36 +134,19 @@ class HeatContent(Diagnostic): thc.standard_name = "integral_of_sea_water_potential_temperature_expressed_as_heat_content" thc.long_name = "Total heat content" thc.units = "J" + thc[:] = results.variables['heatc3d'][:, 0, 0] + heatcsum_handler.close() heatcvmean_handler = Utils.openCdf(heatcvmean_temp) uhc = heatcvmean_handler.createVariable('heatcvmean', float, 'time') uhc.standard_name = "integral_of_sea_water_potential_temperature_expressed_as_heat_content" uhc.long_name = "Heat content per unit volume" uhc.units = "J*m^-3" - - time = 0 - # noinspection PyUnboundLocalVariable - for lines in shell_output: - if not lines: - continue - - for line in lines.split('\n'): - line = line.lstrip() - if line.startswith("Heat Content at level"): - Log.info(line) - elif line.startswith("Total Heat content/volume"): - Log.user_warning(line) - uhc[time] = line[line.index(':') + 1: line.index('Joules')] - time += 1 - if line.startswith("Total Heat content "): - Log.result(line) - thc[time] = line[line.index(':') + 1: line.index('Joules')] - elif line.startswith('TIME : '): - Log.info(line) - - heatcsum_handler.close() + uhc[:] = results.variables['heatc3dpervol'][:, 0, 0] heatcvmean_handler.close() + results.close() + if self.box.min_depth == 0: # For cdftools, this is all levels box_save = None -- GitLab From 1ccd7aa66b43cbd92058fc3c338d1fceab357fb5 Mon Sep 17 00:00:00 2001 From: Javier Vegas-Regidor Date: Wed, 25 Jan 2017 16:13:36 +0100 Subject: [PATCH 6/7] Finished regmean diagnostic. Fixes #19 --- diags.conf | 8 +++--- doc/source/diagnostic_list.rst | 41 ++++++++++++++++++++++++++-- earthdiagnostics/cmormanager.py | 21 ++++++++------ earthdiagnostics/diagnostic.py | 4 ++- earthdiagnostics/ocean/regionmean.py | 34 ++++++++++++----------- 5 files changed, 76 insertions(+), 32 deletions(-) diff --git a/diags.conf b/diags.conf index 6ff22c61..ca5be109 100644 --- a/diags.conf +++ b/diags.conf @@ -16,13 +16,13 @@ CON_FILES = /esnas/autosubmit/con_files/ # Diagnostics to run, space separated. You must provide for each one the name and the parameters (comma separated) or # an alias defined in the ALIAS section (see more below). If you are using the diagnostics just to CMORize, leave it # empty -DIAGS = +DIAGS = regmean,ocean,thetao,T # DIAGS = OHC # Frequency of the data you want to use by default. Some diagnostics do not use this value: i.e. monmean always stores # its results at monthly frequency (obvious) and has a parameter to specify input's frequency. -FREQUENCY = 6hr +FREQUENCY = mon # Path to CDFTOOLS binaries -CDFTOOLS_PATH = +CDFTOOLS_PATH = ~jvegas/CDFTOOLS/bin # If true, copies the mesh files regardless of presence in scratch dir RESTORE_MESHES = False # Limits the maximum amount of threads used. Default: 0 (no limitation, one per virtual core available) @@ -30,7 +30,7 @@ MAX_CORES = 1 [CMOR] # If true, recreates CMOR files regardless of presence. Default = False -FORCE = True +FORCE = False # If true, CMORizes ocean files. Default = True OCEAN_FILES = True FILTER_FILES = 3h 6h diff --git a/doc/source/diagnostic_list.rst b/doc/source/diagnostic_list.rst index 31fd63c5..75aa779c 100644 --- a/doc/source/diagnostic_list.rst +++ b/doc/source/diagnostic_list.rst @@ -193,9 +193,6 @@ averagesection Compute an average of a given zone. The variable MUST be in a regular grid See :class:`~earthdiagnostics.ocean.averagesection.AverageSection` -.. warning:: - This diagnostic is not finished - Options: ******** @@ -427,6 +424,44 @@ Options: This diagnostic has no options +regionmean +~~~~~~~~~~ + +Compute an average of a given zone using cdfmean from CDFTOOLS +See :class:`~earthdiagnostics.ocean.regionmean.RegionMean` + +Options: +******** + +1. Domain: + Variable domain + +2. Variable: + Variable to average + +3. Grid: + Minimum longitude to compute + +4. Save 3d = False: + If True, it also stores the average per level + +5. Min depth: + Minimum depth to compute in levels. If -1, average from the surface + +6. Max depth: + Maximum depth to compute in levels. If -1, average to the bottom + +7. Basin = Global: + Basin to compute + + options_available = (DiagnosticDomainOption('domain'), + DiagnosticOption('variable'), + DiagnosticOption('grid'), + DiagnosticBoolOption('save3D', False), + DiagnosticIntOption('min_depth', -1), + DiagnosticIntOption('max_depth', -1), + DiagnosticBasinOption('basin', Basins.Global)) + siasiesiv ~~~~~~~~~ diff --git a/earthdiagnostics/cmormanager.py b/earthdiagnostics/cmormanager.py index 5970699f..fc0a6849 100644 --- a/earthdiagnostics/cmormanager.py +++ b/earthdiagnostics/cmormanager.py @@ -158,14 +158,19 @@ class CMORManager(DataManager): member + 1, time_bound) elif self.config.data_convention in ('primavera', 'cmip6'): - file_name = '{0}_{1}_{2}_{3}_S{4}-r{5}i1p1_{6}{7}'.format(var, - cmor_table.name, - self.experiment.experiment_name, - self.experiment.model, - startdate, - member + 1, - grid, - time_bound) + if grid is None: + grid = '' + else: + grid = '_{0}'.format(grid) + + file_name = '{0}_{1}_{2}_{3}_S{4}-r{5}i1p1{6}{7}'.format(var, + cmor_table.name, + self.experiment.experiment_name, + self.experiment.model, + startdate, + member + 1, + grid, + time_bound) else: raise Exception('Data convention {0} not supported'.format(self.config.data_convention)) return file_name diff --git a/earthdiagnostics/diagnostic.py b/earthdiagnostics/diagnostic.py index 83b1e44e..3f9a370d 100644 --- a/earthdiagnostics/diagnostic.py +++ b/earthdiagnostics/diagnostic.py @@ -1,5 +1,5 @@ # coding=utf-8 -from earthdiagnostics.constants import Basins +from earthdiagnostics.constants import Basins, Basin from earthdiagnostics.frequency import Frequency from earthdiagnostics.variable_type import VariableType from earthdiagnostics.modelingrealm import ModelingRealms @@ -82,6 +82,8 @@ class Diagnostic(object): :type vartype: VariableType :return: """ + if isinstance(region, Basin): + region = region.fullname self.data_manager.send_file(filetosend, domain, var, startdate, member, chunk, grid, region, box, rename_var, frequency, year, date_str, move_old, diagnostic=self, vartype=vartype) diff --git a/earthdiagnostics/ocean/regionmean.py b/earthdiagnostics/ocean/regionmean.py index c1ca2ead..43e986da 100644 --- a/earthdiagnostics/ocean/regionmean.py +++ b/earthdiagnostics/ocean/regionmean.py @@ -34,7 +34,7 @@ class RegionMean(Diagnostic): alias = 'regmean' "Diagnostic alias for the configuration file" - def __init__(self, data_manager, startdate, member, chunk, domain, variable, grid, box, save3d, variance, basin): + def __init__(self, data_manager, startdate, member, chunk, domain, variable, grid, box, save3d, basin): Diagnostic.__init__(self, data_manager) self.startdate = startdate self.member = member @@ -44,7 +44,6 @@ class RegionMean(Diagnostic): self.grid = grid.upper() self.box = box self.save3d = save3d - self.variance = variance self.basin = basin self.required_vars = [variable] self.generated_vars = [variable + 'vmean'] @@ -71,24 +70,21 @@ class RegionMean(Diagnostic): options_available = (DiagnosticDomainOption('domain'), DiagnosticOption('variable'), DiagnosticOption('grid'), + DiagnosticBasinOption('basin', Basins.Global), DiagnosticBoolOption('save3D', False), - DiagnosticBoolOption('variance', False), - DiagnosticIntOption('min_depth', -1), - DiagnosticIntOption('max_depth', -1), - DiagnosticBasinOption('basin', Basins.Global)) + DiagnosticIntOption('min_depth', 0), + DiagnosticIntOption('max_depth', 0)) options = cls.process_options(options, options_available) box = Box() - if options['min_depth'] >= 0: - box.min_depth = options['min_depth'] - if options['max_depth'] >= 0: - box.max_depth = options['max_depth'] + box.min_depth = options['min_depth'] + box.max_depth = options['max_depth'] job_list = list() for startdate, member, chunk in diags.config.experiment.get_chunk_list(): job_list.append(RegionMean(diags.data_manager, startdate, member, chunk, options['domain'], options['variable'], options['grid'], box, options['save3D'], - options['variance'], options['basin'])) + options['basin'])) return job_list def compute(self): @@ -98,19 +94,25 @@ class RegionMean(Diagnostic): temp = TempFile.get() variable_file = self.data_manager.get_file(self.domain, self.variable, self.startdate, self.member, self.chunk) - cdfmean_options = [self.domain, self.variable, self.grid, 0, 0, 0, 0, self.box.min_depth, self.box.max_depth] + cdfmean_options = [self.variable, self.grid, 0, 0, 0, 0, self.box.min_depth, self.box.max_depth] if self.basin != Basins.Global: - cdfmean_options.append('-maskfile') + cdfmean_options.append('-M') cdfmean_options.append('mask_regions.3d.nc') - cdfmean_options.append('-mask') cdfmean_options.append(self.basin.shortname) cdftools.run('cdfmean', input=variable_file, output=temp, options=cdfmean_options) Utils.setminmax(temp, 'mean_{0}'.format(self.variable)) + + if self.box.min_depth == 0: + # For cdftools, this is all levels + box_save = None + else: + box_save = self.box + self.send_file(temp, ModelingRealms.ocean, self.variable + 'mean', self.startdate, self.member, self.chunk, - box=self.box, rename_var='mean_{0}'.format(self.variable), region=self.basin) + box=box_save, rename_var='mean_{0}'.format(self.variable), region=self.basin) if self.save3d: Utils.setminmax(temp, 'mean_3D{0}'.format(self.variable)) self.send_file(temp, ModelingRealms.ocean, self.variable + '3dmean', self.startdate, self.member, - self.chunk, box=self.box, rename_var='mean_3D{0}'.format(self.variable), region=self.basin) + self.chunk, box=box_save, rename_var='mean_3D{0}'.format(self.variable), region=self.basin) -- GitLab From 826ccfeaed877d357d83a277125359be7c0dc4f0 Mon Sep 17 00:00:00 2001 From: Javier Vegas-Regidor Date: Wed, 25 Jan 2017 16:17:47 +0100 Subject: [PATCH 7/7] Fixed doc for regmean --- doc/source/diagnostic_list.rst | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/doc/source/diagnostic_list.rst b/doc/source/diagnostic_list.rst index 75aa779c..f8392b48 100644 --- a/doc/source/diagnostic_list.rst +++ b/doc/source/diagnostic_list.rst @@ -424,12 +424,15 @@ Options: This diagnostic has no options -regionmean -~~~~~~~~~~ +regmean +~~~~~~~ Compute an average of a given zone using cdfmean from CDFTOOLS See :class:`~earthdiagnostics.ocean.regionmean.RegionMean` +.. warning:: + This diagnostic is a recent addition and needs more testing to be reliable + Options: ******** @@ -440,27 +443,21 @@ Options: Variable to average 3. Grid: - Minimum longitude to compute + NEMO grid used to store the variable: T, U, V ... -4. Save 3d = False: +4. Basin = Global: + Basin to compute + +5. Save 3d = False: If True, it also stores the average per level -5. Min depth: +6. Min depth: Minimum depth to compute in levels. If -1, average from the surface -6. Max depth: +7. Max depth: Maximum depth to compute in levels. If -1, average to the bottom -7. Basin = Global: - Basin to compute - options_available = (DiagnosticDomainOption('domain'), - DiagnosticOption('variable'), - DiagnosticOption('grid'), - DiagnosticBoolOption('save3D', False), - DiagnosticIntOption('min_depth', -1), - DiagnosticIntOption('max_depth', -1), - DiagnosticBasinOption('basin', Basins.Global)) siasiesiv ~~~~~~~~~ -- GitLab