示例#1
0
def makeFigureS20_SatisficingSurfaces_100samples():
    
    designs = ['LHsamples_original_100_AnnQonly','CMIPunscaled_SOWs','Paleo_SOWs','LHsamples_wider_100_AnnQonly']
    titles = ['Box Around Historical','CMIP','Paleo','All-Encompassing']
    structures = ['53_ADC022','7200645','3704614']
    
    sns.set_style("dark")
    
    fig = plt.figure()
    
    for i,structure in enumerate(structures):
        for j,design in enumerate(designs):
            ax = fig.add_subplot(3,4,i*4+j+1)
            allSOWs, historic_percents, frequencies, magnitudes, gridcells, im = plotFailureHeatmap(ax, design, structure, False)
            for k in range(len(historic_percents)):
                if historic_percents[k] != 0: # highlight historical frequencies at each magnitude in orange
                    highlight_cell(k, gridcells[k], ax, color="orange", linewidth=2)
            
            if i == 0:
                ax.set_title(titles[j],fontsize=18)

    cbar_ax = fig.add_axes([0.85, 0.15, 0.03, 0.7])
    cbar = fig.colorbar(im, cax=cbar_ax)
    cbar.ax.set_ylabel("Percent of realizations\nin which criterion is met", rotation=-90, va="bottom",fontsize=16)
    fig.subplots_adjust(right=0.8,wspace=0.5,hspace=0.5)
    fig.set_size_inches([19.2,9.6])
    fig.savefig("FigureS20_SatisficingSurfaces_100samples.pdf")
    fig.clf()
    
    return None
def addPercentileBlocks(historic_percents, gridcells, percentiles,
                        short_magnitudes, ax):
    for i in range(len(percentiles)):
        highlight_cell(int(short_magnitudes[i] / 10) - 1,
                       int((100 - percentiles[i]) / 10) - 1,
                       ax,
                       color="black",
                       linewidth=2)

    for i in range(len(historic_percents)):
        if historic_percents[i] != 0:
            highlight_cell(i, gridcells[i], ax, color="orange", linewidth=2)

    return None
def makeFigureS21_RobustnessRanks_100samples():

    allRobustness = np.load(
        '../Output_analysis/RobustnessRanks_no15mi_100samples.npy')
    nstructures = np.shape(allRobustness)[2]
    colors = ['#fb8072', '#ffffb3', '#b3de69',
              '#bebada']  # original, CMIP, paleo, wider
    colOrder = [0, 2, 3, 1]  # order of columns to plot
    labels = ['Box Around Historical', 'CMIP', 'Paleo', 'All-Encompassing']
    design = 'LHsamples_wider_100_AnnQonly'
    structure = '53_ADC022'

    #sns.set_style("dark")
    mags = np.array([10, 50, 100])
    freqs = np.array([50, 100])

    sns.set_style("dark")

    fig = plt.figure()

    for i in range(len(mags)):
        ax = fig.add_subplot(2, 3, i + 1)
        # sort structures in all-encompassing design
        sortedIndices = np.argsort(-allRobustness[int(mags[i] / 10) - 1, 0, :,
                                                  1])  # freq=10% of the time
        for k in range(4):  # loop through experimental designs
            ax.scatter(range(1,nstructures+1),\
                       ss.rankdata(-allRobustness[int(mags[i]/10)-1,0,:,colOrder[k]])[sortedIndices],\
                           color=colors[k],label=labels[k])

        if i == 2:
            ax.set_xlabel('Robustness Rank in\nAll-Encompassing Experiment',
                          fontsize=16)
        elif i == 0:
            ax.set_ylabel('Robustness Rank in\neach Experiment', fontsize=16)

        ax.tick_params(axis='both', labelsize=14)
        ax.set_title('<' + str(mags[i]) + '% shortage <10% of the time',
                     fontsize=18)

    for j in range(len(freqs)):
        ax = fig.add_subplot(2, 3, j + 4)
        # sort structures in all-encompassing design
        sortedIndices = np.argsort(
            -allRobustness[0, int(freqs[j] / 10) - 1, :,
                           1])  # mag=10% of demand
        for k in range(4):  # loop through experimental designs
            ax.scatter(range(1,nstructures+1),\
                       ss.rankdata(-allRobustness[0,int(freqs[j]/10)-1,:,colOrder[k]])[sortedIndices],\
                           color=colors[k],label=labels[k])

        if j == 0:
            ax.set_ylabel('Robustness Rank in\neach Experiment', fontsize=16)

        ax.tick_params(axis='both', labelsize=14)
        ax.set_title('<10% shortage <' + str(freqs[j]) + '% of the time',
                     fontsize=18)
        ax.set_xlabel('Robustness Rank in\nAll-Encompassing Experiment',
                      fontsize=16)

    handles, labels = ax.get_legend_handles_labels()

    ax = fig.add_subplot(2, 3, 6)
    allSOWs, historic_percents, frequencies, magnitudes, gridcells, im = plotFailureHeatmap(
        ax, design, structure)
    for i in range(len(historic_percents)):
        if historic_percents[
                i] != 0:  # highlight historical frequencies at each magnitude in orange
            highlight_cell(i, gridcells[i], ax, color="orange", linewidth=2)
    # highlight criteria in ranks in black
    for i in range(len(mags)):
        highlight_cell(0,
                       int(mags[i] / 10) - 1,
                       ax,
                       color='black',
                       linewidth=2)
    for i in range(len(freqs)):
        highlight_cell(int(freqs[i] / 10) - 1,
                       0,
                       ax,
                       color='black',
                       linewidth=2)

    fig.set_size_inches([19.2, 9.6])
    fig.subplots_adjust(bottom=0.2, wspace=0.25, hspace=0.35)
    fig.legend(handles,
               labels,
               loc='lower center',
               ncol=2,
               frameon=True,
               fontsize=16)
    fig.savefig('FigureS21_RobustnessRanks_100samples.pdf')
    fig.clf()

    return None