Exemplo n.º 1
0
 def setup_grid(self):
     """Define lat and lon matrices for njord"""
     gc = netcdf_file(self.gridfile)
     self.lat = gc.variables['lat'][:].copy()
     self.gmt = gmtgrid.Shift(gc.variables['lon'][:].copy())
     self.lon = self.gmt.lonvec         
     self.llon,self.llat = np.meshgrid(self.lon,self.lat)
Exemplo n.º 2
0
 def setup_grid(self):
     print self.dataurl
     if not os.path.exists(self.gridfile):
         self.download(self.gridfile)
     gc = netcdf_file(self.gridfile)
     self.lat = gc.variables['latitude'][:]
     self.gmt = gmtgrid.Shift(gc.variables['longitude'][:self.imt].copy())
     self.lon = self.gmt.lonvec
     self.llon, self.llat = np.meshgrid(self.lon, self.lat)
Exemplo n.º 3
0
 def setup_grid(self):
     """Setup necessary variables for grid """
     gc = netcdf_file(self.datadir + '/land.nc')
     self.lat = gc.variables['lat'][:]
     self.gmt = gmtgrid.Shift(gc.variables['lon'][:].copy())
     self.lon = self.gmt.lonvec 
     self.llon,self.llat = np.meshgrid(self.lon,self.lat)
     self.landmask = self.gmt.field(
         gc.variables['land'][:].copy()).astype(np.bool)
Exemplo n.º 4
0
 def setup_grid(self):
     """Setup necessary variables for grid """
     if not os.path.isfile(self.gridfile):
         self.download(self.gridfile, 'vvel')
     g = netcdf_file(self.gridfile, 'r')
     self.latvec = g.variables['lat'][:]
     self.gmt = gmtgrid.Shift(g.variables['lon'][:].copy())
     self.lonvec = self.gmt.lonvec
     self.llon, self.llat = np.meshgrid(self.lonvec, self.latvec)
Exemplo n.º 5
0
 def setup_grid(self):
     """Setup necessary variables for grid """
     g = netcdf_file(self.gridfile, 'r')
     self.llat = g.variables['TLAT'][:]
     self.gmt = gmtgrid.Shift(g.variables['TLONG'][0, :].copy())
     self.lon = self.gmt.lonvec
     self.llon = g.variables['TLONG'][:].copy()
     self.llon[self.llon > 180] = self.llon[self.llon > 180] - 360
     self.llon = self.gmt.field(self.llon)
Exemplo n.º 6
0
 def setup_grid(self):
     """Setup lat-lon matrices for CCMP"""
     if not os.path.isfile(self.gridfile):
         self.load("uvel", yr=2007, mn=12, dy=1)
     gc = netCDF4.Dataset(self.gridfile, 'r')
     self.lat = gc.variables['lat'][:]
     self.gmt = gmtgrid.Shift(gc.variables['lon'][:].copy())
     self.lon = self.gmt.lonvec
     self.llon, self.llat = np.meshgrid(self.lon, self.lat)
Exemplo n.º 7
0
 def setup_grid(self):
     """Setup necessary variables for grid """
     if not os.path.isfile(self.gridfile):
         self.download(self.gridfile, 'vvel')
     g = netcdf_file(self.gridfile, 'r')
     self.llat = g.variables['Latitude'][:]
     self.gmt = gmtgrid.Shift(g.variables['Longitude'][1649, :].copy())
     self.llon = self.gmt.field(g.variables['Longitude'][:].copy())
     self.llon[self.llon > 180] = self.llon[self.llon > 180] - 360
     self.llon[self.llon < -180] = self.llon[self.llon < -180] + 360
Exemplo n.º 8
0
 def setup_grid(self):
     """Setup lat-lon matrices for CCMP"""
     try:
         gc = netcdf_file(self.gridfile, 'r')
     except:
         print 'Error opening the gridfile %s' % datadir + filename
         raise
     self.lat = gc.variables['lat'][:]
     self.gmt = gmtgrid.Shift(gc.variables['lon'][:].copy())
     self.lon = self.gmt.lonvec
     self.llon, self.llat = np.meshgrid(self.lon, self.lat)
