def create_model_file(self): """Creates an object that will eventually output the netCDF file.""" self._model_file = Base(self.data_path, self.parameter.filename_template) self._model_file.variable = self.var self._model_file.model_version = self.obs_or_model self._model_file.period = self.parameter.period self._model_file.ext = "nc" self._model_file.case_id = self.parameter.case_id self._model_file.realization = self.parameter.realization self.apply_custom_keys(self._model_file, self.parameter.custom_keys, self.var)
def __init__(self, parameter, var_name_long, obs_dict, sftlf): logging.getLogger("pcmdi_metrics").setLevel(LOG_LEVEL) self.parameter = parameter self.var_name_long = var_name_long self.obs_dict = obs_dict self.var = var_name_long.split('_')[0] self.sftlf = sftlf self.metrics_def_dictionary = {} self.metrics_dictionary = {} self.out_file = Base(self.parameter.metrics_output_path, self.parameter.output_json_template) self.regrid_method = '' self.regrid_tool = '' self.table_realm = '' self.realm = '' self.setup_regrid_and_realm_vars() self.setup_out_file() self.setup_metrics_dictionary()
def output_interpolated_model_climatologies(self, test, test_data): ''' Save the netCDF file. ''' region_name = self.get_region_name_from_region(test.region) pth = os.path.join(self.parameter.test_clims_interpolated_output, region_name) clim_file = Base(pth, self.parameter.filename_output_template) logging.info('Saving interpolated climatologies to: %s' % clim_file()) clim_file.level = self.out_file.level clim_file.model_version = test.obs_or_model clim_file.table = self.table_realm clim_file.period = self.parameter.period clim_file.case_id = self.parameter.case_id clim_file.set_target_grid(self.parameter.target_grid, self.regrid_tool, self.regrid_method) clim_file.variable = self.var clim_file.region = region_name clim_file.realization = self.parameter.realization DataSet.apply_custom_keys(clim_file, self.parameter.custom_keys, self.var) clim_file.write(test_data, type="nc", id=self.var)
def __init__(self, parameter, var_name_long, obs_dict, sftlf): logging.basicConfig(level=logging.DEBUG) self.parameter = parameter self.var_name_long = var_name_long self.obs_dict = obs_dict self.var = var_name_long.split('_')[0] self.sftlf = sftlf self.metrics_def_dictionary = {} self.metrics_dictionary = {} string_template = "%(variable)%(level)_%(target_grid_name)_" +\ "%(regrid_tool)_%(regrid_method)_metrics" self.out_file = Base(self.parameter.metrics_output_path, string_template) self.regrid_method = '' self.regrid_tool = '' self.table_realm = '' self.realm = '' self.setup_regrid_and_realm_vars() self.setup_out_file() self.setup_metrics_dictionary()
def create_sftlf(parameter): """Create the sftlf file from the parameter.""" sftlf = {} for test in parameter.test_data_set: tmp_name = getattr(parameter, "sftlf_filename_template") if tmp_name is None: # Not defined from commandline or param file tmp_name = parameter.filename_template sft = Base(parameter.test_data_path, tmp_name) sft.model_version = test sft.table = "fx" sft.realm = "atmos" sft.period = getattr(parameter, "period", "") sft.ext = "nc" sft.case_id = getattr(parameter, "case_id", "") sft.target_grid = None sft.realization = "r0i0p0" DataSet.apply_custom_keys(sft, parameter.custom_keys, "sftlf") try: sftlf[test] = {"raw": sft.get("sftlf")} sftlf[test]["filename"] = os.path.basename(sft()) sftlf[test]["md5"] = sft.hash() except Exception: sftlf[test] = {"raw": None} sftlf[test]["filename"] = None sftlf[test]["md5"] = None if parameter.target_grid == "2.5x2.5": t_grid = cdms2.createUniformGrid(-88.875, 72, 2.5, 0, 144, 2.5) else: t_grid = parameter.target_grid sft = cdutil.generateLandSeaMask(t_grid) sft[:] = sft.filled(1.0) * 100.0 sftlf["target_grid"] = sft return sftlf