def setup_out_file(self): ''' Setup for the out_file, which outputs both the .json and .txt. ''' self.out_file.set_target_grid( self.parameter.target_grid, self.regrid_tool, self.regrid_method) self.out_file.variable = self.var self.out_file.realm = self.realm self.out_file.table = self.table_realm self.out_file.case_id = self.parameter.case_id DataSet.apply_custom_keys(self.out_file, self.parameter.custom_keys, self.var)
def setup_out_file(self): ''' Setup for the out_file, which outputs both the .json and .txt. ''' self.out_file.set_target_grid(self.parameter.target_grid, self.regrid_tool, self.regrid_method) self.out_file.variable = self.var self.out_file.realm = self.realm self.out_file.table = self.table_realm self.out_file.case_id = self.parameter.case_id DataSet.apply_custom_keys(self.out_file, self.parameter.custom_keys, self.var)
def setup_out_file(self): ''' Setup for the out_file, which outputs both the .json and .txt. ''' self.out_file.set_target_grid( self.parameter.target_grid, self.regrid_tool, self.regrid_method) self.out_file.variable = self.var self.out_file.realm = self.realm self.out_file.table = self.table_realm self.out_file.case_id = self.parameter.case_id if hasattr(self, "obs_or_model"): self.out_file.model_version = self.obs_or_model for key in self.out_file.keys(): if hasattr(self.parameter, key): setattr(self.out_file, key, getattr(self.parameter, key)) if hasattr(self, key): setattr(self.out_file, key, getattr(self, key)) DataSet.apply_custom_keys(self.out_file, self.parameter.custom_keys, self.var)
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 setup_regrid_and_realm_vars(self): ''' Set the regrid_method, regrid_tool, table_realm, and realm based off the obs dict and var. ''' if DataSet.use_omon(self.obs_dict, self.var): self.regrid_method = self.parameter.regrid_method_ocn self.regrid_tool = self.parameter.regrid_tool_ocn self.table_realm = 'Omon' self.realm = "ocn" else: self.regrid_method = self.parameter.regrid_method self.regrid_tool = self.parameter.regrid_tool self.table_realm = 'Amon' self.realm = "atm"
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.getLogger("pcmdi_metrics").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 setup_metrics_dictionary(self): ''' Initalize the results dict (metrics_dictionary) and the metrics documentation dict (metrics_def_dictionary) which is put in the results dict. ''' self.metrics_def_dictionary = collections.OrderedDict() self.metrics_dictionary = collections.OrderedDict() self.metrics_dictionary["DISCLAIMER"] = self.open_disclaimer() self.metrics_dictionary["RESULTS"] = collections.OrderedDict() self.metrics_dictionary["Variable"] = {} self.metrics_dictionary["Variable"]["id"] = self.var self.metrics_dictionary["json_version"] = '3.0' self.metrics_dictionary["References"] = {} self.metrics_dictionary["RegionalMasking"] = {} level = DataSet.calculate_level_from_var(self.var_name_long) if level is None: self.out_file.level = '' else: self.metrics_dictionary["Variable"]["level"] = level self.out_file.level = "-%i" % (int(level / 100.0))
def setup_metrics_dictionary(self): ''' Initalize the results dict (metrics_dictionary) and the metrics documentation dict (metrics_def_dictionary) which is put in the results dict. ''' self.metrics_def_dictionary = collections.OrderedDict() self.metrics_dictionary = collections.OrderedDict() self.metrics_dictionary["DISCLAIMER"] = self.open_disclaimer() if self.parameter.user_notes is not None: self.metrics_dictionary["USER_NOTES"] = self.parameter.user_notes self.metrics_dictionary["RESULTS"] = collections.OrderedDict() self.metrics_dictionary["Variable"] = {} self.metrics_dictionary["Variable"]["id"] = self.var self.metrics_dictionary["json_version"] = '3.0' self.metrics_dictionary["References"] = {} self.metrics_dictionary["RegionalMasking"] = {} level = DataSet.calculate_level_from_var(self.var_name_long) if level is None: self.out_file.level = '' else: self.metrics_dictionary["Variable"]["level"] = level self.out_file.level = "-%i" % (int(level / 100.0))
def open_disclaimer(self): ''' Return the contents of disclaimer.txt. ''' f = DataSet.load_path_as_file_obj('disclaimer.txt') contents = f.read() f.close() return contents
def open_disclaimer(self): """Return the contents of disclaimer.txt.""" f = DataSet.load_path_as_file_obj("disclaimer.txt") contents = f.read() f.close() return contents