2929 get_two_points , read_config )
3030import argparse
3131import logging
32+ import platform
33+ import os
3234
3335# log pattern
3436LOG_FMT = '%(asctime)s - %(name)s - %(levelname)s: %(message)s'
@@ -84,16 +86,12 @@ def halostack_cli(args):
8486
8587 images = args ['fname_in' ]
8688
87- if len (images ) == 0 :
88- LOGGER .error ("No images given." )
89- LOGGER .error ("Exiting." )
90- return
91-
9289 stacks = []
9390 for stack in args ['stacks' ]:
9491 stacks .append (Stack (stack , len (images ), nprocs = args ['nprocs' ]))
9592
96- base_img = Image (fname = images [0 ], nprocs = args ['nprocs' ])
93+ base_img_fname = images [0 ]
94+ base_img = Image (fname = base_img_fname , nprocs = args ['nprocs' ])
9795 LOGGER .debug ("Using %s as base image." , base_img .fname )
9896 images .remove (images [0 ])
9997
@@ -127,18 +125,24 @@ def halostack_cli(args):
127125 aligner .set_search_area (args ['focus_area' ])
128126 LOGGER .debug ("Alignment initialized." )
129127
128+ if args ['save_prefix' ] is not None :
129+ fname = args ['save_prefix' ] + '_' + \
130+ os .path .splitext (base_img_fname )[0 ] + '.png'
131+ base_img .save (fname )
132+
130133 if len (args ['enhance_images' ]) > 0 :
131134 LOGGER .info ("Preprocessing image." )
132135 base_img .enhance (args ['enhance_images' ])
136+
133137 for stack in stacks :
134138 stack .add_image (base_img )
135139
136140 # memory management
137141 del base_img
138142
139- for img in images :
143+ for img_fname in images :
140144 # Read image
141- img = Image (fname = img , nprocs = args ['nprocs' ])
145+ img = Image (fname = img_fname , nprocs = args ['nprocs' ])
142146
143147 if not args ['no_alignment' ] and len (images ) > 1 :
144148 # align image
@@ -148,9 +152,15 @@ def halostack_cli(args):
148152 LOGGER .warning ("Skipping image." )
149153 continue
150154
155+ if args ['save_prefix' ] is not None :
156+ fname = args ['save_prefix' ] + '_' + \
157+ os .path .splitext (img_fname )[0 ] + '.png'
158+ img .save (fname )
159+
151160 if len (args ['enhance_images' ]) > 0 :
152161 LOGGER .info ("Preprocessing image." )
153162 img .enhance (args ['enhance_images' ])
163+
154164 for stack in stacks :
155165 stack .add_image (img )
156166
@@ -178,7 +188,7 @@ def main():
178188 dest = "correlation_threshold" ,
179189 default = None , metavar = "NUM" , type = float ,
180190 help = "Minimum required correlation [0.7]" )
181- parser .add_argument ("-s" , "--save-images" , dest = "save_postfix " ,
191+ parser .add_argument ("-s" , "--save-images" , dest = "save_prefix " ,
182192 default = None , metavar = "STR" ,
183193 help = "Save aligned images as PNG with the given " \
184194 "filename postfix" )
@@ -229,6 +239,10 @@ def main():
229239 args ['correlation_threshold' ] = 0.7
230240 if not isinstance (args ['no_alignment' ], bool ):
231241 args ['no_alignment' ] = False
242+ if platform .system () == 'Windows' :
243+ LOGGER .warning ("Your operting system is Windows, "
244+ "so limiting to one processor." )
245+ args ['nprocs' ] = 1
232246
233247 # Check which stacks will be made
234248 stacks = []
@@ -252,13 +266,19 @@ def main():
252266 args ['stacks' ] = stacks
253267 args ['stack_fnames' ] = stack_fnames
254268
269+ # Check if there's anything to do
270+ if len (args ['stacks' ]) == 0 and args ['save_prefix' ] is None or \
271+ len (args ['fname_in' ]) == 0 :
272+ LOGGER .error ("Nothing to do." )
273+ parser .print_help ()
274+ return
275+
255276 LOGGER .info ("Starting stacking" )
256277
257278 halostack_cli (args )
258279
259280
260281if __name__ == "__main__" :
261- # global LOGGER
262282 # Setup logging
263283 import logging .config
264284 logging .config .dictConfig (LOG_CONFIG )
0 commit comments