Beispiel #1
0
    def _makebnd(self):
        """
        Generate boundary condition files
        """
        
        if self.modifyedges:        
            modifyBCmarker(self.suntanspath,self.bcpolygonfile)
    
        #Load the boundary object from the grid
        bnd = Boundary(self.suntanspath,(self.starttime,self.endtime,self.dt))
        
        ###
        # Segment (flux) boundaries
        ###
        if self.opt_bcseg == 'constant':
            print 'Setting %d boundary segments to discharge of %6.3f m3/s'%(bnd.Nseg,self.Q0)
            bnd.boundary_Q[:]=self.Q0
            
        elif self.opt_bcseg == 'file':
            print 'Loading river segment data from file...\n'
            for ii, ID in enumerate(bnd.segp):
                print 'Loading discahrge data for boundary segment (%d) StationID: %d...'%(ii,ID)
                
                ts = timeseries.loadDBstation(self.dbasefile,ID,'discharge',timeinfo=(self.starttime,self.endtime,self.dt),\
                    filttype=self.filttype,cutoff=self.cutoff)
                    
                bnd.boundary_Q[:,ii]=ts.y.copy()
            
        else:
            print 'Unknown option: opt_bcseg = %s. Not setting boundary segment data.'%self.opt_bcseg
            
        ###
        # Type-3 boundaries
        ### 
        self.useROMS = False
        self.useOTIS = False
        self.useFILE = False
        self.useOTISFILE = False

        if self.opt_bctype3=='constant':
            print 'Setting constant type-3 boundary conditions...'  
            print 'Setting salinity = %f, temperature = %f'%(self.S0,self.T0)
            bnd.S[:]=self.S0
            bnd.T[:]=self.T0
            
        elif self.opt_bctype3=='depth_profile':
            print 'Setting type-3 boundary T/S from profile...'  
            
            self.loadTSprofile()
            for ii in range(0,bnd.N3):
                bnd.T[0,:,ii] = self.Tz
                bnd.S[0,:,ii] = self.Sz
        
        elif self.opt_bctype3 in ('ROMS'):
            self.useROMS = True

        elif self.opt_bctype3 in ('OTIS'):
            self.useOTIS = True
            
        elif self.opt_bctype3 in ('file'):
            self.useFILE = True
            
        elif self.opt_bctype3 in ('ROMSOTIS'):
            self.useROMS = True
            self.useOTIS = True
        
        elif self.opt_bctype3 in ('ROMSFILE'):
            self.useROMS = True
            self.useFILE = True
        
        elif self.opt_bctype3 in ('OTISFILE'):
            self.useOTISFILE = True

        elif self.opt_bctype3 in ('ROMSOTISFILE'):
            self.useOTISFILE = True
            self.useROMS = True

        else:
            print 'Unknown option: opt_bctype3 = %s. Not setting type-3 boundaries.'%self.opt_bctype3

            
        if self.useROMS:
            bnd.roms2boundary(self.romsfile,setUV=self.useROMSuv,seth=self.useROMSeta)
            
        if self.useOTIS:
            bnd.otis2boundary(self.otisfile,setUV=self.useOTISuv)

        if self.useOTISFILE:
            bnd.otisfile2boundary(self.otisfile,self.dbasefile,self.waterlevelstationID,setUV=self.useOTISuv)
            
        if self.useFILE:
            ID = self.waterlevelstationID
            print 'Loading waterlevel onto all type-3 points from stationID: %d...'%(ID)
            ts = timeseries.loadDBstation(self.dbasefile,ID,'waterlevel',timeinfo=(self.starttime,self.endtime,self.dt),\
                    filttype=self.filttype,cutoff=self.cutoff)
                    
            for ii in range(bnd.N3):
                bnd.h[:,ii] += ts.y.copy()
            
        ###
        # Type-2 boundaries
        ###
        self.useFILE2 = False

        if self.opt_bctype2 == 'constant':
            print 'Setting constant type-2 boundary conditions...'  
            print 'Setting salinity = %f, temperature = %f'%(self.S0,self.T0)
            bnd.boundary_S[:]=self.S0
            bnd.boundary_T[:]=self.T0
        elif self.opt_bctype2 == 'file':
            print 'Using file for type-2 boundary condition (temperature only)'
            print 'Setting salinity = %f'%(self.S0)
            bnd.boundary_S[:]=self.S0
            self.useFILE2 = True
        else:
            print 'Unknown option: opt_bctype2 = %s. Not setting type-2 boundaries.'%self.opt_bctype3
            
            
        if self.useFILE2:
            ID = self.TairstationID
            print 'Loading air temperature onto all type-2 points from stationID: %s...'%(ID)
            ts = timeseries.loadDBstation(self.dbasefile,ID,'Tair',timeinfo=(self.starttime,self.endtime,self.dt),\
            filttype=self.tairfilttype,cutoff=self.taircutoff)
                    
            for ii in range(bnd.N2):
                for kk in range(bnd.Nk):
                    bnd.boundary_T[:,kk,ii] += ts.y.copy()
            
        # Write to netcdf
        bnd.write2NC(self.suntanspath+'/'+self.bcfile)
