t_end = 1
            pfx = 'drysoilCLM'
            time_title_str = None
        else:
            t_end = 1
            pfx = pfx + '_timeavg'
            vd.aggregate_time(time_avg=True)
            if varname is "fogpresent":
                print("multiplying fogpresent avg by 100 to get a percent")
                for k in vd.data.keys():
                    vd.data[k] = vd.data[k] * 100
            time_title_str = 'June 2005'
        for this_t in range(0, t_end):  #
            plotter = VarDiffPlotter(vd,
                                     t_idx=this_t,
                                     layer=0,
                                     domain=DOMAIN,
                                     pfx=pfx,
                                     savedir=out_dir,
                                     time_title_str=time_title_str)
            if DOMAIN == 1:
                cb_orientation = 'horizontal'
            else:
                cb_orientation = 'vertical'
            fig = plotter.plot(cb_orientation=cb_orientation,
                               vmin=1,
                               vmax=21,
                               mask=vd.insignificant_mask)

    print('done driver ({})'.format(datetime.datetime.now() - t0))
    vd = var_diff(
        os.path.join(ctl_dir_new, 'summen_sensitivity_ctl',
                     '*d{:02d}_2009-06-02*.nc'.format(DOMAIN)),
        os.path.join(urb_dir, 'summen_sensitivity_urban',
                     '*d{:02d}_2009-06-02*.nc'.format(DOMAIN)),
        label_A='ctl',
        label_B='urban',
        # varname='LCL')
        varname='QCLOUD')
    # varname='uvmet')
    # varname='wa')
    # varname='LU_INDEX')
    read_data = True
    if read_data:
        vd.read_files()
        # vd.mask_land_or_water(mask_water=False)
    for this_t in range(0, 47):  #
        plotter = VarDiffPlotter(vd,
                                 t_idx=this_t,
                                 layer=0,
                                 domain=DOMAIN,
                                 pfx='QCLOUD_debug04')
        if DOMAIN == 1:
            cb_orientation = 'horizontal'
        else:
            cb_orientation = 'vertical'
        fig = plotter.plot(cb_orientation=cb_orientation)

        # vmin=0,
        # vmax=500)
            t_end = 200
        else:
            t_end = 1
            pfx = pfx + '_timeavg'
            vd.aggregate_time(time_avg=True)
            if varname is "fogpresent":
                print("multiplying fogpresent avg by 100 to get a percent")
                for k in vd.data.keys():
                    vd.data[k] = vd.data[k] * 100
            time_title_str = 'June 2005'
        for this_t in range(10, t_end):  #
            if this_series == 'single':
                time_title_str = vd.time[this_t].strftime('%Y-%m-%d_%H%M')
            plotter = VarDiffPlotter(vd,
                                     t_idx=this_t,
                                     layer=0,
                                     domain=DOMAIN,
                                     pfx=pfx,
                                     savedir=out_dir,
                                     time_title_str=time_title_str)
            if DOMAIN == 1:
                cb_orientation = 'horizontal'
            else:
                cb_orientation = 'vertical'
            fig = plotter.plot(cb_orientation=cb_orientation,
                               vmin=None,
                               vmax=None,
                               mask=None)

    print('done driver ({})'.format(datetime.datetime.now() - t0))
