-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipebias.py
64 lines (53 loc) · 1.57 KB
/
pipebias.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
import math
import sys
import os
import numpy as np
from extract_overscan import extract_overscan
from pipeutils import open_fits_file
from astropy.io import fits
inlist = str(sys.argv[1])
biasname = str(sys.argv[2])
outdir = str(sys.argv[3])+'/'
os.system('rm -f '+outdir+'bsorted*')
def biasmaker():
os.system('mkdir '+outdir)
position = 0
i = 1
for line in file(inlist):
fname = outdir+'bsorted'+"{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+'bsorted* >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]
corrected = data-np.median(overscan)
datamatrix.append(corrected)
print 'medianing'
print np.shape(datamatrix)
master = np.median(datamatrix, axis=0)
print i
mastermatrix.append(master)
i += 1
print 'averaging'
print np.shape(mastermatrix)
bias = np.mean(mastermatrix, axis=0)
phdu = fits.PrimaryHDU(bias)
outname = outdir+biasname
command = 'rm -f '+outname
os.system(command)
phdu.writeto(outname)
os.system('rm -f '+outdir+'bsorted* removeindexlist.dat')
biasmaker()