示例#1
0
def gen_frc(fname,grd,tag='_ccmp'):

  nc=netcdf.Pync(fname,'t',version=3)

  # dims:
  grd_dims=netcdf.fdim(grd)
  gdims='xi_rho','xi_u','xi_v','eta_rho','eta_u','eta_v'
  for name in gdims: nc.add_dim(name,grd_dims[name])
  # time dim:
  nc.add_dim('wind_time',0)

  v=nc.add_var('wind_time',np.dtype('d'),('wind_time',))
  v.add_att('long_name','wind forcing time')
  tunits='days since 1970-01-01'
  v.add_att('units',tunits)

  v=nc.add_var('Uwind'+tag,np.dtype('d'),('wind_time','eta_rho', 'xi_rho'))
  v.add_att('long_name','u-wind')
  v.add_att('units','metre second-1')
  v.add_att('time','time')

  v=nc.add_var('Vwind'+tag,np.dtype('d'),('wind_time','eta_rho', 'xi_rho'))
  v.add_att('long_name','v-wind')
  v.add_att('units','metre second-1')
  v.add_att('time','time')

  # Global Attributes:
  nc.add_att('type','Wind forcing file')
  nc.add_att('title','CCMP wind')
  nc.add_att('grd_file',os.path.realpath(grd))
  from time import ctime
  nc.add_att('history','ROMS  wind  file, '+ctime())
  nc.add_att('author',cb.username()[1]+', '+cb.machinename())

  nc.close()
示例#2
0
  def create(self,model='roms',original=False):
    '''
    Creates netcdf bulk forcing file
    for model 'roms' or 'roms-agrif'
    '''
    nc=netcdf.Pync(self.filename,'t',version=self.ncversion)

    # Dimensions:
    # horizontal dims:
    self.add_horiz_dims(nc)
    # time dim:
    nc.add_dim('time',0)

    # original data dims:
    addOriginal= not original is False
    if addOriginal:
      nc.add_dim('x_original',original[1])
      nc.add_dim('y_original',original[0])

    # Variables:
    if model=='roms': vname='time'
    elif model=='roms-agrif': vname='bulk_time'
    v=nc.add_var(vname,np.dtype('d'),('time',))
    v.add_att('long_name','bulk formulation atmospheric forcing time')
    v.add_att('units',self.tunits)
    if self.cycle: v.add_att('cycle_length',self.cycle)

    if addOriginal:
      nc.add_var('x_original',np.dtype('d'),('y_original', 'x_original'))
      nc.add_var('y_original',np.dtype('d'),('y_original', 'x_original'))

    if model=='roms': vname='Tair'
    elif model=='roms-agrif': vname='tair'
    v=nc.add_var(vname,np.dtype('d'),('time','eta_rho', 'xi_rho'))
    v.add_att('long_name','surface air temperature')
    v.add_att('units','Celsius')
    v.add_att('time','time')

    if addOriginal:
      v=nc.add_var('tair_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','Celsius')

    if model=='roms': vname,vunits='Pair','millibar'
    elif model=='roms-agrif': vname,vunits='pres','Pascal'
    v=nc.add_var(vname,np.dtype('d'),('time','eta_rho', 'xi_rho'))
    v.add_att('long_name','surface pressure')
    v.add_att('units',vunits)
    v.add_att('time','time')

    if addOriginal:
      v=nc.add_var('pres_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','Pascal')

    if model=='roms': vname,vunits='Qair','percentage'
    elif model=='roms-agrif': vname,vunits='rhum','fraction'
    v=nc.add_var(vname,np.dtype('d'),('time','eta_rho', 'xi_rho'))
    v.add_att('long_name','relative humidity')
    v.add_att('units',vunits)
    v.add_att('time','time')

    if addOriginal:
      v=nc.add_var('rhum_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','fraction')

    if model=='roms': vname,vunits='rain','kg m-2 s-1'
    elif model=='roms-agrif': vname,vunits='prate','cm day-1'
    v=nc.add_var(vname,np.dtype('d'),('time','eta_rho', 'xi_rho'))
    v.add_att('long_name','precipitation rate')
    v.add_att('units',vunits)
    v.add_att('time','time')

    if addOriginal:
      v=nc.add_var('prate_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','cm day-1')

    if model=='roms': vname,vlname='lwrad','net longwave radiation flux'
    elif model=='roms-agrif': vname,vlname='radlw','outgoing longwave radiation'
    v=nc.add_var(vname,np.dtype('d'),('time','eta_rho', 'xi_rho'))
    v.add_att('long_name',vlname)
    v.add_att('units','Watts metre-2')
    v.add_att('time','time')
    if model=='roms':
      v.add_att('positive_value','downward flux, heating')
      v.add_att('negative_value','upward flux, cooling')
    elif model=='roms-agrif': # opposite to ROMS !!!
      v.add_att('positive','upward flux, cooling water')

    if addOriginal:
      v=nc.add_var('radlw_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','Watts metre-2')
      if model=='roms':
        v.add_att('negative_value','upward flux, cooling')
      elif model=='roms-agrif':
        v.add_att('positive','upward flux, cooling water')

    if model=='roms': vname='lwrad_down'
    elif model=='roms-agrif': vname='dlwrf'
    v=nc.add_var(vname,np.dtype('d'),('time','eta_rho', 'xi_rho'))
    v.add_att('long_name','downward longwave radiation')
    v.add_att('units','Watts metre-2')
    v.add_att('time','time')
    if model=='roms':
      v.add_att('positive_value','downward flux, heating')
      v.add_att('negative_value','upward flux, cooling')
    elif model=='roms-agrif': # opposite to ROMS !!!
      v.add_att('positive','upward flux, cooling water')

    if addOriginal:
      v=nc.add_var('dlwrf_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','Watts metre-2')
      if model=='roms':
        v.add_att('negative_value','upward flux, cooling')
      elif model=='roms-agrif':
        v.add_att('positive','upward flux, cooling water')

    if model=='roms': vname='swrad'
    elif model=='roms-agrif': vname='radsw'
    v=nc.add_var(vname,np.dtype('d'),('time','eta_rho', 'xi_rho'))
    v.add_att('long_name','shortwave radiation')
    v.add_att('units','Watts metre-2')
    v.add_att('time','time')
    v.add_att('positive_value','downward flux, heating')
    v.add_att('negative_value','upward flux, cooling')

    if addOriginal:
      v=nc.add_var('radsw_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','Watts metre-2')

    if model=='roms': vname='Uwind'
    elif model=='roms-agrif': vname='uwnd'
    v=nc.add_var(vname,np.dtype('d'),('time','eta_rho', 'xi_rho'))
    v.add_att('long_name','u-wind')
    v.add_att('units','metre second-1')
    v.add_att('time','time')

    if model=='roms': vname='Vwind'
    elif model=='roms-agrif': vname='vwnd'
    v=nc.add_var(vname,np.dtype('d'),('time','eta_rho', 'xi_rho'))
    v.add_att('long_name','v-wind')
    v.add_att('units','metre second-1')
    v.add_att('time','time')

    if addOriginal:
      v=nc.add_var('uwnd_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','metre second-1')
      v=nc.add_var('vwnd_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','metre second-1')

    # cloud cover (for roms):
    if model=='roms' or 1: # add it anyway...
      v=nc.add_var('cloud',np.dtype('d'),('time','eta_rho', 'xi_rho'))
      v.add_att('long_name','cloud fraction')
      v.add_att('units','nondimensional')
      v.add_att('time','time')

    if addOriginal:
      v=nc.add_var('cloud_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','cloud fraction')

    #  next only required by roms-agrif (wspd,sustr,svstr)
    v=nc.add_var('wspd',np.dtype('d'),('time','eta_rho', 'xi_rho'))
    v.add_att('long_name','wind speed 10m')
    v.add_att('units','metre second-1')
    v.add_att('time','time')

    v=nc.add_var('sustr',np.dtype('d'),('time','eta_u', 'xi_u'))
    v.add_att('long_name','surface u-momentum stress')
    v.add_att('units','Newton metre-2')
    v.add_att('time','time')

    v=nc.add_var('svstr',np.dtype('d'),('time','eta_v', 'xi_v'))
    v.add_att('long_name','surface v-momentum stress')
    v.add_att('units','Newton metre-2')
    v.add_att('time','time')

    if addOriginal:
      v=nc.add_var('wspd_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','metre second-1')
      v=nc.add_var('sustr_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','Newton metre-2')
      v=nc.add_var('svstr_original',np.dtype('d'),('time','y_original', 'x_original'))
      v.add_att('units','Newton metre-2')


    # Global Attributes:
    nc.add_att('type',self.type)
    nc.add_att('title',self.title)
    nc.add_att('grd_file',realpath(self.grid))
    nc.add_att('history','ROMS blk file, '+ctime())
    nc.add_att('author',cb.username()[1]+', '+cb.machinename())

    # extra attrs:
    for i in self.attr.keys(): nc.add_att(i,self.attr[i])

    nc.close()
示例#3
0
  def create(self):
    '''
    Creates model netcdf boundary conditions file

    '''

    nc=netcdf.Pync(self.filename,'t',version=self.ncversion)

    # Dimensions:
    # horizontal and vertical dims:
    self.add_horiz_dims(nc)
    self.add_vert_dims(nc)
    # time dim:
    nc.add_dim('time',0)

    # Variables:
    v=nc.add_var('bry_time',np.dtype('d'),('time',))
    v.add_att('long_name','open boundary conditions time')
    v.add_att('units',self.tunits)
    v.add_att('field','bry_time, scalar, series')
    if self.cycle: v.add_att('cycle_length',self.cycle)

    v=nc.add_var('temp_time',np.dtype('d'),('time',))
    v.add_att('long_name','potential temperature time')
    v.add_att('units',self.tunits)
    v.add_att('field','temp_time, scalar, series')
    if self.cycle: v.add_att('cycle_length',self.cycle)

    v=nc.add_var('salt_time',np.dtype('d'),('time',))
    v.add_att('long_name','salinity time')
    v.add_att('units',self.tunits)
    v.add_att('field','salt_time, scalar, series')
    if self.cycle: v.add_att('cycle_length',self.cycle)

    v=nc.add_var('u3d_time',np.dtype('d'),('time',))
    v.add_att('long_name','3D momentum time')
    v.add_att('units',self.tunits)
    v.add_att('field','u3d_time, scalar, series')
    if self.cycle: v.add_att('cycle_length',self.cycle)

    #v=nc.add_var('v3d_time',np.dtype('d'),('time',))
    #v.add_att('long_name','3D V-momentum time')
    #v.add_att('units',self.tunits)
    #v.add_att('field','v3d_time, scalar, series')
    #if self.cycle: v.add_att('cycle_length',self.cycle)

    v=nc.add_var('u2d_time',np.dtype('d'),('time',))
    v.add_att('long_name','2D momentum time')
    v.add_att('units',self.tunits)
    v.add_att('field','u2d_time, scalar, series')
    if self.cycle: v.add_att('cycle_length',self.cycle)

    #v=nc.add_var('v2d_time',np.dtype('d'),('time',))
    #v.add_att('long_name','2D V-momentum time')
    #v.add_att('units',self.tunits)
    #v.add_att('field','v2d_time, scalar, series')
    #if self.cycle: v.add_att('cycle_length',self.cycle)

    v=nc.add_var('zeta_time',np.dtype('d'),('time',))
    v.add_att('long_name','free surface time')
    v.add_att('units',self.tunits)
    v.add_att('field','zeta_time, scalar, series')
    if self.cycle: v.add_att('cycle_length',self.cycle)

    names={'n':'north','s':'south','e':'east','w':'west'}
    Names={'n':'northern','s':'southern','e':'eastern','w':'western'}

    Tdims={'n':('time','s_rho','xi_rho'),'s':('time','s_rho','xi_rho'),
           'e':('time','s_rho','eta_rho'),'w':('time','s_rho','eta_rho')}

    Udims={'n':('time','s_rho','xi_u'),'s':('time','s_rho','xi_u'),
           'e':('time','s_rho','eta_u'),'w':('time','s_rho','eta_u')}

    Vdims={'n':('time','s_rho','xi_v'),'s':('time','s_rho','xi_v'),
           'e':('time','s_rho','eta_v'),'w':('time','s_rho','eta_v')}


    for o in 'nsew':
      if o in self.obc:
        v=nc.add_var('temp_'+names[o],np.dtype('d'),Tdims[o])
        v.add_att('long_name','potential temperature '+Names[o]+' boundary condition')
        v.add_att('units','Celsius')
        v.add_att('time','temp_time')
        v.add_att('field','temp_'+names[o]+', scalar, series')

        v=nc.add_var('salt_'+names[o],np.dtype('d'),Tdims[o])
        v.add_att('long_name','salinity '+Names[o]+' boundary condition')
        v.add_att('units','Celsius')
        v.add_att('time','salt_time')
        v.add_att('field','salt_'+names[o]+', scalar, series')

        v=nc.add_var('u_'+names[o],np.dtype('d'),Udims[o])
        v.add_att('long_name','3D u-momentum '+Names[o]+' boundary condition')
        v.add_att('units','metre second-1')
        v.add_att('time','u3d_time')
        v.add_att('field','u_'+names[o]+', scalar, series')

        v=nc.add_var('v_'+names[o],np.dtype('d'),Vdims[o])
        v.add_att('long_name','3D v-momentum '+Names[o]+' boundary condition')
        v.add_att('units','metre second-1')
        v.add_att('time','u3d_time')
        v.add_att('field','v_'+names[o]+', scalar, series')

        v=nc.add_var('ubar_'+names[o],np.dtype('d'),Udims[o][::2])
        v.add_att('long_name','2D u-momentum '+Names[o]+' boundary condition')
        v.add_att('units','metre second-1')
        v.add_att('time','u2d_time')
        v.add_att('field','ubar_'+names[o]+', scalar, series')

        v=nc.add_var('vbar_'+names[o],np.dtype('d'),Vdims[o][::2])
        v.add_att('long_name','2D v-momentum '+Names[o]+' boundary condition')
        v.add_att('units','metre second-1')
        v.add_att('time','u2d_time')
        v.add_att('field','vbar_'+names[o]+', scalar, series')

        v=nc.add_var('zeta_'+names[o],np.dtype('d'),Tdims[o][::2])
        v.add_att('long_name','free surface '+Names[o]+' boundary condition')
        v.add_att('units','metre')
        v.add_att('time','zeta_time')
        v.add_att('field','zeta_'+names[o]+', scalar, series')

        if self.addxz:
          v=nc.add_var('dist_'+names[o],np.dtype('f'),Tdims[o][1:])
          v.add_att('long_name','distance of '+Names[o]+' boundary at rho points')
          v.add_att('units','metre')
          v.add_att('field','dist_'+names[o]+', scalar, series')

          v=nc.add_var('distu_'+names[o],np.dtype('f'),Udims[o][1:])
          v.add_att('long_name','distance of '+Names[o]+' boundary at u points')
          v.add_att('units','metre')
          v.add_att('field','distu_'+names[o]+', scalar, series')

          v=nc.add_var('distv_'+names[o],np.dtype('f'),Vdims[o][1:])
          v.add_att('long_name','distance of '+Names[o]+' boundary at v points')
          v.add_att('units','metre')
          v.add_att('field','distv_'+names[o]+', scalar, series')

          v=nc.add_var('depth_'+names[o],np.dtype('f'),Tdims[o])
          v.add_att('long_name','depths of '+Names[o]+' boundary at rho points')
          v.add_att('units','metre')
          v.add_att('field','depth_'+names[o]+', scalar, series')

          v=nc.add_var('depthu_'+names[o],np.dtype('f'),Udims[o])
          v.add_att('long_name','depths of '+Names[o]+' boundary at u points')
          v.add_att('units','metre')
          v.add_att('field','depthu_'+names[o]+', scalar, series')

          v=nc.add_var('depthv_'+names[o],np.dtype('f'),Vdims[o])
          v.add_att('long_name','depths of '+Names[o]+' boundary at v points')
          v.add_att('units','metre')
          v.add_att('field','depthv_'+names[o]+', scalar, series')


    # sparams vars:
    v=nc.add_var('theta_s',np.dtype('d'),())
    v.add_att('long_name','S-coordinate surface control parameter')

    v=nc.add_var('theta_b',np.dtype('d'),())
    v.add_att('long_name','S-coordinate bottom control parameter')

    v=nc.add_var('Tcline',np.dtype('d'),())
    v.add_att('long_name','S-coordinate surface/bottom layer width')
    v.add_att('units','metre')

    v=nc.add_var('hc',np.dtype('d'),())
    v.add_att('long_name','S-coordinate parameter, critical depth')
    v.add_att('units','metre')

    v=nc.add_var('Vtransform',np.dtype('i'),())
    v.add_att('long_name','vertical terrain-following transformation equation')

    v=nc.add_var('Vstretching',np.dtype('i'),())
    v.add_att('long_name','vertical terrain-following stretching function')


    # Global Attributes:
    nc.add_att('type',self.type)
    nc.add_att('title',self.title)
    if self.grid.startswith('http'): grd=self.grid
    else: grd=realpath(self.grid)
    nc.add_att('grd_file',grd)
    nc.add_att('history','ROMS bry file, '+ctime())
    nc.add_att('obc',self.obc)
    nc.add_att('author',cb.username()[1]+', '+cb.machinename())

    # extra attrs:
    for i in self.attr.keys(): nc.add_att(i,self.attr[i])

    # fill sparams:
    nc.vars['theta_s'][:]=self.sparams[0]
    nc.vars['theta_b'][:]=self.sparams[1]
    nc.vars['Tcline'][:]=self.sparams[2]
    nc.vars['hc'][:]=self.sparams[2]
    nc.vars['Vtransform'][:]=self.sparams[4]
    nc.vars['Vstretching'][:]=self.sparams[5]

    nc.close()