Example #4
0
    data_orig = copy.copy(vd.data)
    for i, this_t in enumerate(pvals_xr.t.values):
        last_i = i
    for i, this_t in enumerate(pvals_xr.t.values):
        if (i <= last_i) and (i > 0):
            vd.d = pvals_xr.mean_diff.data[i, ...]
            vd.abs_max = np.nanmax(np.abs(pvals_xr.mean_diff.data))
            for k in data_orig.keys():
                vd.data[k] = np.mean(data_orig[k][:pvals_xr.idx.values[i],
                                                  ...],
                                     axis=0,
                                     keepdims=True)
            plotter = VarDiffPlotter(
                vd,
                fig_type='png',
                t_idx=0,
                layer=0,
                domain=DOMAIN,
                pfx='pvals_{}_{}'.format(varname, runkey),
                # savedir='/Users/tim/work/Plots/Summen/',
                savedir=os.path.join(cscratchdir, 'plots_temporary'),
                time_title_str=np.datetime_as_string(this_t, unit='m'),
                show_title=False)
            p_insignificant95 = twotail_signif(pvals_xr.p.data[i, ...], 0.95)
            p_insignificant99 = twotail_signif(pvals_xr.p.data[i, ...], 0.99)
            d_LT_epsilon = np.abs(vd.d) < 1e-6
            fig = plotter.plot(cb_orientation='vertical',
                               mask=np.logical_or(p_insignificant95,
                                                  d_LT_epsilon))
            # mask=pvals_xr.p.data[i, ...] < 0.995)
    # for this_series in ['all_tstamps', 'time_avg']:

    t_end = 1
    pfx = pfx + '_timeavg'
    vd.aggregate_time(time_avg=True)
    time_title_str = 'June 2005'

    for k in vd.data.keys():
        vd.data[k][...] = np.ones(vd.data[k].shape)

    xy = get_wrf_xy((SanFrancisco, SantaCruz))
    vd.data['ctl'][0, xy.data[1, 0], xy.data[0, 0]] = 50
    vd.data['no_urban_CLM'][0, xy.data[1, 1], xy.data[0, 1]] = 100

    for this_t in range(0, t_end):  #
        plotter = VarDiffPlotter(vd,
                                 t_idx=this_t,
                                 layer=0,
                                 domain=DOMAIN,
                                 pfx=pfx,
                                 savedir='.',
                                 time_title_str=time_title_str)
        if DOMAIN == 1:
            cb_orientation = 'horizontal'
        else:
            cb_orientation = 'vertical'
        fig, ax = plotter.plot(cb_orientation=cb_orientation,
                               vmin=0,
                               vmax=100,
                               mask=None)  #vd.p > 0.05)
            time_title_str = ''
        for this_t in range(0, t_end):  #
            plotter = VarDiffPlotter(vd,
                                     t_idx=this_t,
                                     layer=0,
                                     domain=DOMAIN,
                                     pfx=pfx,
                                     savedir='.',
                                     time_title_str=time_title_str)
            if DOMAIN == 1:
                cb_orientation = 'horizontal'
            else:
                cb_orientation = 'vertical'
            fig = plotter.plot(cb_orientation=cb_orientation,
                               vmin=None,
                               vmax=None,
                               mask=vd.p > PVAL,
                               hatch_z_score=True)
            # mask=None)

    # ##################################################
    # code to make a data frame of lat, lon, p, z, fog fraction, urban
    # fraction values
    # ##################################################

    # PFT_URBAN = 12  # modified MODIS-IGBP code for urban land use
    # wrfin = {'ctl': os.path.join('/', 'global', 'cscratch1', 'sd',
    #                              'twhilton', 'WRFv4.0_Sensitivity',
    #                              'WRFCLMv4.0_NCEPDOEp2', 'WRFV4',
    #                              'run', 'wrfinput_d02'),
    #          'deurb': os.path.join('/', 'global', 'cscratch1', 'sd',
    ax[3].set_extent(bbox_SFBay, crs=ccrs.PlateCarree())
    ax[4].set_extent(bbox_LA, crs=ccrs.PlateCarree())
    ax[5].set_extent(bbox_LA, crs=ccrs.PlateCarree())

    cbar = fig.colorbar(cm,
                        ax=ax,
                        cmap=cmap,
                        extend='neither',
                        ticks=np.linspace(0.5, 21.5, 21))
    cbar.set_ticks(np.linspace(0.5, 21.5, 21))
    cbar.set_ticklabels(list(ctable['long_name']))

    fig.savefig(fname=os.path.join('/', 'global', 'cscratch1', 'sd',
                                   'twhilton', 'plots_temporary',
                                   'land_use_dominant.png'))
    for this_pft in range(3):  # range(len(ctable)):
        vd_LUfrac = get_LUfrac_diff(this_pft, wrfin)
        lu_str = '{:02d}-{}'.format(
            ctable['PFTnum'][this_pft],
            ctable['long_name'][this_pft].replace('/', ''))
        plotter = VarDiffPlotter(
            vd_LUfrac,
            t_idx=0,
            layer=0,
            domain=2,
            pfx=lu_str,
            savedir=os.path.join('/', 'global', 'cscratch1', 'sd',
                                 'twhilton', 'plots_temporary'),
            time_title_str=lu_str)
        fig = plotter.plot(vmin=0.0, vmax=1.0)
    pfx = '7day_urban'
    # for this_series in ['all_tstamps', 'time_avg']:
    for this_series in ['time_avg']:
        if this_series == 'all_tstamps':
            t_end = 1
            pfx = 'redwoodsurban'
            time_title_str = None
        else:
            t_end = 1
            pfx = pfx + '_timeavg'
            vd.aggregate_time(time_avg=True)
            time_title_str = 'June 2009'
        for this_t in range(0, t_end):  #
            plotter = VarDiffPlotter(vd,
                                     t_idx=this_t,
                                     layer=0,
                                     domain=DOMAIN,
                                     pfx=pfx,
                                     savedir=out_dir,
                                     time_title_str=time_title_str)
            if DOMAIN == 1:
                cb_orientation = 'horizontal'
            else:
                cb_orientation = 'vertical'
            fig = plotter.plot(cb_orientation=cb_orientation,
                               mask=(vd.p < 0.95))
            # vmin=-0.0000001,
            # vmax=1.0000001)

    print('done driver ({})'.format(datetime.datetime.now() - t0))