def find_xml_cmip(model, project, experiment, ensemble, frequency, realm, variable): file_name = join_path( xmldir, str(model) + '_' + str(project) + '_' + str(experiment) + '_' + str(ensemble) + '_glob_' + str(frequency) + '_' + str(realm) + '.xml') xml = CDMS2open(file_name) listvar1 = sorted(xml.listvariables()) if variable not in listvar1: if realm == 'O': new_realm = 'A' elif realm == 'A': new_realm = 'O' # if var is not in realm 'O' (for ocean), look for it in realm 'A' (for atmosphere) file_name = join_path( xmldir, str(model) + '_' + str(project) + '_' + str(experiment) + '_' + str(ensemble) + '_glob_' + str(frequency) + '_' + str(new_realm) + '.xml') xml = CDMS2open(file_name) listvar2 = sorted(xml.listvariables()) if variable not in listvar2: print '\033[95m' + str().ljust(5) + "CMIP var " + str(variable) +\ " cannot be found (realm A and O)" + '\033[0m' print '\033[95m' + str().ljust(10) + "file_name = " + str( file_name) + '\033[0m' print '\033[95m' + str().ljust(10) + "variables = " + str( listvar1) + '\033[0m' print '\033[95m' + str().ljust(10) + "AND" + '\033[0m' print '\033[95m' + str().ljust(10) + "variables = " + str( listvar2) + '\033[0m' exit(1) return file_name
def find_xml_fx(name, project='', experiment='', realm=''): list_obs = ReferenceObservations().keys() if name in list_obs: file_area = join_path(xmldir, 'obs_' + str(name) + '_glob_fx_O_areacell.xml') file_land = join_path(xmldir, 'obs_' + str(name) + '_glob_fx_O_landmask.xml') else: file_area = join_path( xmldir, str(name) + '_' + str(project) + '_' + str(experiment) + '_r0i0p0_glob_fx_' + str(realm) + '_areacell.xml') file_land = join_path( xmldir, str(name) + '_' + str(project) + '_' + str(experiment) + '_r0i0p0_glob_fx_' + str(realm) + '_landmask.xml') try: xml = CDMS2open(file_area) except: file_area = None try: xml = CDMS2open(file_land) except: file_land = None return file_area, file_land
def find_xml_obs(dataset, variable): """ Finds observational variable file, as well as corresponding areacell and landmask Inputs: ------ :param dataset: string model name (e.g., "CNRM-CM5", "IPSL-CM5A-LR") :param variable: string variable name (e.g., "pr", "tos") Outputs: ------- :return file_name: string Path and file name corresponding to the given information (e.g., /path/to/file/filename.xml) :return file_area: string Path and areacell file name corresponding to the given information (e.g., /path/to/file/areacell.xml) Set to None if the file cannot be found :return file_land: string Path and landmask file name corresponding to the given information (e.g., /path/to/file/landmask.xml) Set to None if the file cannot be found """ file_name = OSpath__join(xmldir, "obs_ENSO_metrics_" + str(dataset) + ".xml") xml = CDMS2open(file_name) listvar1 = sorted(xml.listvariables()) if variable not in listvar1: print(bcolors.FAIL + "%%%%% ----- %%%%%") print(str().ljust(5) + "obs var " + str(variable) + " cannot be found") print(str().ljust(10) + "file_name = " + str(file_name)) print(str().ljust(10) + "variables = " + str(listvar1)) print("%%%%% ----- %%%%%" + bcolors.ENDC) SYSexit("") file_area, file_land = find_fx(dataset) return file_name, file_area, file_land
def find_fx(model, project='', experiment='', ensemble='', realm=''): if project in ['CMIP5', 'CMIP6']: if project in ['CMIP5']: my_ens = 'r0i0p0' else: my_ens = deepcopy(ensemble) if realm == 'A': farea1, farea2 = find_path_and_files(ens=my_ens, exp=experiment, fre='fx', mod=model, pro=project, rea=realm, var='areacella') fland1, fland2 = find_path_and_files(ens=my_ens, exp=experiment, fre='fx', mod=model, pro=project, rea=realm, var='sftlf') file_land = OSpath__join(fland1, fland2[0]) elif realm == 'O': farea1, farea2 = find_path_and_files(ens=my_ens, exp=experiment, fre='fx', mod=model, pro=project, rea=realm, var='areacello') file_land = None file_area = OSpath__join(farea1, farea2[0]) else: file_area, file_land = find_xml_fx(model, project=project, experiment=experiment, realm=realm) try: CDMS2open(file_area) except: file_area = None try: CDMS2open(file_land) except: file_land = None return file_area, file_land
def find_xml_obs(obs,frequency, variable): file_name = join_path(xmldir, 'obs_' + str(obs) + '_glob_' + str(frequency) + '_O.xml') xml = CDMS2open(file_name) listvar1 = sorted(xml.listvariables()) if variable not in listvar1: print '\033[95m' + str().ljust(5) + "obs var " + str(variable) + " cannot be found" + '\033[0m' print '\033[95m' + str().ljust(10) + "file_name = " + str(file_name) + '\033[0m' print '\033[95m' + str().ljust(10) + "variables = " + str(listvar1) + '\033[0m' exit(1) return file_name
def find_xml_cmip(model, project, experiment, ensemble, frequency, variable): file_name = join_path(xmldir, str(model) + '_' + str(project) + '_' + str(experiment) + '_' + str(ensemble) + '_eq_pac_' + str(frequency) + '_regular_1x1_grid.xml') xml = CDMS2open(file_name) listvar1 = sorted(xml.listvariables()) if variable not in listvar1: print '\033[95m' + str().ljust(5) + "CMIP var " + str(variable) + " cannot be found " + '\033[0m' print '\033[95m' + str().ljust(10) + "file_name = " + str(file_name) + '\033[0m' print '\033[95m' + str().ljust(10) + "variables = " + str(listvar1) + '\033[0m' exit(1) return file_name
def find_xml_obs(obs, frequency, variable): if obs == 'HadISST': file_name = OSpath__join(xmldir, 'obs_' + str(obs) + 'v1.1.xml') else: file_name = OSpath__join(xmldir, 'obs_' + str(obs) + '.xml') xml = CDMS2open(file_name) listvar1 = sorted(xml.listvariables()) if variable not in listvar1: print '\033[95m' + str().ljust(5) + "obs var " + str( variable) + " cannot be found" + '\033[0m' print '\033[95m' + str().ljust(10) + "file_name = " + str( file_name) + '\033[0m' print '\033[95m' + str().ljust(10) + "variables = " + str( listvar1) + '\033[0m' sys.exit('') file_area, file_land = find_fx(obs) return file_name, file_area, file_land
def find_fx(model, experiment='', project='', realm='', ensemble=''): """ Finds fixed variables, here areacell and sftlf (landmask) Inputs: ------ :param model: string model name (e.g., "CNRM-CM5", "IPSL-CM5A-LR") **Optional arguments:** :param experiment: string, optional experiment name (e.g., "historical", "piControl") :param project: string, optional project name (e.g., "CMIP5", "CMIP6") :param realm: string, optional data realm: "A" for atmosphere, "O" for ocean :param ensemble: string, optional ensemble name (e.g., "r1i1p1", "r1i1p1f1") Outputs: ------- :return file_area: string Path and areacell file name corresponding to the given information (e.g., /path/to/file/areacell.xml) Set to None if the file cannot be found :return file_land: string Path and landmask file name corresponding to the given information (e.g., /path/to/file/landmask.xml) Set to None if the file cannot be found """ if project in ["CMIP5", "CMIP6"]: if project in ['CMIP5']: my_ens = "r0i0p0" else: my_ens = deepcopy(ensemble) if realm == "A": farea1, farea2 = find_path_and_files(ens=my_ens, exp=experiment, fre="fx", mod=model, pro=project, rea=realm, var="areacella") fland1, fland2 = find_path_and_files(ens=my_ens, exp=experiment, fre="fx", mod=model, pro=project, rea=realm, var="sftlf") file_land = OSpath__join(fland1, fland2[0]) else: farea1, farea2 = find_path_and_files(ens=my_ens, exp=experiment, fre="fx", mod=model, pro=project, rea=realm, var="areacello") file_land = None file_area = OSpath__join(farea1, farea2[0]) else: file_area, file_land = find_xml_fx(model, project=project, experiment=experiment, realm=realm) try: CDMS2open(file_area) except: file_area = None try: CDMS2open(file_land) except: file_land = None return file_area, file_land
for var in list_variables: # # finding variable name in file # var_in_file = dict_var[var]['var_name'] if isinstance(var_in_file, list): var0 = var_in_file[0] else: var0 = var_in_file # # finding file for 'mod', 'var' # # @jiwoo: first try in the realm 'O' (for ocean) file_name = find_xml_cmip(mod, project, experiment, ensemble, frequency, realm, var0) file = CDMS2open(file_name) if isinstance(var_in_file, list): list_files = list() for var1 in var_in_file: list_files.append(file_name) else: list_files = file_name # ------------------------------------------------ dict_mod[mod][var] = { 'path + filename': list_files, 'varname': var_in_file } # dictionary needed by nsoMetrics.ComputeMetricsLib.ComputeCollection # @jiwoo the ComputeCollection function it still on development and it does not read the observations requirement # defined in the metric collection, i.e., defCollection(mc_name)['metrics_list']['<metric name>']['obs_name'] # so the function does not take a specific obs to compute the metric so for every obs in 'dict_obs' we must include