Created
May 27, 2015 13:28
-
-
Save vterron/763ad6a82d899edba1af to your computer and use it in GitHub Desktop.
First 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 | |
""" Feed a series of input FITS files to Montage (via montage-wrapper), | |
one by one, identifying those, if any, that cause it to raise an error. """ | |
from __future__ import division | |
from __future__ import print_function | |
from __future__ import absolute_import | |
from __future__ import unicode_literals | |
from astropy import log | |
log.setLevel('WARNING') | |
import montage_wrapper | |
import os | |
import os.path | |
import shutil | |
import sys | |
import tempfile | |
def montage_error_check(path): | |
""" Check whether this image makes Montage raise an error. """ | |
# Input temporary directory, with only this image | |
basename = os.path.basename(path) | |
input_dir = tempfile.mkdtemp(suffix = '_input') | |
source = os.path.abspath(path) | |
link_name = os.path.join(input_dir, basename) | |
os.symlink(source, link_name) | |
# The path to a temporary output directory | |
output_dir = tempfile.mkdtemp(suffix = '_output') | |
os.rmdir(output_dir) | |
try: | |
montage_wrapper.mosaic(input_dir, output_dir) | |
except montage_wrapper.status.MontageError: | |
return True | |
else: | |
return False | |
finally: | |
shutil.rmtree(input_dir) | |
shutil.rmtree(output_dir) | |
if __name__ == "__main__": | |
if len(sys.argv) == 1: | |
msg = "usage: {0} IMAGE...".format(sys.argv[0]) | |
sys.exit(msg) | |
for path in sys.argv[1:]: | |
print(path, end=' ') | |
if not montage_error_check(path): | |
print('OK') | |
else: | |
print('ERROR') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment