def sunhis2initial(hisfile,icfile): """ Main function """ print '#####\nCreating initial condition file (%s) from history file (%s)...'%(icfile,hisfile) # Load the history file sunhis = Spatial(hisfile, tstep=-1, klayer=[-99]) # Load the initial condition object timeic = datetime.strftime(sunhis.time[-1],'%Y%m%d.%H%M%S') sunic = InitialCond(hisfile,timeic) # Load the last time step into each variable sunic.h = sunhis.loadData(variable='eta').reshape((1,sunic.h.shape)) sunic.T = sunhis.loadData(variable='temp').reshape((1,)+sunic.T.shape) sunic.S = sunhis.loadData(variable='salt').reshape((1,)+sunic.S.shape) sunic.uc = sunhis.loadData(variable='uc').reshape((1,)+sunic.uc.shape) sunic.vc = sunhis.loadData(variable='vc').reshape((1,)+sunic.vc.shape) print sunic.h.shape print sunic.T.shape # Load the age if sunhis.hasVar('agec'): sunic.agec = sunhis.loadData(variable='agec').reshape((1,)+sunic.agec.shape) sunic.agealpha = sunhis.loadData(variable='agealpha').reshape((1,)+sunic.agealpha.shape) # Write to the output file sunic.writeNC(icfile)
# Generate an initial condition netcdf file ############################################## if makeinitial: #### # Initial condition options #### icfile = 'SFBay3D_IC.nc' # Initial condition netcdf file name h0 = -5.0 # initial free surface elevation #### # End options #### # Initialise the class IC = InitialCond(suntanspath,starttime) #Set the depth IC.dv = grd.dv # the initial condition arrays are stored in the following fields in the class: # h, uc, vc, T, S # # uc, vc, T and S have dimensions [1, Nk, Nc] # h has dimensions [1, Nc] # We want to set h to constant (other fields are zero by default) IC.h[:] = h0 # Now set T and S based on analytical functions def returnSalinity(x,y):
for ID,flux in zip(segmentID,fluxrate): ind = np.argwhere(bnd.segp==ID) bnd.boundary_Q[:,ind]=flux # Set all type-2 boundary T and S constant bnd.boundary_S[:,:,:] = 0.0 bnd.boundary_T[:,:,:] = T0 # Write the boundary file bnd.write2NC(suntanspath+'/'+bcfile) if makeinitial: # Generates an initial condition netcdf file # Initialise the class IC = InitialCond(suntanspath,starttime) # the initial condition arrays are stored in the following fields in the class: # h, uc, vc, T, S # We just want to set T and S to constant (other fields are zero by default) IC.T[:] = T0 IC.S[:] = S0 # Write the initial condition file IC.writeNC(suntanspath+'/'+icfile) if makewinds: # Create a meteorological input file xpt = grd.xv.mean() ypt = grd.yv.mean()
def _makeinitial(self): """ Generate initial conditions """ # Initialise the class IC = InitialCond(self.suntanspath,self.starttime) if self.opt_ic=='constant': print 'Setting constant initial conditions...' print 'Setting salinity = %f, temperature = %f'%(self.S0ic,self.T0ic) IC.T[:]=self.T0ic IC.S[:]=self.S0ic elif self.opt_ic=='depth_profile': print 'Setting depth-varying initial conditions...' self.loadTSprofile() for ii in range(0,IC.Nc): IC.T[0,:,ii] = self.Tz IC.S[0,:,ii] = self.Sz elif self.opt_ic=='ROMS': print 'Setting initial conditions from ROMS model output...' IC.roms2ic(self.romsfile,setUV=self.useROMSuv,seth=self.useROMSeta,interpmethod='idw',NNear=5,p=2) #interpmethod=self.interpmethod,NNear=self.NNear,p=self.p,\ #varmodel=self.varmodel,nugget=self.nugget,sill=self.sill,\ #vrange=self.vrange) elif self.opt_ic=='SUNTANS': IC.suntans2ic(self.suntansicfile,setUV=self.useROMSuv,seth=self.useROMSeta) else: print 'Unknown option: opt_ic = %s. Not setting initial conditions.'%self.opt_ic # Filter the variables in space if self.icfilterdx>0: IC.filteric(self.icfilterdx) # Set the age source term from a polygon if not self.agesourcepoly==None: print 'Setting age source term with shapefile: %s...'%self.agesourcepoly IC.setAgeSource(self.agesourcepoly) # Write the initial condition file IC.writeNC(self.suntanspath+'/'+self.icfile,dv=self.grd.dv)
############################################## # Generate an initial condition netcdf file ############################################## if makeinitial: #### # Initial condition options #### icfile = 'Headland_IC.nc' # Initial condition netcdf file name #### # End options #### # Initialise the class IC = InitialCond(suntanspath,starttime) # the initial condition arrays are stored in the following fields in the class: # h, uc, vc, T, S # # uc, vc, T and S have dimensions [1, Nk, Nc] # h has dimensions [1, Nc] # We want to set h to constant (other fields are zero by default) IC.h[:] = calc_fs(IC.xv) # Set T as a circle x0 = -0 y0 = b+w R = 500. # Radius
############################################## # Generate an initial condition netcdf file ############################################## if makeinitial: #### # Initial condition options #### icfile = 'Headland_IC.nc' # Initial condition netcdf file name #### # End options #### # Initialise the class IC = InitialCond(suntanspath, starttime) # the initial condition arrays are stored in the following fields in the class: # h, uc, vc, T, S # # uc, vc, T and S have dimensions [1, Nk, Nc] # h has dimensions [1, Nc] # We want to set h to constant (other fields are zero by default) IC.h[:] = calc_fs(IC.xv) # Set T as a circle x0 = -0 y0 = b + w R = 500. # Radius
def sunhis2initial(hisfile, icfile): """ Main function """ print '#####\nCreating initial condition file (%s) from history file (%s)...' % ( icfile, hisfile) # Load the history file sunhis = Spatial(hisfile, tstep=-1, klayer=[-99]) # Load the initial condition object timeic = datetime.strftime(sunhis.time[-1], '%Y%m%d.%H%M%S') sunic = InitialCond(hisfile, timeic) # Load the last time step into each variable sunic.h = sunhis.loadData(variable='eta').reshape((1, sunic.h.shape)) sunic.T = sunhis.loadData(variable='temp').reshape((1, ) + sunic.T.shape) sunic.S = sunhis.loadData(variable='salt').reshape((1, ) + sunic.S.shape) sunic.uc = sunhis.loadData(variable='uc').reshape((1, ) + sunic.uc.shape) sunic.vc = sunhis.loadData(variable='vc').reshape((1, ) + sunic.vc.shape) print sunic.h.shape print sunic.T.shape # Load the age if sunhis.hasVar('agec'): sunic.agec = sunhis.loadData(variable='agec').reshape((1, ) + sunic.agec.shape) sunic.agealpha = sunhis.loadData( variable='agealpha').reshape((1, ) + sunic.agealpha.shape) # Write to the output file sunic.writeNC(icfile)
for ID, flux in zip(segmentID, fluxrate): ind = np.argwhere(bnd.segp == ID) bnd.boundary_Q[:, ind] = flux # Set all type-2 boundary T and S constant bnd.boundary_S[:, :, :] = 0.0 bnd.boundary_T[:, :, :] = T0 # Write the boundary file bnd.write2NC(suntanspath + '/' + bcfile) if makeinitial: # Generates an initial condition netcdf file # Initialise the class IC = InitialCond(suntanspath, starttime) # the initial condition arrays are stored in the following fields in the class: # h, uc, vc, T, S # We just want to set T and S to constant (other fields are zero by default) IC.T[:] = T0 IC.S[:] = S0 # Write the initial condition file IC.writeNC(suntanspath + '/' + icfile) if makewinds: # Create a meteorological input file xpt = grd.xv.mean() ypt = grd.yv.mean()
def _makeinitial(self): """ Generate initial conditions """ # Initialise the class IC = InitialCond(self.suntanspath, self.starttime) if self.opt_ic == 'constant': print 'Setting constant initial conditions...' print 'Setting salinity = %f, temperature = %f' % (self.S0ic, self.T0ic) IC.T[:] = self.T0ic IC.S[:] = self.S0ic elif self.opt_ic == 'depth_profile': print 'Setting depth-varying initial conditions...' self.loadTSprofile() for ii in range(0, IC.Nc): IC.T[0, :, ii] = self.Tz IC.S[0, :, ii] = self.Sz elif self.opt_ic == 'ROMS': print 'Setting initial conditions from ROMS model output...' IC.roms2ic(self.romsfile, setUV=self.useROMSuv, seth=self.useROMSeta, interpmethod='idw', NNear=5, p=2) #interpmethod=self.interpmethod,NNear=self.NNear,p=self.p,\ #varmodel=self.varmodel,nugget=self.nugget,sill=self.sill,\ #vrange=self.vrange) elif self.opt_ic == 'SUNTANS': IC.suntans2ic(self.suntansicfile, setUV=self.useROMSuv, seth=self.useROMSeta) else: print 'Unknown option: opt_ic = %s. Not setting initial conditions.' % self.opt_ic # Filter the variables in space if self.icfilterdx > 0: IC.filteric(self.icfilterdx) # Set the age source term from a polygon if not self.agesourcepoly == None: print 'Setting age source term with shapefile: %s...' % self.agesourcepoly IC.setAgeSource(self.agesourcepoly) # Write the initial condition file IC.writeNC(self.suntanspath + '/' + self.icfile, dv=self.grd.dv)