コード例 #1
0
# X, Y = np.meshgrid(shearbins,areabins/1000)
#
# Zm = ma.masked_where(np.isnan(outarea),outarea)
#
# cmapp = uplot.discrete_cmap(10, base_cmap='RdBu')
# ax5 = fig.add_subplot(33)
# mappable = ax5.pcolormesh(X, Y, Zm.T, cmap=cmapp, vmin=30, vmax=40) # viridis_r
#
# ax5.set_ylabel('Area (10$^3$km$^2$)')
# ax5.set_xlabel('Shear')
# cbar = fig.colorbar(mappable, ticks=np.linspace(30,45,11))
# # cbar.set_label('90th centile')

X, Y = np.meshgrid(shearbins, qbins)
cmapp = uplot.discrete_cmap(10, base_cmap='RdBu')
ax5 = fig.add_subplot(339)
#outperc[outval<30] = np.nan
Zm = ma.masked_where(np.isnan(outperc), outperc)
mappable = ax5.pcolormesh(X, Y, Zm.T, cmap=cmapp, vmin=40,
                          vmax=70)  # viridis_r

ax5.set_ylabel('Max. q925hPa')
ax5.set_xlabel('Max. u925hPa (equally populated)')
ax5.set_title('')
cbar = fig.colorbar(mappable,
                    ticks=np.linspace(40, 70,
                                      11))  # ticks=np.linspace(30,45,11)
cbar.set_label('90th centile max. rain')

# ax5 = fig.add_subplot(235)
コード例 #2
0
def wav_checkDry():

    start_time = time.time()

    # smfile = '/users/global/cornkle/data/OBS/AMSRE/day_aqua/amsre_monthly_anomaly.nc'
    # sm = xr.open_dataset(smfile)
    # sm = sm.sel(lon=slice(-10, 10), lat=slice(10, 18))

    file = '/users/global/cornkle/data/OBS/MSG_LSTA/lsta_netcdf/lsta_daily_' + str(
        DATE['year']) + str(DATE['month']).zfill(2) + str(
            DATE['day']).zfill(2) + '.nc'

    ds = xr.open_dataset(file)

    ds = ds.sel(lon=slice(-10, 10), lat=slice(10, 18))

    lsta2 = ds['LSTA'][0, :, :]

    scales, power, lsta, inter, cells, lsta_raw, wll = run_waveletDry()

    print('Scales:', scales)

    latmin, latmax = (np.min(lsta['lat']), np.max(lsta['lat']))
    lonmin, lonmax = (np.min(lsta['lon']), np.max(lsta['lon']))

    daystring = str(DATE['year']) + '-' + str(
        DATE['month']).zfill(2) + '-' + str(DATE['day']).zfill(2)

    wllmean0 = wll

    xv, yv = np.meshgrid(lsta['lon'], lsta['lat'])
    cmap = u_plot.discrete_cmap(24, base_cmap='gist_ncar')

    f = plt.figure()

    ax1 = f.add_subplot(2, 2, 1)
    # cmap= plt.get_cmap('RdBu_r')
    # cmap.set_bad(color='gray', alpha=1.)
    # plt.pcolormesh(lsta['lon'], lsta['lat'], lsta_raw, vmin=-8, vmax=8, cmap=cmap)
    #
    # plt.colorbar()
    map = lsta.salem.get_map()
    xl, yl = map.grid.transform(xv, yv)
    map.set_data(lsta_raw)

    map.set_plot_params(cmap='RdBu_r', vmin=-8, vmax=8, extend='both')
    map.visualize(ax=ax1, addcbar=False)
    cax = ax1.scatter(xl, yl, c=cells, cmap=cmap, s=5)
    cbar = plt.colorbar(cax, ticks=np.arange(0, 24))
    cbar.set_ticklabels(np.array(np.arange(0, 24), dtype=str))

    plt.title(str(pd.to_datetime(lsta['time'].values)) + ' LSTA')

    ax2 = f.add_subplot(2, 2, 2)
    map.set_data(wllmean0)
    minscales = [np.flip(np.array(scales) * -1, axis=0), np.array(scales)]

    map.set_plot_params(cmap='RdBu_r', vmin=-200, vmax=200)
    map.visualize(ax=ax2, addcbar=True)
    #plt.contourf(day_small['lon'], day_small['lat'], day_small)
    # plt.pcolormesh(lsta['lon'], lsta['lat'], wllmean0, cmap='RdBu_r', vmin=-200, vmax=200)
    # plt.colorbar()
    ax2.scatter(xl, yl, c=cells, cmap=cmap, s=5)
    plt.title('Wavelet powers < 42km')

    ax3 = f.add_subplot(2, 2, 3)
    map.set_data(power)

    map.set_plot_params(cmap='RdBu_r', vmin=-10, vmax=10)
    map.visualize(ax=ax3, addcbar=True)
    ax2.scatter(xl, yl, c=cells, cmap=cmap, s=5)
    plt.title('Wavelet powers < 42km')
