Skip to content

Instantly share code, notes, and snippets.

@vterron
Created June 16, 2015 09:58
Show Gist options
  • Save vterron/bae094dc989c13c6b630 to your computer and use it in GitHub Desktop.
Save vterron/bae094dc989c13c6b630 to your computer and use it in GitHub Desktop.
Run montage_wrapper.mosaic() with BITPIX=-64
#! /usr/bin/env python
# Author: Victor Terron (c) 2015
# Email: `echo vt2rron1iaa32s | tr 132 @.e`
# License: GNU GPLv3
""" Mosaic a series of input FITS images with montage.mosaic(), using
bitpix=-64 (double precision floating point). Both the input and output
temporary directories are immediately removed when the function exits.
"""
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals
import montage_wrapper
import os
import os.path
import shutil
import sys
import tempfile
def montage_bitpix_check(img_paths):
""" Run montage.mosaic() with bitpix=-64 and then remove the output dir. """
# Input temporary directory, with a symlink to the images
input_dir = tempfile.mkdtemp(suffix = '_input')
for path in img_paths:
source = os.path.abspath(path)
basename = os.path.basename(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, bitpix=-64)
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)
paths = sys.argv[1:]
montage_bitpix_check(paths)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment