Skip to content

Instantly share code, notes, and snippets.

@vterron
Last active August 29, 2015 14:22
Show Gist options
  • Save vterron/c63b13a70f986dd5a2e2 to your computer and use it in GitHub Desktop.
Save vterron/c63b13a70f986dd5a2e2 to your computer and use it in GitHub Desktop.
Third attempt at debugging issue #60
#! /usr/bin/env python
# Author: Victor Terron (c) 2015
# Email: `echo vt2rron1iaa32s | tr 132 @.e`
# License: GNU GPLv3
""" Mosaic all the input FITS files using Montage, then all of them except for
the first ten, then all of them minus the first twenty, et cetera. That is: the
number of mosaicked images decreases in steps of ten. We stop as soon as one of
the data sets doesn't cause Montage to raise an error. ."""
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:]
STOP_IMAGE = 'rccd140501.106a.fits' # upper bound of interval
for index, path in enumerate(img_paths):
if os.path.basename(path) == STOP_IMAGE:
img_paths = img_paths[:index+1]
break
else:
msg = "{0} not found among input FITS files".format(STOP_IMAGE)
raise ValueError(msg)
size = len(img_paths)
print("Last FITS file: {0}".format(img_paths[-1]))
fd, output_image = tempfile.mkstemp(suffix = '.fits')
atexit.register(os.unlink, output_image)
os.close(fd)
for n in range(0, size + 1, 10):
if n > size:
n = size
images = img_paths[n:]
cmd = ['lemon', 'mosaic'] + images + [output_image, '--overwrite']
msg = "Mosaicking {0} images (first: {1})..."
args = len(images), os.path.basename(images[0])
print(msg.format(*args), end='')
sys.stdout.flush()
try:
with open(os.devnull, 'w') as fd:
subprocess.check_call(cmd, stdout=fd, stderr=fd)
except subprocess.CalledProcessError:
print(" ERROR")
else:
sys.exit(" OK")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment