-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipedark.py
73 lines (56 loc) · 1.74 KB
/
pipedark.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
import math
import sys
import os
import numpy as np
from astropy.io import fits as pyfits
from extract_overscan import extract_overscan
from pipeutils import open_fits_file
inlist = str(sys.argv[1])
biasname = str(sys.argv[2])
darkname = str(sys.argv[3])
outdir = str(sys.argv[4])+'/'
biasname = outdir+biasname
os.system('rm -f '+outdir+'dsorted*')
def darkmaker():
with open_fits_file(biasname) as hdulist:
bias = hdulist[0].data
position = 0
i = 1
for line in file(inlist):
fname = outdir+'dsorted'+"{0:03d}".format(position)
f = open(fname, 'a')
f.write(line)
f.close()
if i == 50:
i = 0
position += 1
i += 1
os.system('ls '+outdir+'dsorted* >removeindexlist.dat')
i = 1
for line in file('removeindexlist.dat'):
datamatrix = []
mastermatrix = []
call = line.strip('\n')
for line in file(call):
line = line.strip()
with open_fits_file(line) as hdulist:
overscan = extract_overscan(hdulist)
data = hdulist[0].data[0:2048,20:2068]
exposure = hdulist[0].header['exposure']
corrected = (data-np.median(overscan)-bias)/exposure
datamatrix.append(corrected)
print np.shape(datamatrix)
master = np.median(datamatrix, axis=0)
print i
mastermatrix.append(master)
i += 1
print 'averaging'
print np.shape(mastermatrix)
dark = np.mean(mastermatrix, axis=0)
phdu = pyfits.PrimaryHDU(dark)
outname = outdir+darkname
command = 'rm -f '+outname
os.system(command)
phdu.writeto(outname)
os.system('rm -f removeindexlist.dat '+outdir+'dsorted*')
darkmaker()