Exemple #1
0
def mapDomains(includePMSL=False):
    """Creates a map of the outer domain, showing
    the location of the inner domains.
    If includePMSL is True contours of sea level pressure is
    plotted as well (if a WPS-file is found)
    """
    nc1 = openWRF(1)
    nc2 = openWRF(2)
    nc3 = openWRF(3)
    nc4 = openWRF(4)
    m = _getMapForNC(nc1)

    if includePMSL:
        met1 = openWPS(1)
        if met1 is not None:
            PMSL = met1.variables["PMSL"][0]
            _Nx1, _Ny1, _Nz1, longitude1, latitude1, _dx, _dy, _x, _y = getDimensions(nc1)
            x, y = m(longitude1, latitude1)
            cs = plt.contour(x, y, PMSL / 100.0, pmsl_int, colors="black")
            plt.clabel(cs, inline=1, fmt="%1.0f", fontsize=11)
        else:
            print "Could not find wps-file, PMSL not plotted"

    if nc2 is not None:
        _plotBorder(nc2, m)
    if nc3 is not None:
        _plotBorder(nc3, m)
    if nc4 is not None:
        _plotBorder(nc4, m)

    plt.show()
    plt.close()
Exemple #2
0
def mapWind(nest, time):
    """Creates a map of the domain, showing
    wind barbs for the given time
    """
    nc = openWRF(nest)
    nc1 = openWRF(nest + 1)
    Nx, Ny, _Nz, longitude, latitude, _dx, _dy, _x, _y = getDimensions(nc)
    m = _getMapForNC(nc, False, _getDL(nest), 100)
    _makeDots(m)
    u10 = nc.variables["U10"][time, :, :]
    v10 = nc.variables["V10"][time, :, :]
    # Use data from every 10th grid point
    windx = 1 + Nx / 10
    windy = 1 + Ny / 10
    lat10 = np.zeros((windy, windx))
    lon10 = np.zeros((windy, windx))
    uwind = np.zeros((windy, windx))
    vwind = np.zeros((windy, windx))
    for j in range(windy):
        for i in range(windx):
            uwind[j, i] = 0.5 * (u10[j * 10, i * 10] + u10[j * 10, i * 10 + 1])
            # print 'u: ' + str(uwind[j,i])
            vwind[j, i] = 0.5 * (v10[j * 10, i * 10] + v10[j * 10 + 1, i * 10])
            # print 'v: ' + str(vwind[j,i])
            lat10[j, i] = latitude[j * 10, i * 10]
            lon10[j, i] = longitude[j * 10, i * 10]

    x10, y10 = m(lon10, lat10)
    plt.barbs(x10, y10, uwind, vwind, barb_increments=barb_increments, linewidth=1.0, color="green")

    if nc1 is not None:
        _plotBorder(nc1, m, "black")
    plt.show()
    plt.close()
Exemple #3
0
def mapTerrain(nest, includePMSL=False, includeTemp=False):
    """Creates a map of the domain, showing
    filled contours of the terrain
    """
    nc = openWRF(nest)
    met = openWPS(nest)
    nc1 = openWRF(nest + 1)
    _Nx, _Ny, _Nz, longitude, latitude, _dx, _dy, _x, _y = getDimensions(nc)

    m = _getMapForNC(nc, False, _getDL(nest), 100)
    x, y = m(longitude, latitude)
    _makeDots(m)

    if includeTemp and met is not None:
        ST = met.variables["TT"][0][0, :, :]
        cs = plt.contour(x, y, ST - T_zero, arange(-48, 50, 2.0), colors="blue", linestyles="solid")
        plt.clabel(cs, inline=1, fmt="%1.0f", fontsize=12)
    if includePMSL and met is not None:
        levels = arange(960.0, 1040.0, 1.0)
        PMSL = met.variables["PMSL"][0]
        cs = plt.contour(x, y, PMSL / 100.0, levels, colors="black", label="Pressure")
        plt.clabel(cs, inline=1, fmt="%1.0f", fontsize=11)

    heightground = (nc.variables["PH"][0][0, :, :] + nc.variables["PHB"][0][0, :, :]) / g
    plt.contourf(x, y, heightground, levels=arange(0, max_h, 100), cmap=cmap_grey, extend="max")
    plt.colorbar()
    if nc1 is not None:
        _plotBorder(nc1, m, "black")
    plt.show()
    plt.close()
Exemple #4
0
def mapTerrain(nest,includePMSL=False,includeTemp=False):
    """Creates a map of the domain, showing
    filled contours of the terrain
    """
    nc = openWRF(nest)
    met = openWPS(nest)
    nc1 = openWRF(nest+1)
    _Nx,_Ny,_Nz,longitude,latitude,_dx,_dy,_x,_y = getDimensions(nc)

    m = _getMapForNC(nc,False,_getDL(nest),100)
    x, y = m(longitude,latitude)
    _makeDots(m)
    
    if (includeTemp and met is not None):
        ST = met.variables['TT'][0][0,:,:]
        cs = plt.contour(x,y, ST-T_zero,arange(-48,50,2.),colors='blue',linestyles='solid')
        plt.clabel(cs, inline=1,  fmt='%1.0f', fontsize=12)
    if (includePMSL and met is not None):
        levels = arange(960.,1040.,1.)
        PMSL = met.variables['PMSL'][0]
        cs = plt.contour(x,y, PMSL/100.,levels,colors='black',label='Pressure')
        plt.clabel(cs, inline=1,  fmt='%1.0f', fontsize=11)

    heightground = (nc.variables['PH'][0][0,:,:] + nc.variables['PHB'][0][0,:,:])/g
    plt.contourf(x, y, heightground, levels=arange(0,max_h,100),cmap=cmap_grey,extend='max')
    plt.colorbar()
    if (nc1 is not None):
        _plotBorder(nc1,m,'black')
    plt.show()  
    plt.close()
Exemple #5
0
def mapDomains(includePMSL=False):
    """Creates a map of the outer domain, showing
    the location of the inner domains.
    If includePMSL is True contours of sea level pressure is
    plotted as well (if a WPS-file is found)
    """
    nc1 = openWRF(1)
    nc2 = openWRF(2)
    nc3 = openWRF(3)
    nc4 = openWRF(4)
    m = _getMapForNC(nc1)

    if includePMSL:
        met1 = openWPS(1)
        if met1 is not None:
            PMSL = met1.variables['PMSL'][0]
            _Nx1, _Ny1, _Nz1, longitude1, latitude1, _dx, _dy, _x, _y = getDimensions(
                nc1)
            x, y = m(longitude1, latitude1)
            cs = plt.contour(x, y, PMSL / 100., pmsl_int, colors='black')
            plt.clabel(cs, inline=1, fmt='%1.0f', fontsize=11)
        else:
            print 'Could not find wps-file, PMSL not plotted'

    if (nc2 is not None):
        _plotBorder(nc2, m)
    if (nc3 is not None):
        _plotBorder(nc3, m)
    if (nc4 is not None):
        _plotBorder(nc4, m)

    plt.show()
    plt.close()
Exemple #6
0
def mapCloud(nest, time):
    """Creates a map of the domain, showing
    filled contours of the cloud water
    """
    nc = openWRF(nest)
    _Nx, _Ny, _Nz, longitude, latitude, _dx, _dy, _x, _y = getDimensions(nc)

    m = _getMapForNC(nc, False, _getDL(nest), 100)
    x, y = m(longitude, latitude)

    qcloud = 1000.0 * np.sum(nc.variables["QCLOUD"][time, :, :, :], axis=0)
    plt.contourf(x, y, qcloud, cmap=cmap_red)
    plt.colorbar()
    plt.show()
    plt.close()
Exemple #7
0
def mapCloud(nest, time):
    """Creates a map of the domain, showing
    filled contours of the cloud water
    """
    nc = openWRF(nest)
    _Nx, _Ny, _Nz, longitude, latitude, _dx, _dy, _x, _y = getDimensions(nc)

    m = _getMapForNC(nc, False, _getDL(nest), 100)
    x, y = m(longitude, latitude)

    qcloud = 1000.0 * np.sum(nc.variables['QCLOUD'][time, :, :, :], axis=0)
    plt.contourf(x, y, qcloud, cmap=cmap_red)
    plt.colorbar()
    plt.show()
    plt.close()