コード例 #3
0
def wav_checkDry():

    lsta, cells = run_waveletDry()

    xv, yv = np.meshgrid(lsta['lon'], lsta['lat'])

    cmap = u_plot.discrete_cmap(24, base_cmap='gist_ncar')

    era = xr.open_dataset(constants.ERA5 + 'ERA5_2008_12UTCpl.nc')
    eday = era.sel(time=str(DATE['year']) + str(DATE['month']).zfill(2) +
                   str(DATE['day']).zfill(2),
                   level=[950, 700])

    era_on_lsta = lsta.salem.transform(eday)

    shear = era_on_lsta['u'].sel(level=700).values - era_on_lsta['u'].sel(
        level=950).values
    era_on_lsta = era_on_lsta.sel(level=950)
    f = plt.figure()

    ax1 = f.add_subplot(2, 2, 1)

    map = lsta.salem.get_map()
    xl, yl = map.grid.transform(xv, yv)
    st = 20
    xquiv = xl[4::st, 4::st]
    yquiv = yl[4::st, 4::st]

    map.set_data(lsta)

    map.set_plot_params(cmap='RdBu_r', vmin=-8, vmax=8, extend='both')
    map.visualize(ax=ax1, addcbar=False)
    cax = ax1.scatter(xl, yl, c=cells, cmap=cmap, s=5)
    #cbar = plt.colorbar(cax, ticks=np.arange(0,24))
    #cbar.set_ticklabels(np.array(np.arange(0,24), dtype=str))

    plt.title(str(pd.to_datetime(lsta['time'].values)) + ' LSTA')

    ax2 = f.add_subplot(2, 2, 2)
    # plt.contourf(night['lon'], night['lat'], night)
    tera = shear  #era_on_lsta['t'].squeeze()-273.15
    map.set_data((tera))

    map.set_plot_params(cmap='jet', extend='both', vmin=-25,
                        vmax=-10)  #vmin=-0.1, vmax=0.1,
    #map.set_plot_params(cmap='RdBu_r', vmin=-8, vmax=8, extend='both')
    map.visualize(ax=ax2, addcbar=True)

    plt.scatter(xl, yl, c=cells, cmap=cmap, s=5)

    u = era_on_lsta['u'].squeeze()[4::st, 4::st]
    v = era_on_lsta['v'].squeeze()[4::st, 4::st]

    qu = ax2.quiver(xquiv, yquiv, u.values, v.values, scale=120)
    cax = ax2.scatter(xl, yl, c=cells, cmap=cmap, s=5)
    # qk = plt.quiverkey(qu, 0.7, 0.95, 3, '3 m s$^{-1}$',
    #                    labelpos='E', coordinates='figure')

    ax2 = f.add_subplot(2, 2, 3)
    # plt.contourf(night['lon'], night['lat'], night)
    tera = era_on_lsta['d'].squeeze() * 1000
    map.set_data((tera))

    map.set_plot_params(cmap='RdBu', extend='both', vmin=-0.1,
                        vmax=0.1)  # vmin=-0.1, vmax=0.1,
    # map.set_plot_params(cmap='RdBu_r', vmin=-8, vmax=8, extend='both')
    map.visualize(ax=ax2, addcbar=True)

    plt.scatter(xl, yl, c=cells, cmap=cmap, s=5)

    u = era_on_lsta['u'].squeeze()[4::st, 4::st]
    v = era_on_lsta['v'].squeeze()[4::st, 4::st]

    qu = ax2.quiver(xquiv, yquiv, u.values, v.values, scale=120)
    cax = ax2.scatter(xl, yl, c=cells, cmap=cmap, s=5)
コード例 #4
0
        print('bigger than',shl )
        print('smaller than', shearbins[issh+1])

        try:
            cmean = np.percentile(pp[poss], 90)

        except IndexError:
            cmean = np.nan

        prob = np.sum(pp[poss]>=30) / np.sum(pp[poss]>=1)


        outprob[issh,isq] = prob
        outperc[issh,isq] = cmean
        outval[issh,isq] = len(poss[0])

X, Y = np.meshgrid(shearbins,qbins)
cmapp = uplot.discrete_cmap(10, base_cmap='RdBu')
ax5 = fig.add_subplot(224)
#outperc[outval<30] = np.nan
Zm = ma.masked_where(np.isnan(outperc),outperc)
mappable = ax5.pcolormesh(X, Y, Zm.T, cmap=cmapp) # viridis_rvmin=20, vmax=40

