Beispiel #1
0
    def writeg(self,syn_time,nsyn=8,filename=None,dir='.',expid='omaeruv',refine=4,res=None,Verb=1):
       """
        Writes gridded OMI measurements to file.

         refine  -- refinement level for a base 4x5 GEOS-5 grid
                       refine=1  produces a   4  x  5    grid
                       refine=2  produces a   2  x2.50   grid
                       refine=4  produces a   1  x1,25   grid
                       refine=8  produces a  0.50x0.625  grid
                       refine=16 produces a  0.25x0.3125 grid
        Alternatively, one can specify the grid resolution with a
        single letter:

         res     -- single letter denoting GEOS-5 resolution,
                       res='a'  produces a   4  x  5    grid
                       res='b'  produces a   2  x2.50   grid
                       res='c'  produces a   1  x1,25   grid
                       res='d'  produces a  0.50x0.625  grid
                       res='e'  produces a  0.25x0.3125 grid

                   NOTE: *res*, if specified, supersedes *refine*.

         Verb -- Verbose level:
                 0 - really quiet (default)
                 1 - Warns if invalid file is found
                 2 - Prints out non-zero number of fires in each file.


       """

       from gfio     import GFIO

       # Determine synoptic time range
       # -----------------------------
       dt = timedelta(seconds = 12. * 60. * 60. / nsyn)
       t1, t2 = (syn_time-dt,syn_time+dt)

#      Output grid resolution
#      ----------------------
       if res is not None:
           if res=='a': refine = 1 
           if res=='b': refine = 2
           if res=='c': refine = 4
           if res=='d': refine = 8
           if res=='e': refine = 16

#      Lat lon grid
#      ------------
       dx = 5. / refine
       dy = 4. / refine
       im = int(360. / dx)
       jm = int(180. / dy + 1)

       glon = linspace(-180.,180.,im,endpoint=False)
       glat = linspace(-90.,90.,jm)

       nch = self.nch
       nymd = 10000 * syn_time.year + 100 * syn_time.month  + syn_time.day
       nhms = 10000 * syn_time.hour + 100 * syn_time.minute + syn_time.second

       vtitle = [ 'Albedo',
                  'UV Aerosol Index',
                  'Radiance', 
                  'Total Aerosol Optial Depth',
                  'Absorption Aerosol Optial Depth' ]

       vname  = ['albedo','ai', 'rad', 'tauext', 'tauabs' ]
       vunits = [ '%',    '1',  '1',   '1',      '1' ]
       kmvar  = [nch,      0,    nch,    nch,   nch ]

       title = 'Gridded OMI Measurements and VLIDORT Simulations from GEOS-5'
       source = 'NASA/GSFC/GMAO GEOS-5 Aerosol Group'
       contact = '*****@*****.**'

       if filename is None:
           filename = '%s/%s.obs_l3a.%d_%02dz.nc4'%(dir,expid,nymd,nhms/10000)

#      Create the file
#      ---------------
       f = GFIO()
       f.create(filename, vname, nymd, nhms,
                lon=glon, lat=glat, levs=self.channels, levunits='nm',
                vtitle=vtitle, vunits=vunits,kmvar=kmvar,amiss=MISSING,
                title=title, source=source, contact=contact)

       # QA filtering
       # ------------
       I_bad = (self.FinalAlgorithmFlags!=0) # bad data
       
       # Time filter of data
       # -------------------
       lon = self.lon.ravel()
       lat = self.lat.ravel()
       albedo = _timefilter(self.time,t1,t2,self.albedo,I_bad).reshape((-1,nch))
       ai = _timefilter(self.time,t1,t2,self.ai,I_bad).ravel()
       radiance = _timefilter(self.time,t1,t2,self.radiance,I_bad).reshape((-1,nch))
       aod = _timefilter(self.time,t1,t2,self.aod,I_bad).reshape((-1,nch))
       aaod = _timefilter(self.time,t1,t2,self.aaod,I_bad).reshape((-1,nch))

       
#      Grid variable and write to file
#      -------------------------------
       f.write('albedo', nymd, nhms, binobs3d(lon,lat,albedo,  im,jm,MISSING) )
       f.write('ai',     nymd, nhms, binobs2d(lon,lat,ai,      im,jm,MISSING) )
       f.write('rad',    nymd, nhms, binobs3d(lon,lat,radiance,im,jm,MISSING) )
       f.write('tauext', nymd, nhms, binobs3d(lon,lat, aod,    im,jm,MISSING) ) 
       f.write('tauabs', nymd, nhms, binobs3d(lon,lat,aaod,    im,jm,MISSING) ) 

       if Verb >=1:
           print "[w] Wrote file "+filename
Beispiel #2
0
    def writeg(self,filename=None,dir='.',expid='modis',refine=8,res=None,
               channels=None,Verb=1):
       """
        Writes gridded MODIS measurements to file.

         refine  -- refinement level for a base 4x5 GEOS-5 grid
                       refine=1  produces a   4  x  5    grid
                       refine=2  produces a   2  x2.50   grid
                       refine=4  produces a   1  x1,25   grid
                       refine=8  produces a  0.50x0.625  grid
                       refine=16 produces a  0.25x0.3125 grid
        Alternatively, one can specify the grid resolution with a
        single letter:

         res     -- single letter denoting GEOS-5 resolution,
                       res='a'  produces a   4  x  5    grid
                       res='b'  produces a   2  x2.50   grid
                       res='c'  produces a   1  x1,25   grid
                       res='d'  produces a  0.50x0.625  grid
                       res='e'  produces a  0.25x0.3125 grid

                   NOTE: *res*, if specified, supersedes *refine*.

         Verb -- Verbose level:
                 0 - really quiet (default)
                 1 - Warns if invalid file is found
                 2 - Prints out non-zero number of fires in each file.


       """

       # Stop here is no good obs available
       # ----------------------------------
       if self.nobs == 0:
           return # no data to work with
       if any(self.iGood) == False:
           return # no good data to work with

#      Output grid resolution
#      ----------------------
       if res is not None:
           if res=='a': refine = 1 
           if res=='b': refine = 2
           if res=='c': refine = 4
           if res=='d': refine = 8
           if res=='e': refine = 16

#      Lat lon grid
#      ------------
       dx = 5. / refine
       dy = 4. / refine
       im = int(360. / dx)
       jm = int(180. / dy + 1)

       glon = linspace(-180.,180.,im,endpoint=False)
       glat = linspace(-90.,90.,jm)

       if channels is None:
           channels = self.channels
       levs = array(channels)

       nch = len(channels)
       nymd = self.nymd
       nhms = self.nhms

       vtitle = [ 'Aerosol Optical Depth',
                  'Aerosol Optical Depth (Revised)',
                  'Aerosol Optical Depth (Fine Mode)',
                  'Cloud Fraction' ]

       vname  = ['tau', 'tau_', 'tau_fine', 'cloud' ]
       vunits = [ '1',    '1',     '1',       '1',  ]
       kmvar  = [ nch,    nch,     nch,        0    ]

       title = 'Gridded MODIS Measurements'
       source = 'NASA/GSFC/GMAO GEOS-5 Aerosol Group'
       contact = '*****@*****.**'

       if filename is None:
           filename = '%s/%s.obs.%d_%02dz.nc4'%(dir,expid,self.nymd,self.nhms/10000)

       # Create the file
       # ---------------
       f = GFIO()
       f.create(filename, vname, nymd, nhms,
                lon=glon, lat=glat, levs=levs, levunits='nm',
                vtitle=vtitle, vunits=vunits,kmvar=kmvar,amiss=MISSING,
                title=title, source=source, contact=contact)

       # Subset AOD at specified channels
       # --------------------------------
       I = []
       for ch in channels:
           i = list(self.channels).index(ch)
           I = I + [i,]
       aod = self.aod[:,I]
       aod_fine = self.aod_fine[:,I]
       
       # The Revised AOD may not exist
       # -------------------------------
       try:
           aod_ = self.aod_[:,I]
       except:
           aod_ = MISSING * ones(aod.shape) # will compress like a charm

       # Grid variable and write to file
       # -------------------------------
       f.write('tau', nymd, nhms, 
               binobs3d(self.lon,self.lat,aod,im,jm,MISSING) )
       f.write('tau_', nymd, nhms, 
               binobs3d(self.lon,self.lat,aod_,im,jm,MISSING) )
       f.write('tau_fine', nymd, nhms, 
               binobs3d(self.lon,self.lat,aod_fine,im,jm,MISSING) )
       f.write('cloud', nymd, nhms, 
               binobs2d(self.lon,self.lat,self.cloud,im,jm,MISSING) )
           
