예제 #1
0
    def set_run_arguments(self, tag_location='run_location'):

        obj_run_filled = self.obj_run_info_filled

        obj_tmpl_ref = self.obj_template_run_ref
        obj_tmpl_filled = self.obj_template_run_filled

        obj_location_raw = self.obj_run_info_ref[tag_location]

        obj_args_def = {}
        for obj_key, obj_value_raw in obj_location_raw.items():
            for tmpl_key, tmpl_value in obj_tmpl_filled.items():

                if self.tag_arguments in list(obj_value_raw.keys()):

                    if tmpl_key not in list(obj_args_def.keys()):
                        obj_args_def[tmpl_key] = {}

                    args_str_raw = get_dict_value(obj_value_raw, self.tag_arguments)
                    args_list_raw = convert_string_2_list(args_str_raw, ' ')

                    args_list_def = []
                    for args_step in args_list_raw:
                        obj_tmp = fill_tags2string(args_step, obj_tmpl_ref, tmpl_value)
                        args_list_def.append(obj_tmp)

                    args_str_def = convert_list_2_string(args_list_def, ' ')

                    obj_args_def[tmpl_key][self.tag_arguments] = args_str_def

        for obj_args_key, obj_args_dict in obj_args_def.items():
            for obj_dict_key, obj_dict_value in obj_args_dict.items():
                obj_run_filled[obj_args_key][obj_dict_key] = obj_dict_value

        return obj_run_filled, obj_args_def
예제 #2
0
    def __init__(self,
                 obj_algorithm,
                 obj_datasets,
                 key_namelist='namelist',
                 filename_namelist=None,
                 structure_namelist=None,
                 **kwargs):

        self.obj_algorithm = obj_algorithm
        self.obj_datasets = obj_datasets

        if filename_namelist is None:
            filename_namelist = get_dict_value(obj_algorithm, key_namelist,
                                               [])[0]

        if structure_namelist is None:
            structure_namelist = structure_namelist_default

        self.filename_namelist_raw = filename_namelist
        self.structure_namelist_raw = structure_namelist
        self.link_namelist_raw = link_namelist_default

        self.line_indent = 4 * ' '

        self.lut_dt = {
            'iDtData_Forcing': 'DataForcing',
            'iDtData_Updating': 'DataUpdating',
            'iDtData_Output_Gridded': 'DataOutcome',
            'iDtData_Output_Point': 'DataOutcome',
            'iDtData_State_Gridded': 'DataState',
            'iDtData_State_Point': 'DataState'
        }

        self.defined_dt = self.search_dt(self.lut_dt)
예제 #3
0
 def set_tag_value(obj_data, tag_data):
     items_raw = get_dict_value(obj_data, tag_data, [])
     if items_raw.__len__() == 0:
         items_raw = [None]
     items_unique = list(set(items_raw))
     if items_unique.__len__() != 1:
         log_stream.warning(
             ' ===> Tag definition is greater then one item. Could be error in cleaning tmp datasets'
         )
     return items_unique[0]
예제 #4
0
    def search_dt(self, lut_dt, key_dt='hmc_file_frequency'):

        obj_datasets = self.obj_datasets

        obj_dt = {}
        for lut_key, lut_value in lut_dt.items():

            if lut_value in list(obj_datasets.keys()):
                obj_structure = obj_datasets[lut_value]

                if isinstance(obj_structure, dict):
                    collections_dt = []
                    for dataset_key, fields_structure in obj_structure.items():
                        if isinstance(fields_structure, dict):
                            list_dt = get_dict_value(fields_structure, key_dt,
                                                     [])
                            if list_dt.__len__() > 0:
                                digits_dt, alpha_dt = parse_timefrequency_to_timeparts(
                                    list_dt)
                                num_dt = convert_freqstr_to_freqsecs(
                                    digits_dt, alpha_dt)
                                collections_dt.append(num_dt)

                    if collections_dt.__len__() > 0:

                        collections_dt = list(set(collections_dt))
                        if collections_dt.__len__() > 1:
                            value_dt = min(collections_dt)
                            log_stream.warning(
                                ' ===> Datasets dd for "' + lut_value +
                                '" is not defined by unique value. To avoid exceptions '
                                'procedure \n will detect the declared minimum dt "'
                                + str(value_dt) +
                                '" [seconds] and will set it in the model configuration file\n'
                            )

                        elif collections_dt.__len__() == 1:
                            value_dt = collections_dt[0]
                        else:
                            log_stream.error(
                                ' ===> Datasets dt is not defined')
                            raise NotImplementedError(
                                'Case not implemented yet')
                    else:
                        log_stream.error(
                            ' ===> Datasets dt is not correctly defined')
                        raise NotImplementedError('Case not implemented yet')

                    obj_dt[lut_key] = value_dt

        return obj_dt
