def find_client_density(m,client_locations,latscale=1.0,lonscale=1.0,lat_smooth=1,lon_smooth=1):
    lat_array=arange(m.ymin,m.ymax+latscale,latscale)
    lon_array=arange(m.xmin,m.xmax+lonscale,lonscale)
    maxlat=len(lat_array)-1
    maxlon=len(lon_array)-1
    Z=zeros((len(lat_array),len(lon_array)),dtype='float')
    for client in client_locations:
      lat=client[2]
      i_lat=int(float((lat-lat_array[0]))/float(latscale)) 
      lon=client[3]
      i_lon=int(float((lon-lon_array[0]))/float(lonscale)) 
      for i in xrange(-int(lat_smooth),int(lat_smooth+1),1):
        for j in xrange(-int(lon_smooth),int(lon_smooth+1),1):
          if ( i_lat+i >= 0 ) and (i_lat+i < maxlat) : 
            if ( i_lon+j >= 0) and ( i_lon+j < maxlon) :
              Z[i_lat+i,i_lon+j]+=1.0
    Lon,Lat=meshgrid(lon_array,lat_array)
    X,Y=m(Lon,Lat)
    Z= Z + 1.0
    Z=log(Z)
    Z = where(Z <= 0.,1.e10,Z)
    Z = ma.masked_values(Z, 1.e10)
    return X,Y,Z
        fcstprob[icat] = 0.5 * (prob1 + prob2)
        reliability[icat] = 1.e20
        if totfreq[icat] > nsamps / 1000.:
            reliability[icat] = 100. * obfreq[icat] / totfreq[icat]
        frequse[icat] = 100. * totfreq[icat] / nsamps
        print fcstprob[icat],reliability[icat],frequse[icat]\
    # plot reliability diagram if matplotlib installed.

    try:
        from pylab import *
        doplot = True
    except:
        doplot = False
    if doplot:
        from matplotlib.numerix import ma
        reliability = ma.masked_values(reliability, 1.e20)
        fig = figure(figsize=(6.5, 6.5))
        ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
        plot(fcstprob, reliability, 'bo-')
        plot(arange(0, 110, 10), arange(0, 110, 10), 'r--')
        xlabel('forecast probability')
        ylabel('observed frequency')
        title('Reliability Diagram')
        text(55, 15, 'Brier Skill Score = %4.2f' % bss, fontsize=14)
        ax2 = fig.add_axes([.2, .6, .25, .2], axisbg='y')
        bar(10 * arange(10), frequse, width=10)
        xlabel('forecast probability', fontsize=10)
        ylabel('percent issued', fontsize=10)
        title('Frequency of Use', fontsize=12)
        ax2.set_xticklabels(arange(20, 120, 20), fontsize=9)
        ax2.set_yticklabels(arange(20, 120, 20), fontsize=9)
Пример #3
0
# setup of basemap ('lcc' = lambert conformal conic).
# use major and minor sphere radii from WGS84 ellipsoid.
m = Basemap(llcrnrlon=-145.5,llcrnrlat=1.,urcrnrlon=-2.566,urcrnrlat=46.352,\
            rsphere=(6378137.00,6356752.3142),\
            resolution='l',area_thresh=1000.,projection='lcc',\
            lat_1=50.,lon_0=-107.)
# transform to nx x ny regularly spaced native projection grid
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
topodat,x,y = m.transform_scalar(topoin,lonsin,latsin,nx,ny,returnxy=True)
# create the figure.
fig=figure(figsize=(8,8))
# add an axes, leaving room for colorbar on the right.
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# make topodat a masked array, masking values lower than sea level.
topodat = where(topodat < 0.,1.e10,topodat)
topodatm = ma.masked_values(topodat, 1.e10)
palette = cm.YlOrRd
palette.set_bad('aqua', 1.0)
# plot image over map with imshow.
im = m.imshow(topodatm,palette,norm=colors.normalize(vmin=0.0,vmax=3000.0,clip=False))
# setup colorbar axes instance.
l,b,w,h = ax.get_position()
cax = axes([l+w+0.075, b, 0.05, h])
colorbar(cax=cax) # draw colorbar
axes(ax)  # make the original axes current again
# plot blue dot on boulder, colorado and label it as such.
xpt,ypt = m(-104.237,40.125) 
m.plot([xpt],[ypt],'bo') 
text(xpt+100000,ypt+100000,'Boulder')
# draw coastlines and political boundaries.
m.drawcoastlines()
Пример #4
0
from matplotlib.toolkits.basemap import Basemap

