def create_gcp_list(latitude, longitude, rescaling_coef=1.0): n_gcp = 150 # Maximum allow GCPs percentage_gcp_per_line = 0.2 latitude_ds = gdal.OpenShared(str(latitude)) longitude_ds = gdal.OpenShared(str(longitude)) lat = (latitude_ds.GetRasterBand(1)).ReadAsArray().astype(np.float32) lon = (longitude_ds.GetRasterBand(1)).ReadAsArray().astype(np.float32) gcp_list_o = [] pas_pixel = np.int(latitude_ds.RasterXSize * percentage_gcp_per_line) + 1 pas_line = np.int((latitude_ds.RasterYSize * latitude_ds.RasterXSize) / (n_gcp * pas_pixel)) + 1 print latitude_ds.RasterXSize / pas_pixel, ' ', latitude_ds.RasterYSize / pas_line k = 0 for line in range(0, latitude_ds.RasterYSize - 1, pas_line): for px in range(0, latitude_ds.RasterXSize - 1, pas_pixel): gcp = gdal.GCP( np.multiply(np.double(lon[line][px]), rescaling_coef), np.multiply(np.double(lat[line][px]), rescaling_coef), 0, (px), (line)) gcp_list_o.append(gcp) k = k + 1 latitude_ds = None longitude_ds = None return gcp_list_o #Gdal osgeo gcp object
def add_band(src_file, src_add, option="COMPRESS=DEFLATE"): """ adding a band/bands to an existing file just working if the files have the same extent, resolution and nr of pixel add_band(src_file, file_to_add) (bands will be added to src_file) """ #pointer/open to files src_ds = gdal.OpenShared(src_file) add_ds = gdal.OpenShared(src_add) #check extent and resolution and ... src_ext = get_extent(src_file) add_ext = get_extent(src_add) if src_ext.ret_extent() != add_ext.ret_extent(): print("Error in extent, the files are not equal in extent/resolution/pixel\nnot able to perform the function") print("src_file:", src_ext.ret_extent()) print("src_add:", add_ext.ret_extent()) else: #get band counts for the rasters src_bands_count = src_ds.RasterCount add_bands_count = add_ds.RasterCount #create copy of orig in RAM tmp_ds = gdal.GetDriverByName('MEM').CreateCopy('', src_ds, 0) #add all bands del src_ds for bands2add in range(1,add_bands_count+1): add_b = add_ds.GetRasterBand(bands2add).ReadAsArray() tmp_ds.AddBand() tmp_ds.GetRasterBand(src_bands_count+bands2add).WriteArray(add_b) #write / overwrite file to disk gdal.GetDriverByName('GTiff').CreateCopy(src_file, tmp_ds, 0, options=[option]) #CreateCopy(output_path, data2write) del tmp_ds, add_b, add_ds
def __getitem__(self, idx): # Get the number n of workers and the current worker's id info = torch.utils.data.get_worker_info() # Open the data with gdal n times in multithread shared mode # The operation is done once if not self.done: raster_path = self.raster.get('reader', self.raster['path']) self.logger.info(f"Single time load of raster: [{raster_path}]") for _ in range(info.num_workers): raster_ds = gdal.OpenShared(raster_path, gdal.GA_ReadOnly) self.raster_dss.append(raster_ds) self.done = True # Do your processing with the gdal dataset associated with the worker's id image = [] patch = self.samples[idx] for raster_band in self.raster["bands"]: image.append(self.raster_dss[info.id].GetRasterBand(raster_band).ReadAsArray(*patch)) image = np.dstack(image) offsets = patch[:2] half_size = self.patch_size // 2 sample = { self.image_key: np.array(image.data, copy=True, dtype='float32'), self.center_key: (offsets[0] + half_size, offsets[1] + half_size), } if self.transforms: sample = self.transforms(sample) return sample
def __init__(self, raster_path, raster_bands, patch_size, transforms=None, image_key="image"): super().__init__(transforms=transforms) self.logger.debug("Creating %s with [%s]", type(self).__name__, raster_path) self.image_key = image_key self.center_key = "center" self.raster_dss = [] # update raster metadata that can be used by other objects self.raster = {"path": raster_path, "bands": raster_bands} raster_ds = gdal.OpenShared(raster_path, gdal.GA_ReadOnly) parse_raster_metadata(self.raster, raster_ds) xsize = raster_ds.RasterXSize ysize = raster_ds.RasterYSize self.patch_size = patch_size self.raster["xsize"] = xsize self.raster["ysize"] = ysize self.raster["georef"] = raster_ds.GetProjectionRef() self.raster["affine"] = raster_ds.GetGeoTransform() raster_ds = None # noqa # flush dataset # generate patch sample locations lines = ysize - self.patch_size cols = xsize - self.patch_size self.samples = [] for y in range(lines): for x in range(cols): self.samples.append((x, y, self.patch_size, self.patch_size)) self.n_samples = len(self.samples) self.logger.info(f"Number of samples: {self.n_samples}") self.done = False
def pixfun_inv_c(): if not numpy_available: return 'skip' filename = 'data/pixfun_inv_c.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) if ds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % filename) return 'fail' data = ds.GetRasterBand(1).ReadAsArray() reffilename = 'data/cint_sar.tif' refds = gdal.Open(reffilename) if refds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename) return 'fail' refdata = refds.GetRasterBand(1).ReadAsArray() refdata = refdata.astype('complex') delta = data - 1. / refdata if not numpy.alltrue(abs(delta.real) < 1e-13): return 'fail' if not numpy.alltrue(abs(delta.imag) < 1e-13): return 'fail' return 'success'
def raster_to_csv(InRaster, OutCSV): # open the raster and get some properties ds = gdal.OpenShared(InRaster, gdalconst.GA_ReadOnly) GeoTrans = ds.GetGeoTransform() ColRange = range(ds.RasterXSize) RowRange = range(ds.RasterYSize) rBand = ds.GetRasterBand(1) # first band nData = rBand.GetNoDataValue() if nData == None: nData = np.nan # set it to something if not set else: print("NoData value is {0}".format(nData)) # specify the centre offset HalfX = GeoTrans[1] / 2 HalfY = GeoTrans[5] / 2 with open(OutCSV, 'w') as CSVwrite: for ThisRow in RowRange: RowData = rBand.ReadAsArray(0, ThisRow, ds.RasterXSize, 1)[0] for ThisCol in ColRange: if RowData[ThisCol] != nData: if RowData[ThisCol] > -1000: X = GeoTrans[0] + (ThisCol * GeoTrans[1]) Y = GeoTrans[3] + (ThisRow * GeoTrans[5] ) # Y is negative so it's a minus # this gives the upper left of the cell, offset by half a cell to get centre X += HalfX Y += HalfY CSVwrite.write('{0},{1},{2}\n'.format( X, Y, RowData[ThisCol] )) # I think newline might be different on linux
def raster2gpd(InRaster, feature_name, band=1, nodataval=-9999): ''' Description: Takes the path of a raster (.tiff) file and produces a Geopandas Data Frame. Params: - InRaster: the path of the input raster file - feature_name: the name of the feature represented by the pixel values ''' # open the raster and get some properties ds = gdal.OpenShared(InRaster, gdalconst.GA_ReadOnly) GeoTrans = ds.GetGeoTransform() ColRange = range(ds.RasterXSize) RowRange = range(ds.RasterYSize) rBand = ds.GetRasterBand(band) # first band nData = rBand.GetNoDataValue() if nData == None: logging.info(f"No nodataval found, setting to {nodataval}") nData = np.float32(nodataval) # set it to something if not set else: logging.info(f"Nodataval is: {nData}") # specify the center offset (takes the point in middle of pixel) HalfX = GeoTrans[1] / 2 HalfY = GeoTrans[5] / 2 # Check that NoDataValue is of the same type as the raster data RowData = rBand.ReadAsArray(0, 0, ds.RasterXSize, 1)[0] if type(nData) != type(RowData[0]): logging.warning( f"NoData type mismatch: NoDataValue is type {type(nData)} and raster data is type {type(RowData[0])}" ) points = [] for ThisRow in RowRange: RowData = rBand.ReadAsArray(0, ThisRow, ds.RasterXSize, 1)[0] for ThisCol in ColRange: # need to exclude NaN values since there is no nodataval if (RowData[ThisCol] != nData) and not (np.isnan( RowData[ThisCol])): # TODO: implement filters on valid pixels # for example, the below would ensure pixel values are between -100 and 100 #if (RowData[ThisCol] <= 100) and (RowData[ThisCol] >= -100): X = GeoTrans[0] + (ThisCol * GeoTrans[1]) Y = GeoTrans[3] + (ThisRow * GeoTrans[5] ) # Y is negative so it's a minus # this gives the upper left of the cell, offset by half a cell to get centre X += HalfX Y += HalfY points.append( [Point(X, Y), X, Y, RowData[ThisCol], feature_name]) return gpd.GeoDataFrame(points, columns=[ 'geometry', 'longitude', 'latitude', 'feature_value', 'feature_name' ])
def radarGeometryTransformer(latfile, lonfile, epsg=4326): ''' Create a coordinate transformer to convert map coordinates to radar image line/pixels. ''' driver = gdal.GetDriverByName('VRT') inds = gdal.OpenShared(latfile, gdal.GA_ReadOnly) tempds = driver.Create('', inds.RasterXSize, inds.RasterYSize, 0) inds = None tempds.SetMetadata( { 'SRS': 'EPSG:{0}'.format(epsg), 'X_DATASET': lonfile, 'X_BAND': '1', 'Y_DATASET': latfile, 'Y_BAND': '1', 'PIXEL_OFFSET': '0', 'LINE_OFFSET': '0', 'PIXEL_STEP': '1', 'LINE_STEP': '1' }, 'GEOLOCATION') trans = gdal.Transformer(tempds, None, ['METHOD=GEOLOC_ARRAY']) return trans
def pixfun_imag_c(): if not numpy_available: return 'skip' filename = 'data/pixfun_imag_c.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) if ds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % filename) return 'fail' data = ds.GetRasterBand(1).ReadAsArray() reffilename = 'data/cint_sar.tif' refds = gdal.Open(reffilename) if refds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename) return 'fail' refdata = refds.GetRasterBand(1).ReadAsArray() if not numpy.alltrue(data == refdata.imag): gdaltest.post_reason('fail') return 'fail' # Test bugfix of #6599 copied_ds = gdal.Translate('', filename, format='MEM') data_ds = copied_ds.GetRasterBand(1).ReadAsArray() copied_ds = None if not numpy.alltrue(data == data_ds): gdaltest.post_reason('fail') return 'fail' return 'success'
def pixfun_mul_r(): if not numpy_available: return 'skip' filename = 'data/pixfun_mul_r.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) if ds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % filename) return 'fail' data = ds.GetRasterBand(1).ReadAsArray() if numpy_available: refdata = numpy.ones(data.shape, 'float') for reffilename in ('data/uint16.tif', 'data/int32.tif', 'data/float32.tif'): refds = gdal.Open(reffilename) if refds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename) return 'fail' refdata *= refds.GetRasterBand(1).ReadAsArray() if not numpy.alltrue(data == refdata): return 'fail' return 'success'
def pixfun_dB2pow(): if not numpy_available: return 'skip' filename = 'data/pixfun_dB2pow.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) if ds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % filename) return 'fail' data = ds.GetRasterBand(1).ReadAsArray() reffilename = 'data/float32.tif' refds = gdal.Open(reffilename) if refds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename) return 'fail' refdata = refds.GetRasterBand(1).ReadAsArray() refdata = refdata.astype('float64') #if not numpy.allclose(data, 10.**(refdata/10.)): if not numpy.alltrue(data == 10.**(refdata / 10.)): return 'fail' return 'success'
def pixfun_cmul_r(): if not numpy_available: return 'skip' filename = 'data/pixfun_cmul_r.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) if ds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % filename) return 'fail' data = ds.GetRasterBand(1).ReadAsArray() reffilename = 'data/uint16.tif' refds = gdal.Open(reffilename) if refds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename) return 'fail' refdata1 = refds.GetRasterBand(1).ReadAsArray() refdata1 = refdata1.astype('float64') reffilename = 'data/int32.tif' refds = gdal.Open(reffilename) if refds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename) return 'fail' refdata2 = refds.GetRasterBand(1).ReadAsArray() refdata2 = refdata2.astype('float64') if not numpy.alltrue(data == refdata1 * refdata2.conj()): return 'fail' return 'success'
def pixfun_diff_c(): if not numpy_available: return 'skip' filename = 'data/pixfun_diff_c.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) if ds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % filename) return 'fail' data = ds.GetRasterBand(1).ReadAsArray() reffilename = 'data/cint_sar.tif' refds = gdal.Open(reffilename) if refds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename) return 'fail' refdata1 = refds.GetRasterBand(1).ReadAsArray() reffilename = 'data/cfloat64.tif' refds = gdal.Open(reffilename) if refds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename) return 'fail' refdata2 = refds.GetRasterBand(1).ReadAsArray(0, 0, 5, 6) if not numpy.alltrue(data == refdata1 - refdata2): return 'fail' return 'success'
def pixfun_sum_c(): if not numpy_available: return 'skip' filename = 'data/pixfun_sum_c.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) if ds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % filename) return 'fail' data = ds.GetRasterBand(1).ReadAsArray() if numpy_available: refdata = numpy.zeros(data.shape, 'complex') for reffilename in ('data/uint16.tif', 'data/cint_sar.tif', 'data/cfloat64.tif'): refds = gdal.Open(reffilename) if refds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename) return 'fail' refdata += refds.GetRasterBand(1).ReadAsArray(0, 0, 5, 6) if not numpy.alltrue(data == refdata): return 'fail' return 'success'
def pixfun_phase_c(): if not numpy_available: return 'skip' filename = 'data/pixfun_phase_c.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) if ds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % filename) return 'fail' data = ds.GetRasterBand(1).ReadAsArray() reffilename = 'data/cint_sar.tif' refds = gdal.Open(reffilename) if refds is None: gdaltest.post_reason('Unable to open "%s" dataset.' % reffilename) return 'fail' refdata = refds.GetRasterBand(1).ReadAsArray() refdata = refdata.astype('complex128') if not numpy.allclose(data, numpy.arctan2(refdata.imag, refdata.real)): print(data - numpy.arctan2(refdata.imag, refdata.real)) return 'fail' return 'success'
def vrtfilt_3(): ds = gdal.OpenShared('data/rgbsmall.tif') vrt_ds = gdal.GetDriverByName('VRT').CreateCopy('', ds) ds = None filterSourceXML = """ <KernelFilteredSource> <SourceFilename>data/rgbsmall.tif</SourceFilename> <SourceBand>1</SourceBand> <SrcRect xOff="0" yOff="0" xSize="50" ySize="50"/> <DstRect xOff="0" yOff="0" xSize="50" ySize="50"/> <Kernel> <Size>3</Size> <Coefs>0.111111 0.111111 0.111111 0.111111 0.111111 0.111111 0.111111 0.111111 0.111111</Coefs> </Kernel> </KernelFilteredSource>""" try: vrt_ds.GetRasterBand(1).SetMetadataItem except: return 'skip' vrt_ds.GetRasterBand(1).SetMetadataItem('source_0', filterSourceXML, 'vrt_sources') if vrt_ds.GetRasterBand(1).Checksum() != 21890: return 'fail' return 'success'
def raster2gpd(InRaster,feature_name,band=1,nodataval=-9999): ''' Description: Takes the path of a raster (.tiff) file and produces a Geopandas Data Frame. Params: - InRaster: the path of the input raster file - feature_name: the name of the feature represented by the pixel values ''' with rasterio.open(InRaster) as r: T0 = r.transform # upper-left pixel corner affine transform p1 = Proj(r.crs) p2 = Proj(proj='latlong',datum='WGS84') # open the raster and get some properties ds = gdal.OpenShared(InRaster,gdalconst.GA_ReadOnly) GeoTrans = ds.GetGeoTransform() ColRange = range(ds.RasterXSize) RowRange = range(ds.RasterYSize) rBand = ds.GetRasterBand(band) # first band nData = np.float32(rBand.GetNoDataValue()) if nData == None: print("No nodataval for raster") nData = nodataval # set it to something if not set else: print("NoData value is {0}".format(nData)) # specify the center offset (takes the point in middle of pixel) HalfX = GeoTrans[1] / 2 HalfY = GeoTrans[5] / 2 points = [] for ThisRow in RowRange: RowData = rBand.ReadAsArray(0,ThisRow,ds.RasterXSize,1)[0] for ThisCol in ColRange: # need to exclude NaN values since there is no nodataval if (np.float32(RowData[ThisCol]) != nData) and not (np.isnan(RowData[ThisCol])): # TODO: implement filters on valid pixels # for example, the below would ensure pixel values are between -100 and 100 #if (RowData[ThisCol] <= 100) and (RowData[ThisCol] >= -100): X = GeoTrans[0] + ( ThisCol * GeoTrans[1] ) Y = GeoTrans[3] + ( ThisRow * GeoTrans[5] ) # Y is negative so it's a minus # this gives the upper left of the cell, offset by half a cell to get centre X += HalfX Y += HalfY points.append([X,Y,RowData[ThisCol],feature_name]) gdf = gpd.GeoDataFrame(points, columns=['longitude','latitude','feature_value','feature_name']) X, Y = list(gdf.longitude), list(gdf.latitude) T = transform(p1, p2, X, Y) gdf['latitude'] = T[1] gdf['longitude'] = T[0] gdf['geometry'] = gdf.apply(lambda x: Point(x.longitude, x.latitude),axis=1) return gdf
def test_misc_3(): with gdaltest.error_handler(): ds = gdal.OpenShared('../gdrivers/data/small16.aux') ds.GetRasterBand(1).Checksum() cache_size = gdal.GetCacheUsed() with gdaltest.error_handler(): ds2 = gdal.OpenShared('../gdrivers/data/small16.aux') ds2.GetRasterBand(1).Checksum() cache_size2 = gdal.GetCacheUsed() if cache_size != cache_size2: print("--> OpenShared didn't work as expected") ds = None ds2 = None
def misc_3(): ds = gdal.OpenShared('../gdrivers/data/small16.aux') ds.GetRasterBand(1).Checksum() cache_size = gdal.GetCacheUsed() ds2 = gdal.OpenShared('../gdrivers/data/small16.aux') ds2.GetRasterBand(1).Checksum() cache_size2 = gdal.GetCacheUsed() if cache_size != cache_size2: print("--> OpenShared didn't work as expected") ds = None ds2 = None return 'success'
def test_pixfun_phase_unsigned(): filename = 'data/vrt/pixfun_phase_unsigned.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) assert ds is not None, ('Unable to open "%s" dataset.' % filename) data = ds.GetRasterBand(1).ReadAsArray() assert numpy.alltrue(data == numpy.zeros(data.shape))
def test_pixfun_imag_r(): filename = 'data/vrt/pixfun_imag_r.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) assert ds is not None, ('Unable to open "%s" dataset.' % filename) data = ds.GetRasterBand(1).ReadAsArray() assert numpy.alltrue(data == 0)
def changeResolution(): inputTiff = gdal.OpenShared(outputTest, gdal.GA_Update) inputTiff2 = gdal.OpenShared(rasterWarpOut, gdal.GA_Update) #getting geotransform info infoGeoTrans = inputTiff.GetGeoTransform() infoProj = inputTiff.GetProjection() infoGeoTrans2 = inputTiff2.GetGeoTransform() infoProj2 = inputTiff2.GetProjection() #in order to make cell size small enough to register, divide x and y resoultion by 6 xres_var = infoGeoTrans2[1] yres_var = infoGeoTrans2[5] warpOptions = gdal.WarpOptions(xRes= xres_var/6.0, yRes=yres_var/6.0) warp_out = gdal.Warp(rasterWarpOut, outputTest, options=warpOptions) infoGeoTrans3 = inputTiff2.GetGeoTransform() warp_out = None del warp_out inputTiff=None inputTiff2=None
def misc_2(): tab_ds = [None for i in range(5000)] for i, _ in enumerate(tab_ds): tab_ds[i] = gdal.OpenShared('data/byte.tif') if tab_ds[i] is None: return 'fail' return 'success'
def raster2gpd(InRaster, feature_name, band=1, nodataval=-9999): ''' Description: Takes the path of a raster (.tiff) file and produces a Geopandas Data Frame. Params: - InRaster: the path of the input raster file - feature_name: the name of the feature represented by the pixel values ''' # open the raster and get some properties ds = gdal.OpenShared(InRaster, gdalconst.GA_ReadOnly) ds = gdal.Warp('out_raster.tif', ds, dstSRS='EPSG:4326') # fixes projection issue GeoTrans = ds.GetGeoTransform() ColRange = range(ds.RasterXSize) RowRange = range(ds.RasterYSize) rBand = ds.GetRasterBand(band) # first band nData = rBand.GetNoDataValue() if nData == None: print("No nodataval for raster") nData = nodataval # set it to something if not set else: print("NoData value is {0}".format(nData)) # specify the center offset (takes the point in middle of pixel) HalfX = GeoTrans[1] / 2 HalfY = GeoTrans[5] / 2 points = [] for ThisRow in RowRange: RowData = rBand.ReadAsArray(0, ThisRow, ds.RasterXSize, 1)[0] for ThisCol in ColRange: # need to exclude NaN values since there is no nodataval if (RowData[ThisCol] != nData) and not (np.isnan( RowData[ThisCol])): # TODO: implement filters on valid pixels # for example, the below would ensure pixel values are between -100 and 100 #if (RowData[ThisCol] <= 100) and (RowData[ThisCol] >= -100): X = GeoTrans[0] + (ThisCol * GeoTrans[1]) Y = GeoTrans[3] + (ThisRow * GeoTrans[5] ) # Y is negative so it's a minus # this gives the upper left of the cell, offset by half a cell to get centre X += HalfX Y += HalfY points.append( [Point(X, Y), X, Y, RowData[ThisCol], feature_name]) return gpd.GeoDataFrame(points, columns=[ 'geometry', 'longitude', 'latitude', 'feature_value', 'feature_name' ])
def misc_2(): tab_ds = [None for i in range(5000)] for i in range(len(tab_ds)): tab_ds[i] = gdal.OpenShared('data/byte.tif') if tab_ds[i] is None: return 'fail' for i in range(len(tab_ds)): tab_ds[i] = None return 'success'
def tryopends(filepath): dsogr, dsgdal = False, False try: #print "trying" + filepath dsgdal = gdal.OpenShared(filepath) except gdal.GDALError: return False try: dsogr = ogr.OpenShared(filepath) except ogr.OGRError: return False return dsgdal, dsogr
def test_pixfun_dB_c_intensity(): filename = 'data/vrt/pixfun_dB_c_intensity.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) assert ds is not None, ('Unable to open "%s" dataset.' % filename) data = ds.GetRasterBand(1).ReadAsArray() reffilename = 'data/cint_sar.tif' refds = gdal.Open(reffilename) assert refds is not None, ('Unable to open "%s" dataset.' % reffilename) refdata = refds.GetRasterBand(1).ReadAsArray() assert numpy.allclose(data, 10. * numpy.log10(numpy.abs(refdata)))
def test_pixfun_dB2amp(): filename = 'data/vrt/pixfun_dB2amp.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) assert ds is not None, ('Unable to open "%s" dataset.' % filename) data = ds.GetRasterBand(1).ReadAsArray() reffilename = 'data/float32.tif' refds = gdal.Open(reffilename) assert refds is not None, ('Unable to open "%s" dataset.' % reffilename) refdata = refds.GetRasterBand(1).ReadAsArray() assert numpy.allclose(data, 10.**(refdata / 20.))
def test_pixfun_sqrt(): filename = 'data/vrt/pixfun_sqrt.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) assert ds is not None, ('Unable to open "%s" dataset.' % filename) data = ds.GetRasterBand(1).ReadAsArray() reffilename = 'data/float32.tif' refds = gdal.Open(reffilename) assert refds is not None, ('Unable to open "%s" dataset.' % reffilename) refdata = refds.GetRasterBand(1).ReadAsArray() assert numpy.alltrue(data == numpy.sqrt(refdata))
def test_pixfun_intensity_c(): filename = 'data/vrt/pixfun_intensity_c.vrt' ds = gdal.OpenShared(filename, gdal.GA_ReadOnly) assert ds is not None, ('Unable to open "%s" dataset.' % filename) data = ds.GetRasterBand(1).ReadAsArray() reffilename = 'data/cint_sar.tif' refds = gdal.Open(reffilename) assert refds is not None, ('Unable to open "%s" dataset.' % reffilename) refdata = refds.GetRasterBand(1).ReadAsArray() assert numpy.alltrue(data == (refdata * refdata.conj()).real)