ax5.set_ylabel('Max. q925hPa')
ax5.set_xlabel('Max. u925hPa (equally populated)')
ax5.set_title('')
cbar = fig.colorbar(mappable) # ticks=np.linspace(30,45,11) , ticks=np.linspace(20,40,11)
cbar.set_label('90th centile max. rain')
plt.show()
コード例 #5
0
def wav_checkDry():

    start_time = time.time()

    # smfile = '/users/global/cornkle/data/OBS/AMSRE/day_aqua/amsre_monthly_anomaly.nc'
    # sm = xr.open_dataset(smfile)
    # sm = sm.sel(lon=slice(-10, 10), lat=slice(10, 18))

    file = '/users/global/cornkle/data/OBS/MSG_LSTA/lsta_netcdf/lsta_daily_' + str(
        DATE['year']) + str(DATE['month']).zfill(2) + str(
            DATE['day']).zfill(2) + '.nc'
    ftopo = '/users/global/cornkle/data/pythonWorkspace/proj_CEH/topo/gtopo_1min_afr.nc'
    msg_t = '/users/global/cornkle/MCSfiles/blob_map_MCSs_-50_JJAS_points_dominant.nc'
    ds = xr.open_dataset(file)
    top = xr.open_dataarray(ftopo)
    msg = xr.open_dataarray(msg_t)
    msg.name = 'msg'

    ds = ds.sel(lon=slice(-10, 10), lat=slice(10, 20))
    top = top.sel(lon=slice(-10, 10), lat=slice(10, 20))
    msg = msg.sel(lon=slice(-10, 10),
                  lat=slice(10, 20),
                  time=slice('2006-06-28T17:00:00', '2006-06-29T15:00:00'))
    msg_mins = msg.min(dim='time')
    lsta2 = ds['LSTA'][0, :, :]

    wll, scales, power, lsta, inter, cells, lsta_raw = run_waveletDry()

    daystring = str(DATE['year']) + '-' + str(
        DATE['month']).zfill(2) + '-' + str(DATE['day']).zfill(2)

    wllmean0 = wll

    ppower_small = np.sum(power[0:4, :, :], axis=0)
    ppower_mid = np.sum(power[4:7, :, :], axis=0)
    ppower_big = np.sum(power[7::, :, :], axis=0)
    print('Small', scales[0:4])
    print('Mid', scales[4:7])
    print('Big', scales[7::])

    map = lsta.salem.get_map()

    xv, yv = np.meshgrid(lsta['lon'], lsta['lat'])
    xl, yl = map.grid.transform(xv, yv)

    cmap = u_plot.discrete_cmap(8, base_cmap='gnuplot2')  #gist_ncar
    cmap_back = u_plot.discrete_cmap(8, base_cmap='Greys')

    # era = xr.open_dataset(constants.ERA_DAILY_PL)
    # era = era.sel(latitude=slice(None, None, -1))
    #
    # eday = era.sel(
    #                time=str(DATE['year']) + str(DATE['month']).zfill(2) + str(DATE['day']).zfill(2), level=850)
    #
    # u = eday['u'].squeeze()
    # v = eday['v'].squeeze()
    # div = eday['d'].squeeze()
    #
    # u_plot.quick_map(div*1000, vmin=-0.01, vmax=0.01, cmap='RdBu')
    #
    #
    # # ws, wd = u_met.u_v_to_ws_wd(u.values,v.values)
    # # eday['ws10'] = (('time', 'latitude', 'longitude'), ws[None,...])
    # # eday['wd10'] = (('time', 'latitude', 'longitude'), wd[None, ...])
    # ws_on_lsta = ds.salem.transform(div)*1000
    # u_on_lsta = ds.salem.transform(u)
    # u_on_lsta = u_on_lsta[4::50, 4::50]
    # v_on_lsta = ds.salem.transform(v)
    # v_on_lsta = v_on_lsta[4::50, 4::50]
    # xe, ye = np.meshgrid(u_on_lsta['lon'], u_on_lsta['lat'])
    # xx, yy = map.grid.transform(xe, ye, crs=u.salem.grid.proj)

    # transform their coordinates to the map reference system and plot the arrows

    xi, yi = np.where(np.isfinite(cells))

    topo_on_lsta = ds.salem.lookup_transform(top)
    grad = np.gradient(topo_on_lsta.values)
    gradsum = abs(grad[0]) + abs(grad[1])
    msg_on_lsta = ds.salem.transform(msg_mins)
    topo_on_lsta.values[gradsum > 30] = np.nan
    topo_on_lsta.values[topo_on_lsta > 400] = np.nan

    for rh in [3, 6, 9, 12, 15, 18, 21, 24]:
        pos = np.where((cells <= rh) & (cells > rh - 3))

        if rh == 24:
            cells[pos] = 0
        else:
            cells[pos] = rh

    cmap2 = plt.get_cmap('RdBu_r')
    cmap2.set_bad('Grey', 1.)

    wavelet = plt.get_cmap('PuRd')
    wavelet.set_bad('Grey', 1.)

    # topobad = plt.get_cmap('topo')
    # topobad.set_bad('Grey', 1.)

    f = plt.figure(figsize=(13, 7))

    ax1 = f.add_subplot(2, 2, 1)
    masked = np.ma.masked_invalid(lsta_raw)
    map.set_data(masked, interp='linear')
    map.set_plot_params(cmap=cmap2,
                        levels=[-6, -4, -2, -1, -0.5, 0.5, 1, 2, 4, 6])
    #map.set_lonlat_contours(interval=0)

    map.visualize(
        ax=ax1,
        cbar_title='K',
        addcbar=True,
        title='28-06-2006: 0630-1600UTC LSTA & afternoon/nighttime cores')
    cax = ax1.scatter(xl, yl, c=cells, cmap=cmap_back, s=15)
    cax = ax1.scatter(xl, yl, c=cells, cmap=cmap, s=6)
    cbar = plt.colorbar(cax,
                        ticks=[0, 3, 6, 9, 12, 15, 18, 21],
                        fraction=0.07,
                        pad=0.5,
                        orientation='horizontal')
    cbar.set_ticklabels(
        ['22-0', '1-3', '4-6', '7-9', '10-12', '13-15', '16-18', '19-21'])
    cbar.set_label('Hours of day')
    ax1.get_xaxis().set_visible(False)

    # print('Topo min', np.min(topo_on_lsta))
    ax2 = f.add_subplot(2, 2, 2)
    map.set_plot_params(cmap='topo',
                        vmin=np.nanmin(topo_on_lsta),
                        vmax=1000,
                        extend='both')
    masked = np.ma.masked_invalid(topo_on_lsta)
    map.set_data(masked)
    map.set_contour(topo_on_lsta,
                    levels=np.arange(400, 1000, 25),
                    cmap='Greys_r')
    map.set_contour(msg_on_lsta, levels=np.arange(-80, -40, 5), cmap='jet_r')
    map.visualize(ax=ax2, addcbar=True)
    map.visualize(ax=ax2,
                  cbar_title='m',
                  title='Domain topography, total height difference: 342m')
    #cax = ax2.scatter(xl, yl, c=cells, cmap=cmap_back, s=20)
    #cax = ax2.scatter(xl, yl, c=cells, cmap=cmap, s=10)
    #plt.scatter(xv, yv, c=cells, cmap='jet', s=5)
    map.set_contour()

    ax3 = f.add_subplot(2, 2, 3)
    map.set_plot_params(cmap=wavelet, vmin=0, vmax=5)
    map.set_data(ppower_small)
    map.visualize(ax=ax3,
                  cbar_title='Wavelet power',
                  title='Surface scales 9 - 30km')
    #ax3.scatter(xl, yl, c=cells, cmap=cmap, s=5)
    #plt.scatter(xv, yv, c=cells, cmap='jet', s=5)

    ax4 = f.add_subplot(2, 2, 4)
    map.set_plot_params(cmap=wavelet, vmin=0, vmax=5)
    map.set_data(ppower_big)
    map.visualize(ax=ax4,
                  cbar_title='Wavelet power',
                  title='Surface scales 80 - 250km')
    #ax4.scatter(xl, yl, c=cells, cmap=cmap, s=5)

    plt.tight_layout()
