def topophaseRemoval(product): if debug >= 2: print(cyan + "topophaseRemoval() : " + bold + green + "Run to SNAP... " + endC) # Instance de GPF GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() # Def operateur SNAP operator = 'TopoPhaseRemoval' # Set des parametres parameters = HashMap() parameters.put("Orbit Interpolation Degree", 3) parameters.put("Digital Elevation Model", "SRTM 1Sec HGT (Auto Download)") parameters.put("Tile Extension[%]", 100) parameters.put("Output topographic phase band", True) parameters.put("Output elevation band", False) if debug >= 2: print(parameters) # Get snappy Operators result = GPF.createProduct(operator, parameters, product) if debug >= 2: print(cyan + "topophaseRemoval() : " + bold + green + "Done... " + endC) return result
def backGeocoding(product): if debug >= 2: print(cyan + "backGeocoding() : " + bold + green + "Run to SNAP... " + endC) # Instance de GPF GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() # Def operateur SNAP operator = 'Back-Geocoding' # Set des parametres parameters = HashMap() parameters.put("Digital Elevation Model", "SRTM 1Sec HGT (Auto Download)") parameters.put("DEM Resampling Method", "BICUBIC_INTERPOLATION") parameters.put("Resampling Type", "BISINC_5_POINT_INTERPOLATION") parameters.put("Mask out areas with no elevation", True) parameters.put("Output Deramp and Demod Phase", False) if debug >= 2: print(parameters) # Get snappy Operators result = GPF.createProduct(operator, parameters, product) if debug >= 2: print(cyan + "backGeocoding() : " + bold + green + "Done... " + endC) return result
def do_subset_band(source, wkt): print('\tSubsetting...') parameters = HashMap() parameters.put('geoRegion', wkt) #parameters.put('outputImageScaleInDb', True) output = GPF.createProduct('Subset', parameters, source) return output
def goldsteinPhasefiltering(product): if debug >= 2: print(cyan + "goldsteinPhasefiltering() : " + bold + green + "Run to SNAP... " + endC) # Instance de GPF GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() # Def operateur SNAP operator = 'GoldsteinPhaseFiltering' # Set des parametres parameters = HashMap() parameters.put("Adaptive Filter Exponent in(0,1]:", 1.0) parameters.put("FFT Size", 64) parameters.put("Window Size", 3) parameters.put("Use coherence mask", False) parameters.put("Coherence Threshold in[0,1]:", 0.2) if debug >= 2: print(parameters) # Get snappy Operators result = GPF.createProduct(operator, parameters, product) if debug >= 2: print(cyan + "goldsteinPhasefiltering() : " + bold + green + "Done... " + endC) return result
def dem_extract(in_prod, xpix, ypix, bandname="altitude"): """Run the S3 SNOW DEM tool. Args: inprod (java.lang.Object): snappy java object: SNAP image product xpix (float): x position in product to query ypix (float): y position in product to query bandname (str): DEM band name in product Returns: slope_vals (dictionnary): values from all bands at the given x,y""" # Initialise a HashMap parameters = HashMap() parameters.put("elevationBandName", bandname) parameters.put("copyElevationBand", "true") # Run slope operator s3snow_slope = GPF.createProduct("SlopeCalculation", parameters, in_prod) # Initialise dictionnary to store data slope_vals = {} # Get all bands for band in list(s3snow_slope.getBandNames()): currentband = s3snow_slope.getBand(band) currentband.loadRasterData() slope_vals[band] = currentband.getPixelFloat(xpix, ypix) return slope_vals
def topsarDeburst(product): if debug >= 2: print(cyan + "topsarDeburst() : " + bold + green + "Run to SNAP... " + endC) # Instance de GPF GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() # Def operateur SNAP operator = 'TOPSAR-Deburst' # Set des parametres parameters = HashMap() parameters.put("Polarisations", "VV") if debug >= 2: print(parameters) # Get snappy Operators result = GPF.createProduct(operator, parameters, product) if debug >= 2: print(cyan + "topsarDeburst() : " + bold + green + "Done... " + endC) return result
def ellipsoid_correction(speckle, datestamp): params = HashMap() params.put('imgResamplingMethod', 'BILINEAR_INTERPOLATION') params.put('mapProjection', 'WGS84(DD)') ec = GPF.createProduct('Ellipsoid-Correction-GG', params, speckle) write_product(ec, os.path.join(dest_path, '{}_Orb_Cal_ML_TF_Stack_Spk_EC'.format(datestamp))) write_product(ec, os.path.join(dest_path, '{}_Orb_Cal_ML_TF_Stack_Spk_EC'.format(datestamp)), format='GeoTIFF') return ec
def do_calibration(orbit, datestamp): params = HashMap() params.put('outputSigmaBand', False) params.put('outputGammaBand', False) params.put('outputBetaBand', True) calibration = GPF.createProduct('Calibration', params, orbit) # write_product(calibration, os.path.join(dest_path, '{}_Orb_Cal'.format(datestamp))) return calibration
def do_speckle_filtering(source): print('\tSpeckle filtering...') parameters = HashMap() parameters.put('filter', 'Lee') parameters.put('filterSizeX', 5) parameters.put('filterSizeY', 5) output = GPF.createProduct('Speckle-Filter', parameters, source) return output
def TopoPhaseRemoval_config(): parameters = HashMap() parameters.put("Orbit Interpolation Degree", 3) parameters.put("Digital Elevation Model", "SRTM 1Sec HGT") parameters.put("Tile Extension[%]", 100) parameters.put("Output topographic phase band", True) parameters.put("Output elevation band", False) return parameters
def GoldsteinPhaseFiltering_config(): parameters = HashMap() parameters.put("Adaptive Filter Exponent in(0,1]:", 1.0) parameters.put("FFT Size", 64) parameters.put("Window Size", 3) parameters.put("Use coherence mask", False) parameters.put("Coherence Threshold in[0,1]:", 0.2) return parameters
def topophase_removal(product): parameters = HashMap() parameters.put("Orbit Interpolation Degree", 3) parameters.put("Digital Elevation Model", "SRTM 1Sec HGT") parameters.put("Tile Extension[%]", 100) parameters.put("Output topographic phase band", True) parameters.put("Output elevation band", False) return GPF.createProduct("TopoPhaseRemoval", parameters, product)
def BackGeocoding_config(): parameters = HashMap() parameters.put("Digital Elevation Model", "SRTM 1Sec HGT") parameters.put("DEM Resampling Method", "BICUBIC_INTERPOLATION") parameters.put("Resampling Type", "BISINC_5_POINT_INTERPOLATION") parameters.put("Mask out areas with no elevation", True) parameters.put("Output Deramp and Demod Phase", True) return parameters
def resize(product, targetWidth, targetHeight): from snappy import GPF from snappy import HashMap parameters = HashMap() parameters.put('targetWidth', targetWidth) parameters.put('targetHeight', targetHeight) return GPF.createProduct('Resample', parameters, product)
def subset(product, shpPath): parameters = HashMap() wkt = shpToWKT(shpPath) SubsetOp = jpy.get_type('org.esa.snap.core.gpf.common.SubsetOp') geometry = WKTReader().read(wkt) parameters.put('copyMetadata', True) parameters.put('geoRegion', geometry) return GPF.createProduct('Subset', parameters, product)
def topo_removal(file): image = ProductIO.readProduct(file) p = HashMap() p.put('demName', 'SRTM 1Sec HGT') result = GPF.createProduct('TopoPhaseRemoval', p, image) # Write to temporary file outfile = file.split('.dim')[0] + '_noSRTM.dim' ProductIO.writeProduct(result, outfile, 'BEAM-DIMAP')
def back_geocoding(product): parameters = HashMap() parameters.put("Digital Elevation Model", "SRTM 1Sec HGT") parameters.put("DEM Resampling Method", "BICUBIC_INTERPOLATION") parameters.put("Resampling Type", "BISINC_5_POINT_INTERPOLATION") parameters.put("Mask out areas with no elevation", True) parameters.put("Output Deramp and Demod Phase", True) return GPF.createProduct("Back-Geocoding", parameters, product)
def bandMathSnap(input_dim, output_file, expression_list, format_file='float32'): if debug >= 2: print(cyan + "bandmathSnap() : " + bold + green + "Import Dim to SNAP : " + endC + input_dim) # Info input file product = ProductIO.readProduct(input_dim) width = product.getSceneRasterWidth() height = product.getSceneRasterHeight() name = product.getName() description = product.getDescription() band_names = product.getBandNames() if debug >= 2: print(cyan + "bandmathSnap() : " + bold + green + "Product: %s, %d x %d pixels, %s" % (name, width, height, description) + endC) print(cyan + "bandmathSnap() : " + bold + green + "Bands: %s" % (list(band_names)) + endC) # Instance de GPF GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() # Def operateur SNAP operator = 'BandMaths' BandDescriptor = jpy.get_type( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor') targetBands = jpy.array( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', len(expression_list)) # Get des expressions d'entréées i = 0 for expression in expression_list: targetBand = BandDescriptor() targetBand.name = 'band_' + str(i + 1) targetBand.type = format_file targetBand.expression = expression targetBands[i] = targetBand i += 1 # Set des parametres parameters = HashMap() parameters.put('targetBands', targetBands) # Get snappy Operators result = GPF.createProduct(operator, parameters, product) ProductIO.writeProduct(result, output_file, 'BEAM-DIMAP') if debug >= 2: print(cyan + "bandmathSnap() : " + bold + green + "Writing Done : " + endC + str(output_file)) return result
def do_resampling (source): print ('\tResampling ...') HashMap = jpy.get_type('java.util.HashMap') parameters = HashMap() GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() parameters.put('targetResolution', 10) output = GPF.createProduct('Resample', parameters, source) return output
def Convert_to_dB(data, source_band): print('Converting to dB...') parameters = HashMap() parameters.put('sourceBands', source_band) return GPF.createProduct('LinearToFromdB', parameters, data)
def set_no_data_value(product): logger = logging.getLogger('root') params = HashMap() root = xml.etree.ElementTree.parse(home['parameters'] + '/nodatavalue.xml').getroot() for child in root: params.put(child.tag, child.text) result = GPF.createProduct('SetNoDataValue', params, product) logger.info("finished set_no_data_value") return (result)
def calibration(product): logger = logging.getLogger('root') params = HashMap() root = xml.etree.ElementTree.parse(home['parameters'] + '/calibration.xml').getroot() for child in root: params.put(child.tag, child.text) result = GPF.createProduct('Calibration', params, product) logger.info("finished calibration") return (result)
def subset(product, x, y, width, heigth, toPrint=True): # subset of the Sentinel-1 GRD product by specify a rectangle whose top most left corner is defined by x and y coordinates HashMap = jpy.get_type('java.util.HashMap') GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() parameters = HashMap() parameters.put('copyMetadata', True) parameters.put('region', "%s,%s,%s,%s" % (x, y, width, height)) subset = GPF.createProduct('Subset', parameters, product) if toPrint: print("Bands: %s" % (list(subset.getBandNames()))) return subset
def do_biophysical_parameter (source): print ('\tBiophysical Parameters ...') HashMap = jpy.get_type('java.util.HashMap') parameters = HashMap() GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() parameters.put('targetResolution', 10) parameters.put('computeLAI', True) ##parameters.put('computeFcover', True) output = GPF.createProduct('BiophysicalOp', parameters, source) return output
def get_band_math_config(band_name, expression): parameters = HashMap() band_descriptor = jpy.get_type('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor') target_band = band_descriptor() target_band.name = band_name target_band.type = 'float32' target_band.expression = expression target_bands = jpy.array('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 1) target_bands[0] = target_band parameters.put('targetBands', target_bands) return parameters
def check_coverage(file, p): ## Does the image definitely cover our study areas in Peru / Gabon if 'GAB' in file: region = 'POLYGON((12.24885799008746368 -0.14350824099999146, 12.24885110630293283 -0.14259615803456555, 12.24975595848531107 -0.14259626696242139, 12.24975584715663501 -0.14353065658873754, 12.24885799008746368 -0.14350824099999146))' elif 'PER' in file: region = 'POLYGON((-69.72334001018973026 -11.0329910794429793, -69.72334358246895647 -11.03207312025939579, -69.72240573287906784 -11.0320753572009469, -69.7224080470953993 -11.03302282454907512, -69.72334001018973026 -11.0329910794429793))' params = HashMap() params.put('geoRegion', region) fail = 'Empty' in GPF.createProduct('Subset', params, p).getName() return not fail
def data_calibration(calib): parameters = HashMap() parameters.put('auxFile', 'Latest Auxiliary File') parameters.put('outputSigmaBand', False) parameters.put('createBetaBand', True) parameters.put('outputBetaBand', True) parameters.put('selectedPolarisations', polarization) #parameters.put('sourceBands', 'Intensity_' + polarization) parameters.put('sourceBands', band_names) # Or 'Intensity_VV', 'Intensity_VH' return GPF.createProduct('Calibration', parameters, calib)
def calibrate(product): from snappy import jpy from snappy import ProductIO from snappy import GPF from snappy import HashMap parameters = HashMap() parameters.put('outputSigmaBand', True) parameters.put('outputImageScaleInDb', False) Calibrate = GPF.createProduct('Calibration', parameters, product) return Calibrate
def thermal_noise_removal(product): logger = logging.getLogger('root') params = HashMap() root = xml.etree.ElementTree.parse(home['parameters'] + '/thermal_noise.xml').getroot() for child in root: params.put(child.tag, child.text) result = GPF.createProduct('ThermalNoiseRemoval', params, product) logger.info("finished ThermalNoiseRemoval") return (result)
def remove_border_noise(product): logger = logging.getLogger('root') params = HashMap() root = xml.etree.ElementTree.parse(home['parameters'] + '/border-noise.xml').getroot() for child in root: params.put(child.tag, child.text) result = GPF.createProduct('Remove-GRD-Border-Noise', params, product) logger.info("finished Remove-GRD-Border-Noise") return (result)
targetBand1 = BandDescriptor() targetBand1.name = 'band_1' targetBand1.type = 'float32' targetBand1.expression = '(radiance_10 - radiance_7) / (radiance_10 + radiance_7)' targetBand2 = BandDescriptor() targetBand2.name = 'band_2' targetBand2.type = 'float32' targetBand2.expression = '(radiance_9 - radiance_6) / (radiance_9 + radiance_6)' targetBands = jpy.array('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 2) targetBands[0] = targetBand1 targetBands[1] = targetBand2 parameters = HashMap() parameters.put('targetBands', targetBands) result = GPF.createProduct('BandMaths', parameters, product) print("Writing...") ProductIO.writeProduct(result, 'snappy_bmaths_output.dim', 'BEAM-DIMAP') print("Done.") """ Please note: the next major version of snappy/jpy will be more pythonic in the sense that implicit data type conversions are performed. The 'parameters' from above variable could then be given as a Python dict object: parameters = {