Beispiel #1
0
    def setUp(self, verbose=0):
        util_mdtf.check_required_dirs(
            already_exist =[], 
            create_if_nec = [self.MODEL_WK_DIR, self.MODEL_DATA_DIR], 
            verbose=verbose)
        self.envvars.update({
            "DATADIR": self.MODEL_DATA_DIR,
            "variab_dir": self.MODEL_WK_DIR,
            "CASENAME": self.case_name,
            "model": self.model_name,
            "FIRSTYR": self.firstyr.format(precision=1), 
            "LASTYR": self.lastyr.format(precision=1)
        })
        # set env vars for unit conversion factors (TODO: honest unit conversion)
        translate = util_mdtf.VariableTranslator()
        if self.convention not in translate.units:
            raise AssertionError(("Variable name translation doesn't recognize "
                "{}.").format(self.convention))
        temp = translate.variables[self.convention].to_dict()
        for key, val in temp.iteritems():
            util_mdtf.setenv(key, val, self.envvars, verbose=verbose)
        temp = translate.units[self.convention].to_dict()
        for key, val in temp.iteritems():
            util_mdtf.setenv(key, val, self.envvars, verbose=verbose)

        for pod in self.iter_pods():
            self._setup_pod(pod)
        self._build_data_dicts()
Beispiel #2
0
    def _setup_pod(self, pod):
        config = util_mdtf.ConfigManager()
        translate = util_mdtf.VariableTranslator()

        # transfer DataManager-specific settings
        pod.__dict__.update(config.paths.pod_paths(pod, self))
        pod.TEMP_HTML = self.TEMP_HTML
        pod.pod_env_vars.update(self.envvars)
        pod.dry_run = self.dry_run

        # express varlist as DataSet objects
        ds_list = []
        for var in pod.varlist:
            ds_list.append(DataSet.from_pod_varlist(
                pod.convention, var, {'DateFreqMixin': self.DateFreq}))
        pod.varlist = ds_list

        for var in pod.iter_vars_and_alts():
            var.name_in_model = translate.fromCF(self.convention, var.CF_name)
            var.date_range = self.date_range
            var._local_data = self.local_path(self.dataset_key(var))
            var.axes = copy.deepcopy(translate.axes[self.convention])

        if self.data_freq is not None:
            for var in pod.iter_vars_and_alts():
                if var.date_freq != self.data_freq:
                    pod.skipped = PodRequirementFailure(
                        pod,
                        ("{0} requests {1} (= {2}) at {3} frequency, which isn't "
                        "compatible with case {4} providing data at {5} frequency "
                        "only.").format(
                            pod.name, var.name_in_model, var.name, 
                            var.date_freq, self.case_name, self.data_freq
                    ))
                    break
Beispiel #3
0
 def from_pod_varlist(cls, pod_convention, var, dm_args):
     translate = util_mdtf.VariableTranslator()
     var_copy = var.copy()
     var_copy.update(dm_args)
     ds = cls(**var_copy)
     ds.original_name = ds.name
     ds.CF_name = translate.toCF(pod_convention, ds.name)
     alt_ds_list = []
     for alt_var in ds.alternates:
         alt_ds = ds.copy(new_name=alt_var)
         alt_ds.original_name = ds.original_name
         alt_ds.CF_name = translate.toCF(pod_convention, alt_ds.name)
         alt_ds.alternates = []
         alt_ds_list.append(alt_ds)
     ds.alternates = alt_ds_list
     return ds
Beispiel #4
0
 def _post_parse_hook(self, cli_obj, config):
     # init other services
     _ = util_mdtf.TempDirManager()
     _ = util_mdtf.VariableTranslator()
     self.verify_paths(config)