Exemple #8
0
def mapTerrain(nest, includePMSL=False, includeTemp=False):
    """Creates a map of the domain, showing
    filled contours of the terrain
    """
    nc = openWRF(nest)
    met = openWPS(nest)
    nc1 = openWRF(nest + 1)
    _Nx, _Ny, _Nz, longitude, latitude, _dx, _dy, _x, _y = getDimensions(nc)

    m = _getMapForNC(nc, False, _getDL(nest), 100)
    x, y = m(longitude, latitude)
    _makeDots(m)

    if (includeTemp and met is not None):
        ST = met.variables['TT'][0][0, :, :]
        cs = plt.contour(x,
                         y,
                         ST - T_zero,
                         arange(-48, 50, 2.),
                         colors='blue',
                         linestyles='solid')
        plt.clabel(cs, inline=1, fmt='%1.0f', fontsize=12)
    if (includePMSL and met is not None):
        levels = arange(960., 1040., 1.)
        PMSL = met.variables['PMSL'][0]
        cs = plt.contour(x,
                         y,
                         PMSL / 100.,
                         levels,
                         colors='black',
                         label='Pressure')
        plt.clabel(cs, inline=1, fmt='%1.0f', fontsize=11)

    heightground = (nc.variables['PH'][0][0, :, :] +
                    nc.variables['PHB'][0][0, :, :]) / g
    plt.contourf(x,
                 y,
                 heightground,
                 levels=arange(0, max_h, 100),
                 cmap=cmap_grey,
                 extend='max')
    plt.colorbar()
    if (nc1 is not None):
        _plotBorder(nc1, m, 'black')
    plt.show()
    plt.close()
Exemple #9
0
def xzCloudPlot(nest,time,plotTemp=True,plotRH=False):
    nc = openWRF(nest)
    Nx,Ny,Nz,longitude,_lats,_dx,_dy,x_nr,y_nr = getDimensions(nc)
    
    heightground_x,heighthalf_xz = _getHeight(nc, time, Nx, -1, Nz, -1, y_nr)    
    print 'Model height: ' + str(heightground_x[x_nr])

    theta = nc.variables['T'][time,:,y_nr,:] + T_base 
    P = nc.variables['P'][time,:,y_nr,:] + nc.variables['PB'][time,:,y_nr,:] 
    T = theta*(P/P_bot)**kappa # Temperatur i halvflatene (Kelvin)
    rho = P/(R*T) #[kg/m3]

    qcloud_xz = 1000.0*nc.variables['QCLOUD'][time,:,y_nr,:]*rho # regner om til g/m3
    qrain_xz = 1000.0*nc.variables['QRAIN'][time,:,y_nr,:]*rho 
    qsnow_xz = 1000.0*nc.variables['QSNOW'][time,:,y_nr,:]*rho 
   
    plt.figure()
    plt.set_cmap(cmap_red)
    plt.axis([0,Nx-1,0.0,z_max])
    print u'Cloud water red, snow blue, rain green ($g/m^3$)'
    grid = np.reshape(np.tile(arange(Nx),Nz),(Nz,-1))
    plt.contourf(grid, heighthalf_xz, qcloud_xz, alpha=0.9,levels=xz_cloudwater_levels, cmap=cmap_red)#
    plt.colorbar()
    plt.contourf(grid, heighthalf_xz, qrain_xz, alpha=0.6,levels=xz_rain_levels, cmap=cmap_green)#
    plt.colorbar()
    plt.contourf(grid, heighthalf_xz, qsnow_xz, alpha=0.6,levels=xz_snow_levels,cmap=cmap_blue)# 
    plt.colorbar()

    if plotTemp:
        temp_int = arange(-80.0,50.0,2.0)
        cs = plt.contour(grid, heighthalf_xz, T-T_zero, temp_int,colors='black',linestyles='solid')#linewidths=4
        plt.clabel(cs, inline=1,  fmt='%1.0f', fontsize=12,colors='black')
    if plotRH:
        rh = _getRH(nc,time,-1,y_nr,T,P)
        rh_int = arange(90.,111.,5.)
        cs = plt.contour(grid, heighthalf_xz,rh , rh_int, colors='grey')
        plt.clabel(cs, inline=1,  fmt='%1.0f', fontsize=12, colors='grey')
    plt.plot(arange(Nx),heightground_x,color='black')
    plt.fill_between(arange(Nx),heightground_x,0,facecolor='lightgrey')
    plt.xticks(np.arange(0,Nx,8),np.round(longitude[Ny/2,::8], 1), fontsize='small')
    plt.yticks(np.arange(0,z_max,dz), fontsize='small')
    plt.xlabel('Lengdegrad')
    plt.ylabel(u'Høyde [m]')
    plt.show()
    plt.close()        
Exemple #10
0
def skewTPlot(nest, time):
    """
     This is the method to use from the outside
     
     nest: The nesting level of the nc-file from WRF 
     time: The time for which to plot
    """
    nc = openWRF(nest)
    _Nx, _Ny, _Nz, _longs, _lats, _dx, _dy, x, y = getDimensions(nc)

    plt.figure()
    _isotherms()
    _isobars()
    _dry_adiabats()
    _moist_adiabats()

    P = nc.variables['P'][time, :, y, x] + nc.variables['PB'][time, :, y, x]

    _windbarbs(nc, time, y, x, P)
    _temperature(nc, time, y, x, P)
    _dewpoint(nc, time, y, x, P)

    plt.axis([-40, 50, P_b, P_t])
    plt.xlabel('Temperatur ($^{\circ}\! C$) ved 1000hPa')
    xticks = np.arange(-40, 51, 5)
    plt.xticks(xticks,
               ['' if tick % 10 != 0 else str(tick) for tick in xticks])
    plt.ylabel('Trykk (hPa)')
    yticks = np.arange(P_bot, P_t - 1, -10**4)
    plt.yticks(yticks, yticks / 100)

    sfcT = nc.variables['T2'][time, y, x] - T_zero
    sfcP = nc.variables['PSFC'][time, y, x]
    sfcW = nc.variables['Q2'][time, y, x]
    sfcTd = td(e(sfcW, sfcP))
    plt.suptitle('Bakketemp: %4.1f$^{\circ}\! C$  Duggpunkt: %3.1f$^{\circ}\! C$  Trykk: %5.1f hPa' % (sfcT,sfcTd,0.01*sfcP), \
                 fontsize=10, x = 0.5, y = 0.03)

    plt.show()
    plt.close()
Exemple #11
0
def mapWind(nest, time):
    """Creates a map of the domain, showing
    wind barbs for the given time
    """
    nc = openWRF(nest)
    nc1 = openWRF(nest + 1)
    Nx, Ny, _Nz, longitude, latitude, _dx, _dy, _x, _y = getDimensions(nc)
    m = _getMapForNC(nc, False, _getDL(nest), 100)
    _makeDots(m)
    u10 = nc.variables['U10'][time, :, :]
    v10 = nc.variables['V10'][time, :, :]
    # Use data from every 10th grid point
    windx = 1 + Nx / 10
    windy = 1 + Ny / 10
    lat10 = np.zeros((windy, windx))
    lon10 = np.zeros((windy, windx))
    uwind = np.zeros((windy, windx))
    vwind = np.zeros((windy, windx))
    for j in range(windy):
        for i in range(windx):
            uwind[j, i] = 0.5 * (u10[j * 10, i * 10] + u10[j * 10, i * 10 + 1])
            #print 'u: ' + str(uwind[j,i])
            vwind[j, i] = 0.5 * (v10[j * 10, i * 10] + v10[j * 10 + 1, i * 10])
            #print 'v: ' + str(vwind[j,i])
            lat10[j, i] = latitude[j * 10, i * 10]
            lon10[j, i] = longitude[j * 10, i * 10]

    x10, y10 = m(lon10, lat10)
    plt.barbs(x10,
              y10,
              uwind,
              vwind,
              barb_increments=barb_increments,
              linewidth=1.0,
              color='green')

    if (nc1 is not None):
        _plotBorder(nc1, m, 'black')
    plt.show()
    plt.close()
