def _dumpbc(self): """ Dump boundary condition plots For each variable (uc,vc,T,S,eta): - time series at one point (range of all other points) - scatter plots of all points """ varnames = ['uc','vc','T','S','h','boundary_u','boundary_v','boundary_T','boundary_S'] print self.suntanspath, self.bcfile bnd = Boundary(self.suntanspath+'/'+self.bcfile,0) self.tmin = bnd.time[0] self.tmax = bnd.time[-1] for vv in varnames: if bnd.__dict__.has_key(vv): plt.figure() bnd.plot(varname=vv) outfile = '%s/BC_%s_TS.png'%(self.plotdir,vv) bnd.savefig(outfile) # Boundary segments for ii in range(bnd.Nseg): fig=plt.figure() bnd.plot(varname='boundary_Q',j=ii,rangeplot=False,linewidth=2) plt.fill_between(bnd.time,bnd.boundary_Q[:,ii],alpha=0.5) outfile = '%s/BC_Flow_%d.png'%(self.plotdir,bnd.segp[ii]) bnd.savefig(outfile) del fig # Scatter Plots for vv in varnames: if bnd.__dict__.has_key(vv): fig=plt.figure() bnd.scatter(varname=vv) outfile = '%s/BC_%s_scatter.png'%(self.plotdir,vv) bnd.savefig(outfile) del fig
# For this case 101 : Sacramento Rv, 102 : San Joaquin Rv edge_id = [101,102] # Unique identifier of each flux edge (list) Q = [0.0,0.0] # Volume flux rate of each segment boundary [m^3/s] #### # End of options #### # This changes the edge types based on the polygons in the shapefile if not bcpolygonfile==None: modifyBCmarker(suntanspath,bcpolygonfile) #Load the boundary object from the grid # Note that this zeros all of the boundary arrays bnd = Boundary(suntanspath,(starttime,endtime,dt)) #Fill the variables in the boundary object with your data here... # #Type 3 variables are at the cell-centre (xv,yv) and are named: # uv, vc, wc, h, T, S # # Dimensions: [Nt,Nk,N3] # #Type 2 variables are at the cell edges (xe, ye) and are named: # boundary_u # boundary_v # boundary_w # boundary_T # boundary_S # (no h)
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)
######################################### # Interpolate the depths onto the grid ######################################### y_hat,idx = grd.find_nearest_boundary(markertype=1) y_hat[grd.yv>b+w]=1e15 grd.dv = calc_depth2(y_hat,hmin,hmax,w) #grd.dv = calc_depth(grd.xv,grd.yv,hmin,hmax,w) grd.saveBathy('%s/depths.dat-voro'%suntanspath) #Load the boundary object from the grid # Note that this zeros all of the boundary arrays bnd = Boundary(suntanspath,(starttime,endtime,dt)) bnd.setDepth(grd.dv) # Try out a linear interpolation #y0 = bnd.ye.min() #y1 = bnd.ye.max() #du = 0.0 #dy = y1-y0 #Utst = (bnd.ye.ravel()-y0)/dy*du # Normal components nx = hgrd.n1[grd.mark==2] ny = hgrd.n2[grd.mark==2] t = bnd.tsec-bnd.tsec[0]
edgefile = suntanspath + '/edges.dat' grd.saveEdges(edgefile) print 'Updated markers written to: %s' % (edgefile) ######################################### # Interpolate the depths onto the grid ######################################### y_hat, idx = grd.find_nearest_boundary(markertype=1) y_hat[grd.yv > b + w] = 1e15 grd.dv = calc_depth2(y_hat, hmin, hmax, w) #grd.dv = calc_depth(grd.xv,grd.yv,hmin,hmax,w) grd.saveBathy('%s/depths.dat-voro' % suntanspath) #Load the boundary object from the grid # Note that this zeros all of the boundary arrays bnd = Boundary(suntanspath, (starttime, endtime, dt)) bnd.setDepth(grd.dv) # Try out a linear interpolation #y0 = bnd.ye.min() #y1 = bnd.ye.max() #du = 0.0 #dy = y1-y0 #Utst = (bnd.ye.ravel()-y0)/dy*du # Normal components nx = hgrd.n1[grd.mark == 2] ny = hgrd.n2[grd.mark == 2] t = bnd.tsec - bnd.tsec[0]
def _dumpbc(self): """ Dump boundary condition plots For each variable (uc,vc,T,S,eta): - time series at one point (range of all other points) - scatter plots of all points """ varnames = [ 'uc', 'vc', 'T', 'S', 'h', 'boundary_u', 'boundary_v', 'boundary_T', 'boundary_S' ] print self.suntanspath, self.bcfile bnd = Boundary(self.suntanspath + '/' + self.bcfile, 0) self.tmin = bnd.time[0] self.tmax = bnd.time[-1] for vv in varnames: if bnd.__dict__.has_key(vv): plt.figure() bnd.plot(varname=vv) outfile = '%s/BC_%s_TS.png' % (self.plotdir, vv) bnd.savefig(outfile) # Boundary segments for ii in range(bnd.Nseg): fig = plt.figure() bnd.plot(varname='boundary_Q', j=ii, rangeplot=False, linewidth=2) plt.fill_between(bnd.time, bnd.boundary_Q[:, ii], alpha=0.5) outfile = '%s/BC_Flow_%d.png' % (self.plotdir, bnd.segp[ii]) bnd.savefig(outfile) del fig # Scatter Plots for vv in varnames: if bnd.__dict__.has_key(vv): fig = plt.figure() bnd.scatter(varname=vv) outfile = '%s/BC_%s_scatter.png' % (self.plotdir, vv) bnd.savefig(outfile) del fig
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)