def oceanmodel2ic(self,ncfile,\ convert2utm=True,setUV=False,seth=False,zmax=6000.,name='HYCOM'): """ Interpolate data from a downloaded netcdf file to the initial condition """ print 'Loading initial condition data from ocean model netcdf file:\n\t%s...'%ncfile dt = timedelta(days=0.5) trange = [self.time - dt, self.time + 3*dt] # Get the temperature data and coordinate data temp, nc = get_metocean_local(ncfile,'temp',name=name, trange=trange) # Convert to utm if nc.X.ndim==1: X, Y = np.meshgrid(nc.X, nc.Y) else: X, Y = nc.X, nc.Y ll = np.vstack([X.ravel(),Y.ravel()]).T if convert2utm: xy = ll2utm(ll,self.utmzone,north=self.isnorth) else: xy = ll # Construct a 3D mask mask3d = temp.mask mask3d = mask3d[0,...] mask3d = mask3d.reshape((nc.nz,xy.shape[0])) # Ensure that the bottom cell of the ocean model is deeper than the suntans grid nc.Z[-1] = zmax # Construct the 4D interp class F4d =\ Interp4D(xy[:,0],xy[:,1],nc.Z, nc.localtime,\ self.xv,self.yv,self.z_r,self.time,mask=mask3d,**self.interpdict) tempnew = F4d(temp) self.T[:] = tempnew salt, nc = get_metocean_local(ncfile,'salt', name=name, trange=trange) saltnew = F4d(salt) self.S[:] = saltnew if seth: # Construct the 3D interp class for surface height ssh, nc = get_metocean_local(ncfile,'ssh', name=name, trange=trange) mask2d = ssh.mask mask2d = mask2d[0,...].ravel() F3d = Interp4D(xy[:,0],xy[:,1],None,nc.time,\ self.xv,self.yv,None,self.time,mask=mask2d,**self.interpdict) sshnew = F3d(ssh) self.h[:] = sshnew
def oceanmodel2bdy(self,ncfile,\ convert2utm=True,setUV=True,seth=True, zmax=6000., name='HYCOM'): """ Interpolate data from a downloaded netcdf file to the open boundaries """ print 'Loading boundary data from ocean model netcdf file:\n\t%s...'%ncfile dt = timedelta(days=0.5) trange = [self.time[0] - dt, self.time[-1] + dt] # Load the temperature salinity data and coordinate data temp, nc = get_metocean_local(ncfile,'temp', name=name, trange=trange) salt, nc = get_metocean_local(ncfile,'salt', name=name, trange=trange) if nc.X.ndim==1: X, Y = np.meshgrid(nc.X, nc.Y) else: X, Y = nc.X, nc.Y # Convert to utm ll = np.vstack([X.ravel(),Y.ravel()]).T if convert2utm: xy = ll2utm(ll,self.utmzone,north=self.isnorth) else: xy = ll # Construct a 3D mask mask3d = temp.mask mask3d = mask3d[0,...] mask3d = mask3d.reshape((nc.nz,xy.shape[0])) # Ensure that the bottom cell of the ocean model is deeper than the suntans grid nc.Z[-1] = zmax # Type 3 cells if self.N3>0: # Construct the 4D interp class F4d =\ Interp4D(xy[:,0],xy[:,1],nc.Z,nc.localtime,\ self.xv,self.yv,self.z,self.time,mask=mask3d,**self.interpdict) tempnew = F4d(temp) self.T[:] = tempnew saltnew = F4d(salt) self.S[:] = saltnew # Never do this for type-3 #if setUV: # unew = F4d(u) # self.u[:] += unew # vnew = F4d(v) # self.v[:] += vnew if seth: # Construct the 3D interp class for surface height ssh, nc2d = get_metocean_local(ncfile,'ssh', name=name, trange=trange) mask2d = ssh.mask mask2d = mask2d[0,...].ravel() F3d = Interp4D(xy[:,0],xy[:,1],None,nc2d.localtime,\ self.xv,self.yv,None,self.time,mask=mask2d,**self.interpdict) sshnew = F3d(ssh) self.h[:] += sshnew # Type 2 cells : no free-surface if self.N2>0: # Construct the 4D interp class F4d =\ Interp4D(xy[:,0], xy[:,1], nc.Z, nc.localtime,\ self.xe,self.ye,self.z,self.time,mask=mask3d,**self.interpdict) tempnew = F4d(temp) self.boundary_T[:] = tempnew del temp saltnew = F4d(salt) self.boundary_S[:] = saltnew del salt if setUV: u, nc = get_metocean_local(ncfile,'u', name=name, trange=trange) unew = F4d(u) self.boundary_u[:] += unew del u v, nc = get_metocean_local(ncfile,'v', name=name, trange=trange) vnew = F4d(v) self.boundary_v[:] += vnew del v