コード例 #6
0
def plot_colormesh():


    dic = pkl.load( open(cnst.network_data + "figs/LSTA-bullshit/scales/new/dominant_scales_save/scales.p", "rb"))

    bin = np.array(dic['bin'])
    bin = bin[3:-3]
    center = bin[0:-1] + (bin[1::]-bin[0:-1])/2

    data = (dic['blob']- dic['scale'])/(dic['scale'])#dic['scale']#(np.sum(dic['blobc'], axis=0)/np.sum(dic['blobc']))## (np.sum(dic['blobc'], axis=0)/np.sum(dic['blobc'])) #dic['scale']  #(np.sum(dic['blobc'], axis=0)/np.sum(dic['blobc']))
    data = data[:,3:-3]*100
    # data[0:3,-5::]= np.abs(data[0:3,-5::])
    # data[3:7, -9:-4] = np.abs(data[3:7, -9:-4])
    f = plt.figure()
    plt.imshow(data, origin='lower')

    db = dic['blobc']
    filler = np.zeros_like(db)
    for i in range(db.shape[0]):
        for j in range(db.shape[1]):
            low , up = prop.proportion_confint(db[i,j], np.nansum(db[i,:]))

            unrange = (db[i,j] / np.nansum(db[i,:])) - low
            filler[i,j] = unrange

    #mask = np.zeros_like(db)
    #mask[filler[:,3:-3]>(np.abs(dic['blob'][:,3:-3]- dic['scale'][:,3:-3])+0.004)] = 1

    #mask = mask[:,-3:3]
    #data[np.where(mask)] = 0

    #data[np.where(data > 0)] += 1
    data[np.where(np.abs(data*100)<8)]=0
    levels=[-40,-30,-20,-10,-5,5,10,20,30,40]
    f = plt.figure(figsize=(7,5))
    ax = plt.subplot(111)

    pmap = ax.contourf(center, np.arange(0,24), data, levels=[-30, -20, -15, -10,-5,5,10,15, 20, 30], cmap='PuOr_r', extend='both')
    plt.axvline(0, c='k', linestyle='--')
    ax.set_xticks(center, minor=False)
    ax.set_xticklabels(np.array(center, dtype=int)) # center

    X, Y = np.meshgrid(center,np.arange(0,24))
    cmapp = uplot.discrete_cmap(9, base_cmap='RdBu_r')

    Zm = ma.masked_where(np.isnan(data),data)

    mappable = ax.pcolormesh(X, Y, Zm, cmap=cmapp, vmin=-35, vmax=35) # viridis_rvmin=20, vmax=40
    ax.set_ylabel('Time of day')
    ax.set_xlabel('Scale of pos/neg. amplitude (km)')

    cbar = f.colorbar(mappable, ticks=np.linspace(-35,35,10)) # ticks=np.linspace(30,45,11) , ticks=np.linspace(20,40,11)
    cbar.set_label('Difference in surface-scale frequency (%)')


    # cbar = plt.colorbar(pmap)
    # cbar.set_label('Difference in scale frequency | Blobs')

    # ax.set_yticks(np.arange(0,24), minor=False)
    # ax.set_yticklabels(np.arange(0,24))
    # ax.set_xlabel('Scales of pos/neg. amplitude (km)')
    # ax.set_ylabel('Time of day')


    ax1 = ax.twinx()
    ax1.set_yticks(np.arange(dic['blob'].shape[0]), minor=False)
    ax1.set_yticklabels(dic['nblobs'])

    plt.tight_layout()
    f.subplots_adjust(right=0.81)
    cax = f.add_axes([0.89, 0.15, 0.02, 0.75])
    # cbar = f.colorbar(pmap, cax)
    # cbar.ax.tick_params(labelsize=11)
    # cbar.set_label('Difference in surface-scale frequency (%)', fontsize=11)

    plt.show()