Exemple #12
0
def skewTPlot(nest,time):   
    """
     This is the method to use from the outside
     
     nest: The nesting level of the nc-file from WRF 
     time: The time for which to plot
    """  
    nc = openWRF(nest)
    _Nx,_Ny,_Nz,_longs,_lats,_dx,_dy,x,y = getDimensions(nc)

    plt.figure()
    _isotherms()
    _isobars()
    _dry_adiabats()
    _moist_adiabats()

    P = nc.variables['P'][time,:,y,x] + nc.variables['PB'][time,:,y,x] 
    
    _windbarbs(nc,time,y,x,P)
    _temperature(nc,time,y,x,P)
    _dewpoint(nc,time,y,x,P)
    
    plt.axis([-40,50,P_b,P_t])
    plt.xlabel('Temperatur ($^{\circ}\! C$) ved 1000hPa')
    xticks = np.arange(-40,51,5)
    plt.xticks(xticks,['' if tick%10!=0 else str(tick) for tick in xticks])
    plt.ylabel('Trykk (hPa)')
    yticks = np.arange(P_bot,P_t-1,-10**4)
    plt.yticks(yticks,yticks/100)

    sfcT = nc.variables['T2'][time,y,x]-T_zero
    sfcP = nc.variables['PSFC'][time,y,x]
    sfcW = nc.variables['Q2'][time,y,x]
    sfcTd = td(e(sfcW,sfcP))
    plt.suptitle('Bakketemp: %4.1f$^{\circ}\! C$  Duggpunkt: %3.1f$^{\circ}\! C$  Trykk: %5.1f hPa' % (sfcT,sfcTd,0.01*sfcP), \
                 fontsize=10, x = 0.5, y = 0.03)        

    plt.show()
    plt.close()
Exemple #13
0
def tzCloudPlot(nest, plotMetar=False, offset=0):
    nc = openWRF(nest)
    Nx, Ny, Nz, _longs, _lats, _dx, _dy, x_nr, y_nr = getDimensions(nc)

    heightground_t, heighthalf_tz = _getHeight(nc, Nx, Ny, Nz, x_nr, y_nr)

    T_tz = np.zeros((Nz, Nt))
    qcloud_tz = np.zeros((Nz, Nt))
    qice_tz = np.zeros((Nz, Nt))
    qsnow_tz = np.zeros((Nz, Nt))
    qrain_tz = np.zeros((Nz, Nt))

    for t in arange(Nt):
        theta = nc.variables['T'][t, :, y_nr, x_nr] + T_base
        P = nc.variables['P'][t, :, y_nr,
                              x_nr] + nc.variables['PB'][t, :, y_nr, x_nr]
        T_tz[:,
             t] = theta * (P /
                           P_bot)**kappa  # Temperatur i halvflatene (Kelvin)
        rho = P[:] / (R * T_tz[:, t])  # regner om til g/m3
        qcloud_tz[:,
                  t] = 1000.0 * nc.variables['QCLOUD'][t, :, y_nr, x_nr] * rho
        qice_tz[:, t] = 1000.0 * nc.variables['QICE'][t, :, y_nr, x_nr] * rho
        qsnow_tz[:, t] = 1000.0 * nc.variables['QSNOW'][t, :, y_nr, x_nr] * rho
        qrain_tz[:, t] = 1000.0 * nc.variables['QRAIN'][t, :, y_nr, x_nr] * rho

    for s in [u'Snø', 'Regn']:
        plt.figure()
        plt.axis([-offset, Nt - 1, 0.0, z_max])
        grid = np.reshape(np.tile(arange(Nt), Nz), (Nz, -1))
        if (s == u"Snø"):
            var = qsnow_tz
            cm = cmap_blue
            levs = tz_snow_levels
        else:
            var = qrain_tz
            cm = cmap_green
            levs = tz_rain_levels
        plt.contourf(grid,
                     heighthalf_tz,
                     qcloud_tz,
                     alpha=0.9,
                     levels=tz_cloudwater_levels,
                     cmap=cmap_red)  #
        plt.colorbar()
        plt.contourf(grid, heighthalf_tz, var, alpha=0.6, levels=levs,
                     cmap=cm)  #
        plt.colorbar()
        cs = plt.contour(grid,
                         heighthalf_tz,
                         T_tz - T_zero,
                         temp_int,
                         colors='black',
                         linestyles='solid')
        plt.clabel(cs, inline=1, fmt='%1.0f', fontsize=12, colors='black')
        plt.fill_between(arange(-offset, Nt),
                         heightground_t[0],
                         0,
                         facecolor='lightgrey')
        if plotMetar:
            _metar()
        print s + ' ($g/m^3$)'
        plt.xlabel('Timer etter ' + date + 'T00:00Z')
        plt.ylabel(u'Høyde [m]')
        plt.yticks(np.arange(0, z_max, dz), fontsize='small')
        plt.show()
        plt.close()

    fig = plt.figure()
    ax1 = fig.add_subplot(111)
    ax1.set_xlim(0, Nt - 1)
    ax1.plot(np.sum(qcloud_tz, axis=0), color='black', label=u"skyvann")
    ax1.plot(np.sum(qsnow_tz, axis=0), color='green', label=u"snø")
    ax1.set_xlabel('Timer etter ' + date + 'T00:00Z')
    ax1.set_ylabel(u'Skyvann og snø ($g/m^2$)')
    ax2 = ax1.twinx()
    ax2.plot(np.sum(qice_tz, axis=0), color='blue', label="is")
    ax2.plot(np.sum(qrain_tz, axis=0), color='red', label="regn")
    ax2.set_ylabel('Regn og is ($g/m^2$)')
    ax1.set_xlim(0, Nt - 1)
    ax1.legend(loc='upper left')
    ax2.legend(loc='upper right')
    plt.show()
    plt.close()