Exemplo n.º 9
0
 def setup_grid(self):
     """Setup lat-lon matrices for Seawinds"""
     if not os.path.isfile(self.gridfile):
         self.retrive_file(self.dataurl, self.gridfile)
     try:
         n = netCDF4.Dataset(self.gridfile, 'r')
     except:
         print 'Error opening the gridfile %s' % self.gridfile
         raise
     self.lat = n.variables['lat'][:]
     self.gmt = gmtgrid.Shift(n.variables['lon'][:].copy())
     self.lon = self.gmt.lonvec
     self.llon, self.llat = np.meshgrid(self.lon, self.lat)
Exemplo n.º 10
0
 def __init__(self, datadir="/projData/CORE2/"):
     self.jdbase = pl.date2num(dtm(1948, 1, 1)) + 15
     self.datadir = datadir
     filename = "u_10.2005.05APR2010.nc"
     try:
         n = netCDF4.Dataset(datadir + filename)
     except:
         print 'Error opening the gridfile %s' % datadir + filename
         raise
     self.lat = n.variables['LAT'][:]
     self.gmt = gmtgrid.Shift(n.variables['LON'][:].copy())
     self.lon = self.gmt.lonvec
     self.llon, self.llat = np.meshgrid(self.lon, self.lat)
     n.close()
Exemplo n.º 11
0
 def setup_grid(self):
     """Setup necessary variables for grid """
     if not os.path.isfile(self.gridfile):
         self.download(self.gridfile, 'vvel')
     g = netcdf_file(self.gridfile, 'r')
     self.lat = g.variables['LATITUDE_T'][:]
     self.gmt = gmtgrid.Shift(g.variables['LONGITUDE_T'][:].copy())
     self.lon = self.gmt.lonvec
     self.zlev = g.variables['DEPTH_T'][:]
     mat = np.squeeze(g.variables['VVEL'][:].copy())
     mat[mat == 0] = np.nan
     self.depth = self.gmt.field(
         np.nanmax((self.zlev[:, np.newaxis, np.newaxis] * (mat * 0 + 1)),
                   axis=0))
     self.llon, self.llat = np.meshgrid(self.lon, self.lat)
Exemplo n.º 12
0
    def setup_grid(self):
        """Setup necessary variables for grid """
        g = netcdf_file(self.gridfile)

        self.gmt = gmtgrid.Shift(g.variables['gridlon_t'][:].copy())
        self.lon = (self.gmt.lonvec).astype(np.float32).copy()
        self.lat = g.variables['gridlat_t'][:].copy()
        self.depth = self.gmt.field(g.variables['depth_t'][:])
        self.dxt = self.gmt.field(g.variables['dxt'][:])
        self.dyt = self.gmt.field(g.variables['dyt'][:])
        self.dxu = self.gmt.field(g.variables['dxu'][:])
        self.dyu = self.gmt.field(g.variables['dyu'][:])
        #self.dzt   = self.gmt.field(g.variables['dz_t'][:])
        #self.zlev  = self.gmt.field(g.variables['dz_t'][:])
        #if not hasattr(self, 'k1'): self.k1 = 0
        #if not hasattr(self, 'k2'): self.k2 = len(self.zlev)
        self.dz = g.variables['dz_t'][self.k1:self.k2, 25, 30]
        #self.vol = ( self.dxt[np.newaxis,...] *
        #             self.dyt[np.newaxis,...]*self.dzt)
        #self.vol[self.vol<0] = np.nan
        #self.zlev = [0,] + np.cumsum(self.dz)-10
        self.llon, self.llat = np.meshgrid(self.lon, self.lat)
        self.area = self.dxt * self.dyt
Exemplo n.º 13
0
 def setup_grid(self):
     self.latvec = np.linspace(-89.875, 89.875, 720)
     self.gmt = gmtgrid.Shift(np.linspace(0, 360, 1440))
     self.lonvec = self.gmt.lonvec
     self.llon, self.llat = np.meshgrid(self.lonvec, self.latvec)