示例#4
0
  def create(self):
    '''
    Creates model netcdf climatology file

    '''
    nc=netcdf.Pync(self.filename,'t',version=self.ncversion)

    # Dimensions:
    # horizontal and vertical dims:
    self.add_horiz_dims(nc)
    self.add_vert_dims(nc)
    # time dim:
    nc.add_dim('time',0)

    # Variables:
    v=nc.add_var('clim_time',np.dtype('d'),('time',))
    v.add_att('long_name','time for climatology')
    v.add_att('units',self.tunits)
    v.add_att('field','clim_time, scalar, series')
    if self.cycle: v.add_att('cycle_length',self.cycle)

    if not self.one_time:
      v=nc.add_var('temp_time',np.dtype('d'),('time',))
      v.add_att('long_name','time for temperature climatology')
      v.add_att('units',self.tunits)
      v.add_att('field','temp_time, scalar, series')
      if self.cycle: v.add_att('cycle_length',self.cycle)

    if not self.one_time:
      v=nc.add_var('salt_time',np.dtype('d'),('time',))
      v.add_att('long_name','time for salinity climatology')
      v.add_att('units',self.tunits)
      v.add_att('field','salt_time, scalar, series')
      if self.cycle: v.add_att('cycle_length',self.cycle)

    if not self.one_time:
      v=nc.add_var('u3d_time',np.dtype('d'),('time',))
      v.add_att('long_name','time for 3D U-momentum climatology')
      v.add_att('units',self.tunits)
      v.add_att('field','u3d_time, scalar, series')
      if self.cycle: v.add_att('cycle_length',self.cycle)

    if not self.one_time:
      v=nc.add_var('v3d_time',np.dtype('d'),('time',))
      v.add_att('long_name','time for 3D V-momentum climatology')
      v.add_att('units',self.tunits)
      v.add_att('field','v3d_time, scalar, series')
      if self.cycle: v.add_att('cycle_length',self.cycle)

    if not self.one_time:
      v=nc.add_var('u2d_time',np.dtype('d'),('time',))
      v.add_att('long_name','time for 2D U-momentum climatology')
      v.add_att('units',self.tunits)
      v.add_att('field','u2d_time, scalar, series')
      if self.cycle: v.add_att('cycle_length',self.cycle)

    if not self.one_time:
      v=nc.add_var('v2d_time',np.dtype('d'),('time',))
      v.add_att('long_name','time for 2D V-momentum climatology')
      v.add_att('units',self.tunits)
      v.add_att('field','v2d_time, scalar, series')
      if self.cycle: v.add_att('cycle_length',self.cycle)

    if not self.one_time:
      v=nc.add_var('zeta_time',np.dtype('d'),('time',))
      v.add_att('long_name','time for free surface climatology')
      v.add_att('units',self.tunits)
      v.add_att('field','zeta_time, scalar, series')
      if self.cycle: v.add_att('cycle_length',self.cycle)

    v=nc.add_var('temp',np.dtype('d'),('time','s_rho','eta_rho','xi_rho'))
    v.add_att('long_name','potential temperature climatology')
    v.add_att('units','Celsius')
    if self.one_time: v.add_att('time','clim_time')
    else:             v.add_att('time','temp_time')
    v.add_att('coordinates','lon_rho lat_rho s_rho temp_time')
    v.add_att('field','temperature, scalar, series')

    v=nc.add_var('salt',np.dtype('d'),('time','s_rho','eta_rho','xi_rho'))
    v.add_att('long_name','salinity climatology')
    v.add_att('units','PSU')
    if self.one_time: v.add_att('time','clim_time')
    else:             v.add_att('time','salt_time')
    v.add_att('coordinates','lon_rho lat_rho s_rho salt_time')
    v.add_att('field','salinity, scalar, series')

    v=nc.add_var('u',np.dtype('d'),('time','s_rho','eta_u','xi_u'))
    v.add_att('long_name','u-momentum component climatology')
    v.add_att('units','metre second-1')
    if self.one_time: v.add_att('time','clim_time')
    else:             v.add_att('time','u3d_time')
    v.add_att('coordinates','lon_u lat_u s_rho u3d_time')
    v.add_att('field','u-velocity, scalar, series')

    v=nc.add_var('v',np.dtype('d'),('time','s_rho','eta_v','xi_v'))
    v.add_att('long_name','v-momentum component climatology')
    v.add_att('units','metre second-1')
    if self.one_time: v.add_att('time','clim_time')
    else:             v.add_att('time','v3d_time')
    v.add_att('coordinates','lon_v lat_v s_rho v3d_time')
    v.add_att('field','v-velocity, scalar, series')

    v=nc.add_var('ubar',np.dtype('d'),('time','eta_u','xi_u'))
    v.add_att('long_name','vertically integrated  u-momentum component climatology')
    v.add_att('units','metre second-1')
    if self.one_time: v.add_att('time','clim_time')
    else:             v.add_att('time','u2d_time')
    v.add_att('coordinates','lon_u lat_u u2d_time')
    v.add_att('field','ubar-velocity, scalar, series')

    v=nc.add_var('vbar',np.dtype('d'),('time','eta_v','xi_v'))
    v.add_att('long_name','vertically integrated  v-momentum component climatology')
    v.add_att('units','metre second-1')
    if self.one_time: v.add_att('time','clim_time')
    else:             v.add_att('time','v2d_time')
    v.add_att('coordinates','lon_v lat_v v2d_time')
    v.add_att('field','vbar-velocity, scalar, series')

    v=nc.add_var('zeta',np.dtype('d'),('time','eta_rho','xi_rho'))
    v.add_att('long_name','free-surface climatology')
    v.add_att('units','metre')
    if self.one_time: v.add_att('time','clim_time')
    else:             v.add_att('time','zeta_time')
    v.add_att('coordinates','lon_rho lat_rho zeta_time')
    v.add_att('field','free-surface, scalar, series')


    # sparams vars:
    v=nc.add_var('theta_s',np.dtype('d'),())
    v.add_att('long_name','S-coordinate surface control parameter')

    v=nc.add_var('theta_b',np.dtype('d'),())
    v.add_att('long_name','S-coordinate bottom control parameter')

    v=nc.add_var('Tcline',np.dtype('d'),())
    v.add_att('long_name','S-coordinate surface/bottom layer width')
    v.add_att('units','metre')

    v=nc.add_var('hc',np.dtype('d'),())
    v.add_att('long_name','S-coordinate parameter, critical depth')
    v.add_att('units','metre')

    v=nc.add_var('Vtransform',np.dtype('i'),())
    v.add_att('long_name','vertical terrain-following transformation equation')

    v=nc.add_var('Vstretching',np.dtype('i'),())
    v.add_att('long_name','vertical terrain-following stretching function')


    # Global Attributes:
    nc.add_att('type',self.type)
    nc.add_att('title',self.title)
    if self.grid.startswith('http'): grd=self.grid
    else: grd=realpath(self.grid)
    nc.add_att('grd_file',grd)
    nc.add_att('history','ROMS clm file, '+ctime())
    nc.add_att('author',cb.username()[1]+', '+cb.machinename())

    # extra attrs:
    for i in self.attr.keys(): nc.add_att(i,self.attr[i])

    # fill sparams:
    nc.vars['theta_s'][:]=self.sparams[0]
    nc.vars['theta_b'][:]=self.sparams[1]
    nc.vars['Tcline'][:]=self.sparams[2]
    nc.vars['hc'][:]=self.sparams[2]
    nc.vars['Vtransform'][:]=self.sparams[4]
    nc.vars['Vstretching'][:]=self.sparams[5]

    nc.close()
示例#5
0
  def create(self):
    '''
    Creates model netcdf river forcing file
    '''
    nc=netcdf.Pync(self.fname,self.perm,version=self.ncversion)

    nx=netcdf.fdim(self.grid,'xi_rho')
    ny=netcdf.fdim(self.grid,'eta_rho')

    # Dimensions:
    nc.add_dim('s_rho',self.nz)
    nc.add_dim('river',self.nrivers)
    nc.add_dim('river_time',0)

    # Variables:
    v=nc.add_var('river',np.dtype('d'),('river',))
    v.add_att('long_name','river runoff identification number')

    v=nc.add_var('river_Xposition',np.dtype('d'),('river',))
    v.add_att('long_name','river XI-position at RHO-points')
    v.add_att('valid_min',1)
    v.add_att('valid_max',nx-1)

    v=nc.add_var('river_Eposition',np.dtype('d'),('river',))
    v.add_att('long_name','river ETA-position at RHO-points')
    v.add_att('valid_min',1)
    v.add_att('valid_max',ny-1)

    v=nc.add_var('river_direction',np.dtype('d'),('river',))
    v.add_att('long_name','river runoff direction')

    v=nc.add_var('river_Vshape',np.dtype('d'),('s_rho','river'))
    v.add_att('long_name','river runoff mass transport vertical profile')

    v=nc.add_var('river_time',np.dtype('d'),('river_time',))
    v.add_att('long_name','river runoff time')
    v.add_att('units',self.tunits)
    v.add_att('add_offset',0)

    v=nc.add_var('river_transport',np.dtype('d'),('river_time','river'))
    v.add_att('long_name','river runoff vertically integrated mass transport')
    v.add_att('units','metre3 second-1')
    v.add_att('time','river_time')

    v=nc.add_var('river_temp',np.dtype('d'),('river_time','s_rho','river'))
    v.add_att('long_name','river runoff potential temperature')
    v.add_att('units','Celsius')
    v.add_att('time','river_time')

    v=nc.add_var('river_salt',np.dtype('d'),('river_time','s_rho','river'))
    v.add_att('long_name','river runoff salinity')
    v.add_att('units','Celsius')
    v.add_att('time','river_time')

    # Global Attributes:
    nc.add_att('type',self.type)
    nc.add_att('title',self.title)
    nc.add_att('grd_file',os.path.realpath(self.grid))
    nc.add_att('date',dts.currday().isoformat(' '))
    nc.add_att('author',cb.username()[1]+', '+cb.username()[0]+'@'+cb.machinename())

    # extra attrs:
    for i in self.attr.keys(): nc.add_att(i,self.attr[i])

    nc.close()
