コード例 #1
0
ファイル: demBuilder.py プロジェクト: mrayson/soda
    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

            # Parse the data file into two vectors
            print "Reading data from: %s..." % self.infile
            if self.infile[-3:] == ".gz":
                LL, self.Zin = read_xyz_gz(self.infile)

            elif 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)

            elif self.infile[-3:] == ".nc":
                self.loadnc(fv=2)
                LL = self._returnXY()
                self.Zin = np.ravel(self.Zin)

            elif self.infile[-3:] in [".h5", "hdf"]:
                LL, self.Zin = self.load_hdf(self.infile, self.h5groups)

            # rescale the data
            self.Zin = self.scale * self.Zin

            # Convert the coordinates
            self.npt = len(self.Zin)
            if self.convert2utm:

                if self.bbox == None:
                    # Work out the domain limits from the input file
                    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

        # Print out some details before processing
        print 72 * "#"
        print "Grid bounds: "
        print "\tX: ", self.bbox[0:2]
        print "\tY: ", self.bbox[2:4]
        print "Data bounds:"
        print "X min = %f, X max = %f" % (self.XY[:, 0].min(), self.XY[:, 0].max())
        print "Y min = %f, Y max = %f" % (self.XY[:, 1].min(), self.XY[:, 1].max())
        print 72 * "#"

        # Create the grid object
        self.grd = Grid(
            self.bbox,
            self.dx,
            self.dx,
            utmzone=self.utmzone,
            CS=self.CS,
            isnorth=self.isnorth,
            convert2utm=self.convert2utm,
        )
コード例 #2
0
ファイル: demBuilder.py プロジェクト: gorsol/soda
    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

            # Parse the data file into two vectors
            print('Reading data from: %s...' % self.infile)
            if self.infile[-3:] == '.gz':
                LL, self.Zin = read_xyz_gz(self.infile)

            elif 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)

            elif self.infile[-3:] == '.nc':
                self.loadnc(fv=2)
                LL = self._returnXY()
                self.Zin = np.ravel(self.Zin)

            elif self.infile[-3:] in ['.h5', 'hdf']:
                LL, self.Zin = self.load_hdf(self.infile, self.h5groups)

            # rescale the data
            self.Zin = self.scale * self.Zin

            # Convert the coordinates
            self.npt = len(self.Zin)
            if self.convert2utm:

                if self.bbox == None:
                    # Work out the domain limits from the input file
                    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

        # Print out some details before processing
        print(72 * '#')
        print('Grid bounds: ')
        print('\tX: ', self.bbox[0:2])
        print('\tY: ', self.bbox[2:4])
        print('Data bounds:')
        print('X min = %f, X max = %f' %
              (self.XY[:, 0].min(), self.XY[:, 0].max()))
        print('Y min = %f, Y max = %f' %
              (self.XY[:, 1].min(), self.XY[:, 1].max()))
        print(72 * '#')

        # Create the grid object
        self.grd = Grid(self.bbox,self.dx,self.dx,\
                utmzone=self.utmzone,\
                CS=self.CS,\
                isnorth=self.isnorth,
                convert2utm= self.convert2utm)
コード例 #3
0
ファイル: demBuilder.py プロジェクト: mrayson/soda
    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()

            elif self.interptype == "curvmin":
                print "Building DEM using curvmin..."
                self.curvmin()

            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)
コード例 #4
0
ファイル: demBuilder.py プロジェクト: gorsol/soda
    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()

            elif self.interptype == 'curvmin':
                print('Building DEM using curvmin...')
                self.curvmin()

            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))