コード例 #7
0
ファイル: scatter_scales.py プロジェクト: adambamba/proj_CEH
def plot():
    dic = pkl.load(
        open(
            "/users/global/cornkle/figs/LSTA-bullshit/scales/new/dominant_scales_save/scatter_scales.p",
            "rb"))

    cmap = u_plot.discrete_cmap(24, base_cmap='jet')

    f = plt.figure()
    ax = plt.subplot(111)

    chourly = []
    shourly = []
    smhourly = []
    cmhourly = []
    sstd = []
    cstd = []
    hh = []
    for h in range(0, 24, 1):
        c = np.mean(
            dic['cell'][(dic['hour'] == h) & (dic['cell'] >= 15) &
                        (dic['surface'] > 9)])  #& (dic['surface'] < 130)
        s = np.mean(
            np.abs(dic['surface'][(dic['hour'] == h) & (dic['cell'] >= 15) &
                                  (dic['surface'] > 9)]))
        sm = np.mean(dic['surface'][(dic['hour'] == h) & (dic['cell'] >= 15) &
                                    (dic['surface'] < -9)])
        cm = np.mean(
            dic['cell'][(dic['hour'] == h) & (dic['cell'] >= 15) &
                        (dic['surface'] < -9)])  # & (dic['surface'] < 130)

        chourly.append(c)
        shourly.append(s)
        smhourly.append(sm)
        cmhourly.append(cm)
        hh.append(h)

    plt.scatter(chourly, shourly, c=hh, cmap=cmap)
    # plt.errorbar(chourly, shourly, cstd, sstd)
    plt.colorbar()

    clouds = []
    hhh = []
    for h in range(0, 24, 1):
        c = np.mean(dic['cell'][(dic['hour'] == h) & (dic['cell'] >= 15)])
        clouds.append(c)
        hhh.append(h)
    f = plt.figure(figsize=(4, 10))
    ax = plt.subplot(311)
    plt.scatter(hh, chourly, c=hhh, cmap=cmap, edgecolors='k', s=50)
    plt.xlabel('Time of day')
    plt.ylabel('Average cloud core scale (km)')
    ax = plt.subplot(312)
    mpl = plt.scatter(shourly, chourly, c=hh, cmap=cmap, edgecolors='k', s=50)
    plt.xlabel('Average surface scale (km)')
    plt.ylabel('Average cloud core scale (km)')
    plt.title('Warm features', fontsize=10)
    ax = plt.subplot(313)
    mpl = plt.scatter(smhourly,
                      cmhourly,
                      c=hh,
                      cmap=cmap,
                      edgecolors='k',
                      s=50)
    plt.xlabel('Average surface scale (km)')
    plt.ylabel('Average cloud core scale (km)')
    plt.title('Cold features', fontsize=10)
    #plt.colorbar(mpl)
    plt.tight_layout()

    f.subplots_adjust(right=0.83)
    cax = f.add_axes([0.85, 0.33, 0.035, 0.35])
    cbar = f.colorbar(mpl, cax)
    cbar.ax.tick_params(labelsize=10)
    cbar.set_ticklabels(np.arange(0, 24))
    cbar.set_label('Time of day', fontsize=10)
