def _coherence(infile, outfile, logfile): '''A wrapper around SNAP's coherence routine This function takes a co-registered stack of 2 Sentinel-1 SLC products and calculates the coherence. Args: infile: string or os.path object for an OST imported frame in BEAM-Dimap format (i.e. *.dim) outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to ''' # get gpt file gpt_file = h.gpt_path() graph = opj(OST_ROOT, 'graphs', 'S1_SLC2ARD', 'S1_SLC_Coh_Deb.xml') logger.debug('INFO: Coherence estimation') command = '{} {} -x -q {} -Pinput={} -Poutput={}' \ .format(gpt_file, graph, 2, infile, outfile) return_code = h.run_command(command, logfile) if return_code == 0: logger.debug('INFO: Succesfully created coherence product.') else: logger.debug('ERROR: Coherence exited with an error. \ See {} for Snap Error output'.format(logfile)) # sys.exit(121) return return_code
def mt_speckle_filter(in_stack, out_stack, logfile): ''' ''' # get gpt file gpt_file = h.gpt_path() # get path to graph rootpath = imp.find_module('ost')[1] graph = opj(rootpath, 'graphs', 'S1_TS', '2_MT_Speckle.xml') logger.debug("INFO: Applying the multi-temporal speckle-filtering") command = '{} {} -x -q {} -Pinput={} \ -Poutput={}'.format(gpt_file, graph, 2 * os.cpu_count(), in_stack, out_stack) return_code = h.run_command(command, logfile) if return_code == 0: logger.debug( 'INFO: Succesfully applied multi-temporal speckle filtering') else: logger.debug( 'ERROR: Multi-temporal speckle filtering exited with an error. \ See {} for Snap Error output'.format(logfile)) sys.exit(202) return return_code
def _grd_to_db(infile, outfile, logfile): '''A wrapper around SNAP's linear to db routine This function takes an OST calibrated Sentinel-1 product and converts it to dB. Args: infile: string or os.path object for an OST imported frame in BEAM-Dimap format (i.e. *.dim) outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to ''' # get path to SNAP's command line executable gpt gpt_file = h.gpt_path() logger.debug('INFO: Converting the image to dB-scale.') # construct command string command = '{} LinearToFromdB -x -q {} -t \'{}\' {}'.format( gpt_file, 2 * os.cpu_count(), outfile, infile) # run command and get return code return_code = h.run_command(command, logfile) # handle errors and logs if return_code == 0: logger.debug('INFO: Succesfully converted product to dB-scale.') else: logger.debug('ERROR: Linear to dB conversion exited with an error. \ See {} for Snap Error output'.format(logfile)) sys.exit(113) return return_code
def _grd_frame_import_subset(infile, outfile, georegion, logfile, polarisation='VV,VH,HH,HV'): '''A wrapper of SNAP import of a subset of single Sentinel-1 GRD product This function takes an original Sentinel-1 scene (either zip or SAFE format), updates the orbit information (does not fail if not available), removes the thermal noise, subsets it to the given georegion and stores it as a SNAP compatible BEAM-Dimap format. Args: infile: string or os.path object for an original Sentinel-1 GRD product in zip or SAFE format outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to polarisation (str): a string consisiting of the polarisation (comma separated) e.g. 'VV,VH', default value: 'VV,VH,HH,HV' georegion (str): a WKT style formatted POLYGON that bounds the subset region ''' logger.debug('INFO: Importing {} by applying precise orbit file and ' 'removing thermal noise, as well as subsetting.'.format( os.path.basename(infile))) # get path to SNAP's command line executable gpt gpt_file = h.gpt_path() # get path to ost package graph = opj(OST_ROOT, 'graphs', 'S1_GRD2ARD', '1_AO_TNR_SUB.xml') # construct command command = '{} {} -x -q {} -Pinput="{}" -Pregion="{}" -Ppolarisation={} \ -Poutput="{}"'.format(gpt_file, graph, 2 * os.cpu_count(), infile, georegion, polarisation, outfile) # run command and get return code return_code = h.run_command(command, logfile) # handle errors and logs if return_code == 0: logger.debug('INFO: Succesfully imported product') else: raise RuntimeError('ERROR: Frame import exited with an error. \ See {} for Snap Error output'.format(logfile)) return return_code
def _terrain_correction(infile, outfile, logfile, resolution, dem='SRTM 1sec HGT'): '''A wrapper around SNAP's Terrain Correction routine This function takes an OST calibrated Sentinel-1 product and does the geocodification. Args: infile: string or os.path object for an OST imported frame in BEAM-Dimap format (i.e. *.dim) outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to resolution (int): the resolution of the output product in meters dem (str): A Snap compliant string for the dem to use. Possible choices are: 'SRTM 1sec HGT'(default) 'SRTM 3sec' 'ASTER 1sec GDEM' 'ACE30' ''' # get gpt file gpt_file = h.gpt_path() logger.debug("INFO: Geocoding input scene") command = '{} Terrain-Correction -x -q {} \ -PdemResamplingMethod=\'BILINEAR_INTERPOLATION\'\ -PimgResamplingMethod=\'BILINEAR_INTERPOLATION\'\ -PnodataValueAtSea=\'false\'\ -PpixelSpacingInMeter=\'{}\'\ -PdemName=\'{}\'\ -t {} {}'\ .format(gpt_file, 2, resolution, dem, outfile, infile) return_code = h.run_command(command, logfile) if return_code == 0: logger.debug('INFO: Succesfully orthorectified product.') else: logger.debug('ERROR: Geocoding exited with an error. \ See {} for Snap Error output'.format(logfile)) # sys.exit(122) return return_code
def _coreg2(master, slave, outfile, logfile, dem='SRTM 1sec HGT', master_burst_poly=''): '''A wrapper around SNAP's back-geocoding co-registration routine This function takes a list of 2 OST imported Sentinel-1 SLC products and co-registers them properly. This routine is sufficient for coherence estimation, but not for InSAR, since the ESD refinement is not applied. Args: infile: string or os.path object for an OST imported frame in BEAM-Dimap format (i.e. *.dim) outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to dem (str): A Snap compliant string for the dem to use. Possible choices are: 'SRTM 1sec HGT'(default) 'SRTM 3sec' 'ASTER 1sec GDEM' 'ACE30' ''' # get gpt file gpt_file = h.gpt_path() graph = opj(OST_ROOT, 'graphs', 'S1_SLC2ARD', 'S1_SLC_Coreg.xml') logger.debug('INFO: Co-registering {} and {}'.format(master, slave)) command = '{} {} -x -q {} -Pmaster={} -Pslave={} -Poutput={} ' \ '-Pdem=\'{}\' -Pregion="{}"' \ .format(gpt_file, graph, 2, master, slave, outfile, dem, master_burst_poly ) return_code = h.run_command(command, logfile) if return_code == 0: logger.debug('INFO: Succesfully coregistered product.') else: logger.debug('ERROR: Co-registration exited with an error. \ See {} for Snap Error output'.format(logfile)) # sys.exit(112) return return_code
def _import(infile, out_prefix, logfile, swath, burst, polar='VV,VH,HH,HV'): '''A wrapper of SNAP import of a single Sentinel-1 SLC burst This function takes an original Sentinel-1 scene (either zip or SAFE format), updates the orbit information (does not fail if not available), and extracts a single burst based on the given input parameters. Args: infile: string or os.path object for an original Sentinel-1 GRD product in zip or SAFE format out_prefix: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to swath (str): the corresponding IW subswath of the burst burst (str): the burst number as in the Sentinel-1 annotation file polar (str): a string consisiting of the polarisation (comma separated) e.g. 'VV,VH', default value: 'VV,VH,HH,HV' ''' # get gpt file gpt_file = h.gpt_path() graph = opj(OST_ROOT, 'graphs', 'S1_SLC2ARD', 'S1_SLC_BurstSplit_AO.xml') logger.debug('INFO: Importing Burst {} from Swath {} ' 'from scene {}'.format(burst, swath, os.path.basename(infile))) command = '{} {} -x -q {} -Pinput={} -Ppolar={} -Pswath={}\ -Pburst={} -Poutput={}'\ .format(gpt_file, graph, 2, infile, polar, swath, burst, out_prefix) return_code = h.run_command(command, logfile) if return_code == 0: logger.debug('INFO: Succesfully imported product') else: logger.debug('ERROR: Frame import exited with an error. \ See {} for Snap Error output'.format(logfile)) # sys.exit(119) return return_code
def _ls_mask(infile, outfile, logfile, resolution, dem='SRTM 1sec HGT'): '''A wrapper around SNAP's Layover/Shadow mask routine This function takes OST imported Sentinel-1 product and calculates the Layover/Shadow mask. Args: infile: string or os.path object for an OST imported frame in BEAM-Dimap format (i.e. *.dim) outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to resolution (int): the resolution of the output product in meters dem (str): A Snap compliant string for the dem to use. Possible choices are: 'SRTM 1sec HGT'(default) 'SRTM 3sec' 'ASTER 1sec GDEM' 'ACE30' ''' # get gpt file gpt_file = h.gpt_path() graph = opj(OST_ROOT, 'graphs', 'S1_SLC2ARD', 'S1_SLC_LS_TC.xml') logger.debug("INFO: Compute Layover/Shadow mask") command = '{} {} -x -q {} -Pinput={} -Presol={} -Poutput={} -Pdem=\'{}\''\ .format(gpt_file, graph, 2, infile, resolution, outfile, dem) return_code = h.run_command(command, logfile) if return_code == 0: logger.debug('INFO: Succesfully created Layover/Shadow mask') else: logger.debug( 'ERROR: Layover/Shadow mask creation exited with an error. \ See {} for Snap Error output'.format(logfile)) # sys.exit(121) return return_code
def create_grd_stack(filelist, out_stack, logfile, polarisation='VV,VH', pattern=None): ''' :param filelist: list of single Files (space separated) :param outfile: the stack that is generated :return: ''' # get gpt file gpt_file = h.gpt_path() # get path to graph rootpath = imp.find_module('ost')[1] logger.debug("INFO: Creating multi-temporal stack of images") if isinstance(filelist, list): filelist = ','.join(filelist) if pattern: graph = opj(rootpath, 'graphs', 'S1_TS', '1_BS_Stacking_HAalpha.xml') command = '{} {} -x -q {} -Pfilelist={} -PbandPattern=\'{}.*\'\ -Poutput={}'.format(gpt_file, graph, 2 * os.cpu_count(), filelist, pattern, out_stack) else: graph = opj(rootpath, 'graphs', 'S1_TS', '1_BS_Stacking.xml') command = '{} {} -x -q {} -Pfilelist={} -Ppol={} \ -Poutput={}'.format(gpt_file, graph, 2 * os.cpu_count(), filelist, polarisation, out_stack) return_code = h.run_command(command, logfile) if return_code == 0: logger.debug('INFO: Succesfully created multi-temporal stack') else: logger.debug('ERROR: Stack creation exited with an error.' 'See {} for Snap Error output'.format(logfile)) sys.exit(201) return return_code
def _ha_alpha(infile, outfile, logfile, pol_speckle_filter=False): '''A wrapper of SNAP H-A-alpha polarimetric decomposition This function takes an OST imported Sentinel-1 scene/burst and calulates the polarimetric decomposition parameters for the H-A-alpha decomposition. Args: infile: string or os.path object for an original Sentinel-1 GRD product in zip or SAFE format out_prefix: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to pol_speckle_filter (bool): wether or not to apply the polarimetric speckle filter ''' # get gpt file gpt_file = h.gpt_path() if pol_speckle_filter: graph = opj(OST_ROOT, 'graphs', 'S1_SLC2ARD', 'S1_SLC_Deb_Spk_Halpha.xml') else: graph = opj(OST_ROOT, 'graphs', 'S1_SLC2ARD', 'S1_SLC_Deb_Halpha.xml') logger.debug("INFO: Calculating the H-alpha dual polarisation") command = '{} {} -x -q {} -Pinput={} -Poutput={}'\ .format(gpt_file, graph, 2, infile, outfile) return_code = h.run_command(command, logfile) if return_code == 0: logger.debug('INFO: Succesfully created H/Alpha product') else: logger.debug('ERROR: H/Alpha exited with an error. \ See {} for Snap Error output'.format(logfile)) # sys.exit(121) return return_code
def mt_speckle_filter(in_stack, out_stack, logfile, speckle_dict=None): ''' ''' # get gpt file gpt_file = h.gpt_path() if speckle_dict is None: speckle_dict = DEFAULT_MT_SPECKLE_DICT logger.debug(' INFO: Applying multi-temporal speckle filtering.') # contrcut command string command = ('{} Multi-Temporal-Speckle-Filter -x -q {}' ' -PestimateENL={}' ' -PanSize={}' ' -PdampingFactor={}' ' -Penl={}' ' -Pfilter="{}"' ' -PfilterSizeX={}' ' -PfilterSizeY={}' ' -PnumLooksStr={}' ' -PsigmaStr={}' ' -PtargetWindowSizeStr={}' ' -PwindowSize={}' ' -t "{}" "{}"'.format( gpt_file, 2 * os.cpu_count(), speckle_dict['estimate_ENL'], speckle_dict['pan_size'], speckle_dict['damping'], speckle_dict['ENL'], speckle_dict['filter'], speckle_dict['filter_x_size'], speckle_dict['filter_y_size'], speckle_dict['num_of_looks'], speckle_dict['sigma'], speckle_dict['target_window_size'], speckle_dict['window_size'], out_stack, in_stack)) return_code = h.run_command(command, logfile) if return_code == 0: logger.debug( ' INFO: Succesfully applied multi-temporal speckle filtering') else: raise RuntimeError( 'Multi-temporal speckle filtering exited with an error. \ See {} for Snap Error output'.format(logfile)) return return_code
def _grd_speckle_filter(infile, outfile, logfile): '''A wrapper around SNAP's Refined Lee Speckle Filter This function takes OST imported Sentinel-1 product and applies a standardised version of the Lee-Sigma Speckle Filter with SNAP's defaut values. Args: infile: string or os.path object for an OST imported frame in BEAM-Dimap format (i.e. *.dim) outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to ''' # get path to SNAP's command line executable gpt gpt_file = h.gpt_path() logger.debug('INFO: Applying the Refined-Lee Speckle Filter') # contrcut command string command = '{} Speckle-Filter -x -q {} -PestimateENL=true ' \ '-Pfilter=\'Refined Lee\' -t \'{}\' ' \ '\'{}\''.format(gpt_file, 2 * os.cpu_count(), outfile, infile ) # run command and get return code return_code = h.run_command(command, logfile) # hadle errors and logs if return_code == 0: logger.debug('INFO: Succesfully imported product') else: logger.debug('ERROR: Speckle Filtering exited with an error. \ See {} for Snap Error output'.format(logfile)) sys.exit(111) return return_code
def _grd_subset(infile, outfile, logfile, region): '''A wrapper around SNAP's subset routine This function takes an OST imported frame and subsets it according to the coordinates given in the region Args: infile: string or os.path object for an OST imported frame in BEAM-Dimap format (i.e. *.dim) outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to region (str): a list of image coordinates that bound the subset region ''' # get Snap's gpt file gpt_file = h.gpt_path() # format region string region = ','.join([str(int(x)) for x in region]) # construct command command = '{} Subset -x -q {} -Pregion={} -t \'{}\' \'{}\''.format( gpt_file, 2 * os.cpu_count(), region, outfile, infile) # run command and get return code return_code = h.run_command(command, logfile) # handle errors and logs if return_code == 0: logger.debug('INFO: Succesfully subsetted product') else: logger.debug('ERROR: Subsetting exited with an error. \ See {} for Snap Error output'.format(logfile)) sys.exit(107) return return_code
def _grd_subset_georegion(infile, outfile, logfile, georegion): '''A wrapper around SNAP's subset routine This function takes an OST imported frame and subsets it according to the coordinates given in the region Args: infile: string or os.path object for an OST imported frame in BEAM-Dimap format (i.e. *.dim) outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to georegion (str): a WKT style formatted POLYGON that bounds the subset region ''' logger.debug('INFO: Subsetting imported imagery.') # get Snap's gpt file gpt_file = h.gpt_path() # extract window from scene command = '{} Subset -x -q {} -Ssource=\'{}\' -t "{}" \ -PcopyMetadata=true -PgeoRegion="{}"'.format( gpt_file, 2 * os.cpu_count(), infile, outfile, georegion) # run command and get return code return_code = h.run_command(command, logfile) # handle errors and logs if return_code == 0: logger.debug('INFO: Succesfully subsetted product.') else: logger.debug('ERROR: Subsetting exited with an error. \ See {} for Snap Error output'.format(logfile)) sys.exit(107) return return_code
def _slice_assembly(filelist, outfile, logfile, polarisation='VV,VH,HH,HV'): '''A wrapper of SNAP's slice assembly routine This function assembles consecutive frames acquired at the same date. Can be either GRD or SLC products Args: filelist (str): a string of a space separated list of OST imported Sentinel-1 product slices to be assembled outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to ''' logger.debug('INFO: Assembling consecutive frames:') # get path to SNAP's command line executable gpt gpt_file = h.gpt_path() # construct command command = '{} SliceAssembly -x -q {} -PselectedPolarisations={} \ -t \'{}\' {}'.format(gpt_file, 2 * os.cpu_count(), polarisation, outfile, filelist) # run command and get return code return_code = h.run_command(command, logfile) # handle errors and logs if return_code == 0: logger.debug('INFO: Succesfully assembled products') else: logger.debug('ERROR: Slice Assembly exited with an error. \ See {} for Snap Error output'.format(logfile)) sys.exit(101) return return_code
def create_stack(filelist, out_stack, logfile, polarisation=None, pattern=None): ''' :param filelist: list of single Files (space separated) :param outfile: the stack that is generated :return: ''' # get gpt file gpt_file = h.gpt_path() # get path to graph rootpath = importlib.util.find_spec('ost').submodule_search_locations[0] if pattern: graph = opj(rootpath, 'graphs', 'S1_TS', '1_BS_Stacking_HAalpha.xml') command = '{} {} -x -q {} -Pfilelist={} -PbandPattern=\'{}.*\' \ -Poutput={}'.format(gpt_file, graph, 2 * os.cpu_count(), filelist, pattern, out_stack) else: graph = opj(rootpath, 'graphs', 'S1_TS', '1_BS_Stacking.xml') command = '{} {} -x -q {} -Pfilelist={} -Ppol={} \ -Poutput={}'.format(gpt_file, graph, 2 * os.cpu_count(), filelist, polarisation, out_stack) return_code = h.run_command(command, logfile) if return_code == 0: logger.debug(' INFO: Succesfully created multi-temporal stack') else: logger.debug('ERROR: Stack creation exited with an error.' ' See {} for Snap Error output'.format(logfile)) return return_code
def _grd_ls_mask(infile, outfile, logfile, resolution, dem='SRTM 1Sec HGT', dem_file='', resampling='BILINEAR_INTERPOLATION'): '''A wrapper around SNAP's Layover/Shadow mask routine This function takes OST imported Sentinel-1 product and calculates the Layover/Shadow mask. Args: infile: string or os.path object for an OST imported frame in BEAM-Dimap format (i.e. *.dim) outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to resolution (int): the resolution of the output product in meters dem (str): A Snap compliant string for the dem to use. Possible choices are: 'SRTM 1sec HGT'(default) 'SRTM 3sec' 'ASTER 1sec GDEM' 'ACE30' ''' # get path to SNAP's command line executable gpt gpt_file = h.gpt_path() logger.debug('INFO: Creating the Layover/Shadow mask') # get path to workflow xml graph = opj(OST_ROOT, 'graphs', 'S1_GRD2ARD', '3_LSmap.xml') if dem_file != '': with rasterio.open(dem_file, 'r') as dem_f: dem_nodata = dem_f.nodata else: dem_nodata = 0.0 # construct command string command = '{} {} -x -q {} -Pinput=\'{}\' -Presol={} -Pdem=\'{}\' \ -Pdem_file=\'{}\' -Pdem_nodata={} -Presampling={} \ -Poutput=\'{}\''.format(gpt_file, graph, 2 * os.cpu_count(), infile, resolution, dem, dem_file, dem_nodata, resampling, outfile) # run command and get return code return_code = h.run_command(command, logfile) # handle errors and logs if return_code == 0: logger.debug('INFO: Succesfully create a Layover/Shadow mask') else: logger.debug( 'ERROR: Layover/Shadow mask creation exited with an error. \ See {} for Snap Error output'.format(logfile)) raise RuntimeError return return_code
def _grd_backscatter(infile, outfile, logfile, product_type='GTCgamma', dem='SRTM 1Sec HGT', dem_file='', resampling='BILINEAR_INTERPOLATION'): '''A wrapper around SNAP's radiometric calibration This function takes OST imported Sentinel-1 product and generates it to calibrated backscatter. 3 different calibration modes are supported. - Radiometrically terrain corrected Gamma nought (RTC) - ellipsoid based Gamma nought (GTCgamma) - Sigma nought (GTCsigma). Args: infile: string or os.path object for an OST imported frame in BEAM-Dimap format (i.e. *.dim) outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to resolution (int): the resolution of the output product in meters product_type (str): the product type of the output product i.e. RTC, GTCgamma or GTCsigma dem (str): A Snap compliant string for the dem to use. Possible choices are: 'SRTM 1sec HGT'(default) 'SRTM 3sec' 'ASTER 1sec GDEM' 'ACE30' ''' # get path to SNAP's command line executable gpt gpt_file = h.gpt_path() # select xml according to product type if product_type == 'RTC': logger.debug('INFO: Calibrating the product to a RTC product.') graph = opj(OST_ROOT, 'graphs', 'S1_GRD2ARD', '2_CalBeta_TF.xml') if dem_file != '': with rasterio.open(dem_file, 'r') as dem_f: dem_nodata = dem_f.nodata else: dem_nodata = 0.0 elif product_type == 'GTCgamma': logger.debug( 'INFO: Calibrating the product to a GTC product (Gamma0).') graph = opj(OST_ROOT, 'graphs', 'S1_GRD2ARD', '2_CalGamma.xml') elif product_type == 'GTCsigma': logger.debug( 'INFO: Calibrating the product to a GTC product (Sigma0).') graph = opj(OST_ROOT, 'graphs', 'S1_GRD2ARD', '2_CalSigma.xml') else: logger.debug('ERROR: Wrong product type selected.') sys.exit(103) # construct command sring if product_type == 'RTC': command = '{} {} -x -q {} -Pinput="{}" -Pdem=\'{}\' \ -Pdem_file=\'{}\' -Pdem_nodata={} -Presampling={} \ -Poutput=\'{}\''.format(gpt_file, graph, 2 * os.cpu_count(), infile, dem, dem_file, dem_nodata, resampling, outfile) else: command = '{} {} -x -q {} -Pinput=\'{}\' -Poutput=\'{}\''.format( gpt_file, graph, 2 * os.cpu_count(), infile, outfile) # run command and get return code return_code = h.run_command(command, logfile) # handle errors and logs if return_code == 0: logger.debug('INFO: Succesfully calibrated product') else: logger.debug('ERROR: Backscatter calibration exited with an error. \ See {} for Snap Error output'.format(logfile)) sys.exit(103) return return_code
def _grd_terrain_correction_deg(infile, outfile, logfile, resolution, dem='SRTM 1Sec HGT', dem_file='', resampling='BILINEAR_INTERPOLATION'): '''A wrapper around SNAP's Terrain Correction routine This function takes an OST calibrated Sentinel-1 product and does the geocodification. Args: infile: string or os.path object for an OST imported frame in BEAM-Dimap format (i.e. *.dim) outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to resolution (int): the resolution of the output product in meters dem (str): A Snap compliant string for the dem to use. Possible choices are: 'SRTM 1sec HGT'(default) 'SRTM 3sec' 'ASTER 1sec GDEM' 'ACE30' ''' # get path to SNAP's command line executable gpt gpt_file = h.gpt_path() logger.debug('INFO: Geocoding the calibrated product') # calculate the multi-look factor # multilook_factor = int(int(resolution) / 10) multilook_factor = 1 graph = opj(OST_ROOT, 'graphs', 'S1_GRD2ARD', '3_ML_TC_deg.xml') if dem_file != '': with rasterio.open(dem_file, 'r') as dem_f: dem_nodata = dem_f.nodata else: dem_nodata = 0.0 # construct command string command = '{} {} -x -q {} -Pinput=\'{}\' -Presol={} -Pml={} -Pdem=\'{}\' \ -Pdem_file=\'{}\' -Pdem_nodata={} -Presampling={} \ -Poutput=\'{}\''.format(gpt_file, graph, 2 * os.cpu_count(), infile, resolution, multilook_factor, dem, dem_file, dem_nodata, resampling, outfile) # run command and get return code return_code = h.run_command(command, logfile) # handle errors and logs if return_code == 0: logger.debug('INFO: Succesfully imported product') else: logger.debug('ERROR: Terain Correction exited with an error. \ See {} for Snap Error output'.format(logfile)) sys.exit(112) return return_code
def test_gpt(): assert gpt_path()
def _calibration(infile, outfile, logfile, product_type='GTCgamma', dem='SRTM 1sec HGT', resampling=SNAP_S1_RESAMPLING_METHODS[2], dem_file='', dem_nodata=0.0, region=''): '''A wrapper around SNAP's radiometric calibration This function takes OST imported Sentinel-1 product and generates it to calibrated backscatter. 3 different calibration modes are supported. - Radiometrically terrain corrected Gamma nought (RTC) NOTE: that the routine actually calibrates to bet0 and needs to be used together with _terrain_flattening routine - ellipsoid based Gamma nought (GTCgamma) - Sigma nought (GTCsigma). Args: infile: string or os.path object for an OST imported frame in BEAM-Dimap format (i.e. *.dim) outfile: string or os.path object for the output file written in BEAM-Dimap format logfile: string or os.path object for the file where SNAP'S STDOUT/STDERR is written to resolution (int): the resolution of the output product in meters product_type (str): the product type of the output product i.e. RTC, GTCgamma or GTCsigma ''' # get gpt file gpt_file = h.gpt_path() if product_type == 'RTC': logger.debug('INFO: Calibrating the product to a RTC product.') graph = opj(OST_ROOT, 'graphs', 'S1_SLC2ARD', 'S1_SLC_TNR_Calbeta_Deb_ML_TF_SUB.xml') command = '{} {} -x -q {} -Pdem=\'{}\' -Pdem_file="{}" ' \ '-Pdem_nodata={} -Presampling={} -Pregion="{}" -Pinput={} ' \ '-Poutput={}' \ .format(gpt_file, graph, 2, dem, dem_file, dem_nodata, resampling, region, infile, outfile) elif product_type == 'GTCgamma': logger.debug( 'INFO: Calibrating the product to a GTC product (Gamma0).') graph = opj(OST_ROOT, 'graphs', 'S1_SLC2ARD', 'S1_SLC_TNR_CalGamma_Deb_SUB.xml') command = '{} {} -x -q {} -Pregion="{}" -Pinput={} -Poutput={}' \ .format(gpt_file, graph, 2, region, infile, outfile) elif product_type == 'GTCsigma': logger.debug( 'INFO: Calibrating the product to a GTC product (Sigma0).') graph = opj(OST_ROOT, 'graphs', 'S1_SLC2ARD', 'S1_SLC_TNR_CalSigma_Deb_SUB.xml') command = '{} {} -x -q {} -Pregion="{}" -Pinput={} -Poutput={}' \ .format(gpt_file, graph, 2, region, infile, outfile) else: logger.debug('ERROR: Wrong product type selected.') sys.exit(121) logger.debug("INFO: Removing thermal noise, calibrating and debursting") return_code = h.run_command(command, logfile) if return_code == 0: logger.debug('INFO: Succesfully calibrated product') else: logger.debug('ERROR: Frame import exited with an error. \ See {} for Snap Error output'.format(logfile)) # sys.exit(121) return return_code