Beispiel #2
0
        bnd.h[:,ii] = h0 + hamp*np.cos(omega*t)
        for k in range(bnd.Nk):
            bnd.T[:,k,ii] = T0
            bnd.S[:,k,ii] = S0
            
    # Set a constant discharge along the type 2 boundary edge
    for ID,flux in zip(edge_id,Q):
        ind = np.argwhere(bnd.segp==ID)
        bnd.boundary_Q[:,ind]=flux
        
    # Set all type-2 (river) boundary T and S constant
    bnd.boundary_S[:,:,:] = 0.0
    bnd.boundary_T[:,:,:] = T0
    
    # Write the boundary file
    bnd.write2NC(suntanspath+'/'+bcfile)

##############################################
# 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
    ####
Beispiel #3
0
    def _makebnd(self):
        """
        Generate boundary condition files
        """

        if self.modifyedges:
            modifyBCmarker(self.suntanspath, self.bcpolygonfile)

        #Load the boundary object from the grid
        bnd = Boundary(self.suntanspath,
                       (self.starttime, self.endtime, self.dt))

        ###
        # Segment (flux) boundaries
        ###
        if self.opt_bcseg == 'constant':
            print 'Setting %d boundary segments to discharge of %6.3f m3/s' % (
                bnd.Nseg, self.Q0)
            bnd.boundary_Q[:] = self.Q0

        elif self.opt_bcseg == 'file':
            print 'Loading river segment data from file...\n'
            for ii, ID in enumerate(bnd.segp):
                print 'Loading discahrge data for boundary segment (%d) StationID: %d...' % (
                    ii, ID)

                ts = timeseries.loadDBstation(self.dbasefile,ID,'discharge',timeinfo=(self.starttime,self.endtime,self.dt),\
                    filttype=self.filttype,cutoff=self.cutoff)

                bnd.boundary_Q[:, ii] = ts.y.copy()

        else:
            print 'Unknown option: opt_bcseg = %s. Not setting boundary segment data.' % self.opt_bcseg

        ###
        # Type-3 boundaries
        ###
        self.useROMS = False
        self.useOTIS = False
        self.useFILE = False
        self.useOTISFILE = False

        if self.opt_bctype3 == 'constant':
            print 'Setting constant type-3 boundary conditions...'
            print 'Setting salinity = %f, temperature = %f' % (self.S0,
                                                               self.T0)
            bnd.S[:] = self.S0
            bnd.T[:] = self.T0

        elif self.opt_bctype3 == 'depth_profile':
            print 'Setting type-3 boundary T/S from profile...'

            self.loadTSprofile()
            for ii in range(0, bnd.N3):
                bnd.T[0, :, ii] = self.Tz
                bnd.S[0, :, ii] = self.Sz

        elif self.opt_bctype3 in ('ROMS'):
            self.useROMS = True

        elif self.opt_bctype3 in ('OTIS'):
            self.useOTIS = True

        elif self.opt_bctype3 in ('file'):
            self.useFILE = True

        elif self.opt_bctype3 in ('ROMSOTIS'):
            self.useROMS = True
            self.useOTIS = True

        elif self.opt_bctype3 in ('ROMSFILE'):
            self.useROMS = True
            self.useFILE = True

        elif self.opt_bctype3 in ('OTISFILE'):
            self.useOTISFILE = True

        elif self.opt_bctype3 in ('ROMSOTISFILE'):
            self.useOTISFILE = True
            self.useROMS = True

        else:
            print 'Unknown option: opt_bctype3 = %s. Not setting type-3 boundaries.' % self.opt_bctype3

        if self.useROMS:
            bnd.roms2boundary(self.romsfile,
                              setUV=self.useROMSuv,
                              seth=self.useROMSeta)

        if self.useOTIS:
            bnd.otis2boundary(self.otisfile, setUV=self.useOTISuv)

        if self.useOTISFILE:
            bnd.otisfile2boundary(self.otisfile,
                                  self.dbasefile,
                                  self.waterlevelstationID,
                                  setUV=self.useOTISuv)

        if self.useFILE:
            ID = self.waterlevelstationID
            print 'Loading waterlevel onto all type-3 points from stationID: %d...' % (
                ID)
            ts = timeseries.loadDBstation(self.dbasefile,ID,'waterlevel',timeinfo=(self.starttime,self.endtime,self.dt),\
                    filttype=self.filttype,cutoff=self.cutoff)

            for ii in range(bnd.N3):
                bnd.h[:, ii] += ts.y.copy()

        ###
        # Type-2 boundaries
        ###
        self.useFILE2 = False

        if self.opt_bctype2 == 'constant':
            print 'Setting constant type-2 boundary conditions...'
            print 'Setting salinity = %f, temperature = %f' % (self.S0,
                                                               self.T0)
            bnd.boundary_S[:] = self.S0
            bnd.boundary_T[:] = self.T0
        elif self.opt_bctype2 == 'file':
            print 'Using file for type-2 boundary condition (temperature only)'
            print 'Setting salinity = %f' % (self.S0)
            bnd.boundary_S[:] = self.S0
            self.useFILE2 = True
        else:
            print 'Unknown option: opt_bctype2 = %s. Not setting type-2 boundaries.' % self.opt_bctype3

        if self.useFILE2:
            ID = self.TairstationID
            print 'Loading air temperature onto all type-2 points from stationID: %s...' % (
                ID)
            ts = timeseries.loadDBstation(self.dbasefile,ID,'Tair',timeinfo=(self.starttime,self.endtime,self.dt),\
            filttype=self.tairfilttype,cutoff=self.taircutoff)

            for ii in range(bnd.N2):
                for kk in range(bnd.Nk):
                    bnd.boundary_T[:, kk, ii] += ts.y.copy()

        # Write to netcdf
        bnd.write2NC(self.suntanspath + '/' + self.bcfile)