예제 #1
0
	def __init__(	self,
			Source    = 'CMCC-CESM',
			dT        =  1,
			ff        =  1,
			blat	  =  70,
			res       =  200	):

		# Class attributes
		self.Source    = Source
		self.dT        = dT
		self.ff        = ff
		# Dependants
		if self.ff ==    1: self.fstr      = 'fwrd'
		if self.ff ==   -1: self.fstr      = 'back'
		if self.dT ==    1: self.dailymean = True
		if self.dT == 0.25: self.dailymean = False
		# U,V and W DataServers
		if Source == 'ERAInt':
                        self.uds  = reDataServer(Field='U',LevType='plev',Source=Source)
                        self.wds  = reDataServer(Field='W',LevType='plev',Source=Source)
                        self.vds  = reDataServer(Field='V',LevType='plev',Source=Source)
                        self.PVds = reDataServer(Field='pv',LevType='plev',Source=Source)
		elif Source == 'NCEP1':
                        self.uds  = reDataServer(Field='uplev',LevType='plev',Source=Source)
                        self.wds  = reDataServer(Field='omega',LevType='plev',Source=Source)
                        self.vds  = reDataServer(Field='vplev',LevType='plev',Source=Source)
                        #self.qdsh = reDataServer(Field='shum',LevType='plev',Source=Source)
                elif Source[0:3] == 'CAM':
                        self.uds  = reDataServer(Field='U',Source=Source)
                        self.wds  = reDataServer(Field='W',Source=Source)
                        self.vds  = reDataServer(Field='V',Source=Source)
                        #self.qdsh = reDataServer(Field='q',Source=Source)
		else:
			self.wds  = cmipDataServer(Field='wap',LevType='plev',Source=Source,ExpType='rcp85',DataFreq='day')
			self.uds  = cmipDataServer(Field='ua' ,LevType='plev',Source=Source,ExpType='rcp85',DataFreq='day')
			self.vds  = cmipDataServer(Field='va' ,LevType='plev',Source=Source,ExpType='rcp85',DataFreq='day')
			#self.qdsh = cmipDataServer(Field='hus',LevType='plev',Source=Source,ExpType='historical',DataFreq='day')
			#self.qdsr = cmipDataServer(Field='hus',LevType='plev',Source=Source,ExpType='rcp85',DataFreq='day')
			#self.qdss = [self.qdsh,self.qdsr]
		# LambertProjector
		self.res        = res
		self.proj       = LambertProjector(boundinglat=blat,resolution=self.res)
		self.res        = self.proj.res
		print self.res
		self.x,self.y   = self.proj.x[0,:],self.proj.y[:,0]
		self.nx,self.ny = len(self.x),len(self.y)
		# Mass of girdbox on each level
		self.dP = []
		dP = np.diff(self.uds.lev)/2.
		self.dP.append(dP[0])
		for i in range(len(dP)-1):
	        	self.dP.append(dP[i]+dP[i+1])
		self.dP.append(dP[-1])
		self.dP = np.array(self.dP)
		self.dM = 100.*self.dP/9.80665
예제 #2
0
class Reynolds:
    def __init__(self, Season='DJF', case='vq'):
        # Attributes
        self.Season = Season
        self.case = case
        if self.case == 'vq':
            self.Fieldf, self.orr, self.units, self.sf, self.Ef = [
                'q', 'hus'
            ], 'moisture', 'kg s$^{-1}$ m$^{-1}$', 1, 1e03
        if self.case == 'vT':
            self.Fieldf, self.orr, self.units, self.sf, self.Ef = [
                'T', 'ta'
            ], 'temperature', '10$^{3}$ K kg s$^{-1}$ m$^{-1}$', 1e-03, 334e03
        self.proj = LambertProjector(boundinglat=25, resolution=200.)
        # Target grid
        self.lats = np.arange(0, 90 + 1, 1)
        self.lons = np.arange(0, 360, 1)
        self.levs = np.arange(0, 1000 + 50, 50)
        self.dlev = self.levs[-1] - self.levs[0]