Exemple #14
0
def yzCloudPlot(nest, time, plotTemp=True, plotRH=False):
    nc = openWRF(nest)
    Nx, Ny, Nz, _longs, latitude, _dx, _dy, x_nr, y_nr = getDimensions(nc)

    heightground_y, heighthalf_yz = _getHeight(nc, time, -1, Ny, Nz, x_nr, -1)
    print 'Model height: ' + str(heightground_y[y_nr])

    theta = nc.variables['T'][time, :, :, x_nr] + T_base
    P = nc.variables['P'][time, :, :, x_nr] + nc.variables['PB'][time, :, :,
                                                                 x_nr]
    T = theta * (P / P_bot)**kappa  # Temperatur i halvflatene (Kelvin)
    rho = P / (R * T)  #[kg/m3]

    qcloud_yz = 1000.0 * nc.variables['QCLOUD'][
        time, :, :, x_nr] * rho  # regner om til g/m3
    qrain_yz = 1000.0 * nc.variables['QRAIN'][time, :, :, x_nr] * rho
    qsnow_yz = 1000.0 * nc.variables['QSNOW'][time, :, :, x_nr] * rho

    plt.figure()
    plt.set_cmap(cmap_red)
    plt.axis([0, Ny - 1, 0.0, z_max])
    print u'Cloud water red, snow blue, rain green ($g/m^3$)'
    grid = np.reshape(np.tile(arange(Ny), Nz), (Nz, -1))
    plt.contourf(grid,
                 heighthalf_yz,
                 qcloud_yz,
                 alpha=0.9,
                 levels=xz_cloudwater_levels,
                 cmap=cmap_red)  #
    plt.colorbar()
    plt.contourf(grid,
                 heighthalf_yz,
                 qrain_yz,
                 alpha=0.6,
                 levels=xz_rain_levels,
                 cmap=cmap_green)  #
    plt.colorbar()
    plt.contourf(grid,
                 heighthalf_yz,
                 qsnow_yz,
                 alpha=0.6,
                 levels=xz_snow_levels,
                 cmap=cmap_blue)  #
    plt.colorbar()

    if plotTemp:
        cs = plt.contour(grid,
                         heighthalf_yz,
                         T - T_zero,
                         temp_int,
                         colors='black',
                         linestyles='solid')  #linewidths=4
        plt.clabel(cs, inline=1, fmt='%1.0f', fontsize=12, colors='black')
    if plotRH:
        rh = _getRH(nc, time, x_nr, -1, T, P)
        rh_int = arange(90., 111., 5.)
        cs = plt.contour(grid, heighthalf_yz, rh, rh_int, colors='grey')
        plt.clabel(cs, inline=1, fmt='%1.0f', fontsize=12, colors='grey')
    plt.plot(arange(Ny), heightground_y, color='black')
    plt.fill_between(arange(Ny), heightground_y, 0, facecolor='lightgrey')
    plt.xticks(np.arange(0, Ny, 8),
               np.round(latitude[::8, Nx / 2], 1),
               fontsize='small')
    plt.yticks(np.arange(0, z_max, dz), fontsize='small')
    plt.xlabel('Breddegrad')
    plt.ylabel(u'Høyde [m]')
    plt.show()
    plt.close()