@@ -71,6 +71,98 @@ def ortho_func(args):
71
71
orthorectify (args .input_img , o_ortho_path , ortho_params , None , args .dem , args .refine ,
72
72
args .gcps , args .ref_img , args .debug , args .show )
73
73
74
+ def batch_ortho_func (args ):
75
+ geoCosiCorr3DLog ('Batch Orthorectification' , os .getcwd ())
76
+ logging .info (f'Executing batch orthorectification module :{ args } ' )
77
+
78
+ if args .base_images .startswith ('"' ): # for a string pattern including multiple images
79
+ print ("Input is a string" )
80
+ base_images = []
81
+ for pattern in args .base_images .split (',' ):
82
+ base_images .extend (glob .glob (pattern ))
83
+ base_rpcs = []
84
+ for pattern in args .base_rpcs .split (',' ):
85
+ base_rpcs .extend (glob .glob (pattern ))
86
+ if len (base_images ) != len (base_rpcs ):
87
+ raise ValueError (f"Input_base_images:{ len (base_images )} and base_rpcs:{ len (base_rpcs )} -- "
88
+ f"The number of base images and RPCs must be equal when using the --serial option." )
89
+ print (base_images )
90
+ print (base_rpcs )
91
+ print (args .sat_id )
92
+
93
+ with open ('error_log.txt' , 'w' ) as log :
94
+ for base_image , base_rpc in zip (base_images , base_rpcs ):
95
+ try :
96
+ print (f"Processing { base_image } { base_rpc } " )
97
+ ortho_func (argparse .Namespace (input_img = base_image ,
98
+ o_ortho = args .o_ortho ,
99
+ dem = args .dem ,
100
+ refine = args .refine ,
101
+ gcps = args .gcps ,
102
+ gsd = args .gsd ,
103
+ ref_img = args .ref_img ,
104
+ debug = args .debug ,
105
+ show = args .show ,
106
+ model_name = args .model_name ,
107
+ rsm_fn = base_rpc ,
108
+ sat_id = args .sat_id ,
109
+ corr_model = args .corr_model ,
110
+ resampling_method = args .resampling_method ,
111
+ ))
112
+ except Exception as e :
113
+ log .write (f"Error with { f } : { e } \n " )
114
+ log .write (traceback .format_exc () + "\n " )
115
+
116
+ elif args .base_images .endswith ('.txt' ): # for a list of input data
117
+ print ("Input is a text file" )
118
+ base_images = []
119
+ with open (args .base_images , 'r' ) as f :
120
+ for line in f :
121
+ pattern = line .strip () # Remove leading/trailing whitespace/newlines
122
+ if pattern : # Skip empty lines
123
+ base_images .extend (glob .glob (pattern ))
124
+ base_rpcs = []
125
+ with open (args .base_rpcs , 'r' ) as f :
126
+ for line in f :
127
+ pattern = line .strip () # Remove leading/trailing whitespace/newlines
128
+ if pattern : # Skip empty lines
129
+ base_rpcs .extend (glob .glob (pattern ))
130
+ sensors = []
131
+ with open (args .sat_id , 'r' ) as f :
132
+ for line in f :
133
+ pattern = line .strip ()
134
+ if pattern :
135
+ sensors .append (pattern )
136
+ if len (base_images ) != len (base_rpcs ):
137
+ raise ValueError (f"Input_base_images:{ len (base_images )} and base_rpcs:{ len (base_rpcs )} -- "
138
+ f"The number of base images and RPCs must be equal when using the --serial option." )
139
+ print (base_images )
140
+ print (base_rpcs )
141
+ print (sensors )
142
+
143
+ with open ('error_log.txt' , 'w' ) as log :
144
+ for base_image , base_rpc , sensor in zip (base_images , base_rpcs , sensors ):
145
+ try :
146
+ print (f"Processing { base_image } { base_rpc } { sensor } " )
147
+ ortho_func (argparse .Namespace (input_img = base_image ,
148
+ o_ortho = args .o_ortho ,
149
+ dem = args .dem ,
150
+ refine = args .refine ,
151
+ gcps = args .gcps ,
152
+ gsd = args .gsd ,
153
+ ref_img = args .ref_img ,
154
+ debug = args .debug ,
155
+ show = args .show ,
156
+ model_name = args .model_name ,
157
+ rsm_fn = base_rpc ,
158
+ sat_id = sensor ,
159
+ corr_model = args .corr_model ,
160
+ resampling_method = args .resampling_method ,
161
+ ))
162
+ except Exception as e :
163
+ log .write (f"Error with { f } : { e } \n " )
164
+ log .write (traceback .format_exc () + "\n " )
165
+
74
166
75
167
# ----------------------------------------------------------------
76
168
# -------------------------- TRANSFORMATION ----------------------
@@ -384,6 +476,30 @@ def ortho_subparser(subparsers):
384
476
"are supported in GeoCosiCorr3D.pro." )
385
477
rsm_parser .set_defaults (func = ortho_func )
386
478
479
+ def batch_ortho_subparser (subparsers ):
480
+ batch_ortho_parser = subparsers .add_parser ('batch_ortho' , help = 'batch orthorectification process' )
481
+ batch_ortho_parser .add_argument ('base_images' , type = str , help = 'Input files for batch ortho' )
482
+ batch_ortho_parser .add_argument ('--o_ortho' , type = str , default = os .getcwd (), help = 'output files for batch ortho' )
483
+ batch_ortho_parser .add_argument ('--corr_model' , type = str , default = None , help = 'Correction model path (None)' )
484
+ batch_ortho_parser .add_argument ('--dem' , type = str , default = None , help = 'DEM path (None)' )
485
+ batch_ortho_parser .add_argument ('--gsd' , type = float , default = None , help = 'Output file for ortho (None)' )
486
+ batch_ortho_parser .add_argument ('--resampling_method' , type = str , default = C .Resampling_Methods .SINC ,
487
+ choices = C .GEOCOSICORR3D_RESAMLING_METHODS , help = 'Resampling method (SINC)' )
488
+ batch_ortho_parser .add_argument ("--debug" , action = "store_true" )
489
+ batch_ortho_parser .add_argument ("--show" , action = "store_true" )
490
+ batch_ortho_parser .add_argument ("--refine" , action = "store_true" ,
491
+ help = "Refine model, this require GCPs or reference imagery to collect GCPs" )
492
+ batch_ortho_parser .add_argument ('--ref_img' , type = str , default = None , help = 'Reference Ortho image (None)' )
493
+ batch_ortho_parser .add_argument ('--gcps' , type = str , default = None , help = 'GCPs file (None)' )
494
+ model_subparsers = batch_ortho_parser .add_subparsers (title = 'model' , dest = 'model_name' , metavar = '<model_name>' ,
495
+ required = True )
496
+ rfm_parser = model_subparsers .add_parser (C .SATELLITE_MODELS .RFM , help = "RFM model specific arguments" )
497
+ rfm_parser .add_argument ('rfm_fn' , type = str , help = "RFM file name (.tiff or .TXT)" )
498
+ rfm_parser .set_defaults (func = ortho_func )
499
+ rsm_parser = model_subparsers .add_parser (C .SATELLITE_MODELS .RSM , help = "RSM model specific arguments" )
500
+ rsm_parser .add_argument ('sat_id' , type = str , choices = C .GEOCOSICORR3D_SENSORS_LIST , help = "Sat-name" )
501
+ rsm_parser .add_argument ('base_rpcs' , type = str , help = "list of .xml or DIM file" )
502
+ rsm_parser .set_defaults (func = batch_ortho_func )
387
503
388
504
def transform_subparser (subparsers ):
389
505
transform_parser = subparsers .add_parser ('transform' , help = 'Transformation' )
@@ -415,7 +531,7 @@ def correlate_subparser(subparsers):
415
531
correlate_parser .add_argument ("target_image" , type = str , help = "Path to the target image." )
416
532
correlate_parser .add_argument ("--base_band" , type = int , default = 1 , help = "Base image band." )
417
533
correlate_parser .add_argument ("--target_band" , type = int , default = 1 , help = "Target image band." )
418
- correlate_parser .add_argument ("--output_path" , type = str , default = C . SOFTWARE . WKDIR , help = "Output correlation path." )
534
+ correlate_parser .add_argument ("--output_path" , type = str , default = os . getcwd () , help = "Output correlation path." )
419
535
correlate_parser .add_argument ("--method" , type = str ,
420
536
choices = [C .CORR_METHODS .FREQUENCY_CORR .value , C .CORR_METHODS .SPATIAL_CORR .value ],
421
537
default = C .CORR_METHODS .FREQUENCY_CORR .value ,
@@ -452,7 +568,7 @@ def batch_correlate_subparser(subparsers):
452
568
batch_correlate_parser .add_argument ("--all" , action = "store_true" , help = "Correlate all possible combinations." )
453
569
batch_correlate_parser .add_argument ("--base_bands" , type = int , nargs = '+' , help = "List of base image bands." )
454
570
batch_correlate_parser .add_argument ("--target_bands" , type = int , nargs = '+' , help = "List of target image bands." )
455
- batch_correlate_parser .add_argument ("--output_path" , type = str , default = C . SOFTWARE . WKDIR ,
571
+ batch_correlate_parser .add_argument ("--output_path" , type = str , default = os . getcwd () ,
456
572
help = "Output correlation path." )
457
573
batch_correlate_parser .add_argument ("--method" , type = str , choices = [C .CORR_METHODS .FREQUENCY_CORR .value ,
458
574
C .CORR_METHODS .SPATIAL_CORR .value ],
@@ -518,22 +634,19 @@ def multiband_correlate_subparser(subparsers):
518
634
def cosicorr ():
519
635
parser = argparse .ArgumentParser (prog = 'cosicorr3d' , description = 'GeoCosiCorr3D CLI' ,
520
636
formatter_class = argparse .ArgumentDefaultsHelpFormatter )
521
-
522
637
subparsers = parser .add_subparsers (title = 'modules' , dest = 'module' , metavar = '<module>' )
523
-
524
638
ortho_subparser (subparsers )
639
+ batch_ortho_subparser (subparsers )
525
640
transform_subparser (subparsers )
526
641
correlate_subparser (subparsers )
527
642
batch_correlate_subparser (subparsers )
528
643
multiband_correlate_subparser (subparsers )
529
-
530
644
args = parser .parse_args ()
531
-
532
645
if hasattr (args , 'func' ):
533
646
args .func (args )
534
647
else :
535
648
parser .print_help ()
536
649
537
-
538
650
if __name__ == '__main__' :
539
651
cosicorr ()
652
+
0 commit comments