Пример #1
0
    def meanplots(self):
        figpref.current()
        pl.close('all')

        def pcolor(fld, F, cmin, cmax, oneside=True):
            pl.figure(F)
            self.pcolor(miv(fld), oneside=oneside)
            pl.clim(cmin,cmax)

        """
        h = np.where(self.Dchl>0, self.Dchl, np.nan)
        pcolor(nanmean(h, axis=0), 1, 0, 2)
        h = np.where(self.Dchl<0, self.Dchl, np.nan)
        pcolor(-nanmean(h, axis=0), 2, 0, 2)
        
        h = np.where(self.Dsst>0, self.Dsst, np.nan)
        pcolor(nanmean(h, axis=0), 3, 0, 0.4)
        h = np.where(self.Dsst<0, self.Dsst, np.nan)
        pcolor(-nanmean(h, axis=0), 4, 0, 0.4)
        """
        pcolor(nanmean(self.Dchl, axis=0), 5, -0.25, 0.25, False)
        pl.title(r"Mean change of Chl (mg m$^{-3}$)")
        pl.savefig('figs/liege/meanmap_Dchl.pdf',transparent=True)
        pcolor(nanmean(self.Dsst, axis=0), 6, -0.25, 0.25, False)
        pl.title(r"Mean change of SST ($\degree$C)")
        pl.savefig('figs/liege/meanmap_Dsst.pdf',transparent=True)
Пример #2
0
    def movie(self):
        import matplotlib as mpl
        mpl.rcParams['axes.labelcolor'] = 'white'
        pl.close(1)
        pl.figure(1, (8, 4.5), facecolor='k')
        miv = np.ma.masked_invalid
        figpref.current()
        jd0 = pl.date2num(dtm(2005, 1, 1))
        jd1 = pl.date2num(dtm(2005, 12, 31))
        mp = projmaps.Projmap('glob')
        x, y = mp(self.llon, self.llat)
        for t in np.arange(jd0, jd1):
            print pl.num2date(t)
            self.load(t)

            pl.clf()
            pl.subplot(111, axisbg='k')
            mp.pcolormesh(x,
                          y,
                          miv(np.sqrt(self.u**2 + self.v**2)),
                          cmap=cm.gist_heat)
            pl.clim(0, 1.5)
            mp.nice()
            pl.title(
                '%04i-%02i-%02i' % (pl.num2date(t).year, pl.num2date(t).month,
                                    pl.num2date(t).day),
                color='w')
            pl.savefig('/Users/bror/oscar/norm/%03i.png' % t,
                       bbox_inches='tight',
                       facecolor='k',
                       dpi=150)
Пример #3
0
    def glob(self):

        mat = np.load('globcummat.npz')

        figpref.current()
        pl.close(1)
        pl.figure(1)

        pl.plot(*self.cumcum(abs(np.random.rand(500000))), c='g',
                lw=1, ls=":", label='Random values, rectangular distr.')
        pl.plot(*self.cumcum(abs(np.random.randn(500000))),
                c='r', lw=1, ls=":", label='Random values, normal distr.')
        pl.plot(*self.cumcum(abs(np.random.lognormal(0,1,500000))), c='b',
                lw=1, ls=":", label='Random values log-normal distr.')


        pl.plot(np.linspace(0,1,100), np.mean(mat['globmat'],axis=1),
                lw=2, alpha=0.5, label="Global")
        pl.plot(np.linspace(0,1,100), np.mean(mat['northmat'],axis=1),
                lw=2, alpha=0.5, label="Northern hemisphere")
        pl.plot(np.linspace(0,1,100), np.mean(mat['southmat'],axis=1),
                lw=2, alpha=0.5, label="Southern hemisphere")
        pl.ylim(0,1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/glob_glob.pdf',
                   transparent=True, bbox_inches='tight')
Пример #4
0
    def cumcummap(self):

        figpref.current()

        h5fld = self.Dchl
        tlen, jmat, imat = h5fld.shape
        ppp = np.zeros((jmat, imat)) * np.nan
        for j in np.arange(jmat):
            for i in np.arange(imat):
                vec = h5fld[:, j, i]
                vec = vec[vec > 0]
                if len(vec) > 0: ppp[j, i] = self.cumpos(vec)
        pl.close(1)
        pl.figure(1)
        self.pcolor(miv(ppp), oneside=True)
        pl.clim(0.3, 0.8)
        pl.title(r'Cumulative Dchl for 10% highest pos obs.')
        pl.savefig('figs/liege/cumcummap_pos_Dchl.pdf')

        ppp = np.zeros((jmat, imat)) * np.nan
        for j in np.arange(jmat):
            for i in np.arange(imat):
                vec = h5fld[:, j, i]
                vec = -vec[vec < 0]
                if len(vec) > 0: ppp[j, i] = self.cumpos(vec)
        pl.close(2)
        pl.figure(2)
        self.pcolor(miv(ppp), oneside=True)
        pl.clim(0.3, 0.8)
        pl.title(r'Cumulative Dchl for 10% highest neg obs.')
        pl.savefig('figs/liege/cumcummap_neg_Dchl.pdf')

        h5fld = self.Dsst

        tlen, jmat, imat = h5fld.shape
        ppp = np.zeros((jmat, imat)) * np.nan
        for j in np.arange(jmat):
            for i in np.arange(imat):
                vec = h5fld[:, j, i]
                vec = vec[vec > 0]
                if len(vec) > 0: ppp[j, i] = self.cumpos(vec)
        pl.close(3)
        pl.figure(3)
        self.pcolor(miv(ppp), oneside=True)
        pl.clim(0.3, 0.8)
        pl.title(r'Cumulative Dsst for 10% highest pos obs.')
        pl.savefig('figs/liege/cumcummap_pos_Dsst.pdf')

        ppp = np.zeros((jmat, imat)) * np.nan
        for j in np.arange(jmat):
            for i in np.arange(imat):
                vec = h5fld[:, j, i]
                vec = -vec[vec < 0]
                if len(vec) > 0: ppp[j, i] = self.cumpos(vec)
        pl.close(4)
        pl.figure(4)
        self.pcolor(miv(ppp), oneside=True)
        pl.clim(0.3, 0.8)
        pl.title(r'Cumulative Dsst for 10% highest neg obs.')
        pl.savefig('figs/liege/cumcummap_neg_Dsst.pdf')
Пример #5
0
    def o2ar(self):

        cr = bender_liege.cruises.all_cruises()

        figpref.current()
        pl.close(1)
        pl.figure(1)

        pl.plot(*self.cumcum(abs(np.random.rand(500000))),
                c='g',
                lw=1,
                ls=":",
                label='Random values, rectangular distr.')
        pl.plot(*self.cumcum(abs(np.random.randn(500000))),
                c='r',
                lw=1,
                ls=":",
                label='Random values, normal distr.')
        pl.plot(*self.cumcum(abs(np.random.lognormal(0, 1, 500000))),
                c='b',
                lw=1,
                ls=":",
                label='Random values log-normal distr.')

        vec = cr.ncp[cr.ncp > 0]
        pl.plot(*self.cumcum(vec), lw=2, alpha=0.5, label="O2Ar based NCP")
        pl.ylim(0, 1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/glob_o2ar.pdf',
                   transparent=True,
                   bbox_inches='tight')
