def main(project_info):
    """Diagnostics and plotting script for Southern Hemisphere radiation."""

    # ESMValProject provides some easy methods to access information in
    # project_info but you can also access it directly (as in main.py)
    # First we get some general configurations (ESMValProject)
    # and then we read in the model configuration file

    E = ESMValProject(project_info)
    config_file = E.get_configfile()
    plot_dir = E.get_plot_dir()
    verbosity = E.get_verbosity()

    # A-laue_ax+
    diag_script = E.get_diag_script_name()
    res = E.write_references(
        diag_script,  # diag script name
        ["A_maek_ja"],  # authors
        ["A_eval_ma", "A_jone_co"],  # contributors
        [""],  # diag_references
        [""],  # obs_references
        ["P_embrace"],  # proj_references
        project_info,
        verbosity,
        False)
    # A-laue_ax-

    modelconfig = ConfigParser.ConfigParser()
    modelconfig.read(config_file)
    E.ensure_directory(plot_dir)

    # Check which parts of the code to run
    if (modelconfig.getboolean('general', 'plot_scatter')):
        info("Starting scatter plot", verbosity, 2)
        process_scatter(E, modelconfig)
Beispiel #2
0
def main(project_info):
    """Diagnostics and plotting script for Southern Hemisphere radiation."""

    # ESMValProject provides some easy methods to access information in
    # project_info but you can also access it directly (as in main.py)
    # First we get some general configurations (ESMValProject)
    # and then we read in the model configuration file

    E = ESMValProject(project_info)
    config_file = E.get_configfile()
    datakeys = E.get_currVars()
    plot_dir = E.get_plot_dir()
    verbosity = E.get_verbosity()

    # A-laue_ax+
    diag_script = E.get_diag_script_name()
    res = E.write_references(diag_script,              # diag script name
                             ["A_maek_ja"],            # authors
                             ["A_eval_ma", "A_jone_co"], # contributors
                             [""],                     # diag_references
                             [""],                     # obs_references
                             ["P_embrace"],            # proj_references
                             project_info,
                             verbosity,
                             False)
    # A-laue_ax-

    modelconfig = ConfigParser.ConfigParser()
    modelconfig.read(config_file)
    E.ensure_directory(plot_dir)

    # Check at which stage of the program we are
    clouds = False
    fluxes = False
    radiation = False
    if ('clt' in datakeys or 'clivi' in datakeys or 'clwvi' in datakeys):
        clouds = True
    elif ('hfls' in datakeys or 'hfss' in datakeys):
        fluxes = True
    else:
        radiation = True

    # Check which parts of the code to run
    if (modelconfig.getboolean('general', 'plot_clouds') and clouds is True):
        info("Starting to plot clouds", verbosity, 2)
        process_clouds(E, modelconfig)

    if (modelconfig.getboolean('general', 'plot_fluxes') and fluxes is True):
        info("Starting to plot turbulent fluxes", verbosity, 2)
        process_fluxes(E, modelconfig)

    if (modelconfig.getboolean('general', 'plot_radiation') and radiation is True):
        info("Starting to plot radiation graphs", verbosity, 2)
        process_radiation(E, modelconfig)
Beispiel #3
0
def main(project_info):
    """Diagnostics and plotting script for Tropical Variability.
    We use ts as a proxy for Sea Surface Temperature. """

    # ESMValProject provides some easy methods to access information in
    # project_info but you can also access it directly (as in main.py)
    # First we get some general configurations (ESMValProject)
    # and then we read in the model configuration file

    E = ESMValProject(project_info)
    config_file = E.get_configfile()
    plot_dir = E.get_plot_dir()
    verbosity = E.get_verbosity()

    # A-laue_ax+
    diag_script = E.get_diag_script_name()
    res = E.write_references(
        diag_script,  # diag script name
        ["A_maek_ja"],  # authors
        ["A_eval_ma", "A_jone_co"],  # contributors
        ["D_li14jclim"],  # diag_references
        [""],  # obs_references
        ["P_embrace"],  # proj_references
        project_info,
        verbosity,
        False)

    # A-laue_ax-

    modelconfig = ConfigParser.ConfigParser()
    modelconfig.read(config_file)
    E.ensure_directory(plot_dir)

    # Here we check and process only desired parts of the diagnostics
    if (modelconfig.getboolean('general', 'plot_zonal_means')):
        info("Starting to plot zonal means", verbosity, 2)
        process_zonal_means(E, modelconfig)

    if (modelconfig.getboolean('general', 'plot_scatter')):
        info("Starting scatterplot of temperature and precipitation",
             verbosity, 2)
        process_scatterplot(E, modelconfig)

    if (modelconfig.getboolean('general', 'plot_equatorial')):
        info("Starting to gather values for equatorial means", verbosity, 2)
        process_equatorial_means(E, modelconfig)
