1
- #!/usr/bin/env python3
1
+ #!/usr/bin/env python3
2
2
########################
3
3
#Author: Heresh Fattahi
4
4
13
13
maxNodes = 72
14
14
15
15
16
+
16
17
class config (object ):
17
18
"""
18
19
A class representing the config file
@@ -242,6 +243,7 @@ def unwrapSnaphu(self, function):
242
243
self .f .write ('defomax : ' + self .defoMax + '\n ' )
243
244
self .f .write ('rlks : ' + self .rangeLooks + '\n ' )
244
245
self .f .write ('alks : ' + self .azimuthLooks + '\n ' )
246
+ self .f .write ('numProcess : ' + self .numProcess + '\n ' )
245
247
246
248
def denseOffset (self , function ):
247
249
self .f .write ('###################################' + '\n ' )
@@ -258,6 +260,18 @@ def denseOffset(self, function):
258
260
#self.f.write('ww : 256\n')
259
261
#self.f.write('wh : 128\n')
260
262
263
+ def write_wrapper_config2run_file (self , configName , line_cnt , numProcess = 1 ):
264
+ # dispassionate list of commands for single process
265
+ if numProcess == 1 :
266
+ self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
267
+ # aggregate background commands between wait blocks for speed gains
268
+ elif numProcess > 1 :
269
+ self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + ' &\n ' )
270
+ if line_cnt == numProcess :
271
+ self .runf .write ('wait\n \n ' )
272
+ line_cnt = 0
273
+ return line_cnt
274
+
261
275
def finalize (self ):
262
276
self .f .close ()
263
277
@@ -286,6 +300,7 @@ def unpackSLC(self, acquisitionDates, safe_dict):
286
300
swath_path = self .work_dir
287
301
os .makedirs (self .config_path , exist_ok = True )
288
302
303
+ line_cnt = 0
289
304
for slcdate in acquisitionDates :
290
305
configName = os .path .join (self .config_path ,'config_unpack_' + slcdate )
291
306
configObj = config (configName )
@@ -300,8 +315,10 @@ def unpackSLC(self, acquisitionDates, safe_dict):
300
315
configObj .Sentinel1_TOPS ('[Function-1]' )
301
316
configObj .topo ('[Function-2]' )
302
317
configObj .finalize ()
318
+
319
+ line_cnt += 1
320
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt )
303
321
del configObj
304
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
305
322
306
323
def unpackStackReferenceSLC (self , safe_dict ):
307
324
swath_path = self .work_dir
@@ -320,11 +337,14 @@ def unpackStackReferenceSLC(self, safe_dict):
320
337
configObj .Sentinel1_TOPS ('[Function-1]' )
321
338
configObj .topo ('[Function-2]' )
322
339
configObj .finalize ()
340
+
341
+ line_cnt = 1
342
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt )
323
343
del configObj
324
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
325
344
326
345
def unpackSecondarysSLC (self , stackReferenceDate , secondaryList , safe_dict ):
327
346
347
+ line_cnt = 0
328
348
for secondary in secondaryList :
329
349
configName = os .path .join (self .config_path ,'config_secondary_' + secondary )
330
350
outdir = os .path .join (self .work_dir ,'secondarys/' + secondary )
@@ -337,11 +357,14 @@ def unpackSecondarysSLC(self, stackReferenceDate, secondaryList, safe_dict):
337
357
configObj .outDir = outdir
338
358
configObj .Sentinel1_TOPS ('[Function-1]' )
339
359
configObj .finalize ()
360
+
361
+ line_cnt += 1
362
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt , self .numProcess )
340
363
del configObj
341
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
342
364
343
365
def averageBaseline (self , stackReferenceDate , secondaryList ):
344
366
367
+ line_cnt = 0
345
368
for secondary in secondaryList :
346
369
configName = os .path .join (self .config_path ,'config_baseline_' + secondary )
347
370
configObj = config (configName )
@@ -351,10 +374,14 @@ def averageBaseline(self, stackReferenceDate, secondaryList):
351
374
configObj .baselineFile = os .path .join (self .work_dir ,'baselines/' + stackReferenceDate + '_' + secondary + '/' + stackReferenceDate + '_' + secondary + '.txt' )
352
375
configObj .computeAverageBaseline ('[Function-1]' )
353
376
configObj .finalize ()
377
+
378
+ line_cnt += 1
379
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt , self .numProcess )
354
380
del configObj
355
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
356
381
357
382
def gridBaseline (self , stackReferenceDate , secondaryList ):
383
+
384
+ line_cnt = 0
358
385
for secondary in secondaryList :
359
386
configName = os .path .join (self .config_path ,'config_baselinegrid_' + secondary )
360
387
configObj = config (configName )
@@ -364,8 +391,10 @@ def gridBaseline(self, stackReferenceDate, secondaryList):
364
391
configObj .baselineFile = os .path .join (self .work_dir , 'merged/baselines/' + secondary + '/' + secondary )
365
392
configObj .computeGridBaseline ('[Function-1]' )
366
393
configObj .finalize ()
394
+
395
+ line_cnt += 1
396
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt )
367
397
del configObj
368
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
369
398
# also add the reference in itself to be consistent with the SLC dir
370
399
configName = os .path .join (self .config_path ,'config_baselinegrid_reference' )
371
400
configObj = config (configName )
@@ -375,8 +404,10 @@ def gridBaseline(self, stackReferenceDate, secondaryList):
375
404
configObj .baselineFile = os .path .join (self .work_dir , 'merged/baselines/' + stackReferenceDate + '/' + stackReferenceDate )
376
405
configObj .computeGridBaseline ('[Function-1]' )
377
406
configObj .finalize ()
407
+
408
+ line_cnt = 1
409
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt )
378
410
del configObj
379
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
380
411
381
412
382
413
def extractOverlaps (self ):
@@ -386,6 +417,7 @@ def extractOverlaps(self):
386
417
387
418
def geo2rdr_offset (self , secondaryList , fullBurst = 'False' ):
388
419
420
+ line_cnt = 0
389
421
for secondary in secondaryList :
390
422
reference = self .reference_date
391
423
if fullBurst == 'True' :
@@ -407,10 +439,14 @@ def geo2rdr_offset(self, secondaryList, fullBurst='False'):
407
439
configObj .overlapTrueOrFalse = 'True'
408
440
configObj .geo2rdr ('[Function-1]' )
409
441
configObj .finalize ()
442
+
443
+ line_cnt += 1
444
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt , self .numProcess )
410
445
del configObj
411
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
412
446
413
447
def resample_with_carrier (self , secondaryList , fullBurst = 'False' ):
448
+
449
+ line_cnt = 0
414
450
for secondary in secondaryList :
415
451
reference = self .reference_date
416
452
if fullBurst == 'True' :
@@ -433,13 +469,17 @@ def resample_with_carrier(self, secondaryList, fullBurst='False'):
433
469
configObj .overlapTrueOrFalse = 'True'
434
470
configObj .resamp_withCarrier ('[Function-1]' )
435
471
configObj .finalize ()
472
+
473
+ line_cnt += 1
474
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt , self .numProcess )
436
475
del configObj
437
- self . runf . write ( self . text_cmd + 'SentinelWrapper.py -c ' + configName + ' \n ' )
476
+
438
477
439
478
def pairs_misregistration (self , dateList , safe_dict ):
440
479
# generating overlap interferograms, estimate azimuth misregistration for each pair:
441
480
pairs = []
442
481
num_overlap_connections = int (self .num_overlap_connections ) + 1
482
+
443
483
for i in range (len (dateList )- 1 ):
444
484
for j in range (i + 1 ,i + num_overlap_connections ):
445
485
if j < len (dateList ):
@@ -450,6 +490,8 @@ def pairs_misregistration(self, dateList, safe_dict):
450
490
safe_dict [date ].slc_overlap = os .path .join (self .work_dir , 'coreg_secondarys/' + date )
451
491
safe_dict [self .reference_date ].slc = os .path .join (self .work_dir , 'reference' )
452
492
safe_dict [self .reference_date ].slc_overlap = os .path .join (self .work_dir , 'reference' )
493
+
494
+ line_cnt = 0
453
495
for pair in pairs :
454
496
reference = pair [0 ]
455
497
secondary = pair [1 ]
@@ -479,11 +521,12 @@ def pairs_misregistration(self, dateList, safe_dict):
479
521
configObj .rangeMisreg ('[Function-4]' )
480
522
configObj .finalize ()
481
523
482
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
524
+ line_cnt += 1
525
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt , self .numProcess )
526
+ del configObj
483
527
########################
484
528
485
529
486
-
487
530
def timeseries_misregistration (self ):
488
531
#inverting the misregistration offsets of the overlap pairs to estimate the offsets of each date
489
532
self .runf .write (self .text_cmd + 'invertMisreg.py -i ' + os .path .join (self .work_dir ,'misreg/azimuth/pairs/' ) + ' -o ' + os .path .join (self .work_dir ,'misreg/azimuth/dates/' ) + '\n ' )
@@ -499,6 +542,8 @@ def generate_burstIgram(self, dateList, safe_dict, pairs):
499
542
for date in dateList :
500
543
safe_dict [date ].slc = os .path .join (self .work_dir , 'coreg_secondarys/' + date )
501
544
safe_dict [self .reference_date ].slc = os .path .join (self .work_dir , 'reference' )
545
+
546
+ line_cnt = 0
502
547
for pair in pairs :
503
548
reference = pair [0 ]
504
549
secondary = pair [1 ]
@@ -514,14 +559,19 @@ def generate_burstIgram(self, dateList, safe_dict, pairs):
514
559
configObj .overlapTrueOrFalse = 'False'
515
560
configObj .generateIgram ('[Function-1]' )
516
561
configObj .finalize ()
562
+
563
+ line_cnt += 1
564
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt , self .numProcess )
517
565
del configObj
518
566
519
- self . runf . write ( self . text_cmd + 'SentinelWrapper.py -c ' + configName + ' \n ' )
567
+
520
568
521
569
def igram_mergeBurst (self , dateList , safe_dict , pairs ):
522
570
for date in dateList :
523
571
safe_dict [date ].slc = os .path .join (self .work_dir , 'coreg_secondarys/' + date )
524
572
safe_dict [self .reference_date ].slc = os .path .join (self .work_dir , 'reference' )
573
+
574
+ line_cnt = 0
525
575
for pair in pairs :
526
576
reference = pair [0 ]
527
577
secondary = pair [1 ]
@@ -543,12 +593,14 @@ def igram_mergeBurst(self, dateList, safe_dict, pairs):
543
593
configObj .stack = os .path .join (self .work_dir , 'stack' )
544
594
configObj .mergeBurst ('[Function-1]' )
545
595
configObj .finalize ()
546
- del configObj
547
596
548
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
597
+ line_cnt += 1
598
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt , self .numProcess )
599
+ del configObj
549
600
550
601
def mergeSecondarySLC (self , secondaryList , virtual = 'True' ):
551
602
603
+ line_cnt = 0
552
604
for secondary in secondaryList :
553
605
configName = os .path .join (self .config_path ,'config_merge_' + secondary )
554
606
configObj = config (configName )
@@ -566,7 +618,11 @@ def mergeSecondarySLC(self, secondaryList, virtual='True'):
566
618
configObj .stack = os .path .join (self .work_dir , 'stack' )
567
619
configObj .mergeBurst ('[Function-1]' )
568
620
configObj .finalize ()
569
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
621
+
622
+ line_cnt += 1
623
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt )
624
+ del configObj
625
+
570
626
571
627
def mergeReference (self , stackReference , virtual = 'True' ):
572
628
@@ -585,7 +641,10 @@ def mergeReference(self, stackReference, virtual='True'):
585
641
configObj .multiLook = 'False'
586
642
configObj .mergeBurst ('[Function-1]' )
587
643
configObj .finalize ()
588
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
644
+
645
+ line_cnt = 1
646
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt )
647
+ del configObj
589
648
590
649
geometryList = ['lat*rdr' , 'lon*rdr' , 'los*rdr' , 'hgt*rdr' , 'shadowMask*rdr' ,'incLocal*rdr' ]
591
650
multiookToolDict = {'lat*rdr' : 'gdal' , 'lon*rdr' : 'gdal' , 'los*rdr' : 'gdal' , 'hgt*rdr' :"gdal" , 'shadowMask*rdr' :"isce" ,'incLocal*rdr' :"gdal" }
@@ -610,10 +669,14 @@ def mergeReference(self, stackReference, virtual='True'):
610
669
configObj .stack = os .path .join (self .work_dir , 'stack' )
611
670
configObj .mergeBurst ('[Function-1]' )
612
671
configObj .finalize ()
613
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
672
+
673
+ line_cnt += 1
674
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt )
675
+ del configObj
614
676
615
677
def mergeSLC (self , aquisitionDates , virtual = 'True' ):
616
678
679
+ line_cnt = 0
617
680
for slcdate in aquisitionDates :
618
681
configName = os .path .join (self .config_path ,'config_merge_' + slcdate )
619
682
configObj = config (configName )
@@ -630,9 +693,14 @@ def mergeSLC(self, aquisitionDates, virtual='True'):
630
693
configObj .stack = os .path .join (self .work_dir , 'stack' )
631
694
configObj .mergeBurst ('[Function-1]' )
632
695
configObj .finalize ()
633
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
696
+
697
+ line_cnt += 1
698
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt )
699
+
634
700
635
701
geometryList = ['lat*rdr' , 'lon*rdr' , 'los*rdr' , 'hgt*rdr' , 'shadowMask*rdr' ,'incLocal*rdr' ]
702
+
703
+ g_line_cnt = 0
636
704
for i in range (len (geometryList )):
637
705
pattern = geometryList [i ]
638
706
configName = os .path .join (self .config_path ,'config_merge_' + slcdate + '_' + pattern .split ('*' )[0 ])
@@ -650,10 +718,14 @@ def mergeSLC(self, aquisitionDates, virtual='True'):
650
718
configObj .stack = os .path .join (self .work_dir , 'stack' )
651
719
configObj .mergeBurst ('[Function-1]' )
652
720
configObj .finalize ()
653
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
721
+
722
+ g_line_cnt += 1
723
+ g_line_cnt = configObj .write_wrapper_config2run_file (configName , g_line_cnt )
724
+ del configObj
654
725
655
726
def filter_coherence (self , pairs ):
656
727
728
+ line_cnt = 0
657
729
for pair in pairs :
658
730
reference = pair [0 ]
659
731
secondary = pair [1 ]
@@ -673,9 +745,15 @@ def filter_coherence(self, pairs):
673
745
#configObj.filtStrength = str(self.filtStrength)
674
746
configObj .FilterAndCoherence ('[Function-1]' )
675
747
configObj .finalize ()
676
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
748
+
749
+ line_cnt += 1
750
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt , self .numProcess )
751
+ del configObj
752
+
677
753
678
754
def unwrap (self , pairs ):
755
+
756
+ line_cnt = 0
679
757
for pair in pairs :
680
758
reference = pair [0 ]
681
759
secondary = pair [1 ]
@@ -693,10 +771,14 @@ def unwrap(self, pairs):
693
771
configObj .unwMethod = self .unwMethod
694
772
configObj .unwrap ('[Function-1]' )
695
773
configObj .finalize ()
696
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
774
+
775
+ line_cnt += 1
776
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt , self .numProcess )
777
+ del configObj
697
778
698
779
def denseOffsets (self , pairs ):
699
780
781
+ line_cnt = 0
700
782
for pair in pairs :
701
783
reference = pair [0 ]
702
784
secondary = pair [1 ]
@@ -709,9 +791,10 @@ def denseOffsets(self, pairs):
709
791
configObj .output = os .path .join (self .work_dir , 'merged/dense_offsets/' + reference + '_' + secondary + '/' + reference + '_' + secondary )
710
792
configObj .denseOffset ('[Function-1]' )
711
793
configObj .finalize ()
712
- del configObj
713
- self .runf .write (self .text_cmd + 'SentinelWrapper.py -c ' + configName + '\n ' )
714
794
795
+ line_cnt += 1
796
+ line_cnt = configObj .write_wrapper_config2run_file (configName , line_cnt )
797
+ del configObj
715
798
716
799
def finalize (self ):
717
800
self .runf .close ()
@@ -966,8 +1049,6 @@ def get_orbit(self, orbitDir, workDir, margin=60.0):
966
1049
self .orbit = orbitFile [0 ]
967
1050
self .orbitType = 'restituted'
968
1051
969
-
970
-
971
1052
# an example for writing job files when using clusters
972
1053
973
1054
"""
0 commit comments