예제 #5
0
    def __init__(self, file_algorithm, file_datasets, time,
                 tag_general_info='General_Info', tag_run_info='Run_Info', tag_time_info='Time_Info',
                 tag_hmc_info='HMC_Info', tag_geosystem_info='GeoSystem_Info', tag_template='Template',
                 **kwargs):

        # Get argument(s)
        self.file_algorithm = file_algorithm
        self.file_datasets = file_datasets
        self.time = time

        self.tag_general_info = tag_general_info
        self.tag_run_info = tag_run_info
        self.tag_time_info = tag_time_info
        self.tag_hmc_info = tag_hmc_info
        self.tag_geosystem_info = tag_geosystem_info
        self.tag_template = tag_template

        self.tag_template_run = 'run'
        self.tag_template_time = 'time'
        self.tag_template_dset_static = 'dset_static'
        self.tag_template_dset_dynamic_forcing = 'dset_dynamic_forcing'
        self.tag_template_dset_dynamic_outcome = 'dset_dynamic_outcome'
        self.tag_template_dset_dynamic_obs = 'dset_dynamic_obs'

        self.obj_keys_excluded = ['__comment', '_comment', '__comment__']

        # Get algorithm info
        self.obj_algorithm = self.get_file_algorithm(self.file_algorithm)
        # Get datasets info
        tmp_datasets = self.get_file_datasets(self.file_datasets)
        self.obj_datasets = delete_dict_keys(tmp_datasets, self.obj_keys_excluded)

        # Get time info
        self.obj_time_arg = get_time(self.time)

        obj_template_ref = None
        for obj_key, obj_value in self.obj_algorithm.items():
            if obj_key == self.tag_template:
                obj_template_ref = obj_value
                break
        self.obj_algorithm.pop(self.tag_template, None)

        self.obj_template_run_ref = obj_template_ref[self.tag_template_run]
        self.obj_template_time_ref = obj_template_ref[self.tag_template_time]
        self.obj_template_dset_static_ref = obj_template_ref[self.tag_template_dset_static]
        self.obj_template_dset_dynamic_ref = obj_template_ref[self.tag_template_dset_dynamic_forcing]
        self.obj_template_dset_outcome_ref = obj_template_ref[self.tag_template_dset_dynamic_outcome]
        self.obj_template_dset_obs_ref = obj_template_ref[self.tag_template_dset_dynamic_obs]

        obj_template_run_raw = {}
        for obj_key, obj_value in self.obj_template_run_ref.items():
            obj_tmp = get_dict_value(self.obj_algorithm, obj_key, [])
            if obj_tmp.__len__() > 0:
                obj_found = obj_tmp[0]
                obj_template_run_raw[obj_key] = obj_found
            else:
                log_stream.warning(' ===> Template key ' + obj_key + ' is not found in algorithm file settings!')
        self.obj_template_run_raw = obj_template_run_raw

        if tag_general_info in self.obj_algorithm:
            obj_general_info = self.obj_algorithm[tag_general_info]
        else:
            log_stream.error(' ===> General Info is not callable! Check your algorithm file!')
            raise ValueError('Value not valid')
        if tag_run_info in self.obj_algorithm:
            obj_run_info = self.obj_algorithm[tag_run_info]
        else:
            log_stream.error(' ===> Run Info is not callable! Check your algorithm file!')
            raise ValueError('Value not valid')
        if tag_time_info in self.obj_algorithm:
            obj_time_info = self.obj_algorithm[tag_time_info]
        else:
            log_stream.error(' ===> Time Info is not callable! Check your algorithm file!')
            raise ValueError('Value not valid')
        if tag_hmc_info in self.obj_algorithm:
            obj_hmc_info = self.obj_algorithm[tag_hmc_info]
        else:
            log_stream.error(' ===> HMC Info is not callable! Check your algorithm file!')
            raise ValueError('Value not valid')
        if tag_geosystem_info in self.obj_algorithm:
            obj_geosystem_info = self.obj_algorithm[tag_geosystem_info]
        else:
            log_stream.error(' ===> GeoSystem Info is not callable! Check your algorithm file!')
            raise ValueError('Value not valid')

        self.obj_general_info_ref = obj_general_info
        self.obj_run_info_ref = obj_run_info
        self.obj_time_info_ref = obj_time_info
        self.obj_hmc_info_ref = obj_hmc_info
        self.obj_geosystem_info_ref = obj_geosystem_info