Beispiel #4
0
def main(project_info):

    # print(">>>>>>>> entering ww09_ESMValTool.py <<<<<<<<<<<<")

    # create instance of a wrapper that allows easy access to data
    E = ESMValProject(project_info)

    config_file = E.get_configfile()
    plot_dir = E.get_plot_dir()
    verbosity = E.get_verbosity()
    plot_type = E.get_graphic_format()
    diag_script = E.get_diag_script_name()

    res = E.write_references(diag_script,              # diag script name
                             ["A_will_ke"],            # authors
                             [""],                     # contributors
                             ["D_Williams09climdyn"],  # diag_references
                             ["E_isccp_d1"],           # obs_references
                             ["P_cmug"],               # proj_references
                             project_info,
                             verbosity,
                             False)

    modelconfig = ConfigParser.ConfigParser()
    modelconfig.read(config_file)

    # create list of model names (plot labels)
    models = []
    for model in E.project_info['MODELS']:
        models.append(model.split_entries()[1])

    # number of models
    nummod = len(E.project_info['MODELS'])
    crems = np.empty(nummod)

    # get filenames of preprocessed climatological mean files (all models)
    fn_alb = get_climo_filenames(E, variable='albisccp')
    fn_pct = get_climo_filenames(E, variable='pctisccp')
    fn_clt = get_climo_filenames(E, variable='cltisccp')
    fn_su  = get_climo_filenames(E, variable='rsut')
    fn_suc = get_climo_filenames(E, variable='rsutcs')
    fn_lu  = get_climo_filenames(E, variable='rlut')
    fn_luc = get_climo_filenames(E, variable='rlutcs')
    fn_snc = get_climo_filenames(E, variable='snc')
    fn_sic = get_climo_filenames(E, variable='sic')

    if not fn_snc:
        print("no data for variable snc found, using variable snw instead")
        fn_snw = get_climo_filenames(E, variable='snw')

    # loop over models and calulate CREM

    for i in range(nummod):

        if fn_snc:
            snc = fn_snc[i]
        else:
            snc = ""

        pointers = {'albisccp_nc': fn_alb[i],
                    'pctisccp_nc': fn_pct[i],
                    'cltisccp_nc': fn_clt[i],
                    'rsut_nc'    : fn_su[i],
                    'rsutcs_nc'  : fn_suc[i],
                    'rlut_nc'    : fn_lu[i],
                    'rlutcs_nc'  : fn_luc[i],
                    'snc_nc'     : snc,
                    'sic_nc'     : fn_sic[i]}

        if not fn_snc:
            pointers['snw_nc'] = fn_snw[i]

        # calculate CREM

        (CREMpd, __) = crem_calc(E, pointers)

        crems[i] = CREMpd

    print("------------------------------------")
    print(crems)
    print("------------------------------------")

    # plot results

    fig = plt.figure()
    ypos = np.arange(nummod)
    plt.barh(ypos, crems)
    plt.yticks(ypos + 0.5, models)
    plt.xlabel('Cloud Regime Error Metric')

    # draw observational uncertainties (dashed red line)
    plt.plot([0.96, 0.96], [0, nummod], 'r--')

    # if needed, create directory for plots
    if not os.path.exists(plot_dir):
        os.makedirs(plot_dir)

    plt.savefig(plot_dir + 'ww09_metric_multimodel.' + plot_type)
    print("Wrote " + plot_dir + "ww09_metric_multimodel." + plot_type)
