-
Notifications
You must be signed in to change notification settings - Fork 3
/
podi_extractcentral.py
executable file
·74 lines (57 loc) · 2.17 KB
/
podi_extractcentral.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env python3
#
# Copyright 2012-2013 Ralf Kotulla
#
# This file is part of the ODI QuickReduce pipeline package.
#
# If you find this program or parts thereof please make sure to
# cite it appropriately (please contact the author for the most
# up-to-date reference to use). Also if you find any problems
# or have suggestiosn on how to improve the code or its
# functionality please let me know. Comments and questions are
# always welcome.
#
# The code is made publicly available. Feel free to share the link
# with whoever might be interested. However, I do ask you to not
# publish additional copies on your own website or other sources.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
"""
Extract only the central 3x3 extensions frm the input FITS file and write to
output FITS file.
How to run:
-----------
``podi_extractcentral.py /some/output/directory file1.fits file2.fits ...``
"""
import sys
import os
import astropy.io.fits as pyfits
import numpy
from podi_definitions import *
if __name__ == "__main__":
output_dir = sys.argv[1]
for filename in sys.argv[2:]:
stdout_write("Reading %s ..." % (filename))
hdulist = pyfits.open(filename)
out_list = [hdulist[0]]
outfits = "%s/%s.central3x3.fits" % (output_dir, filename[:-5])
if (os.path.isfile(outfits)):
print(" file exists, skipping")
continue
for extension in range(1, len(hdulist)):
extname = hdulist[extension].header['EXTNAME']
if (extname[0:3] != "OTA" or extname[-3:] != "SCI"):
continue
ota_x = int(extname[3])
ota_y = int(extname[4])
if (ota_x >= 2 and ota_x <= 4 and ota_y >= 2 and ota_y <= 4):
out_list.append(hdulist[extension])
out_hdulist = pyfits.HDUList(out_list)
stdout_write(" writing %s ..." % (outfits))
out_hdulist.writeto(outfits, overwrite=True)
#print "-->",outfits
stdout_write(" done!\n")