예제 #3
0
	def makeFiles(self,Years,Months,Ndays,dt,blat0=70,area_integration=True):
		# Make directory for saving files if it does not exist
		os.system('mkdir -p /mnt/climstorage/cian/Tracks/%s/%s/%s' % (self.Source,self.fstr,blat0)) 
		# Initialisation of particles (100 points north of 80N or 360 points along 70N)
		if area_integration:
			proj_tmp    = LambertProjector(boundinglat=80,resolution=200.)
			lon0s,lat0s = proj_tmp.lon.reshape(-1),proj_tmp.lat.reshape(-1)
		else:
			lon0s,lat0s = np.arange(360),[blat0 for kk in range(360)]
		steps       = self.ff*np.arange(24.*Ndays/dt + 1)*dt
		x0s,y0s     = self.proj.m(lon0s,lat0s)
		p0s         = [800 for kk in range(len(x0s))]
		# Loop trhough years and months
		for Year in Years:
			for Month in Months:
				#try:
					fname = '/mnt/climstorage/cian/Tracks/%s/%s/%s/%s_%s_%02d.nc' % (self.Source,self.fstr,blat0,self.fstr,Year,Month)	
					print fname
					if not os.path.isfile(fname):
						print 'Computing %s trajectories for %s %s ...' % (self.fstr,Year,Month)
						self.makeMonth(Year,Month,steps,lon0s,x0s,y0s,p0s,Ndays,dt,fname)
					else:
						print 'File %s already exists' % (fname)
예제 #4
0
    def density0(self,year0=1981,N=23):
	# Attributes
	proj        = LambertProjector(boundinglat=40,resolution=390.)
	projt       = LambertProjector(boundinglat=80,resolution=200.)
	xlim_,ylim0 = proj.m(0,50)
	xlim_,ylim1 = proj.m(180,50)
	xlim0,ylim_ = proj.m(-90,50)
	xlim1,ylim_ = proj.m(90,50)
	print proj.res
	# Axes
	xpole,ypole = proj.m(0,90)
	xyR2        = (proj.x-xpole)**2 + (proj.y-ypole)**2
	xyR2        = xyR2/1e13
	x,y         = proj.x[0,:],proj.y[:,0]
	# Masking of trakectories
	LatRange = [80,85]
	LonRange = [-30,90]
#	LonRange = [90,-150]
#	LonRange = [-150,-30]
	bounds   = self.boxBounds(proj.m,LatRange,LonRange,35)
	if LonRange[1] < LonRange[0]:
		inds = np.where((projt.lon.reshape(-1)<LonRange[1])|(projt.lon.reshape(-1)>LonRange[0])\
			       &(projt.lat.reshape(-1)<LatRange[1])&(projt.lat.reshape(-1)>LatRange[0])==True)[0]
	else:
                inds = np.where((projt.lon.reshape(-1)<LonRange[1])&(projt.lon.reshape(-1)>LonRange[0])\
                               &(projt.lat.reshape(-1)<LatRange[1])&(projt.lat.reshape(-1)>LatRange[0])==True)[0]
	# Data holders
	years1 = range(year0,year0+N/2,1)
	years2 = range(year0+N/2,year0+N,1)
	print years1,len(years1)
	print years2,len(years2)
	#years1 = range(1981,1998+1,1)
	#years2 = range(1999,2016+1,1)
	N1,N2  = np.array([np.zeros((proj.nx,proj.ny)) for i in years1]),np.array([np.zeros((proj.nx,proj.ny)) for i in years2])
	for t in range(len(years1)):
		year      = years1[t]
		print year
		s         = self.getDataSnaps(Year=year,Season='DJF')
		lat,lon,p = s[:,inds,:28,0],s[:,inds,:28,1],s[:,inds,:28,2]
		xs,ys     = proj.m(lon,lat)
		xs,ys     = xs.reshape(-1),ys.reshape(-1)
		for i in range(len(xs)):
			xi,yi    = np.argmin(abs(x-xs[i])),np.argmin(abs(y-ys[i]))
			N1[t,yi,xi] = N1[t,yi,xi] + 1
        for t in range(len(years2)):
		year      = years2[t]
                print year
                s         = self.getDataSnaps(Year=year,Season='DJF')
                lat,lon,p = s[:,inds,:28,0],s[:,inds,:28,1],s[:,inds,:28,2]
                xs,ys     = proj.m(lon,lat)
                xs,ys     = xs.reshape(-1),ys.reshape(-1)
                for i in range(len(xs)):
                        xi,yi    = np.argmin(abs(x-xs[i])),np.argmin(abs(y-ys[i]))
                        N2[t,yi,xi] = N2[t,yi,xi] + 1
	# Full time array for trend
	N0 = np.append(N1,N2,axis=0)
	Ntrend,pval = self.getTrend(years1+years2,N0)
	# Time series
	projlat1 = np.tile(proj.lat[np.newaxis,:,:],(len(years1),1,1))
	projlon1 = np.tile(proj.lon[np.newaxis,:,:],(len(years1),1,1))
	projlat2 = np.tile(proj.lat[np.newaxis,:,:],(len(years2),1,1))
	projlon2 = np.tile(proj.lon[np.newaxis,:,:],(len(years2),1,1))
	nn1 = np.ma.masked_where(projlat1>85,N1)
	nn1 = np.ma.masked_where(projlat1<70,nn1)
	nn1 = np.ma.masked_where(projlon1<20,nn1)
	nn1 = np.ma.masked_where(projlon1>90,nn1)
        nn2 = np.ma.masked_where(projlat2>85,N2)
        nn2 = np.ma.masked_where(projlat2<70,nn2)
        nn2 = np.ma.masked_where(projlon2<20,nn2)
        nn2 = np.ma.masked_where(projlon2>90,nn2)
	nn1 = nn1.sum(axis=1).sum(axis=1)/10000.
	nn2 = nn2.sum(axis=1).sum(axis=1)/10000.
	"""
	pl.plot(years1,nn1,'b',linewidth=1.5)
	pl.plot([years1[-1],years2[0]],[nn1[-1],nn2[0]],'r',linewidth=1.5)
	pl.plot(years2,nn2,'r',linewidth=1.5)
	pl.ylabel('Number density [10$^{4}$]')
	pl.xlabel('Year')
	pl.grid()
	pl.savefig('figs/dshed_timeseries.pdf',format='pdf')
	pl.show()
	"""
	# Format data
	N1,N2        = N1.sum(axis=0),N2.sum(axis=0)
	N1,N2        = N1[1:-1,1:-1]/(120.*len(years1)),N2[1:-1,1:-1]/(120.*len(years2))
	Ntrend       = Ntrend[1:-1,1:-1]/120.
	pval         = pval[1:-1,1:-1]
	x,y          = x[1:-1],y[1:-1]
	N1,xx,yy     = self.interp2d(N1,x,y,6,kind='cubic')
	N2,xx,yy     = self.interp2d(N2,x,y,6,kind='cubic')
	#Ntrend,xx,yy = self.interp2d(Ntrend,x,y,6,kind='cubic')
	#pval,xx,yy   = self.interp2d(pval,x,y,6,kind='cubic')
	# Plot
	cseqa,cseqf = np.arange(-3,3+0.5,0.5),np.arange(0,80+5,5)
	pl.figure(1)
	cf   = pl.contourf(xx,yy,N2-N1,cseqa,cmap=pl.cm.RdBu_r,extend='both')
	cbar = pl.colorbar(cf)
	cbar.set_label(r'Number density {400$\times$400 km$^{2}$ day}$^{-1}$')
	drawCoastlinesNoRivers(proj.m)
	proj.m.drawparallels([70,80],latmax=90)
	pl.xlim(xlim0,xlim1)
	pl.ylim(ylim0,ylim1)
	#pl.xlim(x[1],x[-2])
	#pl.ylim(y[1],y[-2])
	pl.title('%s to %s minus %s to %s' % (years2[0],years2[-1],years1[0],years1[-1]))
	pl.savefig('figs/dshed.pdf',format='pdf')
	pl.clf()
	pl.figure(2)
        cf   = pl.contourf(xx,yy,N1,cseqf,cmap=pl.cm.OrRd,extend='max')
        cbar = pl.colorbar(cf)
        cbar.set_label(r'Number density {400$\times$400 km$^{2}$ day}$^{-1}$')
        drawCoastlinesNoRivers(proj.m)
        proj.m.drawparallels([70,80],latmax=90)
        pl.xlim(x[1],x[-2])
        pl.ylim(y[1],y[-2])
	pl.title('%s to %s' % (years1[0],years1[-1]))
	pl.savefig('figs/shed.%s-%s.pdf' % (years1[0],years1[-1]),format='pdf')
	pl.clf()
        pl.figure(3)
        cf   = pl.contourf(xx,yy,N2,cseqf,cmap=pl.cm.OrRd,extend='max')
        cbar = pl.colorbar(cf)
        cbar.set_label(r'Number density {400$\times$400 km$^{2}$ day}$^{-1}$')
        drawCoastlinesNoRivers(proj.m)
        proj.m.drawparallels([70,80],latmax=90)
        pl.xlim(x[1],x[-2])
        pl.ylim(y[1],y[-2])
	pl.title('%s to %s' % (years2[0],years2[-1]))
	pl.savefig('figs/shed.%s-%s.pdf' % (years2[0],years2[-1]),format='pdf')
	pl.clf()
        pl.figure(4)
	mx,my = np.ma.masked_where(pval>0.1,proj.x[1:-1,1:-1]),np.ma.masked_where(pval>0.1,proj.y[1:-1,1:-1])
        cf    = pl.contourf(x,y,Ntrend,cseqa,cmap=pl.cm.RdBu_r,extend='both')
        cbar  = pl.colorbar(cf)
        cbar.set_label(r'Number density {400$\times$400 km$^{2}$ day}$^{-1}$ decade$^{-1}$')
	pl.plot(mx,my,'k.',alpha=0.3,markersize=4)
        drawCoastlinesNoRivers(proj.m)
        proj.m.drawparallels([70,80],latmax=90)
        for xi,yi in bounds:
        	pl.plot(xi,yi,'b',linewidth=1.5,alpha=0.6)
        pl.xlim(x[1],x[-2])
        pl.ylim(y[1],y[-2])
        pl.title('Trend %s to %s' % (years1[0],years2[-1]))
        pl.savefig('figs/shed_trend.%s.%syears.%s-%sN.%s-%sE.pdf' % (year0,N,LatRange[0],LatRange[1],LonRange[0],LonRange[1]),format='pdf')
	pl.clf()
예제 #5
0
    def trackField2(self,Field,LevType,b1,b2,blat,LonRange):
        # Dates
        dates    = unpick('../WarmArctic/dates.warm.1000.p')
	days     = np.arange(-5,0+0.25,0.25)
        vq,Dates = unpick('newfluxfiles/70/ERAInt/ERAInt.moist.1979-2016.30-1000hPa.70N.Annual.p')
        # Flux axes
        fluxlons = np.array(range(0,180+1,1) + range(-179,0,1))
        inds    = np.arange(-4,4+1,1)
	#inds     = np.arange(0,0+1,1)
        # DataServers
        ds   = reDataServer(Field=Field,LevType=LevType)
        proj = LambertProjector(boundinglat=45,resolution=200.)
        # Get data 
        datelist = ds.getDateList(Year=2000,Month=1)
	#datelist = [ds.getDate(ds.getHours(*dates[8]) + k*24) for k in days]
        for date in datelist:
                s         = proj(ds.snapshot(*date),ds.lon,ds.lat)
                f         = interpolate.interp2d(proj.x, proj.y, s, kind='linear')
                F         = self.snapshot(*date)
                lat,lon,p = F[:,:,0],F[:,:,1],F[:,:,2]
                x,y       = proj.m(lon,lat)
                cseq      = np.arange(0,20+1,1)
                f70,nn0   = np.zeros(360),np.zeros(360)
                pl.figure(1)
                cf   = pl.contourf(proj.x,proj.y,s,cseq,cmap=pl.cm.RdBu_r,extend='both')
                cbar = pl.colorbar()
                cbar.set_label('%s [%s]' % (ds.long_name,ds.units))
                pl.contour(proj.x,proj.y,s,levels=[-20],colors='k',linewidths=1.5)
                for i in range(len(x)):
                        if (b1 < f(x[i][0],y[i][0]) < b2) and (blat<lat[i,0]):
                                P,xii,dx = self.interpolateTrackToLat(lon[i],lat[i],70)
                                pl.plot(x[i][0],y[i][0],'k.')
                                pl.plot(x[i],y[i],'k',alpha=0.3)
                                if xii != -999 and (LonRange[0] < P[0] <= LonRange[1]):	
                                        ixi             = Dates.index(ds.getDate(ds.getHours(*date) - xii*6))
                                        lonx            = np.argmin((fluxlons - P[0])**2)
                                        loninds         = lonx+inds
                                        for il in range(len(loninds)):
                                                if loninds[il]<0:    loninds[il] = loninds[il]+360
                                                if loninds[il]>=360: loninds[il] = loninds[il]-360 
					f70[loninds] += vq[ixi,loninds] + dx*(vq[ixi+1,loninds]-vq[ixi,loninds])
                                        nn0[loninds] += 1
                                        xx,yy      = proj.m(P[0],P[1])
                                        pl.plot(xx,yy,'r.',alpha=0.6)
        	f70,nn0  = np.ma.masked_where(nn0==0,f70),np.ma.masked_where(nn0==0,nn0)
        	f70      = f70/nn0
        	weighted = (f70*nn0).sum()/(nn0.sum())
                proj.m.drawcoastlines()
                proj.m.drawparallels([70,80],latmax=90)
                pl.title('%s' % (str(date)))   
        	fig,ax1 = pl.subplots(num=2)
        	ax2     = ax1.twinx()
        	ax1.plot(range(360),f70,'k')
        	ax1.plot([0,359],[0,0],'k--')
        	ax2.plot(range(360),nn0,'r')
        	#ax1.set_ylim(-100,600) 
        	ax1.set_ylabel('Mean meridional moisture flux')
        	ax2.set_ylabel('Sample number')
        	pl.xlabel('Longitude')
        	pl.xlim(0,359)
        	pl.title('%s %s' % (str(date),weighted))  
        	pl.show()