Пример #6
0
    def heatmap(self, maskvec=None, jd=None, cmap=None, alpha=1, colorbar=True,
                clf=True, map_region=None, log=False, kwargs={}):
        """Plot particle positions on a map
                 
                 mask: Boolean vector determining which particles to plot
                ntrac: Particle ID
                   jd: Julian date to plot, has to be included in jdvec.
                 cmap: color map to use
                alpha: transparancy of pcolormap
                  clf: Clear figure if True
             colorbar: Show colorbar if True (default)
           map_region: Use other map_regions than set by config file
               kwargs: Other arguments to pcolor (must be a dict).
        """
        if maskvec is None:
            maskvec = self.ntrac==self.ntrac
        if jd is not None:
            maskvec = maskvec & (self.jd==jd)

        if USE_FIGPREF:
            figpref.current()
        if clf:
            pl.clf()

        if cmap is not None:
            kwargs['cmap'] = cmap
        if log is True:
            kwargs['norm'] = LogNorm()
        if colorbar is True:
            kwargs['colorbar'] = True
        mat = self.heatmat(nan=True, maskvec=maskvec, jd=None)
        mat[mat==0] = np.nan
        self.gcm.pcolor(mat, **kwargs)
        if jd: pl.title(pl.num2date(jd).strftime("%Y-%m-%d %H:%M"))
Пример #7
0
    def globtime(self):

        mat = np.load('globcummat.npz')
        jd1 = pl.datestr2num('2003-01-01')
        jd2 = pl.datestr2num('2012-12-31')
        jdvec = np.arange(jd1, jd2)

        figpref.current()
        pl.close(1)
        pl.figure(1)

        pl.plot_date(jdvec,
                     mat['northmat'][10, :],
                     'r-',
                     alpha=0.5,
                     label="Northern hemisphere")
        pl.plot_date(jdvec,
                     mat['southmat'][10, :],
                     'b-',
                     alpha=0.5,
                     label="Southern hemisphere")
        pl.ylim(0, 1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/glob_time.pdf',
                   transparent=True,
                   bbox_inches='tight')
Пример #8
0
    def latslice(self, datadir='/Volumes/keronHD3/globChl/result/'):
        from scipy.io import loadmat

        figpref.current()
        pl.close(1)
        pl.figure(1)

        pl.plot(*self.cumcum(abs(np.random.rand(500000))),
                c='g',
                lw=1,
                ls=":",
                label='Random values, rectangular distr.')
        pl.plot(*self.cumcum(abs(np.random.randn(500000))),
                c='r',
                lw=1,
                ls=":",
                label='Random values, normal distr.')
        pl.plot(*self.cumcum(abs(np.random.lognormal(0, 1, 500000))),
                c='b',
                lw=1,
                ls=":",
                label='Random values log-normal distr.')

        for lat in [0, 15, 30, 45, 60, 75]:
            mat = loadmat(datadir + 'latsliceschl_lat%i.mat' % lat)

            pl.plot(*self.cumcum(mat['chl']),
                    lw=2,
                    alpha=0.5,
                    label="Chl, lat=%i" % lat)
        pl.ylim(0, 1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/glob_latslice.pdf',
                   transparent=True,
                   bbox_inches='tight')
Пример #9
0
    def meanplots(self):
        figpref.current()
        pl.close('all')

        def pcolor(fld, F, cmin, cmax, oneside=True):
            pl.figure(F)
            self.pcolor(miv(fld), oneside=oneside)
            pl.clim(cmin, cmax)

        """
        h = np.where(self.Dchl>0, self.Dchl, np.nan)
        pcolor(nanmean(h, axis=0), 1, 0, 2)
        h = np.where(self.Dchl<0, self.Dchl, np.nan)
        pcolor(-nanmean(h, axis=0), 2, 0, 2)
        
        h = np.where(self.Dsst>0, self.Dsst, np.nan)
        pcolor(nanmean(h, axis=0), 3, 0, 0.4)
        h = np.where(self.Dsst<0, self.Dsst, np.nan)
        pcolor(-nanmean(h, axis=0), 4, 0, 0.4)
        """
        pcolor(nanmean(self.Dchl, axis=0), 5, -0.25, 0.25, False)
        pl.title(r"Mean change of Chl (mg m$^{-3}$)")
        pl.savefig('figs/liege/meanmap_Dchl.pdf', transparent=True)
        pcolor(nanmean(self.Dsst, axis=0), 6, -0.25, 0.25, False)
        pl.title(r"Mean change of SST ($\degree$C)")
        pl.savefig('figs/liege/meanmap_Dsst.pdf', transparent=True)
Пример #10
0
    def meantime2plot(self, sst=True, chl=True):

        figpref.current()
        pl.close(1)
        fig = pl.figure(1)
        pl.subplots_adjust(hspace=0, right=0.85, left=0.15)

        def plot(fldname):
            self.histmoeller(fldname)
            pl.fill_between(self.jdvec,
                            self.jdvec * 0,
                            self.posmean,
                            facecolor='powderblue')
            pl.fill_between(self.jdvec,
                            self.negmean,
                            self.jdvec * 0,
                            facecolor='pink')
            pl.plot(self.jdvec, self.negmean + self.posmean, lw=1, c='k')
            pl.gca().xaxis.axis_date()

        if sst:
            ax = pl.subplot(2, 1, 1)
            plot('Dsst')
            pl.ylabel('Dsst ($\degree$C d$^{-1}$')
            pl.setp(ax.get_xticklabels(), visible=False)
        if chl:
            ax = pl.subplot(2, 1, 2)
            plot('Dchl')
            pl.ylim(-2, 2)
            pl.yticks([-2, -1, 0, 1, 2])
            pl.ylabel('Chl (mg m$^{3}$ d$^{-1}$)')
        pl.savefig('figs/liege/meantime_both.pdf')
Пример #11
0
 def movie(self):
     import matplotlib as mpl
     mpl.rcParams['axes.labelcolor'] = 'white'
     pl.close(1)
     pl.figure(1,(8,4.5),facecolor='k')
     miv = np.ma.masked_invalid
     figpref.current()
     jd0 = pl.date2num(dtm(2005,1,1))
     jd1 = pl.date2num(dtm(2005,12,31))
     mp = projmaps.Projmap('glob')
     x,y = mp(self.llon,self.llat)
     for t in np.arange(jd0,jd1):
         print pl.num2date(t)
         self.load(t)
     
         pl.clf()
         pl.subplot(111,axisbg='k')
         mp.pcolormesh(x,y,
                       miv(np.sqrt(self.u**2 +self.v**2)),
                       cmap=cm.gist_heat)
         pl.clim(0,1.5)
         mp.nice()
         pl.title('%04i-%02i-%02i' % (pl.num2date(t).year,
                                      pl.num2date(t).month,
                                      pl.num2date(t).day),
                  color='w')
         pl.savefig('/Users/bror/oscar/norm/%03i.png' % t,
                    bbox_inches='tight',facecolor='k',dpi=150)
Пример #12
0
    def meantime2plot(self, sst=True, chl=True):

        figpref.current()
        pl.close(1)
        fig = pl.figure(1)
        pl.subplots_adjust(hspace=0,right=0.85, left=0.15)

        def plot(fldname):
            self.histmoeller(fldname)            
            pl.fill_between(self.jdvec, self.jdvec*0, self.posmean,
                            facecolor='powderblue')
            pl.fill_between(self.jdvec, self.negmean, self.jdvec*0,
                            facecolor='pink')
            pl.plot(self.jdvec, self.negmean+self.posmean,lw=1,c='k')
            pl.gca().xaxis.axis_date()


        if sst:
            ax = pl.subplot(2,1,1)
            plot('Dsst')
            pl.ylabel('Dsst ($\degree$C d$^{-1}$')
            pl.setp(ax.get_xticklabels(), visible=False)        
        if chl:
            ax = pl.subplot(2,1,2)
            plot('Dchl')
            pl.ylim(-2,2)
            pl.yticks([-2,-1,0,1,2])
            pl.ylabel('Chl (mg m$^{3}$ d$^{-1}$)')
        pl.savefig('figs/liege/meantime_both.pdf')
Пример #13
0
    def cumcum_theory(self):

        figpref.current()
        pl.close(1)
        pl.figure(1)
        pl.plot(*self.cumcum(abs(np.random.rand(500000))), c='g',
                    lw=2, ls="-", label='Random values, rectangular distr.')
        pl.legend(loc='lower right')
        pl.ylim(0,1)
        pl.savefig('figs/liege/cc_theory_rectdist.pdf',
                   transparent=True, bbox_inches='tight')

        pl.plot(*self.cumcum(abs(np.random.randn(500000))), c='r',
                lw=2, ls="-", label='Random values, normal distr.')
        pl.legend(loc='lower right')
        pl.ylim(0,1)
        pl.savefig('figs/liege/cc_theory_normrectdist.pdf',
                   transparent=True, bbox_inches='tight')

        pl.plot(*self.cumcum(abs(np.random.lognormal(0,1,500000))), c='b',
                lw=2, ls="-", label='Random values log-normal distr.')   
        pl.ylim(0,1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/cc_theory_lognormrectdist.pdf',
                   transparent=True, bbox_inches='tight')
Пример #14
0
 def reset(self):
     self.ffmpgF = ("-mbd rd -flags +mv4+aic -trellis 2 " +
                    " -cmp 2 -subcmp 2 -g 300 -y")
     self.oset = " -vcodec libx264 -qscale 1"
     self.tdir = tempfile.mkdtemp()
     print " === Images for video saved at " + self.tdir
     self.n = 0
     pl.close('all')
     figpref.current()
Пример #15
0
 def reset(self):
     self.ffmpgF = ("-mbd rd -flags +mv4+aic -trellis 2 " +
                    " -cmp 2 -subcmp 2 -g 300 -y")
     self.oset = " -vcodec libx264 -qscale 1"
     self.tdir = tempfile.mkdtemp()
     print " === Images for video saved at " + self.tdir
     self.n = 0
     pl.close('all')
     figpref.current()
Пример #16
0
def patch(tr):
    
    figpref.current()
    pl.figure(1)
    sH0,_ = tr.scatter(jd=732371.125+0,s=3,c='g',clf=False)
    sH1,_ = tr.scatter(jd=732371.125+1,s=3,c='r',clf=False)
    sH2,_ = tr.scatter(jd=732371.125+2,s=3,c='b',clf=False)

    pl.legend((sH0,sH1,sH2),('0 Hours','24 Hours','48 Hours') )
    pl.savefig('figs/patch_days.png')
Пример #17
0
def interp(ps,intstart=6353):
    import figpref
    import projmaps
    figpref.current()
    
    ps.c.execute("SELECT distinct(ints) FROM casco__chlor_a " + 
                 "   WHERE intstart=%i" % intstart) 
    ints1,ints2 = ps.c.fetchall()

    sql = """SELECT t1.ntrac,t1.val,t2.val,p.x,p.y,p.ints
               FROM casco__chlor_a t1
               INNER JOIN casco__chlor_a t2 ON t1.ntrac=t2.ntrac
               INNER JOIN casco p ON t1.ntrac=p.ntrac
               WHERE t1.intstart=%i
                  AND t2.intstart=%i
                  AND p.intstart=%i
                  AND t1.ints=%i
                  AND t2.ints=%i;
                  """ % (intstart,intstart,intstart,ints1[0],ints2[0])
    ps.c.execute(sql)
    res = zip(*ps.c.fetchall())
    class trj: pass
    if len(res) > 0:
        for n,a in enumerate(['ntrac','t1val','t2val','x','y','ints']):
            trj.__dict__[a] = np.array(res[n])

    mask = (trj.ints.astype(np.float)/100-trj.ints/100)>0.5
    trj.ints[mask]=trj.ints[mask]+1
    tvec = np.unique(trj.ints)
    tvec = tvec[tvec<=ints2[0]]
    itvec = tvec-tvec.min()
    itvec = itvec.astype(np.float)/itvec.max()

    mp = projmaps.Projmap('casco')
    xl,yl = mp(ps.llon,ps.llat)
    for n,t in enumerate(tvec):
        fld = ps.cs.llat * 0
        cnt = ps.cs.llat * 0

        xvc = (trj.x[trj.ints==t].astype(np.int))
        yvc = (trj.y[trj.ints==t].astype(np.int))
        val = ( np.log(trj.t1val[trj.ints==t])*(1-itvec[n]) +
                np.log(trj.t2val[trj.ints==t])*(itvec[n]) )
        for x,y,v in zip(xvc,yvc,val):
            fld[y,x] += v
            cnt[y,x] += 1

        pl.clf()
        mp.pcolormesh(xl,yl,miv(fld/cnt))
        mp.nice()
        jd = (ps.base_iso +
              (float(t)-(intstart)/8*3600*24)/3600/24 + intstart/8) + 0.583
        pl.title(pl.num2date(jd).strftime("log(Chl) %Y-%m-%d %H:%M"))
        pl.clim(-2,2.5)
        pl.savefig("interp_%i_%03i.png" % (intstart,n), dpi=100)
Пример #18
0
def interp(ps,intstart=6353):
    import figpref
    import projmaps
    figpref.current()
    
    ps.c.execute("SELECT distinct(ints) FROM casco__chlor_a " + 
                 "   WHERE intstart=%i" % intstart) 
    ints1,ints2 = ps.c.fetchall()

    sql = """SELECT t1.ntrac,t1.val,t2.val,p.x,p.y,p.ints
               FROM casco__chlor_a t1
               INNER JOIN casco__chlor_a t2 ON t1.ntrac=t2.ntrac
               INNER JOIN casco p ON t1.ntrac=p.ntrac
               WHERE t1.intstart=%i
                  AND t2.intstart=%i
                  AND p.intstart=%i
                  AND t1.ints=%i
                  AND t2.ints=%i;
                  """ % (intstart,intstart,intstart,ints1[0],ints2[0])
    ps.c.execute(sql)
    res = zip(*ps.c.fetchall())
    class trj: pass
    if len(res) > 0:
        for n,a in enumerate(['ntrac','t1val','t2val','x','y','ints']):
            trj.__dict__[a] = np.array(res[n])

    mask = (trj.ints.astype(np.float)/100-trj.ints/100)>0.5
    trj.ints[mask]=trj.ints[mask]+1
    tvec = np.unique(trj.ints)
    tvec = tvec[tvec<=ints2[0]]
    itvec = tvec-tvec.min()
    itvec = itvec.astype(np.float)/itvec.max()

    mp = projmaps.Projmap('casco')
    xl,yl = mp(ps.llon,ps.llat)
    for n,t in enumerate(tvec):
        fld = ps.cs.llat * 0
        cnt = ps.cs.llat * 0

        xvc = (trj.x[trj.ints==t].astype(np.int))
        yvc = (trj.y[trj.ints==t].astype(np.int))
        val = ( np.log(trj.t1val[trj.ints==t])*(1-itvec[n]) +
                np.log(trj.t2val[trj.ints==t])*(itvec[n]) )
        for x,y,v in zip(xvc,yvc,val):
            fld[y,x] += v
            cnt[y,x] += 1

        pl.clf()
        mp.pcolormesh(xl,yl,miv(fld/cnt))
        mp.nice()
        jd = (ps.base_iso +
              (float(t)-(intstart)/8*3600*24)/3600/24 + intstart/8) + 0.583
        pl.title(pl.num2date(jd).strftime("log(Chl) %Y-%m-%d %H:%M"))
        pl.clim(-2,2.5)
        pl.savefig("interp_%i_%03i.png" % (intstart,n), dpi=100)
Пример #19
0
 def contour(self,fld, *args, **kwargs):
     """Make a pcolor-plot of field"""
     if USE_FIGPREF: figpref.current()
     if not hasattr(self, 'mp'): self.add_mp()
     miv = np.ma.masked_invalid
     if type(fld) == str:
         field = self.__dict__[fld]
     else:
         field = fld
     x,y = self.mp(self.llon, self.llat)
     self.mp.contour(x,y,miv(field), *args, **kwargs)
     self.mp.nice()
