Example #1
0
    def oceanmodel2ic(self,ncfile,convert2utm=True,setUV=False,seth=False,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
        # Get the temperature data and coordinate data
        temp, nc = get_metocean_local(ncfile,'temp',name=name)

        # Convert to utm
        ll = np.vstack([nc.X.ravel(),nc.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]))

        # Construct the 4D interp class
        F4d =\
            Interp4D(xy[:,0],xy[:,1],nc.Z,nc.time,\
                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')
        saltnew = F4d(salt)
        self.S[:] = saltnew

        if seth:
            # Construct the 3D interp class for surface height
            ssh, nc = get_metocean_local(ncfile,'ssh')
            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
Example #2
0
    def oceanmodel2bdy(self,ncfile,convert2utm=True,setUV=True,seth=True,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
        # Load the temperature salinity data and coordinate data
        temp, nc = get_metocean_local(ncfile,'temp',name=name)
        salt, nc = get_metocean_local(ncfile,'salt')
        if setUV:
            u, nc = get_metocean_local(ncfile,'u')
            v, nc = get_metocean_local(ncfile,'v')


        # Convert to utm
        ll = np.vstack([nc.X.ravel(),nc.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]))

        # Type 3 cells
        if self.N3>0:
            # Construct the 4D interp class
            F4d =\
                Interp4D(xy[:,0],xy[:,1],nc.Z,nc.time,\
                    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')
                mask2d = ssh.mask
                mask2d = mask2d[0,...].ravel()

                F3d = Interp4D(xy[:,0],xy[:,1],None,nc2d.time,\
                    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.time,\
                 self.xe,self.ye,self.z,self.time,mask=mask3d,**self.interpdict)

            tempnew = F4d(temp)
            self.boundary_T[:] = tempnew

            saltnew = F4d(salt)
            self.boundary_S[:] = saltnew

            if setUV:
                unew = F4d(u)
                self.boundary_u[:] += unew
                vnew = F4d(v)
                self.boundary_v[:] += vnew