コード例 #8
0
ファイル: scatter_scales.py プロジェクト: cornkle/proj_CEH
def plot():
    dic = pkl.load(
        open("/users/global/cornkle/figs/LSTA-bullshit/scales/new/dominant_scales_save/scatter_scales.p", "rb"))

    cmap = u_plot.discrete_cmap(24, base_cmap='jet')

    f = plt.figure()
    ax = plt.subplot(111)

    chourly = []
    shourly = []
    smhourly = []
    cmhourly = []
    sstd = []
    cstd = []
    hh = []
    for h in range(0,24,1):
        c = np.mean(dic['cell'][(dic['hour']==h) & (dic['cell']>=15)  & (dic['surface'] > 9)]) #& (dic['surface'] < 130)
        s = np.mean(np.abs(dic['surface'][(dic['hour']==h) & (dic['cell']>=15)& (dic['surface'] > 9)]))
        sm = np.mean(dic['surface'][(dic['hour'] == h) & (dic['cell'] >= 15) & (dic['surface'] < -9)])
        cm = np.mean(
            dic['cell'][(dic['hour'] == h) & (dic['cell'] >= 15) & (dic['surface'] < -9)])  # & (dic['surface'] < 130)

        chourly.append(c)
        shourly.append(s)
        smhourly.append(sm)
        cmhourly.append(cm)
        hh.append(h)

    plt.scatter(chourly, shourly, c=hh, cmap=cmap)
   # plt.errorbar(chourly, shourly, cstd, sstd)
    plt.colorbar()

    clouds = []
    hhh = []
    for h in range(0,24,1):
        c = np.mean(dic['cell'][(dic['hour']==h) & (dic['cell']>=15)])
        clouds.append(c)
        hhh.append(h)
    f = plt.figure(figsize=(4,10))
    ax = plt.subplot(311)
    plt.scatter(hh, chourly, c=hhh, cmap=cmap, edgecolors='k', s=50)
    plt.xlabel('Time of day')
    plt.ylabel('Average cloud core scale (km)')
    ax = plt.subplot(312)
    mpl = plt.scatter(shourly, chourly, c=hh, cmap=cmap, edgecolors='k', s=50)
    plt.xlabel('Average surface scale (km)')
    plt.ylabel('Average cloud core scale (km)')
    plt.title('Warm features', fontsize=10)
    ax = plt.subplot(313)
    mpl = plt.scatter(smhourly, cmhourly, c=hh, cmap=cmap, edgecolors='k', s=50)
    plt.xlabel('Average surface scale (km)')
    plt.ylabel('Average cloud core scale (km)')
    plt.title('Cold features', fontsize=10)
    #plt.colorbar(mpl)
    plt.tight_layout()

    f.subplots_adjust(right=0.83)
    cax = f.add_axes([0.85, 0.33, 0.035, 0.35])
    cbar = f.colorbar(mpl, cax)
    cbar.ax.tick_params(labelsize=10)
    cbar.set_ticklabels(np.arange(0,24))
    cbar.set_label('Time of day', fontsize=10)
