def main_plotter(metric_collection, metric, model, experiment, filename_nc, diagnostic_values, diagnostic_units, metric_values, metric_units, path_png=''): dict_param = plot_param(metric_collection, metric) list_var = dict_param['metric_variables'] met_type = dict_param['metric_computation'] reference = dict_param['metric_reference'] dict_reg = dict_param['metric_regions'] if isinstance(model, basestring): pattern = metric_collection + "_" + metric + "_" + experiment + "_" + model else: pattern = metric_collection + "_" + metric + "_" + experiment + "_" + str( len(model)) + "models" # diagnostic dict_diag = dict_param['diagnostic'] fig_name = OSpath__join(path_png, pattern + "_diagnostic") print str().ljust(20) + dict_diag['plot_type'] dict_plot[dict_diag['plot_type']](model, filename_nc, dict_diag, reference, list_var, fig_name, metric_type=met_type, metric_values=metric_values, metric_units=metric_units, diagnostic_values=diagnostic_values, diagnostic_units=diagnostic_units, regions=dict_reg) # dive downs list_dd = sorted([key for key in dict_param.keys() if "dive_down" in key], key=lambda v: v.upper()) for ii, dd in enumerate(list_dd): dict_diag = dict_param[dd] fig_name = OSpath__join(path_png, pattern + "_divedown" + str(ii + 1).zfill(2)) print str().ljust(20) + dict_diag['plot_type'] dict_plot[dict_diag['plot_type']](model, filename_nc, dict_diag, reference, list_var, fig_name, metric_type=None, metric_values=metric_values, metric_units=metric_units, diagnostic_values=diagnostic_values, diagnostic_units=diagnostic_units, regions=dict_reg)
def find_xml_fx(name, project='', experiment='', realm=''): list_obs = ReferenceObservations().keys() if name in list_obs: file_area = OSpath__join(xmldir, 'obs_' + str(name) + '_areacell.xml') file_land = OSpath__join(xmldir, 'obs_' + str(name) + '_landmask.xml') else: file_area = OSpath__join( xmldir, str(name) + '_' + str(project) + '_' + str(experiment) + '_r0i0p0_glob_fx_' + str(realm) + '_areacell.xml') file_land = OSpath__join( xmldir, str(name) + '_' + str(project) + '_' + str(experiment) + '_r0i0p0_glob_fx_' + str(realm) + '_landmask.xml') 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): 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_xml_cmip(model, project, experiment, ensemble, frequency, realm, variable): try: pathnc, filenc = find_path_and_files(ens=ensemble, exp=experiment, fre=frequency, mod=model, pro=project, rea=realm, var=variable) except: 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), and conversely try: pathnc, filenc = find_path_and_files(ens=ensemble, exp=experiment, fre=frequency, mod=model, pro=project, rea=new_realm, var=variable) except: # given variable is neither in realm 'A' nor 'O' print bcolors.FAIL + '%%%%% ----- %%%%%' print 'ERROR: function: ' + str( INSPECTstack()[0][3]) + ', line: ' + str(INSPECTstack()[0][2]) print 'given variable cannot be found in either realm A or O: ' + str( variable) print 'param: ' + str(model) + ', ' + str(project) + ', ' + str( experiment) + ', ' + str(ensemble) + ', ' + str( frequency) + ', ' + str(realm) print '%%%%% ----- %%%%%' + bcolors.ENDC sys.exit('') file_area, file_land = find_fx(model, project=project, experiment=experiment, ensemble=ensemble, realm=new_realm) else: file_area, file_land = find_fx(model, project=project, experiment=experiment, ensemble=ensemble, realm=realm) file_name = OSpath__join(pathnc, filenc[0]) return file_name, file_area, file_land
def find_xml_fx(model, experiment='', project='', realm=''): """ Finds fixed variables, here areacell and sftlf (landmask), mostly used for observational dataset 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 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 """ list_obs = list(ReferenceObservations().keys()) if model in list_obs: if user_name == "yplanton": file_area = None if model in ["20CRv2", "NCEP2"]: file_land = OSpath__join(path_obs, model + "/land.sfc.gauss.nc") elif model == "ERSSTv5": file_land = OSpath__join(path_obs, model + "/lsmask_ERSSTv5.nc") elif model == "CMAP": file_land = OSpath__join(path_obs, model + "/lsmask_fx_cmap.nc") elif model == "GPCPv2.3": file_land = OSpath__join(path_obs, model + "/lsmask_fx_gpcpv2.3.nc") elif model == "OISSTv2": file_land = OSpath__join(path_obs, model + "/lsmask_fx_oisstv2.nc") else: file_land = None else: file_area = None if model in [ "20CRv2", "CMAP", "ERA-Interim", "ERSSTv5", "GPCPv2.3", "NCEP2" ]: file_land = OSpath__join(path_obs, "lsmask_" + model + ".nc") else: file_land = None else: file_area = OSpath__join( xmldir, str(model) + "_" + str(project) + "_" + str(experiment) + "_r0i0p0_glob_fx_" + str(realm) + "_areacell.xml") file_land = OSpath__join( xmldir, str(model) + "_" + str(project) + "_" + str(experiment) + "_r0i0p0_glob_fx_" + str(realm) + "_landmask.xml") return file_area, file_land
def find_xml_cmip(experiment, frequency, model, project, realm, ensemble, variable): """ Finds cmip variable file, as well as corresponding areacell and landmask Inputs: ------ :param experiment: string experiment name (e.g., "historical", "piControl") :param frequency: string data frequency: "day" for daily, "mon" for monthly :param model: string model name (e.g., "CNRM-CM5", "IPSL-CM5A-LR") :param project: string project name (e.g., "CMIP5", "CMIP6") :param realm: string data realm: "A" for atmosphere, "O" for ocean :param ensemble: string ensemble name (e.g., "r1i1p1", "r1i1p1f1") :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 """ try: pathnc, filenc = find_path_and_files(ens=ensemble, exp=experiment, fre=frequency, mod=model, pro=project, rea=realm, var=variable) except: if realm == "O": new_realm = "A" else: new_realm = "O" # if var is not in realm 'O' (for ocean), look for it in realm 'A' (for atmosphere), and conversely try: pathnc, filenc = find_path_and_files(ens=ensemble, exp=experiment, fre=frequency, mod=model, pro=project, rea=new_realm, var=variable) except: pathnc, filenc = None, [None] # given variable is neither in realm 'A' nor 'O' print(bcolors.FAIL + "%%%%% ----- %%%%%") print("ERROR: function: " + str(INSPECTstack()[0][3]) + ", line: " + str(INSPECTstack()[0][2])) print("given variable cannot be found in either realm A or O: " + str(variable)) print("param: " + str(model) + ", " + str(project) + ", " + str(experiment) + ", " + str(ensemble) + ", " + str(frequency) + ", " + str(realm)) print("%%%%% ----- %%%%%" + bcolors.ENDC) SYSexit("") file_area, file_land =\ find_fx(model, project=project, experiment=experiment, ensemble=ensemble, realm=new_realm) else: file_area, file_land = find_fx(model, project=project, experiment=experiment, ensemble=ensemble, realm=realm) file_name = OSpath__join(pathnc, str(filenc[0])) return file_name, file_area, file_land
# Check given model option models = param.modnames print('models:', models) # Realizations realization = param.realization if ('all' in [r.lower() for r in realization]) or (realization == 'all'): realization = 'all' print('realization: ', realization) # case id case_id = param.case_id print('case_id:', case_id) path_main = "/p/user_pub/pmp/pmp_results/pmp_v1.1.2" path_in_json = OSpath__join(path_main, "metrics_results", "enso_metric", mip, exp, case_id, metric_collection) path_out = OSpath__join(path_main, "graphics", "enso_metric", mip, exp, case_id, metric_collection) pattern = "_".join([mip, exp, metric_collection, case_id]) # ---------------------------------------------------# # Adjust model list if "ALL" given # ---------------------------------------------------# # read json file filename_js = OSpath__join(path_in_json, pattern + "_allModels_allRuns.json") print('filename_js:', filename_js) with open(filename_js) as ff: data_json = json.load(ff)['RESULTS']['model'] # Include all models if conditioned
def main_plotter(metric_collection, metric, model, experiment, filename_nc, diagnostic_values, diagnostic_units, metric_values, metric_units, member=None, path_png=None, name_png=None, models2=None, shading=False, plot_ref=False, reference=None): dict_param = plot_param(metric_collection, metric) list_var = dict_param['metric_variables'] met_type = dict_param['metric_computation'] if reference is None: reference = dict_param['metric_reference'] dict_reg = dict_param['metric_regions'] if isinstance(diagnostic_units, str) is True: diagnostic_units = diagnostic_units.replace("C", "$^\circ$C").replace( "long", "$^\circ$long") elif isinstance(diagnostic_units, list) is True: for ii, uni in enumerate(diagnostic_units): diagnostic_units[ii] = uni.replace("C", "$^\circ$C").replace( "long", "$^\circ$long") if isinstance(metric_units, str) is True: metric_units = metric_units.replace("C", "$^\circ$C").replace( "long", "$^\circ$long") elif isinstance(metric_units, list) is True: for ii, uni in enumerate(metric_units): metric_units[ii] = uni.replace("C", "$^\circ$C").replace( "long", "$^\circ$long") if isinstance(name_png, str) is False: name_png = metric_collection + "_" + metric + "_" + experiment + "_" if isinstance(model, str): name_png = name_png + model elif isinstance(model, list) is True and shading is True: name_png = name_png + str(len(model)) + "projects" else: name_png = name_png + str(len(model)) + "models" if member is not None: if (isinstance(model, str) is True and member not in model) or isinstance(model, list) is True: name_png = name_png + "_" + member # diagnostic dict_diag = dict_param['diagnostic'] if isinstance(path_png, str): fig_name = OSpath__join(path_png, name_png + "_diagnostic") else: fig_name = deepcopy(name_png) plt_typ = dict_diag['plot_type'] if plt_typ == "dot" and shading is True: plt_typ = "dot_to_box" t1 = datetime.now() print(str().ljust(20) + plt_typ + " " + str(t1.hour).zfill(2) + ":" + str(t1.minute).zfill(2)) dict_plot[plt_typ](model, filename_nc, dict_diag, reference, list_var, fig_name + "_divedown01", models2=models2, member=member, metric_type=met_type, metric_values=metric_values, metric_units=metric_units, diagnostic_values=diagnostic_values, diagnostic_units=diagnostic_units, regions=dict_reg, shading=shading) if plot_ref is True: model_new = model.replace("GPCPv2.3", "GPCPv23").replace("SODA3.4.2", "SODA342") fig_name_ref = fig_name.replace(model_new, "reference") dict_plot[plt_typ](model, filename_nc, dict_diag, reference, list_var, fig_name_ref + "_divedown01", models2=None, member=None, metric_type=None, metric_values=metric_values, metric_units=metric_units, diagnostic_values=diagnostic_values, diagnostic_units=diagnostic_units, regions=dict_reg, shading=False, plot_ref=plot_ref) dt = datetime.now() - t1 dt = str(int(round(dt.seconds / 60.))) print(str().ljust(30) + "took " + dt + " minute(s)") # dive downs list_dd = sorted( [key for key in list(dict_param.keys()) if "dive_down" in key], key=lambda v: v.upper()) for ii, dd in enumerate(list_dd): dict_diag = dict_param[dd] plt_typ = dict_diag['plot_type'] t1 = datetime.now() print(str().ljust(20) + plt_typ + " " + str(t1.hour).zfill(2) + ":" + str(t1.minute).zfill(2)) if metric_collection in ["ENSO_tel", "test_tel"] and "Map" in metric: metype = deepcopy(met_type) else: metype = None dict_plot[plt_typ](model, filename_nc, dict_diag, reference, list_var, fig_name + "_divedown" + str(ii + 2).zfill(2), models2=models2, member=member, metric_type=metype, metric_values=metric_values, metric_units=metric_units, diagnostic_values=diagnostic_values, diagnostic_units=diagnostic_units, regions=dict_reg, shading=shading) if plot_ref is True: dict_plot[plt_typ](model, filename_nc, dict_diag, reference, list_var, fig_name_ref + "_divedown" + str(ii + 2).zfill(2), models2=None, member=None, metric_type=None, metric_values=metric_values, metric_units=metric_units, diagnostic_values=diagnostic_values, diagnostic_units=diagnostic_units, regions=dict_reg, shading=False, plot_ref=plot_ref) dt = datetime.now() - t1 dt = str(int(round(dt.seconds / 60.))) print(str().ljust(30) + "took " + dt + " minute(s)")
# json files dict_json = { "CMIP5": { "ENSO_perf": "share/EnsoMetrics/cmip5_historical_ENSO_perf_" + version_mod + "_allModels_allRuns.json", "ENSO_proc": "share/EnsoMetrics/cmip5_historical_ENSO_proc_" + version_mod + "_allModels_allRuns.json", "ENSO_tel": "share/EnsoMetrics/cmip5_historical_ENSO_tel_" + version_mod + "_allModels_allRuns.json"}, "CMIP6": { "ENSO_perf": "share/EnsoMetrics/cmip6_historical_ENSO_perf_" + version_mod + "_allModels_allRuns.json", "ENSO_proc": "share/EnsoMetrics/cmip6_historical_ENSO_proc_" + version_mod + "_allModels_allRuns.json", "ENSO_tel": "share/EnsoMetrics/cmip6_historical_ENSO_tel_" + version_mod + "_allModels_allRuns.json"}, "obs2obs": { "ENSO_perf": "share/EnsoMetrics/obs2obs_historical_ENSO_perf_" + version_obs + "_allObservations.json", "ENSO_proc": "share/EnsoMetrics/obs2obs_historical_ENSO_proc_" + version_obs + "_allObservations.json", "ENSO_tel": "share/EnsoMetrics/obs2obs_historical_ENSO_tel_" + version_obs + "_allObservations.json"}} path_main = "/Users/yannplanton/Documents/Yann/Fac/2016_2018_postdoc_LOCEAN/2018_06_ENSO_metrics/2020_05_report" path_nc = OSpath__join(path_main, "Data/" + project.lower() + "/" + experiment + "/" + metric_collection) # figure name path_out = "" dataname2 = dataname.replace("GPCPv2.3", "GPCPv23").replace("SODA3.4.2", "SODA342") figure_name = project.lower() + "_" + experiment + "_" + metric_collection + "_" + dataname2 # ---------------------------------------------------# # ---------------------------------------------------# # Main # ---------------------------------------------------# # read json file with open(dict_json[project][metric_collection]) as ff: data_json = json.load(ff)['RESULTS']['model'][model][member] ff.close() del ff
] #["r1i1p1", "r1i1p1f2", "r1i1p2f2"]#, "r1i1p1f2", "r1i1p1f1"] path_in = "/Users/yannplanton/Documents/Yann/Fac/2016_2018_postdoc_LOCEAN/eval_IPSL-CM6/2019_06_24_eval/Data" #"/Users/yannplanton/Documents/Yann/Fac/2016_2018_postdoc_LOCEAN/Eval_CNRM/v20190901/Data" path_out = "/Users/yannplanton/Documents/Yann/Fac/2016_2018_postdoc_LOCEAN/eval_IPSL-CM6/2019_06_24_eval/Plots_v2" #"/Users/yannplanton/Documents/Yann/Fac/2016_2018_postdoc_LOCEAN/Eval_CNRM/v20190901/Plots_v2" expe = "hist" if experiment == "historical" else "pi" pattern = "yplanton_" + metric_collection + "_modelname_" + experiment + "_membername" # ---------------------------------------------------# # Main # ---------------------------------------------------# # read json file filename_js = OSpath__join( path_in, "yplanton_" + metric_collection + "_all_dataset_" + experiment + "_raw.json") with open(filename_js) as ff: data_json = json.load(ff) ff.close() del ff, filename_js # loop on metrics metrics = sorted(defCollection(metric_collection)['metrics_list'].keys(), key=lambda v: v.upper()) if metric_collection == "ENSO_perf": # metrics = [ # "BiasPrLatRmse", "BiasPrLonRmse", "BiasSstLatRmse", "BiasSstLonRmse", "BiasTauxLatRmse", "BiasTauxLonRmse", # "EnsoAmpl", "EnsoDuration", "EnsoPrTsRmse", "EnsoSeasonality", "EnsoSstLonRmse", "EnsoSstSkew", "EnsoSstTsRmse", # "EnsoTauxTsRmse", "NinoSstDiversity_1", "NinoSstDiversity_2", "SeasonalPrLatRmse", "SeasonalPrLonRmse", # "SeasonalSstLatRmse", "SeasonalSstLonRmse", "SeasonalTauxLatRmse", "SeasonalTauxLonRmse"] metrics = [
# path_in = "/Users/yannplanton/Documents/Yann/Fac/2016_2018_postdoc_LOCEAN/2018_06_ENSO_metrics/2019_08_report/Data" # path_out = "/Users/yannplanton/Documents/Yann/Fac/2016_2018_postdoc_LOCEAN/2018_06_ENSO_metrics/2019_08_report/Plots" path_in = "/Users/yannplanton/Documents/Yann/Fac/2016_2018_postdoc_LOCEAN/Eval_CNRM/v20190901/Data" path_out = "/Users/yannplanton/Documents/Yann/Fac/2016_2018_postdoc_LOCEAN/Eval_CNRM/v20190901/Plots" expe = "hist" if experiment == "historical" else "pi" # pattern = "yplanton_" + metric_collection + "_" + model + "_" + expe + "_" + member pattern = "yplanton_" + metric_collection + "_" + model + "_" + experiment + "_" + member # ---------------------------------------------------# # Main # ---------------------------------------------------# # read json file # filename_js = OSpath__join(path_in, "yplanton_" + metric_collection + "_all_dataset_" + expe + "_raw.json") filename_js = OSpath__join( path_in, "yplanton_" + metric_collection + "_all_dataset_" + experiment + "_raw.json") with open(filename_js) as ff: data_json = json.load(ff) ff.close() del ff, filename_js # loop on metrics metrics = sorted(defCollection(metric_collection)['metrics_list'].keys(), key=lambda v: v.upper()) for met in metrics: print met filename_nc = OSpath__join(path_in, pattern + "_" + met + ".nc") # diagnostic_values = dict((key, data_json['value'][met]["diagnostic"][key]["value"]) # for key in data_json['value'][met]["diagnostic"].keys()) # metric_values = dict((key, data_json['value'][met]["metric"][key]["value"]) # for key in data_json['value'][met]["metric"].keys())
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
""" # ---------------------------------------------------# # Check Arguments # ---------------------------------------------------# print("metric_collection:", metric_collection) print("mip:", mip) print("exp:", exp) print("model:", model) print("run:", run) print("case_id:", case_id) print("debug:", debug) # ---------------------------------------------------# path_main = "/p/user_pub/pmp/pmp_results/pmp_v1.1.2" path_in_json = OSpath__join(path_main, "metrics_results", "enso_metric", mip, exp, case_id, metric_collection) path_in_nc = OSpath__join(path_main, "diagnostic_results", "enso_metric", mip, exp, case_id, metric_collection) if debug: path_main = "/work/lee1043/imsi/result_test" path_out = OSpath__join(path_main, "graphics", "enso_metric", mip, exp, case_id, metric_collection) if not OSpath__exists(path_out): try: OS__makedirs(path_out) print("path_out:", path_out) except: pass
"landmaskname": list_name_land } # # finding file and variable name in file for each models # dict_metric, dict_dive = dict(), dict() dict_var = CmipVariables()["variable_name_in_file"] for mod in list_models: list_ens = find_members(experiment, frequency, mod, project, realm, first_only=first_member_only) pattern_out = OSpath__join( path_netcdf, user_name + "_" + mc_name + "_" + mod + "_" + experiment) dict_ens, dict_ens_dive = dict(), dict() for ens in list_ens: dict_mod = {mod + '_' + ens: {}} for var in list_variables: # # finding variable name in file # var_in_file = dict_var[var]["var_name"] try: areacell_in_file = dict_var["areacell"]["var_name"] except: areacell_in_file = None try: landmask_in_file = dict_var["landmask"]["var_name"] except:
"ENSO_proc": "share/EnsoMetrics/obs2obs_historical_ENSO_proc_" + version_obs + "_allObservations.json", "ENSO_tel": "share/EnsoMetrics/obs2obs_historical_ENSO_tel_" + version_obs + "_allObservations.json"}} # figure name path_out = "" figure_name = "metrics_correlations_" + str(len(list_metric_collections)) + "metric_collections_" + version_mod if len(list_projects) == 1: figure_name += "_" + str(list_projects[0]) else: figure_name += "_" + str(len(list_projects)) + "cmip" if first_member is True: figure_name += "_first_member" else: figure_name += "_members_averaged" if reduced_set is False: figure_name += "_all_metrics" figure_name = OSpath__join(path_out, figure_name) # ---------------------------------------------------# # ---------------------------------------------------# # Functions # ---------------------------------------------------# def compute_correlation(tab_in): """ Computes correlations Input: ----- :param tab_in: `cdms2` variable A `cdms2` variable containing the data to be analysed.
return tab_out, metric_value # ---------------------------------------------------# # ---------------------------------------------------# # main # ---------------------------------------------------# no_var = [ 'months', 'bounds_months', 'bounds_time', 'latitude', 'bounds_latitude', 'bounds_latitude_a', 'bounds_latitude_b', 'longitude', 'bounds_longitude', 'bounds_longitude_a', 'bounds_longitude_b', 'bounds_years', 'bounds_years_a', 'bounds_years_b', 'bounds_years_c', 'bounds_years_d', 'bounds_years_e' ] path_js = OSpath__join(path_main, "JSONs") path_nc = OSpath__join(path_main, metric_col + "_cmip5") dict_MC = defCollection(metric_col)['metrics_list'] # ---------------------------------------------------# print 'curves' # read data dict1 = dict() if ' ': # json file file_js = sorted(list( GLOBiglob( OSpath__join( path_js, "cmip?_" + experiment + "_" + metric_col + "_v2019????.json"))), key=lambda v: v.upper()) if "cmip5" in path_nc:
} # models list_models = [ 'IPSL-CM5B-LR' ] #['CNRM-CM5']#['IPSL-CM5A-LR', 'IPSL-CM5A-MR', 'IPSL-CM5B-LR']#['IPSL-CM6A-LR']# # # finding file and variable name in file for each observations dataset # dict_metric, dict_dive = dict(), dict() dict_var = CmipVariables()['variable_name_in_file'] for mod in list_models: list_ens = [ 'r1i1p1' ] #get_ensembles(exp=experiment, fre=frequency, mod=mod, pro=project, rea=realm) pattern_out = OSpath__join( netcdf_path, user_name + '_' + mc_name + '_' + mod + '_' + experiment) files_in = list(GLOBiglob(pattern_out + '*.json')) #list_ens = list_ens[len(files_in):] dict_ens, dict_ens_dive = dict(), dict() for ens in list_ens: dict_mod = {mod + '_' + ens: {}} # ------------------------------------------------ # @jiwoo: between these dash the program is a bit ad hoc... # it works well for me because I am looking for sst and taux on the ocean grid, and fluxes [lhf, lwr, swr, shf, thf] # on the atmosphere grid # if you want to use atmosphere only, do not use this or create your own way to find the equivalent between the # variable name in the program and the variable name in the file for var in list_variables: # # finding variable name in file #