-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_clean
executable file
·87 lines (80 loc) · 2.79 KB
/
run_clean
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
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
"""
A script that takes a set of directories and file numbers and cleans data appropriately
Inputs are:
Flags (u,s,m and/or d):
Dithered data analysis, destripe, manula click
rdir
Reduction directory, containing flats and darks.
ddir
Raw data directory
cdir
Cube directory, i.e. where to put cleaned data.
fstart
File start number
nfs
Number of files.
"""
import sys
import numpy as np
# This includes an AO Instrument called "aoinst"
import pypoise
import nirc2, conica
import pdb
import os, astropy.io.fits as pyfits
if len(sys.argv)==1:
print("Useage: run_clean [u|s|m|d] rdir ddir cdir fstart [fstart1] [...] nfs [nfs1] [...] [instname]")
sys.exit()
if not sys.argv[len(sys.argv)-1][0] in '0123456789':
instname = sys.argv[len(sys.argv)-1]
else:
instname = 'NIRC2'
if instname=='NIRC2':
#Create a pypoise instance with a nirc2 AO instrument
pp = pypoise.PYPOISE(nirc2.NIRC2())
elif instname=='NACO':
#Create a pypoise instance with a conica AO instrument
pp = pypoise.PYPOISE(conica.CONICA())
do_we_dither = sys.argv[1]
pp.aoinst.rdir = sys.argv[2] + '/' #'/Users/mireland/tel/nirc2/redux/130717/'
pp.aoinst.ddir = sys.argv[3] + '/' #'/Users/mireland/data/nirc2/130717/n'
pp.aoinst.cdir = sys.argv[4] + '/' #'./'
num_cubes = (len(sys.argv) - 5)//2
fstart = sys.argv[5:5+num_cubes]
nfs = sys.argv[5+num_cubes:5+2*num_cubes]
manual_click=False
destripe=True
dither=False
subtract_median=False
if (do_we_dither.find('u') >= 0):
subtract_median=True
if (do_we_dither.find('s') >= 0):
destripe=False
if (do_we_dither.find('m') >= 0):
manual_click=True
if (do_we_dither.find('d') >= 0):
dither = True
fileLists = []
cubeFiles = []
if (not os.path.exists(pp.aoinst.cdir + "CLEAN_COMPLETE")):
if instname=='NACO':
for i in range(len(fstart)):
files = []
for j in os.listdir(pp.aoinst.ddir):
if 'fit' in j:
hdr = pyfits.getheader(pp.aoinst.ddir+'/'+j)
if hdr['ESO TPL START']==fstart[i]:
files.append(pp.aoinst.ddir+'/'+j)
fileLists.append(files)
cubeFiles.append('cube'+fstart[i]+'.fits')
elif instname=='NIRC2':
fnums = [int(fstart[i])+np.arange(int(nfs[i])) for i in range(0,num_cubes)]
extn = '.fits'
for j in range(len(fnums)):
files = [('n{0:04d}' + extn).format(i) for i in fnums[j]]
cubeFiles.append('cube' + str(fnums[j][0]) + '.fits')
fileLists.append(files)
for i in range(num_cubes):
cube = pp.aoinst.clean_dithered(fileLists[i], subarr=192, out_file=cubeFiles[i], manual_click=manual_click, destripe=destripe, subtract_median=subtract_median, dither=dither)
with open(pp.aoinst.cdir + "CLEAN_COMPLETE","w+") as f:
f.close()