예제 #6
0
    def trackField1(self,Field,LevType,b1,b2,YearRange=(1981,2016),blat=85,plot=True,LonRange=(30,90)):
	fname = 'tracked/%s_vq70_%s-%s_%s-%skgm2.%s.p' % (Field,YearRange[0],YearRange[1],b1,b2,blat)
	print fname
	if not os.path.isfile(fname):
		# Dates
		dates    = unpick('../WarmArctic/dates.warm.1000.p')
		vq,Dates = unpick('newfluxfiles/70/ERAInt/ERAInt.moist.1979-2016.30-1000hPa.70N.Annual.p')
		fluxlons = np.array(range(0,180+1,1) + range(-179,0,1))
		inds    = np.arange(-4,4+1,1)
		#inds     = np.arange(0,0+1,1)
		# DataServers
		ds   = reDataServer(Field=Field,LevType=LevType)
		dsv  = reDataServer(Field='V',LevType='plev',LatRange=(70,70))
		dsq  = reDataServer(Field='q',LevType='plev',LatRange=(70,70))
		proj = LambertProjector(boundinglat=80,resolution=200.)
		# Get data
		Years     = range(YearRange[0],YearRange[1]+1,1)
		f70,nn0   = np.zeros(360),np.zeros(360)
		vplev     = np.zeros((16,360))
		nnplev    = np.zeros((16,360))
		pps,llons = [],[]
		datelist  = [ds.getDateList(Year=year,Season='DJF') for year in Years]
		datelist  = [datelist[i][j] for i in range(len(datelist)) for j in range(len(datelist[i]))]
		#datelist  = ds.getDateList(2001,Season='NDJFM')
		Flux,S,PP  = [],[],[]
		for date in datelist:
			print date
			s         = proj(ds.snapshot(*date),ds.lon,ds.lat)
			F         = self.snapshot(*date)
			lat,lon,p = F[:,:,0],F[:,:,1],F[:,:,2]
			x,y       = proj.m(lon,lat)
			for i in range(len(x)):
				ix,iy = np.argmin((proj.x[0,:]-x[i][0])**2),np.argmin((proj.y[:,0]-y[i][0])**2)
				if (b1 < s[iy,ix] < b2) and (blat<lat[i,0]):
					P,xii,dx = self.interpolateTrackToLat(lon[i],lat[i],70)
					if xii != -999 and (LonRange[0] < P[0] <= LonRange[1]):
						ixi     = Dates.index(ds.getDate(ds.getHours(*date) - xii*6))
						lonx    = np.argmin((fluxlons - P[0])**2)
						loninds = lonx+inds
						for il in range(len(loninds)):
							if loninds[il]<0:    loninds[il] = loninds[il]+360
							if loninds[il]>=360: loninds[il] = loninds[il]-360
						vqslice = vq[ixi,loninds] + dx*(vq[ixi+1,loninds]-vq[ixi,loninds])	
						#if vqslice.mean() > 0:	
							#vplev[:,loninds]  += (dsv.snapshot(*Dates[ixi+1])*dsq.snapshot(*Dates[ixi+1]))[:,loninds]
							#nnplev[:,loninds] += 1
							#pps.append(p[i,xii])
							#llon0 = lon[i,xii]
							#if llon0 < 0: llon0 = llon0 + 360
							#llons.append(llon0)
						f70[loninds]  += vqslice
						nn0[loninds]  += 1
						Flux.append(vqslice.mean())
						S.append(s[iy,ix])
						PP.append(p[i,:])
		PM,PS    = np.array(PP).mean(axis=0),np.array(PP).std(axis=0)
		f70,nn0  = np.ma.masked_where(nn0==0,f70),np.ma.masked_where(nn0==0,nn0)
		f70      = f70/nn0
		weighted = (f70*nn0).sum()/(nn0.sum())
		Ntot     = nn0.sum()
		#pl.figure(1)
		#pl.plot(S,Flux,'k.',alpha=0.15)
		#pl.figure(2)
		#days = np.arange(-10,0+0.25,0.25)
		#pl.plot(days,PM[::-1],'k')
		#pl.ylim(1000,700)
		#pl.plot(days,PM[::-1]-PS[::-1],'k--')
		#pl.plot(days,PM[::-1]+PS[::-1],'k--')
		#pl.ylim(1000,700)
		#pl.show()
                #vplev,nnplev = np.ma.masked_where(nnplev==0,vplev),np.ma.masked_where(nnplev==0,nnplev)
                #vplev        = vplev/nnplev
		#cseq         = np.arange(-0.012,0.012+0.002,0.002)
		#pl.contourf(dsv.lon,dsv.lev,vplev,cseq,cmap=pl.cm.RdBu_r,extend='both')
		#pl.plot(llons,pps,'k.',alpha=0.15)
		#pl.colorbar()
		#pl.savefig('figs/neg.test.pdf',format='pdf')
		#pl.ylim(1000,30)
		#pl.show()
		toPick([f70,nn0,weighted,Ntot],fname)
	else:
		f70,nn0,weighted,Ntot = unpick(fname)
	# Plot
	if plot:
		fig,ax1 = pl.subplots(num=2)
		ax2     = ax1.twinx()
		ax1.plot(range(360),f70,'k')
		ax1.plot([0,359],[0,0],'k--')
		ax2.plot(range(360),nn0,'r')
		ax1.set_ylim(-100,600)
		ax2.set_ylim(0,1200)
		ax1.set_ylabel('Mean meridional moisture flux')
		ax2.set_ylabel('Sample number')
		pl.xlabel('Longitude')
		pl.xlim(0,359)
		pl.title('DJF %s to %s: %s' % (YearRange[0],YearRange[1],weighted))
		pl.savefig('figs/characflux/%s_vq70_%s-%s_%s-%skgm2.pdf' % (Field,YearRange[0],YearRange[1],b1,b2), format='pdf')
		pl.close()
	return f70,nn0,weighted,Ntot
