39
39
'handlers' : {
40
40
'console' : {
41
41
'class' : 'logging.StreamHandler' ,
42
- 'level' : 'DEBUG ' ,
42
+ 'level' : 'INFO ' ,
43
43
'formatter' : 'normal'
44
44
},
45
45
'file' : {
78
78
79
79
LOGGER = logging .getLogger ("halostack_cli" )
80
80
81
- def logging_setup (args ):
82
- '''Setup logging.
83
- '''
84
-
85
- # global LOGGER
86
-
87
- # Clear earlier handlers
88
- # LOGGER.handlers = []
89
-
90
- if args is None :
91
- loglevel = logging .DEBUG #INFO
92
- else :
93
- loglevel = args .get ("loglevel" , "DEBUG" ).upper ()
94
- try :
95
- loglevel = getattr (logging , loglevel )
96
- except AttributeError :
97
- loglevel = logging .INFO
98
-
99
- LOGGER .setLevel (loglevel ) # = logging.getLogger("halostack_cli")
100
-
101
81
102
82
def halostack_cli (args ):
103
83
'''Commandline interface.'''
@@ -113,71 +93,69 @@ def halostack_cli(args):
113
93
for stack in args ['stacks' ]:
114
94
stacks .append (Stack (stack , len (images ), nprocs = args ['nprocs' ]))
115
95
116
- base_img = Image (fname = images [0 ], enhancements = args ['enhance_images' ],
117
- nprocs = args ['nprocs' ])
118
- LOGGER .info ("Using %s as base image." , base_img .fname )
96
+ base_img = Image (fname = images [0 ], nprocs = args ['nprocs' ])
97
+ LOGGER .debug ("Using %s as base image." , base_img .fname )
119
98
images .remove (images [0 ])
120
99
121
100
if not args ['no_alignment' ] and len (images ) > 1 :
122
101
view_img = base_img .luminance ()
123
102
if isinstance (args ['view_gamma' ], float ):
124
103
view_img .enhance ({'gamma' : args ['view_gamma' ]})
125
- print "Click tight area (two opposite corners) for " \
126
- "reference location."
104
+ print "\n Click tight area (two opposite corners) for " \
105
+ "reference location.\n "
127
106
args ['focus_reference' ] = get_two_points (view_img )
128
- LOGGER .info ("Reference area: (%d, %d) with radius %d." ,
129
- args ['focus_reference' ][0 ],
130
- args ['focus_reference' ][1 ],
131
- args ['focus_reference' ][2 ])
107
+ LOGGER .debug ("Reference area: (%d, %d) with radius %d." ,
108
+ args ['focus_reference' ][0 ],
109
+ args ['focus_reference' ][1 ],
110
+ args ['focus_reference' ][2 ])
132
111
print "Click two corner points for the area where alignment " \
133
- "reference will be in every image."
112
+ "reference will be in every image.\n "
134
113
args ['focus_area' ] = get_two_points (view_img )
135
114
136
- LOGGER .info ("User-selected search area: (%d, %d) with radius %d." ,
115
+ LOGGER .debug ("User-selected search area: (%d, %d) with radius %d." ,
137
116
args ['focus_area' ][0 ],
138
117
args ['focus_area' ][1 ],
139
118
args ['focus_area' ][2 ])
140
119
del view_img
141
120
142
- for stack in stacks :
143
- LOGGER .debug ("Adding %s to %s stack" , base_img .fname , stack .mode )
144
- stack .add_image (base_img )
145
-
146
121
if not args ['no_alignment' ] and len (images ) > 1 :
147
122
LOGGER .debug ("Initializing alignment." )
148
- aligner = Align (base_img , ref_loc = args ['focus_reference' ],
149
- srch_area = args ['focus_area' ],
123
+ aligner = Align (base_img ,
150
124
cor_th = args ['correlation_threshold' ],
151
125
nprocs = args ['nprocs' ])
152
- LOGGER .info ("Alignment initialized." )
126
+ aligner .set_reference (args ['focus_reference' ])
127
+ aligner .set_search_area (args ['focus_area' ])
128
+ LOGGER .debug ("Alignment initialized." )
129
+
130
+ if len (args ['enhance_images' ]) > 0 :
131
+ LOGGER .info ("Preprocessing image." )
132
+ base_img .enhance (args ['enhance_images' ])
133
+ for stack in stacks :
134
+ stack .add_image (base_img )
153
135
154
136
# memory management
155
137
del base_img
156
138
157
139
for img in images :
158
140
# Read image
159
- LOGGER .info ("Reading %s." , img )
160
- img = Image (fname = img , enhancements = args ['enhance_images' ],
161
- nprocs = args ['nprocs' ])
141
+ img = Image (fname = img , nprocs = args ['nprocs' ])
162
142
163
143
if not args ['no_alignment' ] and len (images ) > 1 :
164
144
# align image
165
- LOGGER .info ("Aligning image." )
166
145
img = aligner .align (img )
167
146
168
147
if img is None :
169
- LOGGER .warning ("Threshold was below threshold, skipping image." )
148
+ LOGGER .warning ("Skipping image." )
170
149
continue
171
150
151
+ if len (args ['enhance_images' ]) > 0 :
152
+ LOGGER .info ("Preprocessing image." )
153
+ img .enhance (args ['enhance_images' ])
172
154
for stack in stacks :
173
- LOGGER .info ("Adding image to %s stack." , stack .mode )
174
155
stack .add_image (img )
175
156
176
157
for i in range (len (stacks )):
177
- LOGGER .info ("Calculating %s stack" , stacks [i ].mode )
178
158
img = stacks [i ].calculate ()
179
- LOGGER .info ("Saving %s stack to %s." , stacks [i ].mode ,
180
- args ['stack_fnames' ][i ])
181
159
img .save (args ['stack_fnames' ][i ],
182
160
enhancements = args ['enhance_stacks' ])
183
161
@@ -198,14 +176,14 @@ def main():
198
176
help = "Output filename of the median stack" )
199
177
parser .add_argument ("-t" , "--correlation-threshold" ,
200
178
dest = "correlation_threshold" ,
201
- default = 0.7 , metavar = "NUM" , type = float ,
179
+ default = None , metavar = "NUM" , type = float ,
202
180
help = "Minimum required correlation [0.7]" )
203
181
parser .add_argument ("-s" , "--save-images" , dest = "save_postfix" ,
204
182
default = None , metavar = "STR" ,
205
183
help = "Save aligned images as PNG with the given " \
206
184
"filename postfix" )
207
185
parser .add_argument ("-n" , "--no-alignment" , dest = "no_alignment" ,
208
- default = False , action = "store_true" ,
186
+ default = None , action = "store_true" ,
209
187
help = "Stack without alignment" )
210
188
parser .add_argument ("-e" , "--enhance-images" , dest = "enhance_images" ,
211
189
default = [], type = str , action = "append" ,
@@ -221,10 +199,8 @@ def main():
221
199
parser .add_argument ("-c" , "--config_item" , dest = "config_item" ,
222
200
metavar = "STR" , default = None ,
223
201
help = "Config item to select parameters" )
224
- parser .add_argument ("-l" , "--loglevel" , dest = "loglevel" , metavar = "LOGLEVEL" ,
225
- type = str , default = "INFO" , help = "Set level of shown messages" )
226
202
parser .add_argument ("-p" , "--nprocs" , dest = "nprocs" , metavar = "INT" ,
227
- type = int , default = 1 ,
203
+ type = int , default = None ,
228
204
help = "Number of parallel processes" )
229
205
parser .add_argument ('fname_in' , metavar = "FILE" , type = str , nargs = '*' ,
230
206
help = 'List of files' )
@@ -236,14 +212,24 @@ def main():
236
212
if args ["config_item" ] is not None :
237
213
args = read_config (args )
238
214
239
- # Re-adjust logging
240
- logging_setup (args )
215
+ # Check which adjustments are made for each image, and then for
216
+ # the resulting stacks
217
+ args ['enhance_images' ] = parse_enhancements (args ['enhance_images' ])
218
+ args ['enhance_stacks' ] = parse_enhancements (args ['enhance_stacks' ])
241
219
242
220
# Workaround for windows for getting all the filenames with *.jpg syntax
243
221
# that is expanded by the shell in linux
244
222
args ['fname_in' ] = get_filenames (args ['fname_in' ])
245
223
LOGGER .debug (args ['fname_in' ])
246
224
225
+ # Check validity
226
+ if not isinstance (args ['nprocs' ], int ):
227
+ args ['nprocs' ] = 1
228
+ if not isinstance (args ['correlation_threshold' ], float ):
229
+ args ['correlation_threshold' ] = 0.7
230
+ if not isinstance (args ['no_alignment' ], bool ):
231
+ args ['no_alignment' ] = False
232
+
247
233
# Check which stacks will be made
248
234
stacks = []
249
235
stack_fnames = []
@@ -266,12 +252,8 @@ def main():
266
252
args ['stacks' ] = stacks
267
253
args ['stack_fnames' ] = stack_fnames
268
254
269
- # Check which adjustments are made for each image, and then for
270
- # the resulting stacks
271
- args ['enhance_images' ] = parse_enhancements (args ['enhance_images' ])
272
- args ['enhance_stacks' ] = parse_enhancements (args ['enhance_stacks' ])
273
-
274
255
LOGGER .info ("Starting stacking" )
256
+
275
257
halostack_cli (args )
276
258
277
259
0 commit comments