def _band_math(self, product, name, expression): GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() HashMap = jpy.get_type('java.util.HashMap') BandDescriptor = jpy.get_type( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor') targetBand = BandDescriptor() targetBand.name = name targetBand.type = 'float32' targetBand.expression = expression bands = jpy.array( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 1) bands[0] = targetBand parameters = HashMap() parameters.put('targetBands', bands) productMap = HashMap() if isinstance(product, list): for ind in range(len(product)): print('p{}'.format(ind + 1)) productMap.put('p{}'.format(ind + 1), product[ind]) result = GPF.createProduct('BandMaths', parameters, productMap) else: result = GPF.createProduct('BandMaths', parameters, product) return result
def band_maths(self, expression): """ Perform a SNAP GPF BandMath operation on the product, excluding non-vegetation and non-soil pixels. Args: expression: The band maths expression to execute """ print("\tBandMaths, product={}".format(self.product.getName())) BandDescriptor = jpy.get_type( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor') band = BandDescriptor() band.name = 'band_maths' band.type = 'float32' band.expression = expression band.noDataValue = np.nan bands = jpy.array( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 1) bands[0] = band HashMap = jpy.get_type('java.util.HashMap') parameters = HashMap() parameters.put('targetBands', bands) self.product = GPF.createProduct('BandMaths', parameters, self.product) return self.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 extract_values(self, file): if not exists(self.plots): mkdir(self.plots) coords = [] with open(file, 'r') as f: for line in f: line = line.replace('\n', '') coords.append([float(x) for x in line.split(' ')]) GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() HashMap = jpy.get_type('java.util.HashMap') Coords = jpy.array('org.esa.snap.pixex.Coordinate', len(coords)) Coord = jpy.get_type('org.esa.snap.pixex.Coordinate') for ind, coord in enumerate(coords): c = Coord('Coord{}'.format(ind), coord[0], coord[1], None) Coords[ind] = c parameters = HashMap() parameters.put('exportBands', True) parameters.put('exportTiePoints', False) parameters.put('exportMasks', False) parameters.put('coordinates', Coords) parameters.put('outputDir', '.') pre = self._extract_values(parameters, self.product_pre) post = self._extract_values(parameters, self.product_post) waves = pre.meta['comments'][-1].replace('\t', ' ') waves = waves.replace('Wavelength:', '').split(' ') waves = filter(lambda x: x != '', waves) waves = [float(x) for x in waves] waves = filter(lambda x: x != 0, waves) bands = ['B{}'.format(ind) for ind in range(1, 9)] bands += ['B8A', 'B9'] bands += ['B{}'.format(ind) for ind in range(11, 13)] print(pre.colnames) print(post.colnames) for ind in range(len(pre)): f, ax = plt.subplots() ax.set_xlabel('Wavelength (nm)') ax.set_ylabel('dl') radiances = list(pre[bands][ind]) ax.plot(waves, radiances, color='g', label='pre') ax.scatter(waves, radiances, color='g') radiances = list(post[bands][ind]) ax.plot(waves, radiances, color='b', label='post') ax.scatter(waves, radiances, color='b') lat = pre['Latitude'][ind] lon = pre['Longitude'][ind] ax.set_title("{}, {}".format(lat, lon)) plt.legend() save = "{}/{}.pdf".format(self.plots, pre['Name'][ind]) f.savefig(save, bbox_inches="tight")
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 BandMathList(stack): product = ProductIO.readProduct(stack) band_names = product.getBandNames() GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() BandDescriptor = jpy.get_type( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor') bandlist = list(band_names) #targetBands = list() x = 0 y = 1 bandlength = len(bandlist) runs = (bandlength - 1) targetBands = jpy.array( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', runs) for i in bandlist: while y <= runs: #print('{}_minus_{}'.format(bandlist[x], bandlist[y])) #targetBand1 = '{}_minus_{}'.format(bandlist[x], bandlist[y]) targetBand1 = BandDescriptor() targetBand1.name = '{}_minus_{}'.format(bandlist[x], bandlist[y]) targetBand1.type = 'float32' targetBand1.expression = '(({} - {})<(-2))? 255 : 0'.format( bandlist[x], bandlist[y]) print("Writing Band {} : {}_minus_{}".format( x, bandlist[x], bandlist[y])) #targetBands.append(targetBand1) targetBands[x] = targetBand1 x = x + 1 y = y + 1 """targetBand1 = BandDescriptor() targetBand1.name = 'first_{}_minus_last_{}'.format(bandlist[0], bandlist[bandlength]) targetBand1.type = 'float32' targetBand1.expression = '(({} - {})<(-2))? 255 : 0'.format(bandlist[x], bandlist[y]) print("Writing Band first_{}_minus_last_{}".format(bandlist[0], bandlist[bandlength]) targetBands[bandlength] = targetBand1""" parameters = HashMap() parameters.put('targetBands', targetBands) result = GPF.createProduct('BandMaths', parameters, product) print("Writing...") ProductIO.writeProduct(result, 'BandMaths.dim', 'BEAM-DIMAP') print("BandMaths.dim Done.") ProductIO.writeProduct(result, 'BandMaths.tif', "GeoTIFF-BigTIFF") print("BandMaths.tif Done.")
def band_math(src, 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 GPF.createProduct("BandMaths", parameters, src)
def sigma_naught(product): targetBands = jpy.array( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 1) targetBand1 = BandDescriptor() targetBand1.name = 'sigma_int' targetBand1.type = 'Int32' targetBand1.expression = 'round(log10(Sigma0_VV)*1000)' targetBands[0] = targetBand1 parameters = HashMap() parameters.put('targetBands', targetBands) result = GPF.createProduct('BandMaths', parameters, product) return (result)
def convertDim2Tiff(input_dim, output_file, name_file, format_file='float32', type_file='GeoTIFF'): if debug >= 2: print(cyan + "convertDim2Tiff() : " + bold + green + "Import Dim to SNAP : " + endC + input_dim) # Info input file product = ProductIO.readProduct(input_dim) band = product.getBand(name_file) width = product.getSceneRasterWidth() height = product.getSceneRasterHeight() # 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', 1) # Get des expressions d'entréées targetBand = BandDescriptor() targetBand.name = 'band_0' targetBand.type = format_file targetBand.expression = name_file targetBands[0] = targetBand # Set des parametres parameters = HashMap() parameters.put('targetBands', targetBands) result = GPF.createProduct(operator, parameters, product) ProductIO.writeProduct(result, output_file, type_file) if debug >= 2: print(cyan + "convertDim2Tiff() : " + bold + green + "Writing Done : " + endC + str(output_file)) return
def compute_vegeation_index(product, index): index = ''.join(index) GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() HashMap = jpy.get_type('java.util.HashMap') BandDescriptor = jpy.get_type( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor') targetBand = BandDescriptor() targetBand.name = index targetBand.type = 'float32' targetBand.expression = indices_expr[index] targetBands = jpy.array( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 1) targetBands[0] = targetBand parameters = HashMap() parameters.put('targetBands', targetBands) print("Start to compute:" + indices_expr[index]) result = GPF.createProduct('BandMaths', parameters, product) print('Expression computed: ' + indices_expr[index]) print result.getBand(index) return result.getBand(index)
def apply_threshold_to_product(self): self.temporary_data_binary = [] snappy.GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() BandDescriptor = jpy.get_type('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor') targetBand = BandDescriptor() targetBand.name = 'band1' targetBand.type = 'float32' targetBand.expression = 'Sigma0_VV_db < -16.5 ' targetBands = jpy.array('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 1) targetBands[0] = targetBand for product in self.temporary_data_list: parameters = snappy.HashMap() parameters.put('name', 'Sigma0_VV_db_Threshold') parameters.put('targetBands', targetBands) binary = snappy.GPF.createProduct('BandMaths', parameters, product) self.temporary_data_binary.append(binary) self.temporary_data_list = self.temporary_data_binary return self.temporary_data_binary
def BandMath(stack): product = ProductIO.readProduct(stack) band_names = product.getBandNames() print(list(band_names)) band1 = input("Enter Band 1:") band2 = input("Enter Band 2 which will be subtracted:") GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() ## Band Math targetBands = jpy.array( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 2) #print('{}_minus_{}'.format(bandlist[x], bandlist[y])) targetBand1 = BandDescriptor() targetBand1.name = '{}_minus_{}'.format(band1, band2) targetBand1.type = 'float32' #targetBand1.expression = '(({} - {})<(-2))? 255 : 0'.format(band1, band2) targetBand1.expression = '(({} - {})<(-2))? 255 : 0'.format(band1, band2) parameters = HashMap() parameters.put('targetBands', targetBands) result = GPF.createProduct('BandMaths', parameters, product) print("Writing...") ProductIO.writeProduct(result, '{}_minus_{}.dim'.format(band1, band2), 'BEAM-DIMAP') print('{}_minus_{}.dim Done.'.format(band1, band2))
GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() HashMap = jpy.get_type('java.util.HashMap') BandDescriptor = jpy.get_type('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor') 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.")
GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() BandDescriptor = jpy.get_type( 'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor') 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
def mosaic(self, src_data, trg_file_path, band_dict, para_dict, trg_file_format='GeoTIFF'): ''' -------------------------------------------------------------------------------------------------------------------------------- Function: Creates a mosaic out of a set of source products. -------------------------------------------------------------------------------------------------------------------------------- Parameter: - src_data: An object ('Product') of the S2-dataset - trg_file_path: A string containing the path to the output S-2 dataset and it's name. - para_dict: - combine=<string> Specifies the way how conditions are combined. Value must be one of 'OR', 'AND'. DEFAULT value is 'OR'. - crs=<string> The CRS of the target product, represented as WKT or authority code. DEFAULT value is 'EPSG:4326'. - northBound=<double> The northern latitude. Valid interval is [-90,90]. DEFAULT value is '75.0'. - eastBound=<double> The eastern longitude. Valid interval is [-180,180]. DEFAULT value is '30.0'. - southBound=<double> The southern latitude. Valid interval is [-90,90]. DEFAULT value is '35.0'. - westBound=<double> The western longitude. Valid interval is [-180,180]. DEFAULT value is '-15.0'. - elevationModelName=<string> The name of the elevation model for the orthorectification. - orthorectify=<boolean> Whether the source product should be orthorectified. DEFAULT value is 'false'. - pixelSizeX=<double> Size of a pixel in X-direction in map units. DEFAULT value is '0.05'. - pixelSizeY=<double> Size of a pixel in Y-direction in map units. DEFAULT value is '0.05'. - resampling=<string> The method used for resampling. Value must be one of 'Nearest', 'Bilinear', 'Bicubic'. DEFAULT value is 'Nearest'. - trg_file_format: A string containing the Export Format Name. e.g. 'BEAM-DIMAP', 'GeoTIFF', 'NetCDF' DEFAULT value is 'BEAM-DIMAP' -------------------------------------------------------------------------------------------------------------------------------- How to run this code: from snappy import ProductIO from snappy_mosaic import mosaicOp src_path_1 = 'C:/S2/S2A_USER_MTD_SAFL2A_..._20151129T112140/S2A_USER_MTD_SAFL2A_..._20151129T112140.xml' src_path_2 = 'C:/S2/S2A_USER_MTD_SAFL2A_..._20151129T112141/S2A_USER_MTD_SAFL2A_..._20151129T112141.xml' trg_path = 'C:/S2/S2A_USER_MTD_SAFL2A_..._20151129T112140_mos/' bands = {'B2': 'B2'} para = {'northBound': 37.4, 'eastBound': 76.8, 'southBound': 36.3, 'westBound': 75.6, \ 'pixelSizeX': 0.001, 'pixelSizeY': 0.001} products = [] products.append(ProductIO.readProduct(src_path_1)) products.append(ProductIO.readProduct(src_path_2)) mosaicOp().mosaic(products, trg_path, bands, para) -------------------------------------------------------------------------------------------------------------------------------- ''' func_name = 'MOSAIC' func_code = 'Mosaic' parameters = self.HashMap() # Set variables. print('{}: Set variables'.format(func_name)) variables = jpy.array('org.esa.snap.core.gpf.common.MosaicOp$Variable', len(band_dict)) for (i, band_name) in enumerate(band_dict): variable_i = self.Variables() variable_i.setName(band_name) variable_i.setExpression(band_dict[band_name]) variables[i] = variable_i parameters.put('variables', variables) # Set parameters. print('{}: Set parameters'.format(func_name)) BB = 0 PS = 0 for para_name in para_dict: if para_name in ('pixelSizeX', 'pixelSizeY'): PS = PS + 1 if para_name in ('northBound', 'eastBound', 'southBound', 'westBound'): BB = BB + 1 parameters.put(para_name, para_dict[para_name]) # Set Bounding Box and Pixelsize if none was defined. if BB == 4 and PS == 2: print( '{}: INFO, Bounding Box Coordinates and Pixelsizes defined through User-Input' .format(func_name)) elif BB == 0: print( '{}: INFO, No Bounding Box Coordinates defined through User-Input' .format(func_name)) print('{}: Set Parameter Bounding Box'.format(func_name)) bboxE, bboxW, bboxS, bboxN, pxSzNS, pxSzEW = ([] for i in range(6)) for data in src_data: (b, y_EW, x_NS) = basicOp().BoundingBox(data) bboxE.append(b[0]) bboxW.append(b[1]) bboxS.append(b[2]) bboxN.append(b[3]) pxSzNS.append(x_NS) pxSzEW.append(y_EW) bbox = [min(bboxE), max(bboxW), min(bboxS), max(bboxN)] parameters.put('eastBound', bbox[1]) parameters.put('westBound', bbox[0]) parameters.put('southBound', bbox[2]) parameters.put('northBound', bbox[3]) if PS != 2: print('{}: Set Parameter Pixelsize'.format(func_name)) pxSzEW_avg_m, pxSzNS_avg_m = basicOp().deg2m( bbox, pxSzEW, pxSzNS) pxSzEW_avg_int_m = int(round(pxSzEW_avg_m / 5.0, 0) * 5.0) pxSzNS_avg_int_m = int(round(pxSzNS_avg_m / 5.0, 0) * 5.0) pxSzEW_avg_deg, pxSzNS_avg_deg = basicOp().m2deg( bbox, pxSzEW_avg_int_m, pxSzNS_avg_int_m) print('{}: pixelSizeY: {}m'.format(func_name, pxSzEW_avg_int_m)) print('{}: pixelSizeX: {}m'.format(func_name, pxSzNS_avg_int_m)) parameters.put('pixelSizeY', pxSzEW_avg_deg) parameters.put('pixelSizeX', pxSzNS_avg_deg) elif 1 <= BB < 4: BB_num = ('One' if BB == 1 else 'Two' if BB == 2 else 'Tree' if BB == 3 else BB.__str__()) BB_nam = ('Coordinate' if BB == 1 else 'Coordinates') print('{}: {} Bounding Box {} defined by Input'.format( func_name, BB_num, BB_nam)) else: print( '{}: ERROR, too many Bounding Box input coordinates ({} instead of 4) or missing Pixelsize.' .format(func_name, BB)) sys.exit(1) # Create product. print('{}: Create product...'.format(func_name)) trg_data = GPF.createProduct(func_code, parameters, src_data) # Save product # <supported-format>: BEAM-DIMAP, GeoTIFF, NetCDF, ... # # ------------------------------------------------------------------------------------------------------------------------------ # ATTENTION, in case of: # RuntimeError: java.lang.OutOfMemoryError: Java heap space # ------------------------------------------------------------------------------------------------------------------------------ # SOLUTION 1: # (http://forum.step.esa.int/t/snappy-error-productio-writeproduct/1102) # # 1. CHANGE <snappy>/jpyconfig.py: # jvm_maxmem = None ----> jvm_maxmem = '6G' # Increase RAM # # 2. CHANGE <snappy>/snappy.ini: # # java_max_mem: 4G ----> java_max_mem: 6G # Remove '#' and increase RAM # ------------------------------------------------------------------------------------------------------------------------------ # SOLUTION 2: # If you swapped Latitude/Longitude in POLYGON(...) there is also a out-of-memory-error # print('{}: Save as {} ...'.format(func_name, trg_file_path)) ProductIO.writeProduct(trg_data, trg_file_path, trg_file_format) print('{}: Done.'.format(func_name))
HashMap = jpy.get_type('java.util.HashMap') BandDescriptor = jpy.get_type( 'org.esa.snap.gpf.operators.standard.BandMathsOp$BandDescriptor') 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.gpf.operators.standard.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
width = Product.getSceneRasterWidth() os.chdir(TempFolder) os.system(snaphu_dir + ' -f snaphu.conf ' + phasen + ' ' + str(width)) print("Phase unwrapping performed successfully ..............................") #%% # Snaphu import bandList = os.listdir(TempFolder) for item in bandList: if item.endswith('.hdr') and item[0:8] == 'UnwPhase': upha = item print(upha) #working_dir='D:\\PhD Info\\InSAR\\Examples\\SNAPPY_Ecuador_Galapagos' #os.chdir (working_dir + '\\' + Fname) # Files = jpy.array('org.esa.snap.core.datamodel.Product', 2) #Files[0] = ProductIO.readProduct(os.path.join(r'D:\PhD Info\InSAR\Examples\SNAPPY_Ecuador_Galapagos','subset_0_of_InSAR_pipeline_II.dim')) Files[0] = read(os.path.join(Fpath, Fname + '.dim')) # reads .dim Files[1] = ProductIO.readProduct(glob.glob(TempFolder + '\\' + upha)[0]) HashMap = jpy.get_type("java.util.HashMap") params = HashMap() Product = GPF.createProduct("SnaphuImport", params, Files) os.chdir(Fpath) ProductIO.writeProduct(Product, Fname + "_ifg_ml_fit_unwph.dim", "BEAM-DIMAP") print("Snaphu import performed successfully .................................") # Phase To Displacement #Product = read(os.path.join(r'D:\PhD Info\InSAR\Examples\SNAPPY_Ecuador_Galapagos\exp_subset','subset_0_of_InSAR_pipeline_II_ifg_ml_fit_unwph.dim')) # reads .dim params = HashMap() Product = GPF.createProduct("PhaseToDisplacement", params, Product) os.chdir(Fpath) ProductIO.writeProduct(Product, Fname + '_ifg_ml_fit_unwph_disp.dim',
snappy.GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() HashMap = jpy.get_type('java.util.HashMap') Coord = jpy.get_type('org.esa.snap.pixex.Coordinate') snow_dataset=pd.read_csv("/home/simsek/workspace/EDUCATION/Thesis/Scripts/turku_SnowCover_insitu.csv", names=["year","month","day","lat","lon","sd"]) nosnow_dataset=pd.read_csv("/home/simsek/workspace/EDUCATION/Thesis/Scripts/turku_NoSnow_insitu.csv", names=["year","month","day","lat","lon","sd"]) snow_coords=np.asarray(nosnow_dataset[["lat","lon"]].drop_duplicates()) n=np.asarray(nosnow_dataset[["lat","lon"]].drop_duplicates()).shape[0] ## Parameters for resampling resampling_parameters = HashMap() resampling_parameters.put('targetResolution', 60) ## Parameters for Pixel extraction insitu_coordinates = jpy.array('org.esa.snap.pixex.Coordinate',n) for i in range(n): insitu_coordinates[i] = Coord('station'+str(i), snow_coords[i,0], snow_coords[i,1], None) #insitu_coordinates[0] = Coord('station0', 61.00, 24.5, None) # insitu_coordinates[1] = Coord('station1', 60.82, 23.5, None) # insitu_coordinates[2] = Coord('station2', 60.45, 23.65, None) # insitu_coordinates[3] = Coord('station3', 60.65, 23.81, None) # insitu_coordinates[4] = Coord('station4', 60.52, 24.65, None) # insitu_coordinates[5] = Coord('station5', 61.12, 24.33, None) # insitu_coordinates[6] = Coord('station6', 60.37, 23.12, None) print(insitu_coordinates[8]) pixex_parameters = HashMap() pixex_parameters.put('PexportBands', 1) pixex_parameters.put('PexportExpressionResult', 0) pixex_parameters.put('PexportMasks', 0)
GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() HashMap = jpy.get_type('java.util.HashMap') BandDescriptor = jpy.get_type('org.esa.snap.gpf.operators.standard.BandMathsOp$BandDescriptor') 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.gpf.operators.standard.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.")