예제 #7
0
    def crossing(self,Year=1998,Month=1):
	fname = '../Tracks/back1_crossings/%s_%s_%02d.nc' % ('cross',Year,Month)
	print fname
	if not os.path.isfile(fname):
		# Create array of all crossings of 70N, meridional moisture flux and time since initialisation
		proj       = LambertProjector(boundinglat=80,resolution=200.)
		ds         = reDataServer(Field='pw',LevType='surface_analysis')
		vq,Dates   = unpick('newfluxfiles/70/ERAInt/ERAInt.moist.1979-2016.30-1000hPa.70N.Annual.p')
		F          = self.getDataSnaps(Year=Year,Month=Month)
		datelist   = self.getDateList(Year=Year,Month=Month)
		hourlist   = [self.getHours(*date) for date in datelist]
		fluxlons   = np.array(range(0,180+1,1) + range(-179,0,1))
		inds       = np.arange(-4,4+1,1)
		lat,lon,p  = F[:,:,:,0],F[:,:,:,1],F[:,:,:,2]
		lon0s      = lon[0,:,0]
		x,y        = proj.m(lon,lat)
		n0,n1,n2   = lat.shape
		flux,steps = np.zeros((n0,n1)),np.zeros((n0,n1))
		loncross   = np.zeros((n0,n1))
		latstart   = np.zeros((n0,n1))
		Pcross     = np.zeros((n0,n1))
		Field      = np.zeros((n0,n1))
		for t in range(len(lat)):
			date = datelist[t]
			snap = proj(ds.snapshot(*date),ds.lon,ds.lat)
			for i in range(len(lat[t])):
				P,xii,dx  = self.interpolateTrackToLat(lon[t,i],lat[t,i],70)	
				ix,iy     = np.argmin((proj.x[0,:]-x[t,i,0])**2),np.argmin((proj.y[:,0]-y[t,i,0])**2)
				if xii != -999:	
					latst     = lat[t,i,0]
					field     = snap[iy,ix]
					lonc      = P[0]
					pc        = p[t,i,xii] + dx*(p[t,i,xii-1] - p[t,i,xii])
					stepc     = xii + 1 - dx
					ixi       = Dates.index(self.getDate(self.getHours(*date) - xii*6))
					lonx      = np.argmin((fluxlons - P[0])**2)
					loninds   = lonx+inds
					for il in range(len(loninds)):
					        if loninds[il]<0:    loninds[il] = loninds[il]+360
					        if loninds[il]>=360: loninds[il] = loninds[il]-360
					vqslice = vq[ixi,loninds] + dx*(vq[ixi+1,loninds]-vq[ixi,loninds])
					vqslice = vqslice.mean()
				else:
					latst   = -9999
					field   = -9999
					lonc    = -9999
					pc      = -9999
					stepc   = -9999
					vqslice = -9999
				latstart[t,i] = latst
				Field[t,i]    = field
				loncross[t,i] = lonc
				Pcross[t,i]   = pc
				steps[t,i]    = stepc
				flux[t,i]     = vqslice
		latstart = np.ma.masked_where(latstart==-9999,latstart)
		Field    = np.ma.masked_where(Field==-9999,Field)
		loncross = np.ma.masked_where(loncross==-9999,loncross)
		Pcross   = np.ma.masked_where(Pcross==-9999,Pcross)
		steps    = np.ma.masked_where(steps==-9999,steps)
		flux     = np.ma.masked_where(flux==-9999,flux)
		crossNetCDF(hourlist,lon0s,latstart,Field,loncross,flux,steps,fname)
	else:
		print 'File %s already exists!' % (fname)