Пример #20
0
    def histmoellerplot(self, fldname="Dchl"):

        self.histmoeller(fldname)
        figpref.current()
        pl.close(1)
        fig = pl.figure(1)
        pl.subplots_adjust(hspace=0, right=0.85, left=0.15)

        def subplot(sp, mat, vec, xvec):
            ax = pl.subplot(2, 1, sp, axisbg='0.8')
            im = pl.pcolormesh(self.jdvec,
                               xvec,
                               miv(mat.T),
                               rasterized=True,
                               norm=LogNorm(vmin=1, vmax=10000),
                               cmap=WRY())
            pl.plot(self.jdvec, vec, lw=2)
            pl.gca().xaxis.axis_date()
            pl.setp(ax, xticklabels=[])
            return im

        im = subplot(1, self.posmat, self.posmean, self.hpos)
        im = subplot(2, self.negmat, self.negmean, -self.hpos)

        pl.figtext(0.08,
                   0.5,
                   r'%s d$^{-1}$)' % fldname,
                   rotation='vertical',
                   size=16,
                   va='center')
        cbar_ax = fig.add_axes([0.87, 0.15, 0.025, 0.7])
        cb = fig.colorbar(im, cax=cbar_ax)
        cb.set_label('Number of grid cells')
        pl.savefig('figs/liege/histmoeller_%s.pdf' % fldname)

        pl.close(2)
        fig = pl.figure(2)
        pl.fill_between(self.jdvec,
                        self.jdvec * 0,
                        self.posmean,
                        facecolor='powderblue')
        pl.fill_between(self.jdvec,
                        self.negmean,
                        self.jdvec * 0,
                        facecolor='pink')
        pl.plot(self.jdvec, self.negmean + self.posmean, lw=1, c='k')
        #pl.title(fldname)
        pl.gca().xaxis.axis_date()

        pl.savefig('figs/liege/meantime_%s.pdf' % fldname)
Пример #21
0
    def cumcumtime(self):

        figpref.current()

        h5fld = self.Dsst
        tlen,_,_ = h5fld.shape
        ppp = []
        for t in np.arange(tlen):
            vec = h5fld[t,:,:]
            vec = vec[vec>0]
            if len(vec) > 0: ppp.append(self.cumpos(vec))
        #pl.close(1)
        #pl.figure(1)
        pl.plot(ppp)
Пример #22
0
    def cumcumtime(self):

        figpref.current()

        h5fld = self.Dsst
        tlen, _, _ = h5fld.shape
        ppp = []
        for t in np.arange(tlen):
            vec = h5fld[t, :, :]
            vec = vec[vec > 0]
            if len(vec) > 0: ppp.append(self.cumpos(vec))
        #pl.close(1)
        #pl.figure(1)
        pl.plot(ppp)
Пример #23
0
def totmatplot(mat,dt):
    """Plot a histmoeller diagram of totmat"""
    xi = np.linspace(np.log(0.001), np.log(10), 101)
    figpref.current()
    pl.clf()
    pl.contourf(np.arange(30),np.exp((xi[1:]+xi[:-1])/2),
                miv(mat/mat.max(axis=0)[np.newaxis,:]), np.arange(0,1.1,0.125),
                cmap=cm.OrRd)
    pl.clim(0,1)
    pl.setp(pl.gca(),yscale='log')
    cb = pl.colorbar(aspect=40, pad=0.001, ticks=[0,0.25,0.5,0.75,1])
    cb.ax.set_ylabel('Relative number of particles')
    pl.xlim(0,26)
    pl.xlabel("Time (days)")
    pl.ylabel(r"Positive change in Chlorophyll (mg l$^{-1}$ d$^{-1}$)")
    pl.title("Biological production from particle tracking. Dt=%i hour(s)" % dt)
Пример #24
0
def cumcum_theory():

    figpref.current()
    pl.close(1)
    pl.figure(1)

    #a = np.random.randn(4,4)
    a = np.random.lognormal(0, 1, (4, 4))
    pl.clf()
    pl.pcolormesh(abs(a), cmap=WRY())
    pl.yticks([])
    pl.xticks([])
    pl.savefig('figs/liege/cc_theory_grid.pdf',
               transparent=True,
               bbox_inches='tight')

    b = np.reshape(np.abs(a), (1, 16))
    pl.clf()
    pl.subplot(8, 1, 1)
    pl.pcolormesh(b, cmap=WRY())
    pl.yticks([])
    pl.xticks([])
    pl.savefig('figs/liege/cc_theory_vec.pdf',
               transparent=True,
               bbox_inches='tight')

    c = np.sort(b)[:, ::-1]
    pl.clf()
    pl.subplot(8, 1, 1)
    pl.pcolormesh(c, cmap=WRY())
    pl.yticks([])
    pl.xticks([])
    pl.savefig('figs/liege/cc_theory_sortvec.pdf',
               transparent=True,
               bbox_inches='tight')

    d = np.hstack((0, np.squeeze(np.cumsum(c) / np.sum(c))))
    pl.clf()
    pl.plot(np.linspace(0, 1, 17), d)
    pl.ylim(0, 1)
    #pl.xticks([])
    pl.savefig('figs/liege/cc_theory_cumcum.pdf',
               transparent=True,
               bbox_inches='tight')
Пример #25
0
    def glob(self):

        mat = np.load('globcummat.npz')

        figpref.current()
        pl.close(1)
        pl.figure(1)

        pl.plot(*self.cumcum(abs(np.random.rand(500000))),
                c='g',
                lw=1,
                ls=":",
                label='Random values, rectangular distr.')
        pl.plot(*self.cumcum(abs(np.random.randn(500000))),
                c='r',
                lw=1,
                ls=":",
                label='Random values, normal distr.')
        pl.plot(*self.cumcum(abs(np.random.lognormal(0, 1, 500000))),
                c='b',
                lw=1,
                ls=":",
                label='Random values log-normal distr.')

        pl.plot(np.linspace(0, 1, 100),
                np.mean(mat['globmat'], axis=1),
                lw=2,
                alpha=0.5,
                label="Global")
        pl.plot(np.linspace(0, 1, 100),
                np.mean(mat['northmat'], axis=1),
                lw=2,
                alpha=0.5,
                label="Northern hemisphere")
        pl.plot(np.linspace(0, 1, 100),
                np.mean(mat['southmat'], axis=1),
                lw=2,
                alpha=0.5,
                label="Southern hemisphere")
        pl.ylim(0, 1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/glob_glob.pdf',
                   transparent=True,
                   bbox_inches='tight')
Пример #26
0
def totmatplot(mat, dt):
    """Plot a histmoeller diagram of totmat"""
    xi = np.linspace(np.log(0.001), np.log(10), 101)
    figpref.current()
    pl.clf()
    pl.contourf(np.arange(30),
                np.exp((xi[1:] + xi[:-1]) / 2),
                miv(mat / mat.max(axis=0)[np.newaxis, :]),
                np.arange(0, 1.1, 0.125),
                cmap=cm.OrRd)
    pl.clim(0, 1)
    pl.setp(pl.gca(), yscale='log')
    cb = pl.colorbar(aspect=40, pad=0.001, ticks=[0, 0.25, 0.5, 0.75, 1])
    cb.ax.set_ylabel('Relative number of particles')
    pl.xlim(0, 26)
    pl.xlabel("Time (days)")
    pl.ylabel(r"Positive change in Chlorophyll (mg l$^{-1}$ d$^{-1}$)")
    pl.title("Biological production from particle tracking. Dt=%i hour(s)" %
             dt)