示例#6
0
    def create(self, model='roms', original=False):
        '''
    Creates netcdf bulk forcing file
    for model 'roms' or 'roms-agrif'
    '''
        nc = netcdf.Pync(self.filename, 't', version=self.ncversion)

        # Dimensions:
        # horizontal dims:
        self.add_horiz_dims(nc)
        # time dim:
        nc.add_dim('time', 0)

        # original data dims:
        addOriginal = not original is False
        if addOriginal:
            nc.add_dim('x_original', original[1])
            nc.add_dim('y_original', original[0])

        # Variables:
        if model == 'roms': vname = 'time'
        elif model == 'roms-agrif': vname = 'bulk_time'
        v = nc.add_var(vname, np.dtype('d'), ('time', ))
        v.add_att('long_name', 'bulk formulation atmospheric forcing time')
        v.add_att('units', self.tunits)
        if self.cycle: v.add_att('cycle_length', self.cycle)

        if addOriginal:
            nc.add_var('x_original', np.dtype('d'),
                       ('y_original', 'x_original'))
            nc.add_var('y_original', np.dtype('d'),
                       ('y_original', 'x_original'))

        if model == 'roms': vname = 'Tair'
        elif model == 'roms-agrif': vname = 'tair'
        v = nc.add_var(vname, np.dtype('d'), ('time', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', 'surface air temperature')
        v.add_att('units', 'Celsius')
        v.add_att('time', 'time')

        if addOriginal:
            v = nc.add_var('tair_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'Celsius')

        if model == 'roms': vname, vunits = 'Pair', 'millibar'
        elif model == 'roms-agrif': vname, vunits = 'pres', 'Pascal'
        v = nc.add_var(vname, np.dtype('d'), ('time', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', 'surface pressure')
        v.add_att('units', vunits)
        v.add_att('time', 'time')

        if addOriginal:
            v = nc.add_var('pres_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'Pascal')

        if model == 'roms': vname, vunits = 'Qair', 'percentage'
        elif model == 'roms-agrif': vname, vunits = 'rhum', 'fraction'
        v = nc.add_var(vname, np.dtype('d'), ('time', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', 'relative humidity')
        v.add_att('units', vunits)
        v.add_att('time', 'time')

        if addOriginal:
            v = nc.add_var('rhum_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'fraction')

        if model == 'roms': vname, vunits = 'rain', 'kg m-2 s-1'
        elif model == 'roms-agrif': vname, vunits = 'prate', 'cm day-1'
        v = nc.add_var(vname, np.dtype('d'), ('time', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', 'precipitation rate')
        v.add_att('units', vunits)
        v.add_att('time', 'time')

        if addOriginal:
            v = nc.add_var('prate_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'cm day-1')

        if model == 'roms':
            vname, vlname = 'lwrad', 'net longwave radiation flux'
        elif model == 'roms-agrif':
            vname, vlname = 'radlw', 'outgoing longwave radiation'
        v = nc.add_var(vname, np.dtype('d'), ('time', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', vlname)
        v.add_att('units', 'Watts metre-2')
        v.add_att('time', 'time')
        if model == 'roms':
            v.add_att('positive_value', 'downward flux, heating')
            v.add_att('negative_value', 'upward flux, cooling')
        elif model == 'roms-agrif':  # opposite to ROMS !!!
            v.add_att('positive', 'upward flux, cooling water')

        if addOriginal:
            v = nc.add_var('radlw_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'Watts metre-2')
            if model == 'roms':
                v.add_att('negative_value', 'upward flux, cooling')
            elif model == 'roms-agrif':
                v.add_att('positive', 'upward flux, cooling water')

        if model == 'roms': vname = 'lwrad_down'
        elif model == 'roms-agrif': vname = 'dlwrf'
        v = nc.add_var(vname, np.dtype('d'), ('time', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', 'downward longwave radiation')
        v.add_att('units', 'Watts metre-2')
        v.add_att('time', 'time')
        if model == 'roms':
            v.add_att('positive_value', 'downward flux, heating')
            v.add_att('negative_value', 'upward flux, cooling')
        elif model == 'roms-agrif':  # opposite to ROMS !!!
            v.add_att('positive', 'upward flux, cooling water')

        if addOriginal:
            v = nc.add_var('dlwrf_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'Watts metre-2')
            if model == 'roms':
                v.add_att('negative_value', 'upward flux, cooling')
            elif model == 'roms-agrif':
                v.add_att('positive', 'upward flux, cooling water')

        if model == 'roms': vname = 'swrad'
        elif model == 'roms-agrif': vname = 'radsw'
        v = nc.add_var(vname, np.dtype('d'), ('time', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', 'shortwave radiation')
        v.add_att('units', 'Watts metre-2')
        v.add_att('time', 'time')
        v.add_att('positive_value', 'downward flux, heating')
        v.add_att('negative_value', 'upward flux, cooling')

        if addOriginal:
            v = nc.add_var('radsw_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'Watts metre-2')

        if model == 'roms': vname = 'Uwind'
        elif model == 'roms-agrif': vname = 'uwnd'
        v = nc.add_var(vname, np.dtype('d'), ('time', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', 'u-wind')
        v.add_att('units', 'metre second-1')
        v.add_att('time', 'time')

        if model == 'roms': vname = 'Vwind'
        elif model == 'roms-agrif': vname = 'vwnd'
        v = nc.add_var(vname, np.dtype('d'), ('time', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', 'v-wind')
        v.add_att('units', 'metre second-1')
        v.add_att('time', 'time')

        if addOriginal:
            v = nc.add_var('uwnd_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'metre second-1')
            v = nc.add_var('vwnd_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'metre second-1')

        # cloud cover (for roms):
        if model == 'roms' or 1:  # add it anyway...
            v = nc.add_var('cloud', np.dtype('d'),
                           ('time', 'eta_rho', 'xi_rho'))
            v.add_att('long_name', 'cloud fraction')
            v.add_att('units', 'nondimensional')
            v.add_att('time', 'time')

        if addOriginal:
            v = nc.add_var('cloud_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'cloud fraction')

        #  next only required by roms-agrif (wspd,sustr,svstr)
        v = nc.add_var('wspd', np.dtype('d'), ('time', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', 'wind speed 10m')
        v.add_att('units', 'metre second-1')
        v.add_att('time', 'time')

        v = nc.add_var('sustr', np.dtype('d'), ('time', 'eta_u', 'xi_u'))
        v.add_att('long_name', 'surface u-momentum stress')
        v.add_att('units', 'Newton metre-2')
        v.add_att('time', 'time')

        v = nc.add_var('svstr', np.dtype('d'), ('time', 'eta_v', 'xi_v'))
        v.add_att('long_name', 'surface v-momentum stress')
        v.add_att('units', 'Newton metre-2')
        v.add_att('time', 'time')

        if addOriginal:
            v = nc.add_var('wspd_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'metre second-1')
            v = nc.add_var('sustr_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'Newton metre-2')
            v = nc.add_var('svstr_original', np.dtype('d'),
                           ('time', 'y_original', 'x_original'))
            v.add_att('units', 'Newton metre-2')

        # Global Attributes:
        nc.add_att('type', self.type)
        nc.add_att('title', self.title)
        nc.add_att('grd_file', realpath(self.grid))
        nc.add_att('history', 'ROMS blk file, ' + ctime())
        nc.add_att('author', cb.username()[1] + ', ' + cb.machinename())

        # extra attrs:
        for i in self.attr.keys():
            nc.add_att(i, self.attr[i])

        nc.close()
示例#7
0
    def create(self):
        '''
    Creates model netcdf boundary conditions file

    '''

        nc = netcdf.Pync(self.filename, 't', version=self.ncversion)

        # Dimensions:
        # horizontal and vertical dims:
        self.add_horiz_dims(nc)
        self.add_vert_dims(nc)
        # time dim:
        nc.add_dim('time', 0)

        # Variables:
        v = nc.add_var('bry_time', np.dtype('d'), ('time', ))
        v.add_att('long_name', 'open boundary conditions time')
        v.add_att('units', self.tunits)
        v.add_att('field', 'bry_time, scalar, series')
        if self.cycle: v.add_att('cycle_length', self.cycle)

        v = nc.add_var('temp_time', np.dtype('d'), ('time', ))
        v.add_att('long_name', 'potential temperature time')
        v.add_att('units', self.tunits)
        v.add_att('field', 'temp_time, scalar, series')
        if self.cycle: v.add_att('cycle_length', self.cycle)

        v = nc.add_var('salt_time', np.dtype('d'), ('time', ))
        v.add_att('long_name', 'salinity time')
        v.add_att('units', self.tunits)
        v.add_att('field', 'salt_time, scalar, series')
        if self.cycle: v.add_att('cycle_length', self.cycle)

        v = nc.add_var('u3d_time', np.dtype('d'), ('time', ))
        v.add_att('long_name', '3D momentum time')
        v.add_att('units', self.tunits)
        v.add_att('field', 'u3d_time, scalar, series')
        if self.cycle: v.add_att('cycle_length', self.cycle)

        #v=nc.add_var('v3d_time',np.dtype('d'),('time',))
        #v.add_att('long_name','3D V-momentum time')
        #v.add_att('units',self.tunits)
        #v.add_att('field','v3d_time, scalar, series')
        #if self.cycle: v.add_att('cycle_length',self.cycle)

        v = nc.add_var('u2d_time', np.dtype('d'), ('time', ))
        v.add_att('long_name', '2D momentum time')
        v.add_att('units', self.tunits)
        v.add_att('field', 'u2d_time, scalar, series')
        if self.cycle: v.add_att('cycle_length', self.cycle)

        #v=nc.add_var('v2d_time',np.dtype('d'),('time',))
        #v.add_att('long_name','2D V-momentum time')
        #v.add_att('units',self.tunits)
        #v.add_att('field','v2d_time, scalar, series')
        #if self.cycle: v.add_att('cycle_length',self.cycle)

        v = nc.add_var('zeta_time', np.dtype('d'), ('time', ))
        v.add_att('long_name', 'free surface time')
        v.add_att('units', self.tunits)
        v.add_att('field', 'zeta_time, scalar, series')
        if self.cycle: v.add_att('cycle_length', self.cycle)

        names = {'n': 'north', 's': 'south', 'e': 'east', 'w': 'west'}
        Names = {
            'n': 'northern',
            's': 'southern',
            'e': 'eastern',
            'w': 'western'
        }

        Tdims = {
            'n': ('time', 's_rho', 'xi_rho'),
            's': ('time', 's_rho', 'xi_rho'),
            'e': ('time', 's_rho', 'eta_rho'),
            'w': ('time', 's_rho', 'eta_rho')
        }

        Udims = {
            'n': ('time', 's_rho', 'xi_u'),
            's': ('time', 's_rho', 'xi_u'),
            'e': ('time', 's_rho', 'eta_u'),
            'w': ('time', 's_rho', 'eta_u')
        }

        Vdims = {
            'n': ('time', 's_rho', 'xi_v'),
            's': ('time', 's_rho', 'xi_v'),
            'e': ('time', 's_rho', 'eta_v'),
            'w': ('time', 's_rho', 'eta_v')
        }

        for o in 'nsew':
            if o in self.obc:
                v = nc.add_var('temp_' + names[o], np.dtype('d'), Tdims[o])
                v.add_att(
                    'long_name', 'potential temperature ' + Names[o] +
                    ' boundary condition')
                v.add_att('units', 'Celsius')
                v.add_att('time', 'temp_time')
                v.add_att('field', 'temp_' + names[o] + ', scalar, series')

                v = nc.add_var('salt_' + names[o], np.dtype('d'), Tdims[o])
                v.add_att('long_name',
                          'salinity ' + Names[o] + ' boundary condition')
                v.add_att('units', 'Celsius')
                v.add_att('time', 'salt_time')
                v.add_att('field', 'salt_' + names[o] + ', scalar, series')

                v = nc.add_var('u_' + names[o], np.dtype('d'), Udims[o])
                v.add_att('long_name',
                          '3D u-momentum ' + Names[o] + ' boundary condition')
                v.add_att('units', 'metre second-1')
                v.add_att('time', 'u3d_time')
                v.add_att('field', 'u_' + names[o] + ', scalar, series')

                v = nc.add_var('v_' + names[o], np.dtype('d'), Vdims[o])
                v.add_att('long_name',
                          '3D v-momentum ' + Names[o] + ' boundary condition')
                v.add_att('units', 'metre second-1')
                v.add_att('time', 'u3d_time')
                v.add_att('field', 'v_' + names[o] + ', scalar, series')

                v = nc.add_var('ubar_' + names[o], np.dtype('d'),
                               Udims[o][::2])
                v.add_att('long_name',
                          '2D u-momentum ' + Names[o] + ' boundary condition')
                v.add_att('units', 'metre second-1')
                v.add_att('time', 'u2d_time')
                v.add_att('field', 'ubar_' + names[o] + ', scalar, series')

                v = nc.add_var('vbar_' + names[o], np.dtype('d'),
                               Vdims[o][::2])
                v.add_att('long_name',
                          '2D v-momentum ' + Names[o] + ' boundary condition')
                v.add_att('units', 'metre second-1')
                v.add_att('time', 'u2d_time')
                v.add_att('field', 'vbar_' + names[o] + ', scalar, series')

                v = nc.add_var('zeta_' + names[o], np.dtype('d'),
                               Tdims[o][::2])
                v.add_att('long_name',
                          'free surface ' + Names[o] + ' boundary condition')
                v.add_att('units', 'metre')
                v.add_att('time', 'zeta_time')
                v.add_att('field', 'zeta_' + names[o] + ', scalar, series')

                if self.addxz:
                    v = nc.add_var('dist_' + names[o], np.dtype('f'),
                                   Tdims[o][1:])
                    v.add_att(
                        'long_name',
                        'distance of ' + Names[o] + ' boundary at rho points')
                    v.add_att('units', 'metre')
                    v.add_att('field', 'dist_' + names[o] + ', scalar, series')

                    v = nc.add_var('distu_' + names[o], np.dtype('f'),
                                   Udims[o][1:])
                    v.add_att(
                        'long_name',
                        'distance of ' + Names[o] + ' boundary at u points')
                    v.add_att('units', 'metre')
                    v.add_att('field',
                              'distu_' + names[o] + ', scalar, series')

                    v = nc.add_var('distv_' + names[o], np.dtype('f'),
                                   Vdims[o][1:])
                    v.add_att(
                        'long_name',
                        'distance of ' + Names[o] + ' boundary at v points')
                    v.add_att('units', 'metre')
                    v.add_att('field',
                              'distv_' + names[o] + ', scalar, series')

                    v = nc.add_var('depth_' + names[o], np.dtype('f'),
                                   Tdims[o])
                    v.add_att(
                        'long_name',
                        'depths of ' + Names[o] + ' boundary at rho points')
                    v.add_att('units', 'metre')
                    v.add_att('field',
                              'depth_' + names[o] + ', scalar, series')

                    v = nc.add_var('depthu_' + names[o], np.dtype('f'),
                                   Udims[o])
                    v.add_att(
                        'long_name',
                        'depths of ' + Names[o] + ' boundary at u points')
                    v.add_att('units', 'metre')
                    v.add_att('field',
                              'depthu_' + names[o] + ', scalar, series')

                    v = nc.add_var('depthv_' + names[o], np.dtype('f'),
                                   Vdims[o])
                    v.add_att(
                        'long_name',
                        'depths of ' + Names[o] + ' boundary at v points')
                    v.add_att('units', 'metre')
                    v.add_att('field',
                              'depthv_' + names[o] + ', scalar, series')

        # sparams vars:
        v = nc.add_var('theta_s', np.dtype('d'), ())
        v.add_att('long_name', 'S-coordinate surface control parameter')

        v = nc.add_var('theta_b', np.dtype('d'), ())
        v.add_att('long_name', 'S-coordinate bottom control parameter')

        v = nc.add_var('Tcline', np.dtype('d'), ())
        v.add_att('long_name', 'S-coordinate surface/bottom layer width')
        v.add_att('units', 'metre')

        v = nc.add_var('hc', np.dtype('d'), ())
        v.add_att('long_name', 'S-coordinate parameter, critical depth')
        v.add_att('units', 'metre')

        v = nc.add_var('Vtransform', np.dtype('i'), ())
        v.add_att('long_name',
                  'vertical terrain-following transformation equation')

        v = nc.add_var('Vstretching', np.dtype('i'), ())
        v.add_att('long_name',
                  'vertical terrain-following stretching function')

        # Global Attributes:
        nc.add_att('type', self.type)
        nc.add_att('title', self.title)
        nc.add_att('grd_file', realpath(self.grid))
        nc.add_att('history', 'ROMS bry file, ' + ctime())
        nc.add_att('obc', self.obc)
        nc.add_att('author', cb.username()[1] + ', ' + cb.machinename())

        # extra attrs:
        for i in self.attr.keys():
            nc.add_att(i, self.attr[i])

        # fill sparams:
        nc.vars['theta_s'][:] = self.sparams[0]
        nc.vars['theta_b'][:] = self.sparams[1]
        nc.vars['Tcline'][:] = self.sparams[2]
        nc.vars['hc'][:] = self.sparams[2]
        nc.vars['Vtransform'][:] = self.sparams[4]
        nc.vars['Vstretching'][:] = self.sparams[5]

        nc.close()
示例#8
0
    def create(self):
        '''
    Creates model netcdf climatology file

    '''
        nc = netcdf.Pync(self.filename, 't', version=self.ncversion)

        # Dimensions:
        # horizontal and vertical dims:
        self.add_horiz_dims(nc)
        self.add_vert_dims(nc)
        # time dim:
        nc.add_dim('time', 0)

        # Variables:
        v = nc.add_var('clim_time', np.dtype('d'), ('time', ))
        v.add_att('long_name', 'time for climatology')
        v.add_att('units', self.tunits)
        v.add_att('field', 'clim_time, scalar, series')
        if self.cycle: v.add_att('cycle_length', self.cycle)

        if not self.one_time:
            v = nc.add_var('temp_time', np.dtype('d'), ('time', ))
            v.add_att('long_name', 'time for temperature climatology')
            v.add_att('units', self.tunits)
            v.add_att('field', 'temp_time, scalar, series')
            if self.cycle: v.add_att('cycle_length', self.cycle)

        if not self.one_time:
            v = nc.add_var('salt_time', np.dtype('d'), ('time', ))
            v.add_att('long_name', 'time for salinity climatology')
            v.add_att('units', self.tunits)
            v.add_att('field', 'salt_time, scalar, series')
            if self.cycle: v.add_att('cycle_length', self.cycle)

        if not self.one_time:
            v = nc.add_var('u3d_time', np.dtype('d'), ('time', ))
            v.add_att('long_name', 'time for 3D U-momentum climatology')
            v.add_att('units', self.tunits)
            v.add_att('field', 'u3d_time, scalar, series')
            if self.cycle: v.add_att('cycle_length', self.cycle)

        if not self.one_time:
            v = nc.add_var('v3d_time', np.dtype('d'), ('time', ))
            v.add_att('long_name', 'time for 3D V-momentum climatology')
            v.add_att('units', self.tunits)
            v.add_att('field', 'v3d_time, scalar, series')
            if self.cycle: v.add_att('cycle_length', self.cycle)

        if not self.one_time:
            v = nc.add_var('u2d_time', np.dtype('d'), ('time', ))
            v.add_att('long_name', 'time for 2D U-momentum climatology')
            v.add_att('units', self.tunits)
            v.add_att('field', 'u2d_time, scalar, series')
            if self.cycle: v.add_att('cycle_length', self.cycle)

        if not self.one_time:
            v = nc.add_var('v2d_time', np.dtype('d'), ('time', ))
            v.add_att('long_name', 'time for 2D V-momentum climatology')
            v.add_att('units', self.tunits)
            v.add_att('field', 'v2d_time, scalar, series')
            if self.cycle: v.add_att('cycle_length', self.cycle)

        if not self.one_time:
            v = nc.add_var('zeta_time', np.dtype('d'), ('time', ))
            v.add_att('long_name', 'time for free surface climatology')
            v.add_att('units', self.tunits)
            v.add_att('field', 'zeta_time, scalar, series')
            if self.cycle: v.add_att('cycle_length', self.cycle)

        v = nc.add_var('temp', np.dtype('d'),
                       ('time', 's_rho', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', 'potential temperature climatology')
        v.add_att('units', 'Celsius')
        if self.one_time: v.add_att('time', 'clim_time')
        else: v.add_att('time', 'temp_time')
        v.add_att('coordinates', 'lon_rho lat_rho s_rho temp_time')
        v.add_att('field', 'temperature, scalar, series')

        v = nc.add_var('salt', np.dtype('d'),
                       ('time', 's_rho', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', 'salinity climatology')
        v.add_att('units', 'PSU')
        if self.one_time: v.add_att('time', 'clim_time')
        else: v.add_att('time', 'salt_time')
        v.add_att('coordinates', 'lon_rho lat_rho s_rho salt_time')
        v.add_att('field', 'salinity, scalar, series')

        v = nc.add_var('u', np.dtype('d'), ('time', 's_rho', 'eta_u', 'xi_u'))
        v.add_att('long_name', 'u-momentum component climatology')
        v.add_att('units', 'metre second-1')
        if self.one_time: v.add_att('time', 'clim_time')
        else: v.add_att('time', 'u3d_time')
        v.add_att('coordinates', 'lon_u lat_u s_rho u3d_time')
        v.add_att('field', 'u-velocity, scalar, series')

        v = nc.add_var('v', np.dtype('d'), ('time', 's_rho', 'eta_v', 'xi_v'))
        v.add_att('long_name', 'v-momentum component climatology')
        v.add_att('units', 'metre second-1')
        if self.one_time: v.add_att('time', 'clim_time')
        else: v.add_att('time', 'v3d_time')
        v.add_att('coordinates', 'lon_v lat_v s_rho v3d_time')
        v.add_att('field', 'v-velocity, scalar, series')

        v = nc.add_var('ubar', np.dtype('d'), ('time', 'eta_u', 'xi_u'))
        v.add_att('long_name',
                  'vertically integrated  u-momentum component climatology')
        v.add_att('units', 'metre second-1')
        if self.one_time: v.add_att('time', 'clim_time')
        else: v.add_att('time', 'u2d_time')
        v.add_att('coordinates', 'lon_u lat_u u2d_time')
        v.add_att('field', 'ubar-velocity, scalar, series')

        v = nc.add_var('vbar', np.dtype('d'), ('time', 'eta_v', 'xi_v'))
        v.add_att('long_name',
                  'vertically integrated  v-momentum component climatology')
        v.add_att('units', 'metre second-1')
        if self.one_time: v.add_att('time', 'clim_time')
        else: v.add_att('time', 'v2d_time')
        v.add_att('coordinates', 'lon_v lat_v v2d_time')
        v.add_att('field', 'vbar-velocity, scalar, series')

        v = nc.add_var('zeta', np.dtype('d'), ('time', 'eta_rho', 'xi_rho'))
        v.add_att('long_name', 'free-surface climatology')
        v.add_att('units', 'metre')
        if self.one_time: v.add_att('time', 'clim_time')
        else: v.add_att('time', 'zeta_time')
        v.add_att('coordinates', 'lon_rho lat_rho zeta_time')
        v.add_att('field', 'free-surface, scalar, series')

        # sparams vars:
        v = nc.add_var('theta_s', np.dtype('d'), ())
        v.add_att('long_name', 'S-coordinate surface control parameter')

        v = nc.add_var('theta_b', np.dtype('d'), ())
        v.add_att('long_name', 'S-coordinate bottom control parameter')

        v = nc.add_var('Tcline', np.dtype('d'), ())
        v.add_att('long_name', 'S-coordinate surface/bottom layer width')
        v.add_att('units', 'metre')

        v = nc.add_var('hc', np.dtype('d'), ())
        v.add_att('long_name', 'S-coordinate parameter, critical depth')
        v.add_att('units', 'metre')

        v = nc.add_var('Vtransform', np.dtype('i'), ())
        v.add_att('long_name',
                  'vertical terrain-following transformation equation')

        v = nc.add_var('Vstretching', np.dtype('i'), ())
        v.add_att('long_name',
                  'vertical terrain-following stretching function')

        # Global Attributes:
        nc.add_att('type', self.type)
        nc.add_att('title', self.title)
        nc.add_att('grd_file', realpath(self.grid))
        nc.add_att('history', 'ROMS clm file, ' + ctime())
        nc.add_att('author', cb.username()[1] + ', ' + cb.machinename())

        # extra attrs:
        for i in self.attr.keys():
            nc.add_att(i, self.attr[i])

        # fill sparams:
        nc.vars['theta_s'][:] = self.sparams[0]
        nc.vars['theta_b'][:] = self.sparams[1]
        nc.vars['Tcline'][:] = self.sparams[2]
        nc.vars['hc'][:] = self.sparams[2]
        nc.vars['Vtransform'][:] = self.sparams[4]
        nc.vars['Vstretching'][:] = self.sparams[5]

        nc.close()
示例#9
0
文件: gennc.py 项目: jcmt/okean
  def create(self):
    '''
    Creates model netcdf initial file
    '''

    nc=netcdf.Pync(self.filename,'t',version=self.ncversion)

    # Dimensions:
    # horizontal and vertical dims:
    self.add_horiz_dims(nc)
    self.add_vert_dims(nc)
    # time dim:
    nc.add_dim('ocean_time',1)

    # Variables:
    v=nc.add_var('ocean_time',np.dtype('d'),('ocean_time',))
    v.add_att('long_name','initial time')
    v.add_att('units',self.tunits)
    v.add_att('field','time, scalar, series')

    v=nc.add_var('temp',np.dtype('d'),('ocean_time','s_rho','eta_rho','xi_rho'))
    v.add_att('long_name','potential temperature')
    v.add_att('units','Celsius')
    v.add_att('time','ocean_time')
    v.add_att('coordinates','lon_rho lat_rho s_rho ocean_time')
    v.add_att('field','temperature, scalar, series')

    v=nc.add_var('salt',np.dtype('d'),('ocean_time','s_rho','eta_rho','xi_rho'))
    v.add_att('long_name','salinity')
    v.add_att('units','PSU')
    v.add_att('time','ocean_time')
    v.add_att('coordinates','lon_rho lat_rho s_rho ocean_time')
    v.add_att('field','salinity, scalar, series')

    v=nc.add_var('u',np.dtype('d'),('ocean_time','s_rho','eta_u','xi_u'))
    v.add_att('long_name','u-momentum component')
    v.add_att('units','metre second-1')
    v.add_att('time','ocean_time')
    v.add_att('coordinates','lon_u lat_u s_rho ocean_time')
    v.add_att('field','u-velocity, scalar, series')

    v=nc.add_var('v',np.dtype('d'),('ocean_time','s_rho','eta_v','xi_v'))
    v.add_att('long_name','v-momentum component')
    v.add_att('units','metre second-1')
    v.add_att('time','ocean_time')
    v.add_att('coordinates','lon_v lat_v s_rho ocean_time')
    v.add_att('field','v-velocity, scalar, series')

    v=nc.add_var('ubar',np.dtype('d'),('ocean_time','eta_u','xi_u'))
    v.add_att('long_name','vertically integrated  u-momentum component')
    v.add_att('units','metre second-1')
    v.add_att('time','ocean_time')
    v.add_att('coordinates','lon_u lat_u ocean_time')
    v.add_att('field','ubar-velocity, scalar, series')

    v=nc.add_var('vbar',np.dtype('d'),('ocean_time','eta_v','xi_v'))
    v.add_att('long_name','vertically integrated  v-momentum component')
    v.add_att('units','metre second-1')
    v.add_att('time','ocean_time')
    v.add_att('coordinates','lon_v lat_v ocean_time')
    v.add_att('field','vbar-velocity, scalar, series')

    v=nc.add_var('zeta',np.dtype('d'),('ocean_time','eta_rho','xi_rho'))
    v.add_att('long_name','free-surface')
    v.add_att('units','metre')
    v.add_att('time','ocean_time')
    v.add_att('coordinates','lon_rho lat_rho ocean_time')
    v.add_att('field','free-surface, scalar, series')


    # sparams vars:
    v=nc.add_var('theta_s',np.dtype('d'),())
    v.add_att('long_name','S-coordinate surface control parameter')

    v=nc.add_var('theta_b',np.dtype('d'),())
    v.add_att('long_name','S-coordinate bottom control parameter')

    v=nc.add_var('Tcline',np.dtype('d'),())
    v.add_att('long_name','S-coordinate surface/bottom layer width')
    v.add_att('units','metre')

    v=nc.add_var('hc',np.dtype('d'),())
    v.add_att('long_name','S-coordinate parameter, critical depth')
    v.add_att('units','metre')

    v=nc.add_var('Vtransform',np.dtype('i'),())
    v.add_att('long_name','vertical terrain-following transformation equation')

    v=nc.add_var('Vstretching',np.dtype('i'),())
    v.add_att('long_name','vertical terrain-following stretching function')


    # Global Attributes:
    nc.add_att('type',self.type)
    nc.add_att('title',self.title)
    nc.add_att('grd_file',realpath(self.grid))
    nc.add_att('history','ROMS ini file, '+ctime())
    nc.add_att('author',cb.username()[1]+', '+cb.machinename())

    # extra attrs:
    for i in self.attr.keys(): nc.add_att(i,self.attr[i])

    # fill time:
    nc.vars['ocean_time'][:]=self.time

    # fill sparams:
    nc.vars['theta_s'][:]=self.sparams[0]
    nc.vars['theta_b'][:]=self.sparams[1]
    nc.vars['Tcline'][:]=self.sparams[2]
    nc.vars['hc'][:]=self.sparams[2]
    nc.vars['Vtransform'][:]=self.sparams[4]
    nc.vars['Vstretching'][:]=self.sparams[5]

    nc.close()