コード例 #9
0
def wav_checkDry():

    start_time = time.time()

    # smfile = '/users/global/cornkle/data/OBS/AMSRE/day_aqua/amsre_monthly_anomaly.nc'
    # sm = xr.open_dataset(smfile)
    # sm = sm.sel(lon=slice(-10, 10), lat=slice(10, 18))


    file = '/users/global/cornkle/data/OBS/MSG_LSTA/lsta_netcdf/lsta_daily_'+str(DATE['year'])+str(DATE['month']).zfill(2)+str(DATE['day']).zfill(2)+'.nc'
    ftopo = '/users/global/cornkle/data/pythonWorkspace/proj_CEH/topo/gtopo_1min_afr.nc'
    msg_t = '/users/global/cornkle/MCSfiles/blob_map_MCSs_-50_JJAS_points_dominant.nc'
    ds = xr.open_dataset(file)
    top = xr.open_dataarray(ftopo)
    msg = xr.open_dataarray(msg_t)
    msg.name = 'msg'

    ds = ds.sel(lon=slice(-10,10), lat=slice(10,20))
    top = top.sel(lon=slice(-10, 10), lat=slice(10, 20))
    msg = msg.sel(lon=slice(-10, 10), lat=slice(10, 20), time=slice('2006-06-28T17:00:00','2006-06-29T15:00:00'))
    msg_mins = msg.min(dim='time')
    lsta2 = ds['LSTA'][0,:,:]

    wll, scales, power, lsta, inter, cells, lsta_raw = run_waveletDry()

    daystring = str(DATE['year'])+'-'+str(DATE['month']).zfill(2)+'-'+str(DATE['day']).zfill(2)

    wllmean0=wll

    ppower_small = np.sum(power[0:4,:,:], axis=0)
    ppower_mid = np.sum(power[4:7, :, :], axis=0)
    ppower_big = np.sum(power[7::, :, :], axis=0)
    print('Small', scales[0:4])
    print('Mid', scales[4:7])
    print('Big', scales[7::])

    map = lsta.salem.get_map()

    xv, yv = np.meshgrid(lsta['lon'], lsta['lat'])
    xl, yl = map.grid.transform(xv, yv)

    cmap = u_plot.discrete_cmap(8, base_cmap='gnuplot2')  #gist_ncar
    cmap_back = u_plot.discrete_cmap(8, base_cmap='Greys')

    # era = xr.open_dataset(constants.ERA_DAILY_PL)
    # era = era.sel(latitude=slice(None, None, -1))
    #
    # eday = era.sel(
    #                time=str(DATE['year']) + str(DATE['month']).zfill(2) + str(DATE['day']).zfill(2), level=850)
    #
    # u = eday['u'].squeeze()
    # v = eday['v'].squeeze()
    # div = eday['d'].squeeze()
    #
    # u_plot.quick_map(div*1000, vmin=-0.01, vmax=0.01, cmap='RdBu')
    #
    #
    # # ws, wd = u_met.u_v_to_ws_wd(u.values,v.values)
    # # eday['ws10'] = (('time', 'latitude', 'longitude'), ws[None,...])
    # # eday['wd10'] = (('time', 'latitude', 'longitude'), wd[None, ...])
    # ws_on_lsta = ds.salem.transform(div)*1000
    # u_on_lsta = ds.salem.transform(u)
    # u_on_lsta = u_on_lsta[4::50, 4::50]
    # v_on_lsta = ds.salem.transform(v)
    # v_on_lsta = v_on_lsta[4::50, 4::50]
    # xe, ye = np.meshgrid(u_on_lsta['lon'], u_on_lsta['lat'])
    # xx, yy = map.grid.transform(xe, ye, crs=u.salem.grid.proj)

    # transform their coordinates to the map reference system and plot the arrows


    xi, yi = np.where(np.isfinite(cells))

    topo_on_lsta = ds.salem.lookup_transform(top)
    grad = np.gradient(topo_on_lsta.values)
    gradsum = abs(grad[0]) + abs(grad[1])
    msg_on_lsta = ds.salem.transform(msg_mins)
    topo_on_lsta.values[gradsum > 30] = np.nan
    topo_on_lsta.values[topo_on_lsta>400] = np.nan



    for rh in [3,6,9,12,15,18,21,24]:
        pos = np.where((cells<=rh) & (cells>rh-3))

        if rh == 24:
            cells[pos] = 0
        else:
            cells[pos] = rh

    cmap2 = plt.get_cmap('RdBu_r')
    cmap2.set_bad('Grey', 1.)

    wavelet = plt.get_cmap('PuRd')
    wavelet.set_bad('Grey', 1.)

    # topobad = plt.get_cmap('topo')
    # topobad.set_bad('Grey', 1.)

    f= plt.figure(figsize=(13,7))

    ax1=f.add_subplot(2,2,1)
    masked = np.ma.masked_invalid(lsta_raw)
    map.set_data(masked, interp='linear')
    map.set_plot_params(cmap=cmap2, levels=[-6,-4,-2,-1,-0.5,0.5,1,2,4,6])
    #map.set_lonlat_contours(interval=0)

    map.visualize(ax=ax1, cbar_title='K', addcbar=True, title='28-06-2006: 0630-1600UTC LSTA & afternoon/nighttime cores')
    cax = ax1.scatter(xl, yl, c=cells, cmap=cmap_back, s=15)
    cax = ax1.scatter(xl, yl, c=cells, cmap=cmap, s=6)
    cbar = plt.colorbar(cax, ticks=[0,3,6,9,12,15,18,21], fraction=0.07, pad=0.5, orientation='horizontal')
    cbar.set_ticklabels([ '22-0','1-3','4-6','7-9','10-12','13-15', '16-18', '19-21'])
    cbar.set_label('Hours of day')
    ax1.get_xaxis().set_visible(False)

    # print('Topo min', np.min(topo_on_lsta))
    ax2 = f.add_subplot(2, 2, 2)
    map.set_plot_params(cmap='topo', vmin=np.nanmin(topo_on_lsta), vmax=1000, extend='both')
    masked = np.ma.masked_invalid(topo_on_lsta)
    map.set_data(masked)
    map.set_contour(topo_on_lsta, levels=np.arange(400,1000,25), cmap='Greys_r')
    map.set_contour(msg_on_lsta, levels=np.arange(-80,-40,5), cmap='jet_r')
    map.visualize(ax=ax2, addcbar=True )
    map.visualize(ax=ax2, cbar_title='m', title='Domain topography, total height difference: 342m')
    #cax = ax2.scatter(xl, yl, c=cells, cmap=cmap_back, s=20)
    #cax = ax2.scatter(xl, yl, c=cells, cmap=cmap, s=10)
    #plt.scatter(xv, yv, c=cells, cmap='jet', s=5)
    map.set_contour()

    ax3 = f.add_subplot(2, 2, 3)
    map.set_plot_params(cmap=wavelet, vmin=0, vmax=5)
    map.set_data(ppower_small)
    map.visualize(ax=ax3, cbar_title='Wavelet power', title='Surface scales 9 - 30km')
    #ax3.scatter(xl, yl, c=cells, cmap=cmap, s=5)
    #plt.scatter(xv, yv, c=cells, cmap='jet', s=5)

    ax4 = f.add_subplot(2, 2, 4)
    map.set_plot_params(cmap=wavelet, vmin=0, vmax=5)
    map.set_data(ppower_big)
    map.visualize(ax=ax4, cbar_title='Wavelet power', title='Surface scales 80 - 250km')
    #ax4.scatter(xl, yl, c=cells, cmap=cmap, s=5)

    plt.tight_layout()
