Skip to content

Commit a79de80

Browse files
committed
only serial processing with windows, use map() instead of pool.map() for single thread in align and blur, remove deprecated blur functions, change pool and nprocs to private members, update plan, implement saving of aligned images, check if there's something to do
1 parent de7622b commit a79de80

File tree

7 files changed

+105
-118
lines changed

7 files changed

+105
-118
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ python:
88
before_install:
99
- sudo apt-get update -qq
1010
- sudo apt-get install -qq python-numpy python-matplotlib python-pythonmagick
11+
- sudo apt-get install --qq python3-matplotlib python3-numpy
1112
virtualenv:
1213
system_site_packages: true
1314
install:

bin/halostack_cli.py

+30-10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
get_two_points, read_config)
3030
import argparse
3131
import logging
32+
import platform
33+
import os
3234

3335
# log pattern
3436
LOG_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

260281
if __name__ == "__main__":
261-
# global LOGGER
262282
# Setup logging
263283
import logging.config
264284
logging.config.dictConfig(LOG_CONFIG)

doc/source/plan.rst

+25-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ GUI
1010

1111
- full graphical user interface
1212

13+
- help needed
14+
15+
- that is, need someone else to implement GUI
1316

1417
Image input
1518
-----------
@@ -19,6 +22,13 @@ Image input
1922
- python-exif for linux, windows?
2023
- separate CSV file needed for TIFF and/or windows?
2124

25+
- use Wand instead of PythonMagick
26+
27+
- provides also EXIF functionality
28+
29+
- possibility to give directory containing all the photos
30+
- possibility to give image filenames/masks in config file
31+
2232

2333
Image alignment
2434
------------------
@@ -47,9 +57,23 @@ Image enhancements
4757
- for example, several average stacks with different
4858
pre/postprocessing applied
4959

50-
- ``-a avg.png -a avg_pre_usm.png -e usm:25,2 -a avg_pre_post_usm.png -e usm:25,2 -E usm:25,2 -a avg_br.png -E gradient,br``
60+
- ``-a avg.png -a avg_pre_usm.png -e usm:25,2 -a
61+
avg_pre_post_usm.png -e usm:25,2 -E usm:25,2 -a avg_br.png -E
62+
gradient,br``
5163

5264
- bias subtraction
5365
- flat correction
5466

5567
- for dust and vignetting removal
68+
69+
- when applying to single image, skip Stack
70+
71+
- also remove requirement for command-line switch for a stack
72+
73+
Python3
74+
-------
75+
76+
- Get things ready for Python3
77+
78+
- replace PythonMagick with Wand
79+
- check other parts

doc/source/usage.rst

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ ____________________
139139
- gradient removal (blurring)
140140

141141
- default: ``1``
142+
- unfortunately, in Windows you are limited to one thread
142143

143144
- ``<list of filenames>``
144145

halostack/align.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,16 @@ def __init__(self, img, cor_th=70.0, mode='simple', nprocs=1):
5656

5757
self.img = img
5858
self.correlation_threshold = cor_th
59-
self.nprocs = nprocs
59+
self._nprocs = nprocs
6060

6161
self.ref_loc = None
6262
self.srch_area = None
6363
self.ref = None
6464

65-
self.pool = Pool(self.nprocs)
65+
if self._nprocs > 1:
66+
self._pool = Pool(self._nprocs)
67+
else:
68+
self._pool = None
6669

6770
try:
6871
self.align_func = modes[mode]
@@ -156,7 +159,10 @@ def _parallel_search(self, img, xlims, ylims, ref_shp):
156159
xran = range(i-ref_shp[1], i+ref_shp[1]+1)
157160
data.append((img[:, xran], ylims, self.ref))
158161

159-
result = self.pool.map(_simple_search_worker, data)
162+
if self._nprocs > 1:
163+
result = self._pool.map(_simple_search_worker, data)
164+
else:
165+
result = map(_simple_search_worker, data)
160166

161167
result = np.array(result)
162168
idx = np.argmin(result[:, 0])
@@ -195,7 +201,7 @@ def _simple_match(self, img):
195201
ylims[0], ylims[1])
196202

197203
LOGGER.debug("Searching for best match using %d thread(s).",
198-
self.nprocs)
204+
self._nprocs)
199205
best_res = self._parallel_search(img, xlims, ylims, ref_shp)
200206

201207
# Calculate correlation coeff for the best fit

0 commit comments

Comments
 (0)