Created
May 28, 2015 16:56
-
-
Save vterron/f0c9a33eebe16eaf341e to your computer and use it in GitHub Desktop.
Second attempt at debugging issue #60
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# Author: Victor Terron (c) 2015 | |
# Email: `echo vt2rron1iaa32s | tr 132 @.e` | |
# License: GNU GPLv3 | |
""" Mosaic the first ten FITS files using Montage, then the first twenty, then | |
the first thirty, et cetera. That is: the number of mosaicked images increases | |
in steps of ten, stopping as soon as an error, if any, is encountered.""" | |
from __future__ import division | |
from __future__ import print_function | |
from __future__ import absolute_import | |
from __future__ import unicode_literals | |
import atexit | |
import os | |
import subprocess | |
import sys | |
import tempfile | |
if __name__ == "__main__": | |
if len(sys.argv) == 1: | |
msg = "usage: {0} IMAGE...".format(sys.argv[0]) | |
sys.exit(msg) | |
img_paths = sys.argv[1:] | |
size = len(img_paths) | |
fd, output_image = tempfile.mkstemp(suffix = '.fits') | |
atexit.register(os.unlink, output_image) | |
os.close(fd) | |
for n in range(10, size + 1, 10): | |
if n > size: | |
n = size | |
images = img_paths[:n] | |
cmd = ['lemon', 'mosaic'] + images + [output_image, '--overwrite'] | |
try: | |
msg = "Mosaicking {0} images (last: {1})..." | |
args = len(images), os.path.basename(images[-1]) | |
print(msg.format(*args), end='') | |
sys.stdout.flush() | |
with open(os.devnull, 'w') as fd: | |
subprocess.check_call(cmd, stdout=fd, stderr=fd) | |
print(" OK") | |
except subprocess.CalledProcessError: | |
sys.exit(" ERROR") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment