def test_fuzzy(): """ test fuzzy cluster """ dat1 = Data() dat1.data = np.ma.identity(3) dat1.data.mask = np.zeros([3, 3]) dat1.data.data[0, 0] = 1.1 dat2 = Data() dat2.data = np.ma.ones([3, 3]) dat2.data.mask = np.zeros([3, 3]) tmp = fuzzy_clust.FuzzyClust(None) tmp.indata = {'Raster': [dat1, dat2]} tmp.spinbox_minclusters.setValue(2) tmp.spinbox_maxclusters.setValue(2) tmp.combobox_alg.setCurrentIndex(0) tmp.settings(True) datout2 = tmp.outdata['Cluster'][0].data.data datout = np.array([[1, 2, 2], [2, 1, 2], [2, 2, 1]]) if datout2[0, 0] == 2: datout = np.abs(datout - 3) np.testing.assert_array_equal(datout2, datout)
def gdal_to_dat(dest, bandid='Data'): """ GDAL to Data format Parameters ---------- dest - GDAL format GDAL format bandid - str band identity """ dat = Data() gtr = dest.GetGeoTransform() rtmp = dest.GetRasterBand(1) dat.data = rtmp.ReadAsArray() nval = rtmp.GetNoDataValue() dat.data = np.ma.masked_equal(dat.data, nval) dat.data.set_fill_value(nval) dat.data = np.ma.fix_invalid(dat.data) dat.nrofbands = dest.RasterCount dat.tlx = gtr[0] dat.tly = gtr[3] dat.dataid = bandid dat.nullvalue = nval dat.rows = dest.RasterYSize dat.cols = dest.RasterXSize dat.xdim = abs(gtr[1]) dat.ydim = abs(gtr[5]) dat.wkt = dest.GetProjection() dat.gtr = gtr return dat
def gdal_to_dat(dest, bandid='Data'): """ GDAL to Data format Parameters ---------- dest - GDAL format GDAL format bandid - str band identity """ dat = Data() gtr = dest.GetGeoTransform() rtmp = dest.GetRasterBand(1) dat.data = rtmp.ReadAsArray() nval = rtmp.GetNoDataValue() dat.data = np.ma.masked_equal(dat.data, nval) dat.data.set_fill_value(nval) dat.data = np.ma.fix_invalid(dat.data) dat.nrofbands = dest.RasterCount dat.tlx = gtr[0] dat.tly = gtr[3] dat.dataid = bandid dat.nullvalue = nval dat.rows = dest.RasterYSize dat.cols = dest.RasterXSize dat.xdim = abs(gtr[1]) dat.ydim = abs(gtr[5]) dat.wkt = dest.GetProjection() dat.gtr = gtr return dat
def test_normalisation(): """Tests for normalisation.""" datin = Data() datin.data = np.ma.array([[1., 2.], [1., 2.]]) tmp = normalisation.Normalisation(None) tmp.indata = {'Raster': [datin, datin]} tmp.radiobutton_interval.setChecked(True) tmp.settings(True) datout = np.ma.array([[0., 1.], [0., 1.]]) np.testing.assert_array_equal(tmp.outdata['Raster'][0].data, datout) tmp.radiobutton_mean.setChecked(True) tmp.settings(True) datout = np.ma.array([[-1., 1.], [-1., 1.]]) np.testing.assert_array_equal(tmp.outdata['Raster'][0].data, datout) tmp.radiobutton_median.setChecked(True) tmp.settings(True) datout = np.ma.array([[-1., 1.], [-1., 1.]]) np.testing.assert_array_equal(tmp.outdata['Raster'][0].data, datout) tmp.radiobutton_8bit.setChecked(True) tmp.settings(True) datout = np.ma.array([[0., 255.], [0., 255.]]) np.testing.assert_array_equal(tmp.outdata['Raster'][0].data, datout)
def smalldata(): """Small test dataset.""" dat = Data() dat.data = np.ma.array([[29000., 29000.], [29000., 29000.]], mask=[[0, 0], [0, 0]]) dat.extent = (25, 25, -28, -27) # left, right, bottom, top return dat
def test_rtp(): """test rtp.""" datin = Data() datin.data = np.ma.array([[1, 2], [1, 2]]) dat2 = [[0.8763800720931049, 2.123619927906895], [0.8763800720931049, 2.123619927906895]] dat = dataprep.rtp(datin, 60, 30) np.testing.assert_array_equal(dat.data, dat2)
def test_equation(): """tests equation editor.""" datin = Data() datin.data = np.ma.array([[1., 2.], [1., 2.]]) datout = datin.data * 2 tmp = equation_editor.EquationEditor() tmp.indata = {'Raster': [datin, datin]} tmp.settings('i0+i1') np.testing.assert_array_equal(tmp.outdata['Raster'][0].data, datout)
def test_trimraster(): """test trim raster.""" datin = Data() datin.data = np.ma.masked_equal( [[0, 0, 0, 0], [0, 1, 2, 0], [0, 1, 2, 0], [0, 0, 0, 0]], 0) datin.nullvalue = 0 dat2 = [[1, 2], [1, 2]] dat = dataprep.trim_raster([datin]) np.testing.assert_array_equal(dat[0].data, dat2)
def init_grid(self, data): """ Initializes raster variables in the Data class Args: data (numpy masked array): masked array containing raster data.""" grid = Data() grid.data = data grid.xdim = self.dxy grid.ydim = self.dxy grid.extent = [self.xrange[0], self.xrange[1], self.yrange[0], self.yrange[1]] return grid
def test_crisp(): """ test crisp cluster """ dat1 = Data() dat1.data = np.ma.identity(3) dat1.data.mask = np.zeros([3, 3]) dat2 = Data() dat2.data = np.ma.ones([3, 3]) dat2.data.mask = np.zeros([3, 3]) tmp = crisp_clust.CrispClust(None) tmp.indata = {'Raster': [dat1, dat2]} tmp.spinbox_minclusters.setValue(2) tmp.spinbox_maxclusters.setValue(2) tmp.settings(True) datout2 = tmp.outdata['Cluster'][0].data.data datout = np.array([[1, 2, 2], [2, 1, 2], [2, 2, 1]]) if datout2[0, 0] == 2: datout = np.abs(datout - 3) np.testing.assert_array_equal(datout2, datout)
def init_grid(self, data): """ Initializes raster variables in the Data class Args: data (numpy masked array): masked array containing raster data.""" grid = Data() grid.data = data grid.cols = self.numx grid.rows = self.numy grid.xdim = self.dxy grid.ydim = self.dxy grid.tlx = self.xrange[0] grid.tly = self.yrange[1] return grid
def init_grid(self, data): """ Initializes raster variables in the Data class Args: data (numpy masked array): masked array containing raster data.""" grid = Data() grid.data = data grid.cols = self.numx grid.rows = self.numy grid.xdim = self.dxy grid.ydim = self.dxy grid.tlx = self.xrange[0] grid.tly = self.yrange[1] return grid
def test_IGRF(smalldata): """Tests IGRF Calculation.""" datin2 = Data() datin2.data = np.ma.array([[0., 0.], [0., 0.]], mask=[[0, 0], [0, 0]]) datin2.extent = (25, 25, -28, -27) # left, right, bottom, top dat2 = [[940.640983, 864.497698], [1164.106631, 1079.494023]] tmp = igrf.IGRF() tmp.indata = {'Raster': [smalldata, datin2]} tmp.dateedit.setDate(QtCore.QDate(2000, 1, 1)) tmp.dsb_alt.setValue(0.) tmp.settings(True) dat = tmp.outdata['Raster'][-1].data np.testing.assert_array_almost_equal(dat, dat2)
def rtp(data, I_deg, D_deg): """ Reduction to the Pole """ datamedian = np.ma.median(data.data) ndat = data.data - datamedian ndat.data[ndat.mask] = 0 fftmod = np.fft.fft2(ndat) ny, nx = fftmod.shape nyqx = 1/(2*data.xdim) nyqy = 1/(2*data.ydim) kx = np.linspace(-nyqx, nyqx, nx) ky = np.linspace(-nyqy, nyqy, ny) KX, KY = np.meshgrid(kx, ky) I = np.deg2rad(I_deg) D = np.deg2rad(D_deg) alpha = np.arctan2(KY, KX) filt = 1/(np.sin(I)+1j*np.cos(I)*np.cos(D-alpha))**2 zrtp = np.fft.ifft2(fftmod*filt) zrtp = zrtp.real + datamedian # Create dataset dat = Data() dat.data = np.ma.masked_invalid(zrtp) dat.data.mask = np.ma.getmaskarray(data.data) dat.rows, dat.cols = zrtp.shape dat.nullvalue = data.data.fill_value dat.dataid = data.dataid dat.tlx = data.tlx dat.tly = data.tly dat.xdim = data.xdim dat.ydim = data.ydim return dat
def rtp(data, I_deg, D_deg): """ Reduction to the Pole """ datamedian = np.ma.median(data.data) ndat = data.data - datamedian ndat.data[ndat.mask] = 0 fftmod = np.fft.fft2(ndat) ny, nx = fftmod.shape nyqx = 1 / (2 * data.xdim) nyqy = 1 / (2 * data.ydim) kx = np.linspace(-nyqx, nyqx, nx) ky = np.linspace(-nyqy, nyqy, ny) KX, KY = np.meshgrid(kx, ky) I = np.deg2rad(I_deg) D = np.deg2rad(D_deg) alpha = np.arctan2(KY, KX) filt = 1 / (np.sin(I) + 1j * np.cos(I) * np.cos(D - alpha))**2 zrtp = np.fft.ifft2(fftmod * filt) zrtp = zrtp.real + datamedian # Create dataset dat = Data() dat.data = np.ma.masked_invalid(zrtp) dat.data.mask = np.ma.getmaskarray(data.data) dat.rows, dat.cols = zrtp.shape dat.nullvalue = data.data.fill_value dat.dataid = data.dataid dat.tlx = data.tlx dat.tly = data.tly dat.xdim = data.xdim dat.ydim = data.ydim return dat
def acceptall(self): """Accept.""" dxy = self.dsb_dxy.value() nullvalue = self.dsb_null.value() data = self.indata['Point'][0] newdat = [] for data in self.pbar.iter(self.indata['Point']): if data.dataid != self.dataid.currentText(): continue filt = (data.zdata != nullvalue) x = data.xdata[filt] y = data.ydata[filt] z = data.zdata[filt] for i in [x, y, z]: filt = np.logical_not(np.isnan(i)) x = x[filt] y = y[filt] z = z[filt] tmp = quickgrid(x, y, z, dxy, showtext=self.parent.showprocesslog) mask = np.ma.getmaskarray(tmp) gdat = tmp.data # Create dataset dat = Data() dat.data = np.ma.masked_invalid(gdat[::-1]) dat.data.mask = mask[::-1] dat.nullvalue = nullvalue dat.dataid = data.dataid dat.xdim = dxy dat.ydim = dxy dat.extent = [x.min(), x.max(), y.min(), y.max()] newdat.append(dat) self.outdata['Raster'] = newdat self.outdata['Point'] = self.indata['Point']
def acceptall(self): """ accept """ dxy = self.dsb_dxy.value() data = self.indata['Point'][0] newdat = [] for data in self.pbar.iter(self.indata['Point']): if data.dataid != self.dataid.currentText(): continue x = data.xdata y = data.ydata z = data.zdata for i in [x, y, z]: filt = np.logical_not(np.isnan(i)) x = x[filt] y = y[filt] z = z[filt] tmp = quickgrid(x, y, z, dxy, showtext=self.parent.showprocesslog) mask = np.ma.getmaskarray(tmp) gdat = tmp.data # Create dataset dat = Data() dat.data = np.ma.masked_invalid(gdat[::-1]) dat.data.mask = mask[::-1] dat.rows, dat.cols = gdat.shape dat.nullvalue = dat.data.fill_value dat.dataid = data.dataid dat.tlx = x.min() dat.tly = y.max() dat.xdim = dxy dat.ydim = dxy newdat.append(dat) self.outdata['Raster'] = newdat self.outdata['Point'] = self.indata['Point']
def init_grid(self, data): """ Initializes raster variables in the Data class. Parameters ---------- data : numpy array Masked array containing raster data. Returns ------- grid : PyGMI Data PyGMI raster dataset. """ grid = Data() grid.data = data grid.xdim = self.dxy grid.ydim = self.dxy grid.extent = [ self.xrange[0], self.xrange[1], self.yrange[0], self.yrange[1] ] return grid
def test_tilt(): """test tilt depth.""" datin = Data() datin.data = np.ma.array([[0, 0, .1, .5, 1], [0, .1, .5, 1, .5], [.1, .5, 1, .5, .1], [.5, 1, .5, .1, 0], [1, .5, .1, 0, 0]]) tmp = tiltdepth.TiltDepth(None) tmp.indata = {'Raster': [datin]} tmp.dsb_dec.setValue(0.) tmp.dsb_inc.setValue(90.) tmp.settings(True) tmp.change_band1() datout2 = tmp.depths datout = np.array([[3.93612464, -1.99438548, 1., 0.32962923], [3.49438548, -2.49438548, 1., 0.34958333], [2.99438548, -2.99438548, 1., 0.34958333], [1.98888969, -1.98888969, 2., 0.36451351], [2.48888969, -1.48759916, 2., 0.3654272]]) np.testing.assert_array_almost_equal(datout2, datout)
def gdal_to_dat(dest, bandid='Data'): """ GDAL to Data format. Parameters ---------- dest - GDAL format GDAL format bandid - str band identity """ dat = Data() gtr = dest.GetGeoTransform() nbands = dest.RasterCount if nbands == 1: rtmp = dest.GetRasterBand(1) dat.data = rtmp.ReadAsArray() else: dat.data = [] for i in range(nbands): rtmp = dest.GetRasterBand(i + 1) dat.data.append(rtmp.ReadAsArray()) dat.data = np.array(dat.data) dat.data = np.moveaxis(dat.data, 0, -1) nval = rtmp.GetNoDataValue() dat.data = np.ma.masked_equal(dat.data, nval) dat.data.set_fill_value(nval) dat.data = np.ma.fix_invalid(dat.data) dat.extent_from_gtr(gtr) dat.dataid = bandid dat.nullvalue = nval dat.wkt = dest.GetProjection() return dat
def tiltdepth(self, data): """ Calculate tilt depth """ self.pbar.setValue(0) self.pbar.setMaximum(4) # RTP inc = self.dsb_inc.value() dec = self.dsb_dec.value() zout = dataprep.rtp(data, inc, dec) # Tilt self.pbar.setValue(1) nr, nc = zout.data.shape dy, dx = np.gradient(zout.data) dxtot = np.sqrt(dx**2 + dy**2) dz = cooper.vertical(zout.data) t1 = np.arctan(dz / dxtot) self.pbar.setValue(2) # A negative number implies we are straddling 0 # Contour tilt x = zout.extent[0] + np.arange(nc) * zout.xdim + zout.xdim / 2 y = zout.extent[-1] - np.arange(nr) * zout.ydim - zout.ydim / 2 X, Y = np.meshgrid(x, y) Z = np.rad2deg(t1) self.X = X self.Y = Y self.Z = Z cnt0 = self.axes.contour(X, Y, Z, [0]) cnt45 = self.axes.contour(X, Y, Z, [45], alpha=0) cntm45 = self.axes.contour(X, Y, Z, [-45], alpha=0) self.pbar.setValue(3) gx0, gy0, cgrad0, cntid0 = vgrad(cnt0) gx45, gy45, _, _ = vgrad(cnt45) gxm45, gym45, _, _ = vgrad(cntm45) g0 = np.transpose([gx0, gy0]) self.pbar.setValue(4) dmin1 = [] dmin2 = [] for i, j in self.pbar.iter(g0): dmin1.append(distpc(gx45, gy45, i, j, 0)) dmin2.append(distpc(gxm45, gym45, i, j, 0)) dx1 = gx45[dmin1] - gx0 dy1 = gy45[dmin1] - gy0 dx2 = gxm45[dmin2] - gx0 dy2 = gym45[dmin2] - gy0 grad = np.arctan2(dy1, dx1) * 180 / pi grad[grad > 90] -= 180 grad[grad < -90] += 180 gtmp1 = np.abs(90 - np.abs(grad - cgrad0)) grad = np.arctan2(dy2, dx2) * 180 / pi grad[grad > 90] -= 180 grad[grad < -90] += 180 gtmp2 = np.abs(90 - np.abs(grad - cgrad0)) gtmp = np.logical_and(gtmp1 <= 10, gtmp2 <= 10) gx0 = gx0[gtmp] gy0 = gy0[gtmp] cntid0 = cntid0[gtmp] dx1 = dx1[gtmp] dy1 = dy1[gtmp] dx2 = dx2[gtmp] dy2 = dy2[gtmp] dist1 = np.sqrt(dx1**2 + dy1**2) dist2 = np.sqrt(dx2**2 + dy2**2) dist = np.min([dist1, dist2], 0) self.x0 = gx0 self.x1 = dx1 + gx0 self.x2 = dx2 + gx0 self.y0 = gy0 self.y1 = dy1 + gy0 self.y2 = dy2 + gy0 self.depths = np.transpose([gx0, gy0, cntid0.astype(int), dist]) tmp = dataprep.quickgrid(gx0, gy0, dist, data.xdim, showtext=self.showtext) mask = np.ma.getmaskarray(tmp) gdat = tmp.data dat = Data() dat.data = np.ma.masked_invalid(gdat[::-1]) dat.data.mask = mask[::-1] dat.nullvalue = dat.data.fill_value dat.dataid = data.dataid dat.xdim = data.xdim dat.ydim = data.xdim dat.extent = [gx0.min(), gx0.max(), gy0.min(), gy0.max()] self.outdata['Raster'] = [dat]
def grid(): """ First 2 columns must be x and y """ filename = r'C:\Work\Programming\pygmi\data\sue\filt_magdata.csv' ofile = r'C:\Work\Programming\pygmi\data\magdata.tif' srows = 0 dlim = None xcol = 0 ycol = 1 zcol = 2 dxy = 15 # This bit reads in the first line to see if it is a header pntfile = open(filename) ltmp = pntfile.readline() pntfile.close() ltmp = ltmp.lower() isheader = any(c.isalpha() for c in ltmp) # Check for comma delimiting if ',' in ltmp: dlim = ',' # Set skip rows if isheader: srows = 1 # Now read in data datatmp = np.genfromtxt(filename, unpack=True, delimiter=dlim, skip_header=srows, usemask=False) # Now we interpolate xdata = datatmp[xcol] ydata = datatmp[ycol] zdata = datatmp[zcol] points = datatmp[:2].T newxdata = np.arange(xdata.min(), xdata.max(), dxy) newydata = np.arange(ydata.min(), ydata.max(), dxy) newpoints = np.meshgrid(newxdata, newydata) newpoints = (newpoints[0].flatten(), newpoints[1].flatten()) grid = si.griddata(points, zdata, newpoints, method='cubic') grid.shape = (newydata.shape[0], newxdata.shape[0]) grid = grid[::-1] # export data odat = Data() odat.dataid = '' odat.tlx = newxdata.min() odat.tly = newydata.max() odat.xdim = dxy odat.ydim = dxy odat.nrofbands = 1 odat.nullvalue = 1e+20 odat.rows, odat.cols = grid.shape odat.data = np.ma.masked_invalid(grid) tmp = pio.ExportData(None) tmp.ifile = ofile # tmp.export_ascii_xyz([odat]) # tmp.export_gdal([odat], 'ENVI') tmp.export_gdal([odat], 'GTiff') # Plotting section # dataex = (newxdata.min(), newxdata.max(), newydata.min(), newydata.max()) # plt.imshow(grid, cmap = plt.cm.jet, extent=dataex, origin='upper') plt.tricontourf(xdata, ydata, zdata, 40, cmap=plt.cm.jet) # plt.plot(xdata, ydata, '.') plt.colorbar() plt.show() pdb.set_trace()
def test_smooth(): """Tests for smoothing.""" datin = Data() datin.data = np.ma.ones([7, 7]) datin.data[5, 5] = 2 tmp = smooth.Smooth(None) tmp.indata = {'Raster': [datin]} tmp.radiobutton_2dmean.setChecked(True) tmp.radiobutton_box.setChecked(True) tmp.choosefilter() tmp.settings(True) datout2 = tmp.outdata['Raster'][0].data.data datout = np.array([[0.36, 0.48, 0.6, 0.6, 0.6, 0.48, 0.36], [0.48, 0.64, 0.8, 0.8, 0.8, 0.64, 0.48], [0.6, 0.8, 1., 1., 1., 0.8, 0.6], [0.6, 0.8, 1., 1.04, 1.04, 0.84, 0.64], [0.6, 0.8, 1., 1.04, 1.04, 0.84, 0.64], [0.48, 0.64, 0.8, 0.84, 0.84, 0.68, 0.52], [0.36, 0.48, 0.6, 0.64, 0.64, 0.52, 0.4]]) np.testing.assert_array_almost_equal(datout2, datout) tmp.radiobutton_disk.setChecked(True) tmp.choosefilter() tmp.settings(True) datout2 = tmp.outdata['Raster'][0].data.data datout = np.array([[ 0.30379747, 0.36708861, 0.43037975, 0.44303797, 0.43037975, 0.37974684, 0.3164557 ], [ 0.36708861, 0.44303797, 0.53164557, 0.5443038, 0.53164557, 0.46835443, 0.39240506 ], [ 0.43037975, 0.53164557, 0.62025316, 0.63291139, 0.62025316, 0.5443038, 0.4556962 ], [ 0.44303797, 0.5443038, 0.63291139, 0.63291139, 0.63291139, 0.55696203, 0.46835443 ], [ 0.43037975, 0.53164557, 0.62025316, 0.63291139, 0.62025316, 0.5443038, 0.4556962 ], [ 0.37974684, 0.46835443, 0.5443038, 0.55696203, 0.5443038, 0.48101266, 0.40506329 ], [ 0.3164557, 0.39240506, 0.4556962, 0.46835443, 0.4556962, 0.40506329, 0.34177215 ]]) np.testing.assert_array_almost_equal(datout2, datout) tmp.radiobutton_gaussian.setChecked(True) tmp.choosefilter() tmp.settings(True) datout = np.array( [[ 0.25999671, 0.38869512, 0.50989872, 0.50989872, 0.50989872, 0.50989872, 0.38120031 ], [ 0.38869512, 0.58109927, 0.76229868, 0.76229868, 0.76229868, 0.76229868, 0.56989453 ], [0.50989872, 0.76229868, 1., 1., 1., 1., 0.74760005], [0.50989872, 0.76229868, 1., 1., 1., 1., 0.74760005], [0.50989872, 0.76229868, 1., 1., 1.06370574, 1.06499268, 0.81130578], [0.50989872, 0.76229868, 1., 1., 1.06499268, 1.06630562, 0.81259272], [ 0.38120031, 0.56989453, 0.74760005, 0.74760005, 0.81130578, 0.81259272, 0.62261157 ]]) datout2 = tmp.outdata['Raster'][0].data.data np.testing.assert_array_almost_equal(datout2, datout) tmp.radiobutton_2dmedian.setChecked(True) tmp.radiobutton_box.setChecked(True) tmp.choosefilter() tmp.settings(True) datout2 = tmp.outdata['Raster'][0].data.data datout = np.array([[1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1., 1.]]) np.testing.assert_array_almost_equal(datout2, datout) tmp.radiobutton_disk.setChecked(True) tmp.choosefilter() tmp.settings(True) datout2 = tmp.outdata['Raster'][0].data.data np.testing.assert_array_almost_equal(datout2, datout)
def get_tiff(self, ifile, firstrun=False): """ Gets tiff images Parameters ---------- ifile : str Filename to import. firstrun : bool, optional Option for first time running this routine. The default is False. Returns ------- datall : dictionary or None Data images """ datall = {} ifile = ifile[:] dataset = gdal.Open(ifile, gdal.GA_ReadOnly) self.pbar.setMinimum(0) self.pbar.setValue(0) self.pbar.setMaximum(dataset.RasterCount - 1) gtr = dataset.GetGeoTransform() cols = dataset.RasterXSize rows = dataset.RasterYSize dx = abs(gtr[1]) dy = abs(gtr[5]) dxlim = (gtr[0], gtr[0] + gtr[1] * cols) dylim = (gtr[3] + gtr[5] * rows, gtr[3]) ############################################################################### axes = self.canvas.ax1 if firstrun is True: axes.set_xlim(dxlim[0], dxlim[1]) axes.set_ylim(dylim[0], dylim[1]) ext = (axes.transAxes.transform([(1, 1)]) - axes.transAxes.transform([(0, 0)]))[0] xlim, ylim = axes.get_xlim(), axes.get_ylim() xoff = max(int((xlim[0] - dxlim[0]) / dx), 0) yoff = max(-int((ylim[1] - dylim[1]) / dy), 0) xoff1 = min(int((xlim[1] - dxlim[1]) / dx), 0) yoff1 = min(-int((ylim[0] - dylim[0]) / dy), 0) xsize = cols - xoff + xoff1 ysize = rows - yoff + yoff1 xdim = dx * xsize / int(ext[0]) ydim = dy * ysize / int(ext[1]) xbuf = min(xsize, int(ext[0])) ybuf = min(ysize, int(ext[1])) gtrnew = (gtr[0] + xoff * dx, xdim, 0, gtr[3] - yoff * dy, 0, -ydim) ############################################################################### for i in range(dataset.RasterCount): rtmp = dataset.GetRasterBand(i + 1) nval = rtmp.GetNoDataValue() bandid = rtmp.GetDescription() if bandid == '': bandid = 'Band ' + str(i + 1) dat = Data() dat.data = rtmp.ReadAsArray(xoff, yoff, xsize, ysize, xbuf, ybuf) if dat.data is None: print('Error: Dataset could not be read properly') if dat.data.dtype.kind == 'i': if nval is None: nval = 999999 nval = int(nval) elif dat.data.dtype.kind == 'u': if nval is None: nval = 0 nval = int(nval) else: if nval is None: nval = 1e+20 nval = float(nval) dat.nrofbands = 1 # dataset.RasterCount dat.nullvalue = nval dat.xdim = xdim dat.ydim = ydim dat.extent_from_gtr(gtrnew) dat.wkt = dataset.GetProjection() datall[i + 1] = dat self.pbar.setValue(i) if datall == {}: datall = None dataset = None return datall