Exemplo n.º 14
0
    def __init__(self, fname='BEC.gx3.22.pi.cv2.Ar.daily.2004-02.nc',
                 datadir='/projData/CSMBGC/Ar_daily/',
                 t1=None, t2=None, k1=None, k2=None,
                 i1=None, i2=None, j1=None, j2=None,
                 ln='', dt=''):
        """Init the class and setup the grid. Paths are defined here."""  
        n = Dataset(datadir + os.path.split(fname)[1])
        g = Dataset(datadir + 'grid_cell_xy.nc')
        self.datadir = datadir
        self.t1 = t1; self.t2 = t2
        self.i1 = i1; self.i2 = i2
        self.j1 = j1; self.j2 = j2
        self.k1 = k1; self.k2 = k2
        if t1>60:
            self.tw = t1-60
        else:
            self.tw = t1

        self.fname = os.path.split(fname)[1]
        self.gmt = gmtgrid.Shift(g.variables['TLONG'][0,:])
        self.llat = self.readfield(n,  'TLAT')[j1:j2,i1:i2]
        self.llon = self.readfield(n, 'TLONG')[j1:j2,i1:i2]
        self.llon[self.llon>180] = self.llon[self.llon>180] - 360
        self.lat = self.llat[:,0]
        self.lon = self.gmt.lonvec
        
        self.dz   = n.variables['dz'][:] / 100 
        self.dzt  = self.dz.copy()
        self.dyu  = self.gmt.field(g.variables['DYU'][:]/100)[j1:j2,i1:i2] 
        self.dxu  = self.gmt.field(g.variables['DXU'][:]/100)[j1:j2,i1:i2] 
        self.area = self.gmt.field(n.variables['TAREA'][:]/100/100)[j1:j2,i1:i2]
        self.zlev = n.variables['z_t'][:] /100
        self.create_tvec()

        def lim(val1,val2):
            if not val1: return val2
            return val1
            

        self.t1 = lim(t1,0); self.t2 = lim(t2,len(self.tvec))
        self.i1 = lim(i1,0); self.i2 = lim(i2,self.llat.shape[1])
        self.j1 = lim(j1,0); self.j2 = lim(j2,self.llat.shape[0])
        self.k1 = lim(k1,0); self.k2 = lim(k2,len(self.zlev))



        self.keypref = 'daily_'

        self.pa = {'tvec':('time',120),
                   'o2fl':('FG_O2',-864),
                   'nwndsqr':('U10_SQR', 0.0001),
                   'nwnd':('',1),
                   'arfl':('FG_Ar',  864),
                   'o2ss':('O2SAT',1),
                   'arss':('ArSAT',1),
                   'o2pv':('PV_O2',864),
                   'arpv':('PV_Ar',864),
                   'ncpo':('NCP_O2',24*3600),
                   'o2ct':('O2',1),
                   'arct':('Ar',1),
                   'mldp':('HMXL',1.0e-2),
                   'uvel':('UVEL',864),
                   'vvel':('VVEL',864),
                   'salt':('SALT',1000),
                   'temp':('TEMP',1),
                   'atpr':('ATM_PRESS_USED',1),
                   'taux':('TAUX',1),
                   'tauy':('TAUY',1),
                   'poco':('',1),
                   'spC':('spC',1),
                   'diatC':('diatC',1),
                   'diazC':('diazC',1),
                   'chlo':    ('',1),
                   'spChl':   ('spChl',1),
                   'diatChl': ('diatChl',1),
                   'diazChl': ('diazChl',1),
                   'pars': ('PAR_avg',1),
                   'feco': ('Fe',1),
                   'o2st':('',1),
                   'arst':('',1),
                   'o2ar':('',1),
                   'dens':('',1),
                   'mldk':('',1),
                   'nn10':('',1),
                   'nrm10':('',1),
                   'wpv':('',1),
                   'ssht':('',1),
                   'icef':('IFRAC',1),
                   'wwfl':('',1),
                   'crwwfl':('',1),
                   'depth':('',1),
                   }

        self.km = self.dzt.shape[0];  self.kr = np.arange(self.km)
        self.im = self.area.shape[0]; self.ir = range(self.im)
        self.jm = self.area.shape[1]; self.jr = range(self.jm)
        self.vol = np.zeros([self.km, self.im, self.jm])
        for k in self.kr: 
            self.vol[k,:,:]=self.area[:,:] * self.dzt[k]
        self.create_pardict()
        self.tm = self.tvec.shape[0]; self.tr = np.arange(self.tm)

        self.params=[]
        self.gcm = 'csm'