Пример #27
0
    def globtime(self):

        mat = np.load('globcummat.npz')
        jd1 = pl.datestr2num('2003-01-01')
        jd2 = pl.datestr2num('2012-12-31')
        jdvec = np.arange(jd1,jd2)
        
        figpref.current()
        pl.close(1)
        pl.figure(1)
        
        pl.plot_date(jdvec, mat['northmat'][10,:],'r-',
                     alpha=0.5, label="Northern hemisphere")
        pl.plot_date(jdvec, mat['southmat'][10,:],'b-',
                     alpha=0.5, label="Southern hemisphere")
        pl.ylim(0,1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/glob_time.pdf',
                   transparent=True, bbox_inches='tight')
Пример #28
0
    def freqmaps(self):

        figpref.current()
        pl.close(1)
        pl.figure(1)
        h = np.where(self.Dchl > 0.5, 1, 0)
        fld = np.sum(h, axis=0).astype(np.float) / np.nansum(
            self.Dchl * 0 + 1, 0)
        self.pcolor(miv(fld * 100), oneside=True)
        pl.clim(0, 25)
        pl.title(r'Percent observations where Dchl > 0.5 mg $m^{-3}$')
        pl.savefig('figs/liege/freqmap_pos_Dchl.pdf', transparent=True)

        pl.close(2)
        pl.figure(2)
        h = np.where(self.Dchl < -0.5, 1, 0)
        fld = np.sum(h, axis=0).astype(np.float) / np.nansum(
            self.Dchl * 0 + 1, 0)
        self.pcolor(miv(fld * 100), oneside=True)
        pl.clim(0, 25)
        pl.title('Percent observations where Dchl < -0.5 mg $m^{-3}$')
        pl.savefig('figs/liege/freqmap_neg_Dchl.pdf')

        figpref.current()
        pl.close(3)
        pl.figure(3)
        h = np.where(self.Dsst > 0.4, 1, 0)
        fld = np.sum(h, axis=0).astype(np.float) / np.nansum(
            self.Dsst * 0 + 1, 0)
        self.pcolor(miv(fld * 100), oneside=True)
        pl.clim(0, 25)
        pl.title(r'Percent observations where Dsst > 0.4 $\degree$C')
        pl.savefig('figs/liege/freqmap_pos_Dsst.pdf')

        pl.close(4)
        pl.figure(4)
        h = np.where(self.Dsst < -0.4, 1, 0)
        fld = np.sum(h, axis=0).astype(np.float) / np.nansum(
            self.Dsst * 0 + 1, 0)
        self.pcolor(miv(fld * 100), oneside=True)
        pl.clim(0, 25)
        pl.title('Percent observations where Dsst < -0.4 $\degree$C')
        pl.savefig('figs/liege/freqmap_neg_Dsst.pdf')
Пример #29
0
 def pcolor(self, fld, title=None, colorbar=False, **kwargs):
     """Make a pcolor-plot of field"""
     if USE_FIGPREF: figpref.current()
     if not hasattr(self, 'mp'): self.add_mp()
     miv = np.ma.masked_invalid
     if type(fld) == str:
         field = getattr(self, fld)
     else:
         field = fld
     x,y = self.mp(self.llon, self.llat)
     self.mp.pcolormesh(x,y,miv(field), **kwargs)
     self.mp.nice()
     if title is not None:
         pl.title(title)        
     if colorbar:
         if type(colorbar) is dict:
             self.mp.colorbar(**colorbar)
         else:
             self.mp.colorbar()
Пример #30
0
    def cumcumtot(self):

        figpref.current()
        pl.close(1)
        pl.figure(1)

        pl.plot(*self.cumcum(abs(np.random.rand(500000))), c='g',
                lw=1, ls=":", label='Random values, rectangular distr.')
        pl.plot(*self.cumcum(abs(np.random.randn(500000))),
                c='r', lw=1, ls=":", label='Random values, normal distr.')
        pl.plot(*self.cumcum(abs(np.random.lognormal(0,1,500000))), c='b',
                 lw=1, ls=":", label='Random values log-normal distr.')
    
        vec = self.Dsst[~np.isnan(self.Dsst)]
        pl.plot(*self.cumcum(vec[vec>0]),  lw=2, alpha=0.5,
                label="SST, positive values")
        pl.ylim(0,1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/cumcumtot_pos_sst.pdf',
                   transparent=True, bbox_inches='tight')
        pl.plot(*self.cumcum(-vec[vec<0]), lw=2, alpha=0.5,
                label="SST, negative values")
        pl.ylim(0,1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/cumcumtot_posneg_sst.pdf',
                   transparent=True, bbox_inches='tight')

        vec = self.Dchl[~np.isnan(self.Dchl)]
        pl.plot(*self.cumcum(vec[vec>0]),  lw=2, alpha=0.5,
                label="Chl, positive values")
        pl.ylim(0,1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/cumcumtot_posneg_sst_pos_chl.pdf',
                   transparent=True, bbox_inches='tight')

        pl.plot(*self.cumcum(-vec[vec<0]), lw=2, alpha=0.5,
                label="Chl, negative values")
        pl.ylim(0,1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/cumcumtot_posneg_sst_posneg_chl.pdf',
                   transparent=True, bbox_inches='tight')
   
        pl.savefig('figs/liege/cumcumtot.pdf')
Пример #31
0
    def tauregmap(self):
        if not hasattr(self,'regtaus'): self.calc_halftimes()
        if not hasattr(self,'reg'): self.regvec_from_regions()
        if not hasattr(self,'lon'): self.ijll()

        figpref.current()
        pl.close(1)
        pl.figure(1)
        mask = (self.jd==self.jd.min()) & (self.reg>0)
        x,y = self.gcm.mp(self.lon[mask], self.lat[mask])
        regs = self.reg[mask]
        taus = self.reg[mask].astype(np.float)
        for n,t in enumerate(self.regtaus):
            taus[regs==n] = t
        self.gcm.mp.scatter(x, y, 5, taus*24)
        pl.clim(0,30)
        cb = pl.colorbar(aspect=30,pad=0.02,ticks=[0,6,12,18,24,30])
        cb.ax.set_ylabel(r'$\tau$ (Hours)')
        self.gcm.mp.nice()
        pl.title('Residence times defined as e-folding half-life ')
        pl.savefig('residencetimes.png')
Пример #32
0
def hr_vs_dy_figs(ntrac=200):

    figpref.current()
    tr = Discs('bem', 'bem')
    tr.load()
    tr.fld2trajs('chlo')
    tr.ijll()
    mask = tr.ntrac == ntrac
    chl = tr.chlo[mask][:200]
    jd = tr.jd[mask][:200]
    dchl = chl[1:] - chl[:-1]

    #plot_date(jd,chl,'-')
    #plot(jd[1:], cumsum(dchl)+chl[0])
    plot_date(jd[1:], dchl, '-')
    plot(jd[1::24], dchl[::24])

    pl.figure(1)
    pl.clf()
    x, y = tr.gcm.mp(tr.lon[mask], tr.lat[mask])
    tr.gcm.mp.scatter(x, y)
    tr.gcm.mp.nice()
    pl.savefig('chlhrdy_map_%i.png' % ntrac)

    pl.figure(2)
    pl.clf()
    pl.subplot(2, 1, 1)
    pl.plot_date(jd, chl, '-')
    pl.plot(jd[1::24], (cumsum(dchl) + chl[0])[::24], 'o-')
    pl.ylabel('Chl (mg C / ml)')

    pl.gca().xaxis.set_major_formatter(mf)

    pl.subplot(2, 1, 2)
    pl.plot_date(jd[1:], dchl, '-')
    pl.plot(jd[1::24], dchl[::24], 'o-')
    pl.gca().xaxis.set_major_formatter(mf)
    pl.ylabel('Change in Chl (mg C / ml)')
    pl.xlabel('Time (days)')
    pl.savefig('chlhrdy_dchl_%i.png' % ntrac)
