def __init__(self, **kwargs): self.__dict__.update(kwargs) # Check if the input file is not a list T = type(self.infile) if T != list: self.multifile = False # Read in the array print 'Reading data from: %s...' % self.infile if self.infile[-3:] == '.gz': LL, self.Zin = read_xyz_gz(self.infile) if self.infile[-3:] == 'txt': LL, self.Zin = read_xyz(self.infile) elif self.infile[-3:] == 'shp': LL, self.Zin = readShpBathy(self.infile) elif self.infile[-3:] == 'dem': LL, self.Zin = readDEM(self.infile, True) if self.infile[-3:] == '.nc': self.loadnc(fv=2) LL = self._returnXY() self.Zin = np.ravel(self.Zin) self.npt = len(self.Zin) if self.convert2utm: if self.bbox == None: # Work out the domain limits from the input file pdb.set_trace() self.bbox = [ LL[:, 0].min(), LL[:, 0].max(), LL[:, 1].min(), LL[:, 1].max() ] else: # Clip the points outside of the domain print 'Clipping points outside of the bounding box...' LL = self.clipPoints(LL) # Convert the coordinates print 'Transforming the coordinates to UTM...' self.XY = ll2utm(LL, self.utmzone, self.CS, self.isnorth) else: self.XY = LL else: # Multiple files self.multifile = True # Create the grid object self.grd = Grid(self.bbox, self.dx, self.dx, utmzone=self.utmzone, CS=self.CS, isnorth=self.isnorth)
def __init__(self,**kwargs): self.__dict__.update(kwargs) # Check if the input file is not a list T = type(self.infile) if T!=list: self.multifile=False # Read in the array print 'Reading data from: %s...'%self.infile if self.infile[-3:]=='.gz': LL,self.Zin = read_xyz_gz(self.infile) if self.infile[-3:]=='txt': LL,self.Zin = read_xyz(self.infile) elif self.infile[-3:]=='shp': LL,self.Zin = readShpBathy(self.infile) elif self.infile[-3:]=='dem': LL,self.Zin = readDEM(self.infile,True) if self.infile[-3:]=='.nc': self.loadnc(fv=2) LL = self._returnXY() self.Zin = np.ravel(self.Zin) self.npt = len(self.Zin) if self.convert2utm: if self.bbox==None: # Work out the domain limits from the input file pdb.set_trace() self.bbox = [LL[:,0].min(),LL[:,0].max(),LL[:,1].min(),LL[:,1].max()] else: # Clip the points outside of the domain print 'Clipping points outside of the bounding box...' LL=self.clipPoints(LL) # Convert the coordinates print 'Transforming the coordinates to UTM...' self.XY=ll2utm(LL,self.utmzone,self.CS,self.isnorth) else: self.XY=LL else: # Multiple files self.multifile=True # Create the grid object self.grd = Grid(self.bbox,self.dx,self.dx,utmzone=self.utmzone,CS=self.CS,isnorth=self.isnorth)
def build(self): tic=time.clock() if self.multifile==False: if self.interptype=='nn': print 'Building DEM with Nearest Neighbour interpolation...' self.nearestNeighbour() elif self.interptype=='blockavg': print 'Building DEM with Block Averaging...' self.blockAvg() elif self.interptype=='idw': print 'Building DEM with Inverse Distance Weighted Interpolation...' self.invdistweight() elif self.interptype=='kriging': print 'Building DEM with Kriging Interpolation...' self.krig() elif self.interptype=='griddata': print 'Building DEM using griddata...' self.griddata() else: print 'Error - Unknown interpolation type: %s.'%self.interptype else: # Multiple file interpolation print 'Multiple input files detected - setting "interptype" to "blockavg".' self.interptype = 'blockavg' self.Z = np.zeros((self.grd.ny,self.grd.nx)) self.N = np.zeros((self.grd.ny,self.grd.nx)) ctr=0 for f in self.infile: ctr+=1 # Read in the array print 'Reading data file (%d of %d): %s...'%(ctr,len(self.infile),f) if f[-3:]=='.gz': LL,self.Zin = read_xyz_gz(f) if f[-3:]=='txt': LL,self.Zin = read_xyz(f) elif f[-3:]=='shp': LL,self.Zin = readShpBathy(f) elif f[-3:]=='dem': LL,self.Zin = readDEM(f,True) self.npt = len(self.Zin) if self.convert2utm: # Clip the points outside of the domain #print 'Clipping points outside of the bounding box...' #LL=self.clipPoints(LL) # Convert the coordinates print 'Transforming the coordinates to UTM...' self.XY=ll2utm(LL,self.utmzone,self.CS,self.isnorth) else: self.XY=LL del LL # Interpolate print 'Building DEM with Block Averaging...' self.blockAvgMulti() # Memory cleanup del self.XY del self.Zin # Compute the block average for all of the files self.Z = np.divide(self.Z,self.N) toc=time.clock() print 'Elapsed time %10.3f seconds.'%(toc-tic)
def build(self): tic = time.clock() if self.multifile == False: if self.interptype == 'nn': print 'Building DEM with Nearest Neighbour interpolation...' self.nearestNeighbour() elif self.interptype == 'blockavg': print 'Building DEM with Block Averaging...' self.blockAvg() elif self.interptype == 'idw': print 'Building DEM with Inverse Distance Weighted Interpolation...' self.invdistweight() elif self.interptype == 'kriging': print 'Building DEM with Kriging Interpolation...' self.krig() elif self.interptype == 'griddata': print 'Building DEM using griddata...' self.griddata() else: print 'Error - Unknown interpolation type: %s.' % self.interptype else: # Multiple file interpolation print 'Multiple input files detected - setting "interptype" to "blockavg".' self.interptype = 'blockavg' self.Z = np.zeros((self.grd.ny, self.grd.nx)) self.N = np.zeros((self.grd.ny, self.grd.nx)) ctr = 0 for f in self.infile: ctr += 1 # Read in the array print 'Reading data file (%d of %d): %s...' % ( ctr, len(self.infile), f) if f[-3:] == '.gz': LL, self.Zin = read_xyz_gz(f) if f[-3:] == 'txt': LL, self.Zin = read_xyz(f) elif f[-3:] == 'shp': LL, self.Zin = readShpBathy(f) elif f[-3:] == 'dem': LL, self.Zin = readDEM(f, True) self.npt = len(self.Zin) if self.convert2utm: # Clip the points outside of the domain #print 'Clipping points outside of the bounding box...' #LL=self.clipPoints(LL) # Convert the coordinates print 'Transforming the coordinates to UTM...' self.XY = ll2utm(LL, self.utmzone, self.CS, self.isnorth) else: self.XY = LL del LL # Interpolate print 'Building DEM with Block Averaging...' self.blockAvgMulti() # Memory cleanup del self.XY del self.Zin # Compute the block average for all of the files self.Z = np.divide(self.Z, self.N) toc = time.clock() print 'Elapsed time %10.3f seconds.' % (toc - tic)