diff --git a/contrib/stack/topsStack/Stack.py b/contrib/stack/topsStack/Stack.py index fbbd604..1f421fa 100644 --- a/contrib/stack/topsStack/Stack.py +++ b/contrib/stack/topsStack/Stack.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 + #!/usr/bin/env python3 ######################## #Author: Heresh Fattahi @@ -13,6 +13,7 @@ defoMax = '2' maxNodes = 72 + class config(object): """ A class representing the config file @@ -242,6 +243,7 @@ class config(object): self.f.write('defomax : ' + self.defoMax + '\n') self.f.write('rlks : ' + self.rangeLooks + '\n') self.f.write('alks : ' + self.azimuthLooks + '\n') + self.f.write('numProcess : ' + self.numProcess + '\n') def denseOffset(self, function): self.f.write('###################################'+'\n') @@ -258,6 +260,18 @@ class config(object): #self.f.write('ww : 256\n') #self.f.write('wh : 128\n') + def write_wrapper_config2run_file(self, configName, line_cnt, numProcess = 1): + # dispassionate list of commands for single process + if numProcess == 1: + self.runf.write(self.text_cmd + 'SentinelWrapper.py -c ' + configName + '\n') + # aggregate background commands between wait blocks for speed gains + elif numProcess > 1: + self.runf.write(self.text_cmd + 'SentinelWrapper.py -c ' + configName + ' &\n') + if line_cnt == numProcess: + self.runf.write('wait\n\n') + line_cnt = 0 + return line_cnt + def finalize(self): self.f.close() @@ -286,6 +300,7 @@ class run(object): swath_path = self.work_dir os.makedirs(self.config_path, exist_ok=True) + line_cnt = 0 for slcdate in acquisitionDates: configName = os.path.join(self.config_path,'config_unpack_'+slcdate) configObj = config(configName) @@ -300,8 +315,10 @@ class run(object): configObj.Sentinel1_TOPS('[Function-1]') configObj.topo('[Function-2]') configObj.finalize() + + line_cnt += 1 + line_cnt = configObj.write_wrapper_config2run_file(configName, line_cnt) del configObj - self.runf.write(self.text_cmd + 'SentinelWrapper.py -c ' + configName + '\n') def unpackStackReferenceSLC(self, safe_dict): swath_path = self.work_dir @@ -320,11 +337,14 @@ class run(object): configObj.Sentinel1_TOPS('[Function-1]') configObj.topo('[Function-2]') configObj.finalize() + + line_cnt = 1 + line_cnt = configObj.write_wrapper_config2run_file(configName, line_cnt) del configObj - self.runf.write(self.text_cmd + 'SentinelWrapper.py -c ' + configName + '\n') def unpackSecondarysSLC(self, stackReferenceDate, secondaryList, safe_dict): + line_cnt = 0 for secondary in secondaryList: configName = os.path.join(self.config_path,'config_secondary_'+secondary) outdir = os.path.join(self.work_dir,'secondarys/'+secondary) @@ -337,11 +357,14 @@ class run(object): configObj.outDir = outdir configObj.Sentinel1_TOPS('[Function-1]') configObj.finalize() + + line_cnt += 1 + line_cnt = configObj.write_wrapper_config2run_file(configName, line_cnt, self.numProcess) del configObj - self.runf.write(self.text_cmd + 'SentinelWrapper.py -c ' + configName+'\n') def averageBaseline(self, stackReferenceDate, secondaryList): + line_cnt = 0 for secondary in secondaryList: configName = os.path.join(self.config_path,'config_baseline_'+secondary) configObj = config(configName) @@ -351,10 +374,14 @@ class run(object): configObj.baselineFile = os.path.join(self.work_dir,'baselines/' + stackReferenceDate +'_' + secondary + '/' + stackReferenceDate +'_'+ secondary + '.txt') configObj.computeAverageBaseline('[Function-1]') configObj.finalize() + + line_cnt += 1 + line_cnt = configObj.write_wrapper_config2run_file(configName, line_cnt, self.numProcess) del configObj - self.runf.write(self.text_cmd + 'SentinelWrapper.py -c ' + configName+'\n') def gridBaseline(self, stackReferenceDate, secondaryList): + + line_cnt = 0 for secondary in secondaryList: configName = os.path.join(self.config_path,'config_baselinegrid_'+secondary) configObj = config(configName) @@ -364,8 +391,10 @@ class run(object): configObj.baselineFile = os.path.join(self.work_dir, 'merged/baselines/' + secondary + '/' + secondary ) configObj.computeGridBaseline('[Function-1]') configObj.finalize() + + line_cnt += 1 + line_cnt = configObj.write_wrapper_config2run_file(configName, line_cnt) del configObj - self.runf.write(self.text_cmd + 'SentinelWrapper.py -c ' + configName+'\n') # also add the reference in itself to be consistent with the SLC dir configName = os.path.join(self.config_path,'config_baselinegrid_reference') configObj = config(configName) @@ -375,8 +404,10 @@ class run(object): configObj.baselineFile = os.path.join(self.work_dir, 'merged/baselines/' + stackReferenceDate + '/' + stackReferenceDate) configObj.computeGridBaseline('[Function-1]') configObj.finalize() + + line_cnt = 1 + line_cnt = configObj.write_wrapper_config2run_file(configName, line_cnt) del configObj - self.runf.write(self.text_cmd + 'SentinelWrapper.py -c ' + configName+'\n') def extractOverlaps(self): @@ -386,6 +417,7 @@ class run(object): def geo2rdr_offset(self, secondaryList, fullBurst='False'): + line_cnt = 0 for secondary in secondaryList: reference = self.reference_date if fullBurst == 'True': @@ -407,10 +439,14 @@ class run(object): configObj.overlapTrueOrFalse = 'True' configObj.geo2rdr('[Function-1]') configObj.finalize() + + line_cnt += 1 + line_cnt = configObj.write_wrapper_config2run_file(configName, line_cnt, self.numProcess) del configObj - self.runf.write(self.text_cmd + 'SentinelWrapper.py -c ' + configName + '\n') def resample_with_carrier(self, secondaryList, fullBurst='False'): + + line_cnt = 0 for secondary in secondaryList: reference = self.reference_date if fullBurst == 'True': @@ -433,13 +469,17 @@ class run(object): configObj.overlapTrueOrFalse = 'True' configObj.resamp_withCarrier('[Function-1]') configObj.finalize() + + line_cnt += 1 + line_cnt = configObj.write_wrapper_config2run_file(configName, line_cnt, self.numProcess) del configObj - self.runf.write(self.text_cmd + 'SentinelWrapper.py -c ' + configName + '\n') + def pairs_misregistration(self, dateList, safe_dict): # generating overlap interferograms, estimate azimuth misregistration for each pair: pairs = [] num_overlap_connections = int(self.num_overlap_connections) + 1 + for i in range(len(dateList)-1): for j in range(i+1,i+num_overlap_connections): if j