Exemple #1
0
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


# metric collection
mc_name = 'ENSO_perf'#'MC1'#
dict_mc = defCollection(mc_name)
list_metric = sorted(dict_mc['metrics_list'].keys())

# parameters
project = 'CMIP5'
experiment = 'piControl'#'historical'
ensemble = 'r1i1p1'
frequency = 'mon'
realm = 'A'

# list of variables
list_variables = list()
for metric in list_metric:
    listvar = dict_mc['metrics_list'][metric]['variables']
    for var in listvar:
        if var not in list_variables:
]
# references
ref_colors = {'model': 'r', 'obs': 'k'}
ref_obs = {
    'ssh': 'AVISO',
    'pr': 'GPCPv2.3',
    'sst': 'HadISST',
    'lhf': 'Tropflux',
    'lwr': 'Tropflux',
    'shf': 'Tropflux',
    'swr': 'Tropflux',
    'taux': 'Tropflux',
    'thf': 'Tropflux'
}
# metric collections
list_MC = sorted(defCollection().keys(), key=lambda v: v.upper())
list_obs = sorted(ReferenceObservations().keys(), key=lambda v: v.upper())
# model
model = "CNRM-CM5"
# path
path_main = '/Users/yannplanton/Documents/Yann/Fac/2016_2018_postdoc_LOCEAN/2018_06_ENSO_metrics/2019_05_report/Data/v20190515'
path_plot = '/Users/yannplanton/Documents/Yann/Fac/2016_2018_postdoc_LOCEAN/2018_06_ENSO_metrics/2019_05_report/Wiki'
# ---------------------------------------------------#
# get arguments
try:
    SYSargv[1]
except:
    print '     no argument given'
    print ''
    metric_col = 'ENSO_perf'  # 'CM6_perf'
    experiment = 'historical'
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 = [
        "SeasonalPrLonRmse", "SeasonalSstLonRmse", "SeasonalTauxLonRmse"
    ]
elif metric_collection == "ENSO_proc":
    # metrics = ["EnsoAmpl", "EnsoFbSshSst", "EnsoFbSstLhf", "EnsoFbSstLwr", "EnsoFbSstShf", "EnsoFbSstSwr",
    #            "EnsoFbSstTaux", "EnsoFbSstThf", "EnsoFbTauxSsh", "EnsodSstOce_1", "EnsodSstOce_2"]
    metrics = [
        "EnsoFbSshSst", "EnsoFbSstLhf", "EnsoFbSstLwr", "EnsoFbSstShf",