Beispiel #5
0
def main(project_info):
    """
    ;; Description
    ;;    Main fuction
    ;;    Call all callable fuctions to
    ;;    read CMIP5 data, compute and plot diagnostic
    """

    E = ESMValProject(project_info)
    plot_dir = E.get_plot_dir()
    work_dir = E.get_work_dir()
    verbosity = E.get_verbosity()
    fileout = work_dir
    
    if not os.path.exists(plot_dir):
        os.makedirs(plot_dir)

    for model in project_info['MODELS']:
        info(model, verbosity, required_verbosity=1) 

        if not os.path.exists(work_dir+'/sample_events'):
            os.makedirs(work_dir+'/sample_events')

        if not os.path.exists(work_dir+'/event_output'):
            os.makedirs(work_dir+'/event_output')


        # --------------------------------------
        # Get input data to compute diagnostic
        # --------------------------------------

        # Read cmip5 model data
        pr, sm, topo, lon, lat, time, time_bnds_1 = read_pr_sm_topo(project_info, model)

        # --------------------------------------
        # Get sm monthly climatology
        # at selected local time: 6:00 am
        # --------------------------------------

        smclim = get_smclim(sm, lon, time)

        # -------------------------------
        # Compute diagnostic per month
        # -------------------------------

        samplefileout = fileout + 'sample_events/'

        for mn in np.arange(1, 13):

            # -------------------------------------------------
            # Create montly arrays required by fortran routines
            # -------------------------------------------------

            prbef, smbef, praft, smaft, \
                monthlypr, monthlysm, days_per_year = get_monthly_input(project_info, mn, time, 
                                                         lon, lat, time_bnds_1, pr, sm, fileout,
                                                         samplefileout, model,
                                                         verbosity)

            # -----------------------
            # Run fortran routines
            # -----------------------

            info('Executing global_rain_sm for month ' + str(mn), verbosity, required_verbosity=1)

            grs.global_rain_sm(np.asfortranarray(monthlypr),
                               np.asfortranarray(prbef),
                               np.asfortranarray(praft),
                               np.asfortranarray(monthlysm),
                               np.asfortranarray(smbef),
                               np.asfortranarray(smaft),
                               np.asfortranarray(smclim[mn - 1, :, :]),
                               np.asfortranarray(topo),
                               np.asfortranarray(lon),
                               np.asfortranarray(mn),
                               fileout, days_per_year)

            info('Executing sample_events for month ' + str(mn), verbosity, required_verbosity=1)

            se.sample_events(np.asfortranarray(monthlysm),
                             np.asfortranarray(smbef),
                             np.asfortranarray(smaft),
                             np.asfortranarray(lon),
                             np.asfortranarray(lat),
                             np.asfortranarray(mn),
                             fileout, days_per_year, samplefileout)

        # ---------------------------------------------------
        # Compute p_values (as in Fig. 3, Taylor et al 2012)
        # --------------------------------------------------
        info('Computing diagnostic', verbosity, required_verbosity=1)

        xs, ys, p_vals = get_p_val(samplefileout)

        # --------------------------------------------------
        # Save diagnostic to netCDF file and plot
        # --------------------------------------------------
        write_nc(fileout, xs, ys, p_vals, project_info, model)
        
        plot_diagnostic(fileout, plot_dir, project_info, model)

        # --------------------------------------------------
        # Remove temporary folders
        # --------------------------------------------------
        shutil.rmtree(str(fileout) + 'event_output')
        shutil.rmtree(str(fileout) + 'sample_events') 