コード例 #10
0
def wav_checkDry():

    start_time = time.time()

    # smfile = '/users/global/cornkle/data/OBS/AMSRE/day_aqua/amsre_monthly_anomaly.nc'
    # sm = xr.open_dataset(smfile)
    # sm = sm.sel(lon=slice(-10, 10), lat=slice(10, 18))


    file = '/users/global/cornkle/data/OBS/MSG_LSTA/lsta_netcdf/lsta_daily_'+str(DATE['year'])+str(DATE['month']).zfill(2)+str(DATE['day']).zfill(2)+'.nc'

    ds = xr.open_dataset(file)

    ds = ds.sel(lon=slice(-10,10), lat=slice(10,18))

    lsta2 = ds['LSTA'][0,:,:]


    scales, power, lsta, inter, cells, lsta_raw , wll= run_waveletDry()

    print('Scales:', scales)

    latmin, latmax = (np.min(lsta['lat']), np.max(lsta['lat']))
    lonmin, lonmax = (np.min(lsta['lon']), np.max(lsta['lon']))

    daystring = str(DATE['year'])+'-'+str(DATE['month']).zfill(2)+'-'+str(DATE['day']).zfill(2)

    wllmean0=wll

    xv, yv = np.meshgrid(lsta['lon'], lsta['lat'])
    cmap = u_plot.discrete_cmap(24, base_cmap='gist_ncar')

    f= plt.figure()

    ax1=f.add_subplot(2,2,1)
    # cmap= plt.get_cmap('RdBu_r')
    # cmap.set_bad(color='gray', alpha=1.)
    # plt.pcolormesh(lsta['lon'], lsta['lat'], lsta_raw, vmin=-8, vmax=8, cmap=cmap)
    #
    # plt.colorbar()
    map = lsta.salem.get_map()
    xl, yl = map.grid.transform(xv, yv)
    map.set_data(lsta_raw)

    map.set_plot_params(cmap='RdBu_r', vmin=-8, vmax=8, extend='both')
    map.visualize(ax=ax1, addcbar=False )
    cax = ax1.scatter(xl, yl, c=cells, cmap=cmap, s=5)
    cbar = plt.colorbar(cax, ticks=np.arange(0,24))
    cbar.set_ticklabels(np.array(np.arange(0,24), dtype=str))


    plt.title(str(pd.to_datetime(lsta['time'].values))+' LSTA')



    ax2 = f.add_subplot(2, 2, 2)
    map.set_data(wllmean0)
    minscales = [np.flip(np.array(scales)*-1, axis=0), np.array(scales)]

    map.set_plot_params(cmap='RdBu_r', vmin=-200, vmax=200)
    map.visualize(ax=ax2, addcbar=True)
    #plt.contourf(day_small['lon'], day_small['lat'], day_small)
    # plt.pcolormesh(lsta['lon'], lsta['lat'], wllmean0, cmap='RdBu_r', vmin=-200, vmax=200)
    # plt.colorbar()
    ax2.scatter(xl, yl, c=cells, cmap=cmap, s=5)
    plt.title('Wavelet powers < 42km')

    ax3 = f.add_subplot(2, 2, 3)
    map.set_data(power)

    map.set_plot_params(cmap='RdBu_r', vmin=-10, vmax=10)
    map.visualize(ax=ax3, addcbar=True)
    ax2.scatter(xl, yl, c=cells, cmap=cmap, s=5)
    plt.title('Wavelet powers < 42km')