# read in data from netCDF file.
infile    = 'ccsm_popgrid.nc'
fpin      = NetCDFFile(infile)
tlat      = fpin.variables['TLAT'][:]
tlon      = fpin.variables['TLONG'][:]
temp      = fpin.variables['TEMP'][:]
fillvalue = fpin.variables['TEMP'].attributes['_FillValue']
fpin.close()

# make longitudes monotonically increasing.
tlon = N.where(N.greater_equal(tlon,min(tlon[:,0])),tlon-360,tlon)

# create a masked array with temperature data (continents masked).
temp = MA.masked_values(temp,fillvalue)

# stack grids side-by-side (in longitiudinal direction), so
# any range of longitudes may be plotted on a world map.
tlon = N.concatenate((tlon,tlon+360),1)
tlat = N.concatenate((tlat,tlat),1)
temp = MA.concatenate((temp,temp),1)
tlon = tlon-360.

pl.figure(figsize=(8.5,11))
pl.subplot(2,1,1)
# subplot 1 just shows POP grid cells.
map = Basemap(projection='merc', lat_ts=20, llcrnrlon=-180, \
      urcrnrlon=180, llcrnrlat=-84, urcrnrlat=84, resolution='c')

map.drawcoastlines()
Пример #5
0
# setup of basemap ('lcc' = lambert conformal conic).
# use major and minor sphere radii from WGS84 ellipsoid.
m = Basemap(llcrnrlon=-145.5,llcrnrlat=1.,urcrnrlon=-2.566,urcrnrlat=46.352,\
            rsphere=(6378137.00,6356752.3142),\
            resolution='l',area_thresh=1000.,projection='lcc',\
            lat_1=50.,lon_0=-107.)
# transform to nx x ny regularly spaced native projection grid
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
topodat,x,y = m.transform_scalar(topoin,lonsin,latsin,nx,ny,returnxy=True)
# set up figure with same aspect ratio as map.
fig=m.createfigure()
ax = fig.add_axes([0.1,0.1,0.7,0.7],axisbg='aqua')
# make topodat a masked array, masking values lower than sea level.
topodat = where(topodat < 0.,1.e10,topodat)
topodat = ma.masked_values(topodat, 1.e10)
# plot image over map with imshow.
im = m.imshow(topodat,cm.jet,norm=colors.normalize(vmin=-4000.0,vmax=3000.0,clip=False))
cax = axes([0.875, 0.1, 0.05, 0.7]) # setup colorbar axes
colorbar(tickfmt='%d', cax=cax) # draw colorbar
axes(ax)  # make the original axes current again
# plot blue dot on boulder, colorado and label it as such.
xpt,ypt = m(-104.237,40.125) 
m.plot([xpt],[ypt],'bo') 
text(xpt+100000,ypt+100000,'Boulder')
# draw coastlines and political boundaries.
m.drawcoastlines()
m.drawcountries()
m.drawstates()
# draw parallels and meridians.
# label on left, right and bottom of map.
Пример #6
0
    fdate = hrs_since_day1CE_todate(int(time*24.0)) 
    verifdates.append(fdate.strftime('%Y%m%d%H'))
print fcsthrs
print verifdates
levs = levels[:]
lats = latitudes[:]
lons = longitudes[:]
lons, lats = meshgrid(lons,lats)

# unpack 2-meter temp forecast data.

t2mvar = data['tmp2m']
missval = t2mvar.missing_value
t2m = t2mvar[:,:,:]
if missval < 0:
    t2m = ma.masked_values(where(t2m>-1.e20,t2m,1.e20), 1.e20)
else:
    t2m = ma.masked_values(where(t2m<1.e20,t2m,1.e20), 1.e20)
t2min = amin(t2m.compressed()); t2max= amax(t2m.compressed())
print t2min,t2max
clevs = frange(around(t2min/10.)*10.-5.,around(t2max/10.)*10.+5.,4)
print clevs[0],clevs[-1]
llcrnrlat = 22.0
urcrnrlat = 48.0
latminout = 22.0
llcrnrlon = -125.0
urcrnrlon = -60.0
standardpar = 50.0
centerlon=-105.
# create Basemap instance for Lambert Conformal Conic projection.
m = Basemap(llcrnrlon=llcrnrlon,llcrnrlat=llcrnrlat,
Пример #7
0
from matplotlib.toolkits.basemap import Basemap

# read in data from netCDF file.
infile = 'ccsm_popgrid.nc'
fpin = NetCDFFile(infile)
tlat = fpin.variables['TLAT'][:]
tlon = fpin.variables['TLONG'][:]
temp = fpin.variables['TEMP'][:]
fillvalue = fpin.variables['TEMP'].attributes['_FillValue']
fpin.close()

# make longitudes monotonically increasing.
tlon = N.where(N.greater_equal(tlon, min(tlon[:, 0])), tlon - 360, tlon)

# create a masked array with temperature data (continents masked).
temp = MA.masked_values(temp, fillvalue)

# stack grids side-by-side (in longitiudinal direction), so
# any range of longitudes may be plotted on a world map.
tlon = N.concatenate((tlon, tlon + 360), 1)
tlat = N.concatenate((tlat, tlat), 1)
temp = MA.concatenate((temp, temp), 1)
tlon = tlon - 360.

pl.figure(figsize=(8.5, 11))
pl.subplot(2, 1, 1)
# subplot 1 just shows POP grid cells.
map = Basemap(projection='merc', lat_ts=20, llcrnrlon=-180, \
      urcrnrlon=180, llcrnrlat=-84, urcrnrlat=84, resolution='c')

map.drawcoastlines()
Пример #8
0
    verifdates.append(fdate.strftime("%Y%m%d%H"))
print fcsthrs
print verifdates
levs = levels[:]
lats = latitudes[:]
lons = longitudes[:]
lons, lats = meshgrid(lons, lats)

# unpack 2-meter temp forecast data.

print data.variables.keys()
t2mvar = data.variables["t2m"]
missval = t2mvar.missing_value
t2m = t2mvar[:, :, :]
if missval < 0:
    t2m = ma.masked_values(where(t2m > -1.0e20, t2m, 1.0e20), 1.0e20)
else:
    t2m = ma.masked_values(where(t2m < 1.0e20 .e - 12, t2m, 1.0e20), 1.0e20)
t2min = amin(t2m.compressed())
t2max = amax(t2m.compressed())
print t2min, t2max
clevs = frange(around(t2min / 10.0) * 10.0, around(t2max / 10.0) * 10.0, 4)
llcrnrlat = 22.0
urcrnrlat = 48.0
latminout = 22.0
llcrnrlon = -125.0
urcrnrlon = -60.0
standardpar = 50.0
centerlon = -105.0
# create Basemap instance for Lambert Conformal Conic projection.
m = Basemap(
     prob2 = (icat+1)*10.
     fcstprob[icat] = 0.5*(prob1+prob2)
     reliability[icat]=1.e20
     if totfreq[icat] > nsamps/1000.:
         reliability[icat] = 100.*obfreq[icat]/totfreq[icat]
     frequse[icat] = 100.*totfreq[icat]/nsamps
     print fcstprob[icat],reliability[icat],frequse[icat]\
 # plot reliability diagram if matplotlib installed.
 try:
     from pylab import *
     doplot = True
 except:
     doplot = False
 if doplot:
     from matplotlib.numerix import ma
     reliability = ma.masked_values(reliability, 1.e20)
     fig=figure(figsize=(6.5,6.5))
     ax = fig.add_axes([0.1,0.1,0.8,0.8])
     plot(fcstprob,reliability,'bo-')
     plot(arange(0,110,10),arange(0,110,10),'r--')
     xlabel('forecast probability')
     ylabel('observed frequency')
     title('Reliability Diagram')
     text(55,15,'Brier Skill Score = %4.2f' % bss,fontsize=14)
     ax2 = fig.add_axes([.2, .6, .25, .2], axisbg='y')
     bar(10*arange(10), frequse, width=10)
     xlabel('forecast probability',fontsize=10)
     ylabel('percent issued',fontsize=10)
     title('Frequency of Use',fontsize=12)
     ax2.set_xticklabels(arange(20,120,20),fontsize=9)
     ax2.set_yticklabels(arange(20,120,20),fontsize=9)