예제 #8
0
    # Draw the coastlines, with a thin line and same color as the continent fill.
    coasts = m.drawcoastlines(zorder=1, color='white', linewidth=0)
    # Exact the paths from coasts
    coasts_paths = coasts.get_paths()
    # In order to see which paths you want to retain or discard
    # you'll need to plot them one at a time noting those that you want etc.
    for ipoly in range(0, 35 + 1, 1):
        if ipoly > poly_stop: continue
        r = coasts_paths[ipoly]
        # Convert into lon/lat vertices
        polygon_vertices = [(vertex[0], vertex[1])
                            for (vertex,
                                 code) in r.iter_segments(simplify=False)]
        px = [polygon_vertices[i][0] for i in xrange(len(polygon_vertices))]
        py = [polygon_vertices[i][1] for i in xrange(len(polygon_vertices))]
        m.plot(px, py, 'k-', linewidth=linewidth, color=color, zorder=50)
        #pl.title(ipoly)
        #pl.show()
        #pl.clf()


if __name__ == "__main__":

    import sys
    sys.path.insert(0, '/mnt/climstorage/cian/scripts')
    from LambertProjector import *
    import matplotlib.pyplot as pl

    proj = LambertProjector(boundinglat=55, resolution=350.)
    drawCoastlinesNoRivers(proj.m)
예제 #9
0
    dUdz = dudz(U, Z)
    f = (2 * (7.29e-5) * np.sin(lat * np.pi / 180))[:, np.newaxis]
    gr = (0.31 * 9.81 * f * dUdz / N)
    return gr, N, dUdz, f


if __name__ == "__main__":

    import sys
    sys.path.insert(0, '/home/cian/scripts')
    from ReanalysisDataServer import *
    from LambertProjector import *

    import matplotlib.pyplot as pl

    proj = LambertProjector(boundinglat=60, resolution=100.)
    dsu = DataServer(Field='U',
                     LevType='plev',
                     LevRange=(500, 925),
                     LatRange=(30, 90))
    dsz = DataServer(Field='Z',
                     LevType='plev',
                     LevRange=(500, 925),
                     LatRange=(30, 90))
    dst = DataServer(Field='T',
                     LevType='plev',
                     LevRange=(500, 925),
                     LatRange=(30, 90))
    latx = np.argmin((dst.lat - 70)**2)

    for date in dsu.getDateList(Year=2016, Month=12):