Skip to content

Commit

Permalink
only serial processing with windows, use map() instead of pool.map() …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
pnuu committed Apr 24, 2015
1 parent de7622b commit a79de80
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 118 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ python:
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq python-numpy python-matplotlib python-pythonmagick
- sudo apt-get install --qq python3-matplotlib python3-numpy
virtualenv:
system_site_packages: true
install:
Expand Down
40 changes: 30 additions & 10 deletions bin/halostack_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
get_two_points, read_config)
import argparse
import logging
import platform
import os

# log pattern
LOG_FMT = '%(asctime)s - %(name)s - %(levelname)s: %(message)s'
Expand Down Expand Up @@ -84,16 +86,12 @@ def halostack_cli(args):

images = args['fname_in']

if len(images) == 0:
LOGGER.error("No images given.")
LOGGER.error("Exiting.")
return

stacks = []
for stack in args['stacks']:
stacks.append(Stack(stack, len(images), nprocs=args['nprocs']))

base_img = Image(fname=images[0], nprocs=args['nprocs'])
base_img_fname = images[0]
base_img = Image(fname=base_img_fname, nprocs=args['nprocs'])
LOGGER.debug("Using %s as base image.", base_img.fname)
images.remove(images[0])

Expand Down Expand Up @@ -127,18 +125,24 @@ def halostack_cli(args):
aligner.set_search_area(args['focus_area'])
LOGGER.debug("Alignment initialized.")

if args['save_prefix'] is not None:
fname = args['save_prefix'] + '_' + \
os.path.splitext(base_img_fname)[0] + '.png'
base_img.save(fname)

if len(args['enhance_images']) > 0:
LOGGER.info("Preprocessing image.")
base_img.enhance(args['enhance_images'])

for stack in stacks:
stack.add_image(base_img)

# memory management
del base_img

for img in images:
for img_fname in images:
# Read image
img = Image(fname=img, nprocs=args['nprocs'])
img = Image(fname=img_fname, nprocs=args['nprocs'])

if not args['no_alignment'] and len(images) > 1:
# align image
Expand All @@ -148,9 +152,15 @@ def halostack_cli(args):
LOGGER.warning("Skipping image.")
continue

if args['save_prefix'] is not None:
fname = args['save_prefix'] + '_' + \
os.path.splitext(img_fname)[0] + '.png'
img.save(fname)

if len(args['enhance_images']) > 0:
LOGGER.info("Preprocessing image.")
img.enhance(args['enhance_images'])

for stack in stacks:
stack.add_image(img)

Expand Down Expand Up @@ -178,7 +188,7 @@ def main():
dest="correlation_threshold",
default=None, metavar="NUM", type=float,
help="Minimum required correlation [0.7]")
parser.add_argument("-s", "--save-images", dest="save_postfix",
parser.add_argument("-s", "--save-images", dest="save_prefix",
default=None, metavar="STR",
help="Save aligned images as PNG with the given " \
"filename postfix")
Expand Down Expand Up @@ -229,6 +239,10 @@ def main():
args['correlation_threshold'] = 0.7
if not isinstance(args['no_alignment'], bool):
args['no_alignment'] = False
if platform.system() == 'Windows':
LOGGER.warning("Your operting system is Windows, "
"so limiting to one processor.")
args['nprocs'] = 1

# Check which stacks will be made
stacks = []
Expand All @@ -252,13 +266,19 @@ def main():
args['stacks'] = stacks
args['stack_fnames'] = stack_fnames

# Check if there's anything to do
if len(args['stacks']) == 0 and args['save_prefix'] is None or \
len(args['fname_in']) == 0:
LOGGER.error("Nothing to do.")
parser.print_help()
return

LOGGER.info("Starting stacking")

halostack_cli(args)


if __name__ == "__main__":
# global LOGGER
# Setup logging
import logging.config
logging.config.dictConfig(LOG_CONFIG)
Expand Down
26 changes: 25 additions & 1 deletion doc/source/plan.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ GUI

- full graphical user interface

- help needed

- that is, need someone else to implement GUI

Image input
-----------
Expand All @@ -19,6 +22,13 @@ Image input
- python-exif for linux, windows?
- separate CSV file needed for TIFF and/or windows?

- use Wand instead of PythonMagick

- provides also EXIF functionality

- possibility to give directory containing all the photos
- possibility to give image filenames/masks in config file


Image alignment
------------------
Expand Down Expand Up @@ -47,9 +57,23 @@ Image enhancements
- for example, several average stacks with different
pre/postprocessing applied

- ``-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``
- ``-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``

- bias subtraction
- flat correction

- for dust and vignetting removal

- when applying to single image, skip Stack

- also remove requirement for command-line switch for a stack

Python3
-------

- Get things ready for Python3

- replace PythonMagick with Wand
- check other parts
1 change: 1 addition & 0 deletions doc/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ ____________________
- gradient removal (blurring)

- default: ``1``
- unfortunately, in Windows you are limited to one thread

- ``<list of filenames>``

Expand Down
14 changes: 10 additions & 4 deletions halostack/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ def __init__(self, img, cor_th=70.0, mode='simple', nprocs=1):

self.img = img
self.correlation_threshold = cor_th
self.nprocs = nprocs
self._nprocs = nprocs

self.ref_loc = None
self.srch_area = None
self.ref = None

self.pool = Pool(self.nprocs)
if self._nprocs > 1:
self._pool = Pool(self._nprocs)
else:
self._pool = None

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

result = self.pool.map(_simple_search_worker, data)
if self._nprocs > 1:
result = self._pool.map(_simple_search_worker, data)
else:
result = map(_simple_search_worker, data)

result = np.array(result)
idx = np.argmin(result[:, 0])
Expand Down Expand Up @@ -195,7 +201,7 @@ def _simple_match(self, img):
ylims[0], ylims[1])

LOGGER.debug("Searching for best match using %d thread(s).",
self.nprocs)
self._nprocs)
best_res = self._parallel_search(img, xlims, ylims, ref_shp)

# Calculate correlation coeff for the best fit
Expand Down
Loading

0 comments on commit a79de80

Please sign in to comment.