#       try:
#           f.close()
#       except:
#           pass

       if Verb >=1:
           print "[w] Wrote file "+filename
Beispiel #3
0
    def writeGridded(self, syn_tyme,
                         filename=None,dir='.',expid='aeronet',refine=8,res=None,
                         nsyn=8,doFilter=True):
       """
        Writes gridded AERONET AOD to a GFIO file.

         refine  -- refinement level for a base 4x5 GEOS-5 grid
                       refine=1  produces a   4  x  5    grid
                       refine=2  produces a   2  x2.50   grid
                       refine=4  produces a   1  x1,25   grid
                       refine=8  produces a  0.50x0.625  grid
                       refine=16 produces a  0.25x0.3125 grid
        Alternatively, one can specify the grid resolution with a
        single letter:

         res     -- single letter denoting GEOS-5 resolution,
                       res='a'  produces a   4  x  5    grid
                       res='b'  produces a   2  x2.50   grid
                       res='c'  produces a   1  x1,25   grid
                       res='d'  produces a  0.50x0.625  grid
                       res='e'  produces a  0.25x0.3125 grid

                   NOTE: *res*, if specified, supersedes *refine*.

       """
       from binObs_  import binobs2d, binobs3d
       from gfio     import GFIO
       
       # Interval for this synoptic time
       # -------------------------------
       if doFilter:
           hdt = timedelta(seconds=60*60*int(24/nsyn)/2) # usually 3/2 hours
           t1 = syn_tyme - hdt
           t2 = syn_tyme + hdt
           I = (self.tyme>=t1)&(self.tyme<t2)
       else:
           I = ones(self.lon.shape).astype('bool') # all that comes in
       lon = self.lon[I]
       nobs = len(lon)

       nymd = syn_tyme.year*10000 + syn_tyme.month*100  + syn_tyme.day
       nhms = syn_tyme.hour*10000 + syn_tyme.minute*100 + syn_tyme.second

       if filename is None:
           #filename = '%s/%s.sfc.%d_%02dz.nc4'%(dir,expid,nymd,nhms/10000)
           filename = '%s/%s.aod.%d.nc4'%(dir,expid,nymd)

       # Stop here is no good obs available
       # ----------------------------------
       if nobs == 0:
           return filename # no data to work with

#      Output grid resolution
#      ----------------------
       if res is not None:
           if res=='a': refine = 1 
           if res=='b': refine = 2
           if res=='c': refine = 4
           if res=='d': refine = 8
           if res=='e': refine = 16

#      Lat lon grid
#      ------------
       dx = 5. / refine
       dy = 4. / refine
       im = int(360. / dx)
       jm = int(180. / dy + 1)

       glon = linspace(-180.,180.,im,endpoint=False)
       glat = linspace(-90.,90.,jm)

       vtitle = [ 'AERONET Aerosol Optical Depth at 550nm (Level 2, interpolated)',]
       vname  = ['tau_550', ]
       vunits = [ '1',  ]
       kmvar  = [  0 ,  ]
       levs = array([550.,])
       
       title = 'Gridded AERONET Level 2 Aerosol Retrievals'
       source = 'NASA/GSFC GEOS-5 Aerosol Group (from L2 AERONET Retrievals)'
       contact = '*****@*****.**'

       # Create the file
       # ---------------
       if os.path.exists(filename):
           f = GFIO(filename,mode='w')
       else:
           f = GFIO()
           timinc = (24/nsyn) * 10000
           f.create(filename, vname, nymd, nhms, timinc=timinc,
                    lon=glon, lat=glat, levs=levs, levunits='nm',
                    vtitle=vtitle, vunits=vunits,kmvar=kmvar,amiss=MISSING,
                    title=title, source=source, contact=contact)

       # Grid variable and write to file
       # -------------------------------
       f.write('tau_550', nymd, nhms, 
               binobs2d(self.lon[I],self.lat[I],self.AOT_550[I],im,jm,MISSING) )

       if self.verb:
           print "[w] Wrote file "+filename+" at %02dZ"%(nhms/10000)

       return filename
Beispiel #4
0
def writeg_del(obs,
               ana,
               bkg,
               lon,
               lat,
               vname,
               units,
               filename,
               title,
               time,
               refine=8,
               res=None,
               Verbose=True):
    """
         Grid & Write Obs, Ana and Bkg to file.

         vname   -- variable name for long name, e.g., 'AOD'
         units   -- variable unit

         filename - output file name
         title   -- title for file
         time    -- time stamp for file
         
         refine  -- refinement level for a base 4x5 GEOS-5 grid
                       refine=1  produces a   4  x  5    grid
                       refine=2  produces a   2  x2.50   grid
                       refine=4  produces a   1  x1,25   grid
                       refine=8  produces a  0.50x0.625  grid
                       refine=16 produces a  0.25x0.3125 grid
        Alternatively, one can specify the grid resolution with a
        single letter:

         res     -- single letter denoting GEOS-5 resolution,
                       res='a'  produces a   4  x  5    grid
                       res='b'  produces a   2  x2.50   grid
                       res='c'  produces a   1  x1,25   grid
                       res='d'  produces a  0.50x0.625  grid
                       res='e'  produces a  0.25x0.3125 grid

                   NOTE: *res*, if specified, supersedes *refine*.

         Verb -- Verbose level:
                 0 - really quiet (default)
                 1 - Warns if invalid file is found
                 2 - Prints out non-zero number of fires in each file.


       """

    #      Output grid resolution
    #      ----------------------
    if res is not None:
        if res == 'a': refine = 1
        if res == 'b': refine = 2
        if res == 'c': refine = 4
        if res == 'd': refine = 8
        if res == 'e': refine = 16

#      Lat lon grid
#      ------------
    dx = 5. / refine
    dy = 4. / refine
    im = int(360. / dx)
    jm = int(180. / dy + 1)

    glon = linspace(-180., 180., im, endpoint=False)
    glat = linspace(-90., 90., jm)

    nymd = 10000 * time.year + 100 * time.month + time.day
    nhms = 10000 * time.hour + 100 * time.minute + time.hour

    Vtitle = [
        vname + ' Observations (mean)',
        vname + ' Analysis (mean)',
        vname + ' Background (mean)',
        vname + ' Observations (RMS)',
        vname + ' Analysis (RMS)',
        vname + ' Background (RMS)',
    ]

    Vname = ['obs', 'ana', 'bkg', 'obs_rms', 'ana_rms', 'bkg_rms']

    Vunits = 6 * [
        units,
    ]
    Kmvar = 6 * [
        0,
    ]

    source = 'NASA/GSFC/GMAO GEOS-5 Aerosol Group'
    contact = '*****@*****.**'

    #      Create the file
    #      ---------------
    f = GFIO()
    f.create(filename,
             Vname,
             nymd,
             nhms,
             lon=glon,
             lat=glat,
             levs=[
                 1,
             ],
             levunits='1',
             vtitle=Vtitle,
             vunits=Vunits,
             kmvar=Kmvar,
             amiss=MISSING,
             title=title,
             source=source,
             contact=contact)

    #      Grid variable and write to file
    #      -------------------------------
    f.write('obs', nymd, nhms, binobs2d(lon, lat, obs, im, jm, MISSING))
    f.write('ana', nymd, nhms, binobs2d(lon, lat, ana, im, jm, MISSING))
    f.write('bkg', nymd, nhms, binobs2d(lon, lat, bkg, im, jm, MISSING))
    f.write('obs_rms', nymd, nhms, binrms2d(lon, lat, obs, im, jm, MISSING))
    f.write('ana_rms', nymd, nhms, binrms2d(lon, lat, ana, im, jm, MISSING))
    f.write('bkg_rms', nymd, nhms, binrms2d(lon, lat, bkg, im, jm, MISSING))

    if Verbose:
        print "[w] Wrote file " + filename