Пример #1
0
    def calc_age_max(self,ncfile,dx,dy,xlims=None,ylims=None):
        # Set the xy limits
        if xlims==None or ylims==None:
                xlims=self.xlims 
                ylims=self.ylims

        scalefac = 1/86400.

        xp,yp,agemax = self.readAgeMax(ncfile)
        
        grd = RegGrid(xlims,ylims,dx,dy)

        agegrid = grd.griddata(xp,yp,agemax)*scalefac

        return grd.X,grd.Y,agegrid
Пример #2
0
    def plotAgeMax(self,ncfile,dx,dy,vmax=7,xlims=None,ylims=None,**kwargs):
    	"""
        Filled contour plot of the maximum age of particle based on their initial locations
        """
        # Set the xy limits
        if xlims==None or ylims==None:
                xlims=self.xlims 
                ylims=self.ylims


        xp,yp,agemax = self.readAgeMax(ncfile)
        
        grd = RegGrid(xlims,ylims,dx,dy)

        agegrid = grd.griddata(xp,yp,agemax)*scalefac

        fig=plt.gcf()
        self.contourf(z=-self.dv,clevs=20,titlestr='',xlims=xlims,ylims=ylims,\
            filled=False,colors='k',linestyles='solid',linewidths=0.2)
        plt.pcolor(grd.X,grd.Y,agegrid,vmax=vmax,**kwargs)
        plt.colorbar()
        plt.title('Particle Age [days]\n(file name: %s)'%ncfile)
Пример #3
0
    def calcAgeMaxProb(self,ncfiles,dx,dy,exceedance_thresh,plot=True,xlims=None,ylims=None,**kwargs):
    	"""
        Calculate the probability of the age exceeding a threshold time from
        a series of particle tracking runs. 
        """
        scalefac = 1/86400.
        # Set the xy limits
        if xlims==None or ylims==None:
                xlims=self.xlims 
                ylims=self.ylims

        # Create the probability grid
        grd = RegGrid(xlims,ylims,dx,dy)
        nruns = len(ncfiles)
        prob = np.zeros((grd.ny,grd.nx))

        # Loop through the files and add one to the probability matrix
        # where the age exceeds the threshold
        for ncfile in ncfiles:
            print 'Reading file: %s'%ncfile
            xp,yp,agemax = self.readAgeMax(ncfile)
        
            agegrid = grd.griddata(xp,yp,agemax)

            ind = agegrid >= exceedance_thresh

            prob[ind] = prob[ind]+1

        # Return the probability as a percentage
        prob = prob/nruns*100.0

        if plot:
            fig=plt.gcf()
            self.contourf(z=-self.dv,clevs=20,titlestr='',xlims=xlims,ylims=ylims,\
            filled=False,colors='k',linestyles='solid',linewidths=0.2)
            plt.pcolor(grd.X,grd.Y,prob,vmax=100,cmap=plt.cm.Spectral_r)
            plt.colorbar()
            plt.title('Probability (%%) of particle age exceeding %3.1f days'%(exceedance_thresh*scalefac))