Пример #33
0
def hr_vs_dy_figs(ntrac=200):

    figpref.current()
    tr = Discs('bem','bem')
    tr.load()
    tr.fld2trajs('chlo')
    tr.ijll()
    mask = tr.ntrac == ntrac
    chl = tr.chlo[mask][:200]
    jd = tr.jd[mask][:200]
    dchl = chl[1:]-chl[:-1]

    #plot_date(jd,chl,'-')
    #plot(jd[1:], cumsum(dchl)+chl[0])
    plot_date(jd[1:], dchl,'-')
    plot(jd[1::24], dchl[::24])

    pl.figure(1)
    pl.clf()
    x,y = tr.gcm.mp(tr.lon[mask],tr.lat[mask])
    tr.gcm.mp.scatter(x,y)
    tr.gcm.mp.nice()
    pl.savefig('chlhrdy_map_%i.png' % ntrac)

    pl.figure(2)
    pl.clf()
    pl.subplot(2,1,1)
    pl.plot_date(jd,chl,'-')
    pl.plot(jd[1::24], (cumsum(dchl)+chl[0])[::24],'o-')
    pl.ylabel('Chl (mg C / ml)')

    pl.gca().xaxis.set_major_formatter(mf)

    pl.subplot(2,1,2)
    pl.plot_date(jd[1:], dchl,'-')
    pl.plot(jd[1::24], dchl[::24],'o-')
    pl.gca().xaxis.set_major_formatter(mf)
    pl.ylabel('Change in Chl (mg C / ml)')
    pl.xlabel('Time (days)')
    pl.savefig('chlhrdy_dchl_%i.png' % ntrac)
Пример #34
0
def cumcum_theory():

    figpref.current()
    pl.close(1)
    pl.figure(1)
        
    #a = np.random.randn(4,4)
    a = np.random.lognormal(0,1,(4,4))
    pl.clf()
    pl.pcolormesh(abs(a), cmap=WRY())
    pl.yticks([])
    pl.xticks([])
    pl.savefig('figs/liege/cc_theory_grid.pdf',
               transparent=True, bbox_inches='tight')

    b = np.reshape(np.abs(a),(1,16))
    pl.clf()
    pl.subplot(8,1,1)
    pl.pcolormesh(b, cmap=WRY())
    pl.yticks([])
    pl.xticks([])
    pl.savefig('figs/liege/cc_theory_vec.pdf',
               transparent=True, bbox_inches='tight')

    c = np.sort(b)[:,::-1]
    pl.clf()
    pl.subplot(8,1,1)
    pl.pcolormesh(c, cmap=WRY())
    pl.yticks([])
    pl.xticks([])
    pl.savefig('figs/liege/cc_theory_sortvec.pdf',
               transparent=True, bbox_inches='tight')

    d = np.hstack((0,np.squeeze(np.cumsum(c)/np.sum(c))))
    pl.clf()
    pl.plot(np.linspace(0,1,17), d)
    pl.ylim(0,1)
    #pl.xticks([])
    pl.savefig('figs/liege/cc_theory_cumcum.pdf',
               transparent=True, bbox_inches='tight')
Пример #35
0
    def freqmaps(self):

        figpref.current()
        pl.close(1)
        pl.figure(1)
        h = np.where(self.Dchl>0.5, 1, 0)
        fld = np.sum(h, axis=0).astype(np.float) / np.nansum(self.Dchl*0+1,0)
        self.pcolor(miv(fld*100), oneside=True)
        pl.clim(0,25)
        pl.title(r'Percent observations where Dchl > 0.5 mg $m^{-3}$')
        pl.savefig('figs/liege/freqmap_pos_Dchl.pdf',transparent=True)

        pl.close(2)
        pl.figure(2)
        h = np.where(self.Dchl<-0.5, 1, 0)
        fld = np.sum(h, axis=0).astype(np.float) / np.nansum(self.Dchl*0+1,0)
        self.pcolor(-miv(fld*100), oneside="neg")
        pl.clim(-25,0)
        pl.title('Percent observations where Dchl < -0.5 mg $m^{-3}$')
        pl.savefig('figs/liege/freqmap_neg_Dchl.pdf')

        figpref.current()
        pl.close(3)
        pl.figure(3)
        h = np.where(self.Dsst>0.4, 1, 0)
        fld = np.sum(h, axis=0).astype(np.float) / np.nansum(self.Dsst*0+1,0)
        self.pcolor(miv(fld*100), oneside=True)
        pl.clim(0,25)
        pl.title(r'Percent observations where Dsst > 0.4 $\degree$C')
        pl.savefig('figs/liege/freqmap_pos_Dsst.pdf')

        pl.close(4)
        pl.figure(4)
        h = np.where(self.Dsst<-0.4, 1, 0)
        fld = np.sum(h, axis=0).astype(np.float) / np.nansum(self.Dsst*0+1,0)
        self.pcolor(-miv(fld*100), oneside="neg")
        pl.clim(-25,0)
        pl.title('Percent observations where Dsst < -0.4 $\degree$C')
        pl.savefig('figs/liege/freqmap_neg_Dsst.pdf')
Пример #36
0
    def histmoellerplot(self, fldname="Dchl"):

        self.histmoeller(fldname)
        figpref.current()
        pl.close(1)
        fig = pl.figure(1)
        pl.subplots_adjust(hspace=0,right=0.85, left=0.15)

        def subplot(sp, mat, vec, xvec):
            ax = pl.subplot(2,1,sp, axisbg='0.8')
            im =pl.pcolormesh(self.jdvec, xvec, miv(mat.T), rasterized=True,
                              norm=LogNorm(vmin=1,vmax=10000), cmap=WRY())
            pl.plot(self.jdvec, vec, lw=2)
            pl.gca().xaxis.axis_date()
            pl.setp(ax, xticklabels=[])
            return im

        im = subplot(1, self.posmat, self.posmean,  self.hpos)
        im = subplot(2, self.negmat, self.negmean, -self.hpos)

        pl.figtext(0.08,0.5, r'%s d$^{-1}$)' % fldname,
                   rotation='vertical', size=16, va='center')
        cbar_ax = fig.add_axes([0.87, 0.15, 0.025, 0.7])
        cb = fig.colorbar(im, cax=cbar_ax)
        cb.set_label('Number of grid cells')
        pl.savefig('figs/liege/histmoeller_%s.pdf' % fldname)

        pl.close(2)
        fig = pl.figure(2)
        pl.fill_between(self.jdvec, self.jdvec*0, self.posmean,
                        facecolor='powderblue')
        pl.fill_between(self.jdvec, self.negmean, self.jdvec*0,
                        facecolor='pink')
        pl.plot(self.jdvec, self.negmean+self.posmean,lw=1,c='k')
        #pl.title(fldname)
        pl.gca().xaxis.axis_date()

        pl.savefig('figs/liege/meantime_%s.pdf' % fldname)
Пример #37
0
    def o2ar(self):

        cr =bender_liege.cruises.all_cruises()

        figpref.current()
        pl.close(1)
        pl.figure(1)


        pl.plot(*self.cumcum(abs(np.random.rand(500000))), c='g',
                lw=1, ls=":", label='Random values, rectangular distr.')
        pl.plot(*self.cumcum(abs(np.random.randn(500000))),
                c='r', lw=1, ls=":", label='Random values, normal distr.')
        pl.plot(*self.cumcum(abs(np.random.lognormal(0,1,500000))), c='b',
                lw=1, ls=":", label='Random values log-normal distr.')

        vec = cr.ncp[cr.ncp>0]
        pl.plot(*self.cumcum(vec),  lw=2, alpha=0.5,
                label="O2Ar based NCP")
        pl.ylim(0,1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/glob_o2ar.pdf',
                   transparent=True, bbox_inches='tight')
