Ejemplo n.º 1
0
def wfdei_saves(multiprocessing=False):
    """
    Function to create all netcdf files that are needed for later plotting. All scenarios!
    :return: Netcdf files for single models (_singleModel.nc), multi-model cube (_allModels.nc) and anomalies per model
     in a multi-model cube in absolute values (_anomalies.nc) and in percentage change (_anomaliesPerc.nc).
    """

    ###
    # CHOOSE OPTIONS RELATED TO ALL METRICS
    ###
    outpath = cnst.METRIC_DATADIR
    bc_and_resolution = ['WFDEI']  # mdlgrid does not work cause models are not on the same grid!
    region = cnst.ATLAS_REGION

    atlas_utils.create_outdirs(outpath, bc_and_resolution)
    multi_list = []
    for row in cnst.METRICS_TORUN:
        metric = row[0]
        variable = row[1]
        season = row[2]
        multi_list.append((variable, outpath, season, metric, region, cnst.OVERWRITE))

    print multi_list
    
    if multiprocessing:
        pool = Pool(processes=multiprocessing)
        res = pool.map(wNetcdf.wfdei, multi_list)
        #print res.get(timeout=1)
        pool.close()
    else:
    # Metric-specific options are set in constants.py
        for m in multi_list:
            wNetcdf.wfdei(m)

    print 'All Netcdf files written, ready to plot!'
Ejemplo n.º 2
0
def plot(multiprocessing=False):

    """
    Plotting script, could run loops. Has to define regions etc. (full cube is West Africa) 
    Plots must also handle collapsing e.g hovmoeller lon collapse if needed.
    """

    ###
    # USER CHOICE: SET OPTIONS RELATED TO ALL METRICS
    ###
    inpath = cnst.METRIC_DATADIR
    outpath = cnst.METRIC_PLOTDIR

    bc_and_resolution = cnst.BC_RES
    region = cnst.ATLAS_REGION
    print region
    #####
    
    atlas_utils.create_outdirs(outpath, bc_and_resolution, metrics=inpath)

    # Metric-specific options are set in constants.py

    multi_list = []
    for row in cnst.METRICS_TORUN:
        metric = row[0]
        variable = row[1]
        season = row[2]
        multi_list.append((inpath, outpath, bc_and_resolution, region, variable, season, metric))

    if multiprocessing:
        pool = Pool(processes=multiprocessing)
        res = pool.map(allScenarios_plot, multi_list)
        # print res.get(timeout=1)
        pool.close()
    else:
        # Metric-specific options are set in constants.py
        for m in multi_list:
            allScenarios_plot(m)

    if multiprocessing:
        pool = Pool(processes=multiprocessing)
        res = pool.map(singleScenario_plot, multi_list)
        # print res.get(timeout=1)
        pool.close()
    else:
        # Metric-specific options are set in constants.py
        for m in multi_list:
            singleScenario_plot(m)

    print '#######################################'
    print 'Finished plotting'
    print '#######################################'
Ejemplo n.º 3
0
def saves(multiprocessing=False):
    """
    Function to create all netcdf files that are needed for later plotting. All scenarios!

    Calls the functions to write single model, multi-model and anomaly NetCDF files.

    :param variable: string list of chosen variables: e.g. ['pr', 'tasmax']
    :param bc_and_resolution: string list of chosen correction option: e.g. ['BC_0.5x0.5' , '0.5x0.5']
    :param inpath: path to CMIP5 Africa directory: '/my/path/CMIP5_Africa'
    :param outpath: path where intermediate NetCDF files should be saved (single / multi-model / anomalies)
    :param season: string list months for which the metric is to be computed: ['jas', 'ann']
    :param metric: STRING identifing a metric (the calculation file), no list: 'annualMax'
    :param overwrite: whether or not existing NetCDF files should be overwritten

    :return: Netcdf files for single models (_singleModel.nc), multi-model cube (_allModels.nc) and anomalies per model
     in a multi-model cube in absolute values (_anomalies.nc) and in percentage change (_anomaliesPerc.nc).
    """

    ###
    # CHOOSE OPTIONS RELATED TO ALL METRICS
    ###
    inpath = cnst.DATADIR
    outpath = cnst.METRIC_DATADIR
    bc_and_resolution = cnst.BC_RES  # mdlgrid does not work cause models are not on the same grid!
    region = cnst.ATLAS_REGION
    scenarios = cnst.SCENARIO

    atlas_utils.create_outdirs(outpath, bc_and_resolution)
    multi_list = []
    for row in cnst.METRICS_TORUN:
        metric = row[0]
        variable = row[1]
        season = row[2]
        multi_list.append((variable, scenarios, bc_and_resolution, inpath,
                           outpath, season, metric, region, cnst.OVERWRITE))

    print multi_list

    if multiprocessing:
        pool = Pool(processes=multiprocessing)
        res = pool.map(wNetcdf.model_files, multi_list)
        pool.close()
    else:
        # Metric-specific options are set in constants.py
        for m in multi_list:
            wNetcdf.model_files(m)

    print 'All Netcdf files written, ready to plot!'
Ejemplo n.º 4
0
def plot():
    """
    Plotting script, could run loops. Has to define regions etc. (full cube is West Africa) 
    Plots must also handle collapsing e.g hovmoeller lon collapse if needed.
    """

    ###
    # USER CHOICE: SET OPTIONS RELATED TO ALL METRICS
    ###
    inpath = cnst.METRIC_DATADIR
    outpath = cnst.METRIC_PLOTDIR

    bc_and_resolution = cnst.BC_RES
    region = cnst.ATLAS_REGION
    #####

    atlas_utils.create_outdirs(outpath, bc_and_resolution, metrics=inpath)

    # Metric-specific options are set in constants.py
    for row in cnst.METRICS_TORUN:

        metric = row[0]
        variable = row[1]
        season = row[2]
        print '#######################################'
        print 'Plotting data for: '
        print metric, variable, season
        print '#######################################'

        allScenarios_plot(inpath, outpath, bc_and_resolution, region, variable,
                          season, metric)
        singleScenario_plot(inpath, outpath, bc_and_resolution, region,
                            variable, season, metric)

    print '#######################################'
    print 'Finished plotting'
    print '#######################################'