-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipered.py
68 lines (54 loc) · 2 KB
/
pipered.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
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
from functools import partial
from multiprocessing.dummy import Pool as ThreadPool
inlist = str(sys.argv[1])
biasname = str(sys.argv[2])
darkname = str(sys.argv[3])
flatname = str(sys.argv[5])
caldir = str(sys.argv[6])+'/'
outdir = str(sys.argv[7])+'/'
biasname = caldir+biasname
darkname = caldir+darkname
flatname = caldir+flatname
os.system('rm -f '+outdir+'processed.dat')
def reduce_file(filename, bias, dark, flat):
with open_fits_file(filename) 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-(dark*exposure))/flat
path, fname = os.path.split(filename)
outname = outdir+'proc'+fname.replace('.bz2', '')
print outname
hdulist[0].data = corrected
hdulist[0].header.add_history('Overscan of '+str(np.median(overscan))+' subtracted')
hdulist[0].header.add_history('Bias subtracted using '+str(biasname))
hdulist[0].header.add_history('Dark subtracted using '+str(darkname))
hdulist[0].header.add_history('Flat corrected using '+str(flatname))
command = 'rm -f '+outname
os.system(command)
hdulist.writeto(outname)
dfile = outdir+'processed.dat'
f = open(dfile, 'a')
f.write(outname)
f.close()
def reducer():
with open_fits_file(biasname) as hdulist:
bias = hdulist[0].data
with open_fits_file(darkname) as hdulist:
dark = hdulist[0].data
with open_fits_file(flatname) as hdulist:
flat = hdulist[0].data
pool = ThreadPool()
fn = partial(reduce_file, bias=bias, dark=dark, flat=flat)
with open(inlist) as infile:
filenames = [line.strip() for line in infile]
pool.map(fn, filenames)
if __name__ == '__main__':
reducer()