Пример #38
0
    def cumcum_theory(self):

        figpref.current()
        pl.close(1)
        pl.figure(1)
        pl.plot(*self.cumcum(abs(np.random.rand(500000))),
                c='g',
                lw=2,
                ls="-",
                label='Random values, rectangular distr.')
        pl.legend(loc='lower right')
        pl.ylim(0, 1)
        pl.savefig('figs/liege/cc_theory_rectdist.pdf',
                   transparent=True,
                   bbox_inches='tight')

        pl.plot(*self.cumcum(abs(np.random.randn(500000))),
                c='r',
                lw=2,
                ls="-",
                label='Random values, normal distr.')
        pl.legend(loc='lower right')
        pl.ylim(0, 1)
        pl.savefig('figs/liege/cc_theory_normrectdist.pdf',
                   transparent=True,
                   bbox_inches='tight')

        pl.plot(*self.cumcum(abs(np.random.lognormal(0, 1, 500000))),
                c='b',
                lw=2,
                ls="-",
                label='Random values log-normal distr.')
        pl.ylim(0, 1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/cc_theory_lognormrectdist.pdf',
                   transparent=True,
                   bbox_inches='tight')
Пример #39
0
    def latslice(self, datadir='/Volumes/keronHD3/globChl/result/'):
        from scipy.io import loadmat

        figpref.current()
        pl.close(1)
        pl.figure(1)

        pl.plot(*self.cumcum(abs(np.random.rand(500000))), c='g',
                lw=1, ls=":", label='Random values, rectangular distr.')
        pl.plot(*self.cumcum(abs(np.random.randn(500000))),
                c='r', lw=1, ls=":", label='Random values, normal distr.')
        pl.plot(*self.cumcum(abs(np.random.lognormal(0,1,500000))), c='b',
                lw=1, ls=":", label='Random values log-normal distr.')


        for lat in [0,15,30,45,60,75]:
            mat = loadmat(datadir + 'latsliceschl_lat%i.mat' % lat)
            
            pl.plot(*self.cumcum(mat['chl']),  lw=2, alpha=0.5,
                    label="Chl, lat=%i" % lat)
        pl.ylim(0,1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/glob_latslice.pdf',
                   transparent=True, bbox_inches='tight')
Пример #40
0
    def scatter(self,mask=None, ntrac=None, jd=None, k1=None, k2=None,
                c="g", alpha=1, lc='-w', lw='0.5', clf=True, coord="latlon", 
                land="nice", map_region=None):
        """Plot particle positions on a map
                 
                 mask: Boolean vector determining which particles to plot
                ntrac: Particle ID
                   jd: Julian date to plot, has to be included in jdvec.
                   k1: only plot particle deeper than k1
                   k2: only plot particle shallower than k1
                    c: color of particles (string or array)
                alpha: transparancy of particles
                  clf: Clear figure  if True
                coord: Use lat-lon coordinates if set to "latlon" (default),
                           i-j coordinates if set to "ij" 
                 land: Use landmask from basemap if set to "nice" (default),
                           landmask from model if set to "model". 
           map_region: Use other map_regions than set by config file

        """
        if mask is None:
            mask = self.ntrac==self.ntrac
            if jd is not None:
                mask = mask & (self.jd==jd)
            if ntrac is not None:
                mask = mask & (self.ntrac==ntrac)

        if (type(c) != str) & (len(c) == len(mask)):
            c = c[mask]

        if USE_FIGPREF:
            figpref.current()
        if clf:
            pl.clf()


        """
        if coord is "latlon":
            x,y = self.mp(self.lon[mask],self.lat[mask])
            scH = self.mp.scatter(x, y, 5, c, lw=0, alpha=alpha)
        else:
            scH = pl.scatter(self.x[mask],self.y[mask], 5, c,lw=0, alpha=alpha)
        """

        if coord is "latlon":
            if (not hasattr(self,'mp'))  & (coord=="latlon"):
                self.add_mp(map_region)
            if (not hasattr(self,'lon')) & (coord=="latlon"):
                self.ijll()
            xvec,yvec = self.mp(self.lon[mask], self.lat[mask])
            scatter = self.mp.scatter
        else:
            xvec,yvec = self.x[mask],self.y[mask]
            scatter = pl.scatter
        scH = mp.scatter(xvec, yvec, 5, c, lw=0, alpha=alpha)

            
        if land is "nice":
            land = self.gcm.mp.nice()
        elif coord is "latlon":
            self.mp.pcolormesh(self.mpxll,
                               self.mpyll,
                               np.ma.masked_equal(self.landmask, True),
                               cmap=GR_CMAP)
        else:
            pl.pcolormesh(np.arange(self.gcm.i1, self.gcm.i2+1),
                          np.arange(self.gcm.j1, self.gcm.j2+1),
                          np.ma.masked_equal(self.landmask, True),
                          cmap=GR_CMAP)
            pl.xlim(0, self.imt)
            pl.ylim(0, self.jmt)
        if (ntrac is not None) & (coord is "latlon"):
            self.mp.plot(x,y,lc,lw=lw)

        """ 
        xl,yl = self.mp(
            [self.llon[0,0], self.llon[0,-1], self.llon[-1,-1],
             self.llon[-1,0],self.llon[0,0]],
            [self.llat[0,0], self.llat[0,-1], self.llat[-1,-1],
             self.llat[-1,0], self.llat[0,0]]
             )
        #self.mp.plot(xl,yl,'0.5')
        """
        if jd: pl.title(pl.num2date(jd).strftime("%Y-%m-%d %H:%M"))
        return scH
Пример #41
0
    def cumcummap(self):

        figpref.current()

        h5fld = self.Dchl
        tlen,jmat,imat = h5fld.shape
        ppp = np.zeros((jmat,imat)) * np.nan
        for j in np.arange(jmat):
            for i in np.arange(imat):
                vec = h5fld[:,j,i]
                vec = vec[vec>0]
                if len(vec) > 0: ppp[j,i] = self.cumpos(vec)
        pl.close(1)
        pl.figure(1)
        self.pcolor(miv(ppp), oneside=True)
        pl.clim(0.3,0.8)
        pl.title(r'Cumulative Dchl for 10% highest pos obs.')
        pl.savefig('figs/liege/cumcummap_pos_Dchl.pdf')

        
        ppp = np.zeros((jmat,imat)) * np.nan
        for j in np.arange(jmat):
            for i in np.arange(imat):
                vec = h5fld[:,j,i]
                vec = -vec[vec<0]
                if len(vec) > 0: ppp[j,i] = self.cumpos(vec)
        pl.close(2)
        pl.figure(2)
        self.pcolor(miv(ppp), oneside=True)
        pl.clim(0.3,0.8)
        pl.title(r'Cumulative Dchl for 10% highest neg obs.')
        pl.savefig('figs/liege/cumcummap_neg_Dchl.pdf')

        h5fld = self.Dsst

        tlen,jmat,imat = h5fld.shape
        ppp = np.zeros((jmat,imat)) * np.nan
        for j in np.arange(jmat):
            for i in np.arange(imat):
                vec = h5fld[:,j,i]
                vec = vec[vec>0]
                if len(vec) > 0: ppp[j,i] = self.cumpos(vec)
        pl.close(3)
        pl.figure(3)
        self.pcolor(miv(ppp), oneside=True)
        pl.clim(0.3,0.8)
        pl.title(r'Cumulative Dsst for 10% highest pos obs.')
        pl.savefig('figs/liege/cumcummap_pos_Dsst.pdf')

        ppp = np.zeros((jmat,imat)) * np.nan
        for j in np.arange(jmat):
            for i in np.arange(imat):
                vec = h5fld[:,j,i]
                vec = -vec[vec<0]
                if len(vec) > 0: ppp[j,i] = self.cumpos(vec)
        pl.close(4)
        pl.figure(4)
        self.pcolor(miv(ppp), oneside=True)
        pl.clim(0.3,0.8)
        pl.title(r'Cumulative Dsst for 10% highest neg obs.')
        pl.savefig('figs/liege/cumcummap_neg_Dsst.pdf')