Beispiel #6
0
def main(project_info):
    """
    main interface routine to ESMValTool

    Parameters
    ----------
    project_info : dict
        dictionary that contains all relevant informations
        it is provided by the ESMValTool launcher
    """

    # extract relevant information from project_info using a generic python
    # interface library
    # logging configuration
    verbosity = project_info['GLOBAL']['verbosity']
    if verbosity == 1:
        logger.setLevel(logging.WARNING)
    elif verbosity == 2:
        logger.setLevel(logging.INFO)
    else:
        logger.setLevel(logging.DEBUG)

    # create instance of a wrapper that allows easy access to data
    E = ESMValProject(project_info)

    # get information  for runoff/ET script
    # input file directory, returns a dict
    ifile_dict = E.get_raw_inputfile()

    # A-laue_ax+
    diag_script = E.get_diag_script_name()
    res = E.write_references(diag_script,              # diag script name
                             ["A_somm_ph", "A_hage_st"],      # authors
                             ["A_loew_al"],            # contributors
                             ["D_hagemann13jadvmodelearthsyst"],  # diag_references
                             ["E_duemenil00mpi", "E_weedon14waterresourres"], # obs_references
                             ["P_embrace"],            # proj_references
                             project_info,
                             verbosity,
                             False)
    # A-laue_ax-

    # set up of input files dictionary, rewrite ifile_dict to match for
    # catchment_analysis_tool_val
    # ifiles={<<<MODEL>>>:
    #             {<<<VAR>>>:
    #                 {'file':<file>[, 'unit':<unit>, 'cdo':<cdo>,
    #                                'vname':<vname>, 'reffile':<file>,
    #                                'refvname':<vname>]}}}
    # dictionary containing the model names as keys and a second dictionary as
    # value.
    # This (second) dictionaries contain the variable names (eihter 'runoff' or
    # 'ET') as key and a third dictionary as value.
    # This (third) dictionaries contain the key
    #   - 'file'     for the datafile for the climatological mean
    #   and optionally
    #   - 'unit'     for the unit of the data. If 'unit' is not set, it will be
    #                taken from the nc-file multiplied by 'm^2'
    #   - 'cdo'      for additional cdo-commands (e.g. multiplication for
    #                changing
    #                the units)
    #   - 'vname'    for the name of the variable in the datafile (if not set,
    #                the variable name as used for the key will be used).
    #   - 'reffile'  for the reference file (if not set, defaultreffile will be
    #                used and <<<VAR>>> will be replaced by the variable name
    #                as given in the key
    #   - 'refvname' for the name of the variable in the reference file (if not
    #                set, the variable name as used for the key will be used).
    ifiles = {}
    for model, vlst in ifile_dict.items():
        ifiles[str(model)] = {}
        for var in map(str, vlst.keys()):
            if var == 'evspsbl':
                myvar = 'ET'
                # units are are kg m-2 s-1 and therefore must be multiplied
                # by the amount of seconds in one year
                ifiles[str(model)][myvar] = {'unit': 'mm/a', 'vname': var,
                                             'cdo': '-mulc,86400 -muldpy '}
            elif var == 'mrro':
                myvar = 'runoff'
                # units are are kg m-2 s-1 and therefore must be multiplied
                # by the amount of seconds in one year
                ifiles[str(model)][myvar] = {'unit': 'mm/a', 'vname': var,
                                             'cdo': '-mulc,86400 -muldpy '}
            elif var == 'pr':
                myvar = 'precip'
                # units are are kg m-2 s-1 and therefore must be multiplied
                # by the amount of seconds in one year
                ifiles[str(model)][myvar] = {'unit': 'mm/a', 'vname': var,
                                             'cdo': '-mulc,86400 -muldpy '}
            else:
                # only ET, mrro and precip are supported trough reference
                # values. Therefore raise error
                raise ValueError(
                    "Only mrro (runoff), pr (precipitation) and evspsbl "
                    "(evapotranspration) are supported!")
            # try to get reformated data and if this does not work (because no
            # CMIP5 project, use raw input data
            try:
                ifiles[str(model)][myvar]['file'] = map(str, glob.glob(
                    E.get_clim_model_filenames(var)[model]))
            except ValueError:
                indir = str(ifile_dict[model][var]['directory'])
                indir = msd["dir"]
                if indir[-1] != os.sep:
                    indir += os.sep
                infile = str(ifile_dict[model][var]['files'])

                ifiles[str(model)][myvar]['file'] = indir + infile

            # A-laue_ax+
            for file in ifiles[str(model)][myvar]['file']:
                E.add_to_filelist(file)
            # A-laue_ax-

    POUT = str(os.path.join(E.get_plot_dir(), E.get_diag_script_name()))
    POUT = POUT + os.sep
    if not os.path.exists(POUT):
        os.makedirs(POUT)

    # catchment_dir = data_directory + 'cat/'
    catchment_dir = os.path.dirname(os.path.abspath(inspect.getfile(
        inspect.currentframe()))) + '/'
    # set path to nc-file containing the catchment definition
    pcatchment = os.path.join(catchment_dir, "aux/catchment_analysis", "big_catchments.nc")

    # A-laue_ax+
    E.add_to_filelist(pcatchment)
    # A-laue_ax-

    # ---- File input declaration ----
    # input file (needs to contain grid informations). For the
    # analysis the data will be regridded to pcatchments. Data is expected to
    # be in mm/s (if not, see 'cdo' in ifiles dictionary below)

    # ---- switches ----
    # CALCULATION: switch to calculate climatological means (True) or use
    # already existing files
    CALCULATION = True
    # KEEPTIMMEAN: switch to keep files created during calculation. if true,
    # files like 'tmp_<<<MODEL>>>_<<<var>>>_<<<CATCHMENT>>>.<<<fmt>>>' will be
    # stored in the output directory (POUT) containing the timmean data for
    # the catchments (note that the file format <<<fmt>>> is defined by the
    # input file)
    KEEPTIMMEAN = False
    # PLOT: switch to set plotting. If true, one plot for each model named
    # POUT+<<<MODEL>>>_bias-plot.pdf containg all variables will be generated
    PLOT = True
    # SEPPLOTS: Integer to control diagram style. If 2: relative and absolute
    # variables will be plotted in separate files named
    # POUT+<<<MODEL>>>_rel-bias-plot.pdf and
    # POUT+<<<MODEL>>>_abs-bias-plot.pdf.
    # If 3: they will be plotted into one # figure but separated axes in file
    # POUT+<<<MODEL>>>_sep-bias-plot.pdf, if 5: # they will be plotted into one
    # single axes within file POUT+<<<MODEL>>>_bias-plot.pdf. Multiplication
    # (e.g. 6, 15 or 30) is also possible to make more than one option at the
    # same time
    SEPPLOTS = 3
    # ETREFCALCULATION: If True, create reference file
    # ref_ET_catchments.txt from timmean of precfile and runoff data from
    # ref_runoff_catchments.txt.  If None, use default reference values, save
    # them to defaultreffile and delete it afterwards. If False, use existing
    # file defined by defaultreffile or reffile defined in ifiles (see above).
    ETREFCALCULATION = None

    # formatoptions for plot (ax2 modifies diagrams showing relative values)
    # (for keywords see function xyplotformatter in
    # catchment_analysis_tool_val)
    # be aware that the additional setting of a keyword for the plot of the
    # absolute values may also influence the plot of relative value. To prevent
    # from that, define the option for 'ax2' manually.
    # ---
    # set minimal and maximal bounds of y-axis (Syntax: [ymin, ymax]). 'minmax'
    # will cause y-axis limits with minimum and maximum value and makes the
    # plot symmetric around 0 in case of SEPPLOTS%5 == 0. To let the plotting
    # routine (i.e. pyplot) choose the limits, set ylim to None
    # ---
    # Set yticks: integer or list (Default (i.e. without manipulation by the
    # plotting routine of catchment_analysis_tool_val): None). Defines the
    # y-ticks. If integer i, every i-th tick of the automatically

    # other formatoptions as provided by function
    # catchment_analysis_tool_val.xyplotformatter may be included in the
    # dictionary below

    fmt = {
        myvar: {
            'ylim': 'minmax', 'yticks': None,
            'ax2': {'ylim': 'minmax', 'yticks': None}
               }
        for myvar in ifiles.values()[0].keys()
          }

    # start computation
    analysecatchments(
        project_info,
        POUT=POUT,
        pcatchment=pcatchment,
        ifiles=ifiles,
        CALCULATION=CALCULATION,
        KEEPTIMMEAN=KEEPTIMMEAN,
        PLOT=PLOT,
        SEPPLOTS=SEPPLOTS,
        ETREFCALCULATION=ETREFCALCULATION,
        fmt=fmt,
        # precfile=precfile,
        # defaultreffile=defaultreffile
        )