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

Removed variable manger singleton to make config easier to test

parent 38245e79
......@@ -88,7 +88,7 @@ OCEAN_TIMESTEP = 6
# CHUNK_SIZE is the size of each data file, given in months
# CHUNKS is the number of chunks. You can specify less chunks than present on the experiment
EXPID = testing_erainterim
STARTDATES = 19801101 19811101 19821101 19831101 19841101 19851101 19861101 19871101 19881101 19891101 19701101 19711101 19721101 19731101 19741101 19751101 19761101 19771101 19781101 19791101
STARTDATES = 20001101 20011101 20021101 20031101 20041101 20051101 20061101 20071101 20081101 20091101 20101101 20111101 20121101 20131101 20141101 20151101 20161101
# STARTDATES = 19840101 19850101
MEMBERS = 0
MEMBER_DIGITS = 1
......
......@@ -13,7 +13,6 @@ from bscearth.utils.date import parse_date, chunk_end_date, previous_day, date2s
from earthdiagnostics.frequency import Frequency, Frequencies
from earthdiagnostics.modelingrealm import ModelingRealms
from earthdiagnostics.utils import TempFile, Utils
from earthdiagnostics.variable import VariableManager
from earthdiagnostics.datafile import NetCDFFile
......@@ -397,7 +396,7 @@ class Cmorizer(object):
:param variable: variable's name
:type variable: str
"""
alias, var_cmor = VariableManager().get_variable_and_alias(variable)
alias, var_cmor = self.config.var_manager.get_variable_and_alias(variable)
if var_cmor is None:
return
......
......@@ -20,6 +20,7 @@ class Config(object):
"""
def __init__(self, path):
parser = ConfigParser()
parser.optionxform = str
parser.read(path)
......@@ -58,7 +59,8 @@ class Config(object):
self.data_convention = parser.get_choice_option('DIAGNOSTICS', 'DATA_CONVENTION',
('specs', 'primavera', 'cmip6', 'preface'), 'specs',
ignore_case=True)
VariableManager().load_variables(self.data_convention)
self.var_manager = VariableManager()
self.var_manager.load_variables(self.data_convention)
self._diags = parser.get_option('DIAGNOSTICS', 'DIAGS')
self.frequency = Frequency(parser.get_option('DIAGNOSTICS', 'FREQUENCY'))
"Default data frequency to be used by the diagnostics"
......@@ -67,6 +69,10 @@ class Config(object):
"Path to CDFTOOLS executables"
self.max_cores = parser.get_int_option('DIAGNOSTICS', 'MAX_CORES', 0)
"Maximum number of cores to use"
self.parallel_downloads = parser.get_int_option('DIAGNOSTICS', 'PARALLEL_DOWNLOADS', 1)
"Maximum number of simultaneous downloads"
self.parallel_uploads = parser.get_int_option('DIAGNOSTICS', 'PARALLEL_UPLOADS', 1)
"Maximum number of simultaneous uploads"
self.restore_meshes = parser.get_bool_option('DIAGNOSTICS', 'RESTORE_MESHES', False)
"If True, forces the tool to copy all the mesh and mask files for the model, regardless of existence"
......@@ -112,7 +118,7 @@ class Config(object):
class CMORConfig(object):
def __init__(self, parser):
def __init__(self, parser, var_manager):
self.force = parser.get_bool_option('CMOR', 'FORCE', False)
self.force_untar = parser.get_bool_option('CMOR', 'FORCE_UNTAR', False)
self.filter_files = parser.get_option('CMOR', 'FILTER_FILES', '')
......@@ -134,14 +140,14 @@ class CMORConfig(object):
self.activity = parser.get_option('CMOR', 'ACTIVITY', 'CMIP')
vars_string = parser.get_option('CMOR', 'VARIABLE_LIST', '')
var_manager = VariableManager()
self.var_manager = var_manager
if vars_string:
self._variable_list = list()
for domain_var in vars_string.split(' '):
if domain_var.startswith('#'):
break
splitted = domain_var.split(':')
cmor_var = var_manager.get_variable(splitted[1], silent=True)
cmor_var = self.var_manager.get_variable(splitted[1], silent=True)
if not cmor_var:
continue
if ModelingRealm(splitted[0]) != cmor_var.domain:
......@@ -174,7 +180,7 @@ class CMORConfig(object):
if self._variable_list is None:
return True
for var in variables:
if self.cmorize(VariableManager().get_variable(var, silent=True)):
if self.cmorize(self.var_manager.get_variable(var, silent=True)):
return True
return False
......
......@@ -23,7 +23,7 @@ class DataManager(object):
self.config = config
self.experiment = config.experiment
self._checked_vars = list()
self.variable_list = VariableManager()
self.variable_list = config.var_manager
UnitConversion.load_conversions()
self.lock = threading.Lock()
self.requested_files = {}
......
......@@ -330,23 +330,29 @@ class DiagnosticListFrequenciesOption(DiagnosticOption):
class DiagnosticVariableOption(DiagnosticOption):
def __init__(self, name='variable', default_value=None):
def __init__(self, var_manager, name='variable', default_value=None):
super(DiagnosticVariableOption, self).__init__(name, default_value)
self.var_manager = var_manager
def parse(self, option_value):
option_value = self.check_default(option_value)
real_name = VariableManager().get_variable(option_value, False)
real_name = self.var_manager.get_variable(option_value, False)
if real_name is None:
return option_value
return real_name.short_name
class DiagnosticVariableListOption(DiagnosticOption):
def __init__(self, var_manager, name, default_value=None):
super(DiagnosticVariableListOption, self).__init__(name, default_value)
self.var_manager = var_manager
def parse(self, option_value):
option_value = self.check_default(option_value)
var_names = []
for value in option_value.split('-'):
real_name = VariableManager().get_variable(value, False)
real_name = self.var_manager.get_variable(value, False)
if real_name is None:
var_names.append(value)
else:
......
......@@ -228,7 +228,7 @@ class EarthDiags(object):
return True
def _get_variable_report(self, startdate, member):
var_manager = VariableManager()
var_manager = self.config.var_manager
results = list()
for var in var_manager.get_all_variables():
if var.domain is None:
......
......@@ -66,7 +66,7 @@ class Attribute(Diagnostic):
"""
options_available = (DiagnosticDomainOption(),
DiagnosticVariableOption(),
DiagnosticVariableOption(diags.data_manager.config.var_manager),
DiagnosticOption('name'),
DiagnosticComplexStrOption('value'),
DiagnosticOption('grid', ''))
......
......@@ -71,7 +71,7 @@ class DailyMean(Diagnostic):
"""
options_available = (DiagnosticDomainOption(),
DiagnosticVariableOption(),
DiagnosticVariableOption(diags.data_manager.config.var_manager),
DiagnosticFrequencyOption(),
DiagnosticOption('grid', ''))
options = cls.process_options(options, options_available)
......
......@@ -66,9 +66,9 @@ class Module(Diagnostic):
:return:
"""
options_available = (DiagnosticDomainOption(),
DiagnosticVariableOption('componentu'),
DiagnosticVariableOption('componentv'),
DiagnosticVariableOption('module'),
DiagnosticVariableOption(diags.data_manager.config.var_manager, 'componentu'),
DiagnosticVariableOption(diags.data_manager.config.var_manager, 'componentv'),
DiagnosticVariableOption(diags.data_manager.config.var_manager, 'module'),
DiagnosticOption('grid', ''))
options = cls.process_options(options, options_available)
job_list = list()
......
......@@ -69,7 +69,7 @@ class MonthlyMean(Diagnostic):
"""
options_available = (DiagnosticDomainOption(),
DiagnosticVariableOption(),
DiagnosticVariableOption(diags.data_manager.config.var_manager),
DiagnosticFrequencyOption('frequency', Frequencies.daily),
DiagnosticOption('grid', ''))
options = cls.process_options(options, options_available)
......
......@@ -41,6 +41,7 @@ class Relink(Diagnostic):
self.domain = domain
self.move_old = move_old
self.grid = grid
self.var_manager = data_manager.config.var_manager
def __str__(self):
return 'Relink output Startdate: {0.startdate} Member: {0.member} Chunk: {0.chunk} Move old: {0.move_old} ' \
......@@ -63,7 +64,7 @@ class Relink(Diagnostic):
:return:
"""
options_available = (DiagnosticDomainOption(),
DiagnosticVariableOption(),
DiagnosticVariableOption(diags.data_manager.config.var_manager),
DiagnosticBoolOption('move_old', True),
DiagnosticOption('grid', ''))
options = cls.process_options(options, options_available)
......@@ -83,7 +84,7 @@ class Relink(Diagnostic):
"""
Runs the diagnostic
"""
self.data_manager.link_file(self.domain, self.variable, VariableManager().get_variable(self.variable),
self.data_manager.link_file(self.domain, self.variable, self.var_manager.get_variable(self.variable),
self.startdate, self.member, self.chunk,
move_old=self.move_old, grid=self.grid)
......@@ -59,7 +59,7 @@ class Rewrite(Diagnostic):
:return:
"""
options_available = (DiagnosticDomainOption(),
DiagnosticVariableOption(),
DiagnosticVariableOption(diags.data_manager.config.var_manager),
DiagnosticOption('grid', ''))
options = cls.process_options(options, options_available)
job_list = list()
......
......@@ -71,7 +71,7 @@ class Scale(Diagnostic):
:return:
"""
options_available = (DiagnosticDomainOption(),
DiagnosticVariableOption(),
DiagnosticVariableOption(diags.data_manager.config.var_manager),
DiagnosticFloatOption('value'),
DiagnosticFloatOption('offset'),
DiagnosticOption('grid', ''),
......
......@@ -66,7 +66,7 @@ class SelectLevels(Diagnostic):
:return:
"""
options_available = (DiagnosticDomainOption(),
DiagnosticVariableListOption('variables'),
DiagnosticVariableListOption(diags.data_manager.config.var_manager, 'variables'),
DiagnosticIntOption('first_level'),
DiagnosticIntOption('last_level'),
DiagnosticOption('grid', ''))
......
......@@ -62,7 +62,7 @@ class SimplifyDimensions(Diagnostic):
:return:
"""
options_available = (DiagnosticDomainOption(),
DiagnosticVariableListOption('variables'),
DiagnosticVariableListOption(diags.data_manager.config.var_manager, 'variables'),
DiagnosticOption('grid', ''))
options = cls.process_options(options, options_available)
job_list = list()
......
......@@ -66,7 +66,7 @@ class VerticalMeanMetersIris(Diagnostic):
:type options: list[str]
:return:
"""
options_available = (DiagnosticVariableOption(),
options_available = (DiagnosticVariableOption(diags.data_manager.config.var_manager),
DiagnosticFloatOption('min_depth', -1),
DiagnosticFloatOption('max_depth', -1),
DiagnosticDomainOption(default_value=ModelingRealms.ocean))
......
......@@ -71,7 +71,7 @@ class YearlyMean(Diagnostic):
"""
options_available = (DiagnosticDomainOption(),
DiagnosticVariableOption(),
DiagnosticVariableOption(diags.data_manager.config.var_manager),
DiagnosticFrequencyOption(default_value=diags.config.frequency),
DiagnosticOption('grid', ''))
options = cls.process_options(options, options_available)
......
......@@ -66,7 +66,7 @@ class AverageSection(Diagnostic):
:return:
"""
options_available = (DiagnosticDomainOption(),
DiagnosticVariableOption(),
DiagnosticVariableOption(diags.data_manager.config.var_manager),
DiagnosticIntOption('min_lon'),
DiagnosticIntOption('max_lon'),
DiagnosticIntOption('min_lat'),
......
......@@ -79,7 +79,7 @@ class CutSection(Diagnostic):
:type options: list[str]
:return:
"""
options_available = (DiagnosticVariableOption(),
options_available = (DiagnosticVariableOption(diags.data_manager.config.var_manager),
DiagnosticBoolOption('zonal'),
DiagnosticIntOption('value'),
DiagnosticDomainOption(default_value=ModelingRealms.ocean))
......
......@@ -84,7 +84,7 @@ class Interpolate(Diagnostic):
:return:
"""
options_available = (DiagnosticOption('target_grid'),
DiagnosticVariableListOption('variable'),
DiagnosticVariableListOption(diags.data_manager.config.var_manager, 'variable'),
DiagnosticDomainOption(default_value=ModelingRealms.ocean),
DiagnosticBoolOption('invert_lat', False),
DiagnosticOption('original_grid', ''))
......
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