Пример #42
0
    def scatter(self,
                mask=None,
                ntrac=None,
                jd=None,
                k1=None,
                k2=None,
                c="g",
                clf=True,
                coord="latlon",
                land="nice",
                map_region=None):
        """Plot particle positions on a map

                 mask: Boolean vector inidcating which particles to plot
                ntrac: Particle ID
                   jd: Julian date to plot, has to be included in jdvec.
                   k1: only plot particle deeper than k1
                   k2: only plot particle shallower than k1
                    c: color of particles
                  clf: Clear figure  if True
                coord: Use lat-lon coordinates if set to "latlon" (default),
                           i-j coordinates if set to "ij" 
                 land: Use landmask from basemap if set to "nice" (default),
                           landmask from model if set to "model". 
           map_region: Use other map_regions than set by config file

        """
        if (not hasattr(self, 'mp')) & (coord == "latlon"):
            self.add_mp(map_region)
        if (not hasattr(self, 'lon')) & (coord == "latlon"):
            self.ijll()
        if mask is None:
            mask = self.ntrac == self.ntrac
            if jd is not None:
                mask = mask & (self.jd == jd)
            if ntrac is not None:
                mask = mask & (self.ntrac == ntrac)

        figpref.current()
        if clf: pl.clf()

        if coord is "latlon":
            x, y = self.mp(self.lon[mask], self.lat[mask])
            scH = self.mp.scatter(x, y, 5, c)
        else:
            scH = pl.scatter(self.x[mask], self.y[mask], 5, c)

        if land is "nice":
            land = self.gcm.mp.nice()
        elif coord is "latlon":
            self.mp.pcolormesh(self.mpxll,
                               self.mpyll,
                               np.ma.masked_equal(self.landmask, False),
                               cmap=GrGr())
        else:
            pl.pcolormesh(np.arange(self.gcm.i1, self.gcm.i2 + 1),
                          np.arange(self.gcm.j1, self.gcm.j2 + 1),
                          np.ma.masked_equal(self.landmask, False),
                          cmap=GrGr())
        if (ntrac is not None) & (coord is "latlon"):
            self.mp.plot(x, y, '-w', lw=0.5)
        """ 
        xl,yl = self.mp(
            [self.llon[0,0], self.llon[0,-1], self.llon[-1,-1],
             self.llon[-1,0],self.llon[0,0]],
            [self.llat[0,0], self.llat[0,-1], self.llat[-1,-1],
             self.llat[-1,0], self.llat[0,0]]
             )
        #self.mp.plot(xl,yl,'0.5')
        """
        if jd: pl.title(pl.num2date(jd).strftime("%Y-%m-%d %H:%M"))
        return scH
Пример #43
0
    def cumcumtot(self):

        figpref.current()
        pl.close(1)
        pl.figure(1)

        pl.plot(*self.cumcum(abs(np.random.rand(500000))),
                c='g',
                lw=1,
                ls=":",
                label='Random values, rectangular distr.')
        pl.plot(*self.cumcum(abs(np.random.randn(500000))),
                c='r',
                lw=1,
                ls=":",
                label='Random values, normal distr.')
        pl.plot(*self.cumcum(abs(np.random.lognormal(0, 1, 500000))),
                c='b',
                lw=1,
                ls=":",
                label='Random values log-normal distr.')

        vec = self.Dsst[~np.isnan(self.Dsst)]
        pl.plot(*self.cumcum(vec[vec > 0]),
                lw=2,
                alpha=0.5,
                label="SST, positive values")
        pl.ylim(0, 1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/cumcumtot_pos_sst.pdf',
                   transparent=True,
                   bbox_inches='tight')
        pl.plot(*self.cumcum(-vec[vec < 0]),
                lw=2,
                alpha=0.5,
                label="SST, negative values")
        pl.ylim(0, 1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/cumcumtot_posneg_sst.pdf',
                   transparent=True,
                   bbox_inches='tight')

        vec = self.Dchl[~np.isnan(self.Dchl)]
        pl.plot(*self.cumcum(vec[vec > 0]),
                lw=2,
                alpha=0.5,
                label="Chl, positive values")
        pl.ylim(0, 1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/cumcumtot_posneg_sst_pos_chl.pdf',
                   transparent=True,
                   bbox_inches='tight')

        pl.plot(*self.cumcum(-vec[vec < 0]),
                lw=2,
                alpha=0.5,
                label="Chl, negative values")
        pl.ylim(0, 1)
        pl.legend(loc='lower right')
        pl.savefig('figs/liege/cumcumtot_posneg_sst_posneg_chl.pdf',
                   transparent=True,
                   bbox_inches='tight')

        pl.savefig('figs/liege/cumcumtot.pdf')
Пример #44
0
    def scatter(self,mask=None, ntrac=None, jd=None, k1=None, k2=None,
                c="g", clf=True, coord="latlon", land="nice", map_region=None):
        """Plot particle positions on a map

                 mask: Boolean vector inidcating which particles to plot
                ntrac: Particle ID
                   jd: Julian date to plot, has to be included in jdvec.
                   k1: only plot particle deeper than k1
                   k2: only plot particle shallower than k1
                    c: color of particles
                  clf: Clear figure  if True
                coord: Use lat-lon coordinates if set to "latlon" (default),
                           i-j coordinates if set to "ij" 
                 land: Use landmask from basemap if set to "nice" (default),
                           landmask from model if set to "model". 
           map_region: Use other map_regions than set by config file

        """
        if (not hasattr(self,'mp'))  & (coord=="latlon"):
            self.add_mp(map_region)
        if (not hasattr(self,'lon')) & (coord=="latlon"):
            self.ijll()
        if mask is None:
            mask = self.ntrac==self.ntrac
            if jd is not None:
                mask = mask & (self.jd==jd)
            if ntrac is not None:
                mask = mask & (self.ntrac==ntrac)

        figpref.current()
        if clf: pl.clf()
    
        if coord is "latlon":
            x,y = self.mp(self.lon[mask],self.lat[mask])
            scH = self.mp.scatter(x, y, 5, c)
        else:
            scH = pl.scatter(self.x[mask], self.y[mask], 5, c)
    
        if land is "nice":
            land = self.gcm.mp.nice()
        elif coord is "latlon":
            self.mp.pcolormesh(self.mpxll,
                               self.mpyll,
                               np.ma.masked_equal(self.landmask, False),
                               cmap=GrGr())
        else:
            pl.pcolormesh(np.arange(self.gcm.i1, self.gcm.i2+1),
                          np.arange(self.gcm.j1, self.gcm.j2+1),
                          np.ma.masked_equal(self.landmask, False),
                          cmap=GrGr())
        if (ntrac is not None) & (coord is "latlon"):
            self.mp.plot(x,y,'-w',lw=0.5)

        """ 
        xl,yl = self.mp(
            [self.llon[0,0], self.llon[0,-1], self.llon[-1,-1],
             self.llon[-1,0],self.llon[0,0]],
            [self.llat[0,0], self.llat[0,-1], self.llat[-1,-1],
             self.llat[-1,0], self.llat[0,0]]
             )
        #self.mp.plot(xl,yl,'0.5')
        """
        if jd: pl.title(pl.num2date(jd).strftime("%Y-%m-%d %H:%M"))
        return scH