예제 #1
0
def irma_percen(irma_tc_s, irma_tc_n, exp_s, exp_n):
    """ Plot irma damage in % in lesser antilles and TCA. """
    if_exp = ImpactFuncSet()
    if_em = IFTropCyclone()
    if_em.set_emanuel_usa()
    if_exp.add_func(if_em)

    fig, axs = plt.subplots(1,
                            2,
                            figsize=(16, 20),
                            subplot_kw=dict(projection=ccrs.PlateCarree()),
                            squeeze=True,
                            sharex=False,
                            sharey=False)

    for idx, axis in enumerate(axs.flatten()):
        grid = axis.gridlines(draw_labels=True, alpha=0.2)
        grid.xlabels_top = grid.ylabels_right = False
        grid.xformatter = LONGITUDE_FORMATTER
        grid.yformatter = LATITUDE_FORMATTER

    # south
    plot_percen(irma_tc_s, exp_s, if_exp, axs[0])

    # nord
    im = plot_percen(irma_tc_n, exp_n, if_exp, axs[1])

    plt.subplots_adjust(wspace=0.14)
    fig.subplots_adjust(right=0.88)
    cbar_ax = fig.add_axes([0.885, 0.4285, 0.03, 0.148])
    fig.colorbar(im, cax=cbar_ax, orientation='vertical', label='% Damage')

    return fig
예제 #2
0
def calc_imp(expo_dict, tc_dict, data_dir):
    """ Compute impacts of TCs in every island group. """
    try:
        abs_path = os.path.join(data_dir, 'imp_isl.p')
        with open(abs_path, 'rb') as f:
            imp_dict = pickle.load(f)
        print('Loaded imp_isl:', len(imp_dict))
    except FileNotFoundError:
        if_exp = ImpactFuncSet()
        if_em = IFTropCyclone()
        if_em.set_emanuel_usa()
        if_exp.add_func(if_em)

        imp_dict = dict()
        for isl_iso in expo_dict:
            imp = Impact()
            imp.calc(expo_dict[isl_iso], if_exp, tc_dict[isl_iso])
            imp_dict[isl_iso] = imp

        save(os.path.join(data_dir, 'imp_isl.p'), imp_dict)

    return imp_dict
예제 #3
0
def plot_right(irma_tc, exp, ax, scale_pos, plot_line=False):
    """ Plot irma damage in USD. """
    if_exp = ImpactFuncSet()
    if_em = IFTropCyclone()
    if_em.set_emanuel_usa()
    if_exp.add_func(if_em)

    imp_irma = Impact()
    imp_irma.calc(exp, if_exp, irma_tc)
    extent = [
        exp.longitude.min() - BUFFER_DEG,
        exp.longitude.max() + BUFFER_DEG,
        exp.latitude.min() - BUFFER_DEG,
        exp.latitude.max() + BUFFER_DEG
    ]
    ax.set_extent((extent))
    u_plot.add_shapes(ax)

    sel_pos = np.argwhere(imp_irma.eai_exp > 0)[:, 0]
    hex_bin = ax.hexbin(imp_irma.coord_exp[sel_pos, 1],
                        imp_irma.coord_exp[sel_pos, 0],
                        C=imp_irma.eai_exp[sel_pos],
                        reduce_C_function=np.average,
                        transform=ccrs.PlateCarree(),
                        gridsize=2000,
                        norm=LogNorm(vmin=MIN_VAL, vmax=MAX_VAL),
                        cmap='YlOrRd',
                        vmin=MIN_VAL,
                        vmax=MAX_VAL)
    ax.set_title('')
    ax.grid(False)
    add_cntry_names(ax, extent)
    scale_bar(ax, scale_pos, 10)

    if plot_line:
        x1, y1 = [-64.57, -64.82], [18.28, 18.47]
        ax.plot(x1, y1, linewidth=1.0, color='grey', linestyle='--')

    return hex_bin