def climate(currProject, currDiag, project_info, model, field, base_variable, variable_attributes): """ @brief Wrapper to call ncl script that calculates climatology @param currProject An instance of the current project @param project_info Dictionary with all info from the namelist @param currDiag Current diagnostic """ infilename = currProject.get_cf_fullpath(project_info, model, field, base_variable, variable_attributes) cfield_m, cfield_s, cfield_a = currDiag.get_climate_field_type(field) file_monthly_clim = currProject.get_cf_fullpath(project_info, model, cfield_m, base_variable, variable_attributes) file_season_clim = currProject.get_cf_fullpath(project_info, model, cfield_s, base_variable, variable_attributes) file_annual_clim = currProject.get_cf_fullpath(project_info, model, cfield_a, base_variable, variable_attributes) if ((not os.path.isfile(file_monthly_clim) or not os.path.isfile(file_season_clim) or not os.path.isfile(file_annual_clim)) or project_info['GLOBAL']['force_processing']): verbosity = project_info['GLOBAL']['verbosity'] project_info['TEMPORARY'] = {} project_info['TEMPORARY']['infilename'] = infilename project_info['TEMPORARY']['mfile'] = file_monthly_clim project_info['TEMPORARY']['sfile'] = file_season_clim project_info['TEMPORARY']['afile'] = file_annual_clim project_info['TEMPORARY']['base_variable'] = base_variable info(" Calling climate.py", verbosity, required_verbosity=1) info(" INFILE = " + infilename, 1, verbosity) info(" OUTFILES = " + file_monthly_clim, 1, verbosity) info(" " + file_season_clim, 1, verbosity) info(" " + file_annual_clim, 1, verbosity) exit_on_warning = project_info['GLOBAL']['exit_on_warning'] executable = "./interface_scripts/climate.ncl" projects.run_executable(executable, project_info, verbosity, exit_on_warning) del (project_info['TEMPORARY'])
def write_references(self, ref_script, ref_auth, ref_contr, ref_diag, ref_obs, ref_proj, project_info, verbosity, exit_on_warning): self.project_info['TEMPORARY'] = {} self.project_info['TEMPORARY']['ref_auth'] = ref_auth self.project_info['TEMPORARY']['ref_contr'] = ref_contr self.project_info['TEMPORARY']['ref_obs'] = ref_obs self.project_info['TEMPORARY']['ref_proj'] = ref_proj self.project_info['TEMPORARY']['ref_diag'] = ref_proj self.project_info['TEMPORARY']['ref_script'] = ref_script projects.run_executable("interface_scripts/write_references.ncl", project_info, verbosity, exit_on_warning)
parser.setContentHandler(Project) parser.parse(input_xml_full_path) # Project_info is a dictionary with all info from the namelist. project_info = Project.project_info if options.reformat: if 'REFORMAT' not in project_info.keys(): error('No REFORMAT tag specified in {0}'.format(input_xml_full_path)) if len(project_info['REFORMAT']) == 0: info('No reformat script specified', 1, 1) print_header({}, options.reformat) for k, v in project_info['REFORMAT'].iteritems(): if not os.path.exists(v): error('Path {0} does not exist'.format(v)) projects.run_executable(v, project_info, 1, False, write_di=False) sys.exit(0) verbosity = project_info['GLOBAL']['verbosity'] climo_dir = project_info['GLOBAL']['climo_dir'] exit_on_warning = project_info['GLOBAL'].get('exit_on_warning', False) # Additional entries to 'project_info'. The 'project_info' construct # is one way by which Python passes on information to the NCL-routines. project_info['RUNTIME'] = {} # Input xml path/file project_info['RUNTIME']['xml'] = input_xml_full_path input_xml_file = os.path.basename(input_xml_full_path) project_info['RUNTIME']['xml_name'] = input_xml_file
def cmor_reformat(currProject, project_info, variable, model): model_name = currProject.get_model_name(model) project_name = currProject.get_project_name(model) project_basename = currProject.get_project_basename() project_info['RUNTIME']['model'] = model_name project_info['RUNTIME']['project'] = project_name project_info['RUNTIME']['project_basename'] = project_basename verbosity = project_info["GLOBAL"]["verbosity"] exit_on_warning = project_info['GLOBAL'].get('exit_on_warning', False) # Variable put in environment to be used for the (optional) # wildcard syntax in the model path, ".../${VARIABLE}/..." # in the namelist os.environ['__ESMValTool_base_var'] = variable.var # Build input and output file names indir, infile = currProject.get_cf_infile(project_info, model, variable.fld, variable.var, variable.mip, variable.exp) fullpath = currProject.get_cf_fullpath(project_info, model, variable.fld, variable.var, variable.mip, variable.exp) # print "indir = %s" % indir # print "infile = %s" % infile # print "fullpath = %s" % fullpath if (not os.path.isdir(os.path.dirname(fullpath))): os.makedirs(os.path.dirname(fullpath)) # Area file name for ocean grids areafile_path = currProject.get_cf_areafile(project_info, model) # Land-mask file name for land variables lmaskfile_path = currProject.get_cf_lmaskfile(project_info, model) omaskfile_path = currProject.get_cf_omaskfile(project_info, model) # Porosity file name for land variables porofile_path = currProject.get_cf_porofile(project_info, model) # Additional grid file names for ocean grids, if available (ECEARTH) hgridfile_path = False zgridfile_path = False lsmfile_path = False if hasattr(currProject, "get_cf_hgridfile"): hgridfile_path = currProject.get_cf_hgridfile(project_info, model) if hasattr(currProject, "get_cf_zgridfile"): zgridfile_path = currProject.get_cf_zgridfile(project_info, model) if hasattr(currProject, "get_cf_lsmfile"): lsmfile_path = \ currProject.get_cf_lsmfile(project_info, model, variable.fld) # General fx file name entry fx_file_path = False if hasattr(currProject, "get_cf_fx_file"): fx_file_path = currProject.get_cf_fx_file(project_info, model) project, name, ensemble, start_year, end_year, dir\ = currProject.get_cf_sections(model) info("project is " + project, verbosity, required_verbosity=4) info("ensemble is " + ensemble, verbosity, required_verbosity=4) info("dir is " + dir, verbosity, required_verbosity=4) # Check if the current project has a specific reformat routine, # otherwise use default if (os.path.isdir("reformat_scripts/" + project)): which_reformat = project else: which_reformat = 'default' reformat_script = os.path.join("reformat_scripts", which_reformat, "reformat_" + which_reformat + "_main.ncl") # Set enviroment variables project_info['TEMPORARY'] = {} project_info['TEMPORARY']['indir_path'] = indir project_info['TEMPORARY']['outfile_fullpath'] = fullpath project_info['TEMPORARY']['infile_path'] = os.path.join(indir, infile) project_info['TEMPORARY']['areafile_path'] = areafile_path project_info['TEMPORARY']['lmaskfile_path'] = lmaskfile_path project_info['TEMPORARY']['omaskfile_path'] = omaskfile_path project_info['TEMPORARY']['porofile_path'] = porofile_path project_info['TEMPORARY']['start_year'] = start_year project_info['TEMPORARY']['end_year'] = end_year project_info['TEMPORARY']['ensemble'] = ensemble project_info['TEMPORARY']['variable'] = variable.var project_info['TEMPORARY']['field'] = variable.fld # FX file path if fx_file_path: project_info['TEMPORARY']['fx_file_path'] = fx_file_path # Special cases if 'realm' in currProject.get_model_sections(model): project_info['TEMPORARY']['realm'] = \ currProject.get_model_sections(model)["realm"] if 'shift_year' in currProject.get_model_sections(model): project_info['TEMPORARY']['shift_year'] = \ currProject.get_model_sections(model)["shift_year"] if 'case_name' in currProject.get_model_sections(model): project_info['TEMPORARY']['case_name'] = \ currProject.get_model_sections(model)["case_name"] if hgridfile_path and zgridfile_path: project_info['TEMPORARY']['hgridfile_path'] = hgridfile_path project_info['TEMPORARY']['zgridfile_path'] = zgridfile_path if lsmfile_path: project_info['TEMPORARY']['lsmfile_path'] = lsmfile_path # Execute the ncl reformat script if ((not os.path.isfile(project_info['TEMPORARY']['outfile_fullpath'])) or project_info['GLOBAL']['force_processing']): info(" Calling " + reformat_script + " to check/reformat model data", verbosity, required_verbosity=1) projects.run_executable(reformat_script, project_info, verbosity, exit_on_warning) if 'NO_REFORMAT' in reformat_script: pass else: if (not os.path.isfile(project_info['TEMPORARY']['outfile_fullpath'])): raise exceptions.IOError( 2, "Expected reformatted file isn't available: ", project_info['TEMPORARY']['outfile_fullpath']) del (project_info['TEMPORARY'])