1 | #!/bin/env python |
---|
2 | # coding: utf-8 |
---|
3 | |
---|
4 | VERSION='1.2' |
---|
5 | |
---|
6 | # Version 1.2 : partie droite débute à 1086 et non 1087 |
---|
7 | |
---|
8 | import pyfits |
---|
9 | from optparse import OptionParser |
---|
10 | |
---|
11 | import numpy |
---|
12 | from scipy import * |
---|
13 | |
---|
14 | parser = OptionParser() |
---|
15 | parser.add_option("-n","--nobias",action="store_true", |
---|
16 | dest="nobias", default=False, |
---|
17 | help="no suppression of the bias (based on overscans)") |
---|
18 | |
---|
19 | (options, args) = parser.parse_args () |
---|
20 | |
---|
21 | if (len(args) !=2) : |
---|
22 | print "Usage : pre.py [-n --nobias] input.fits output.fits" |
---|
23 | exit(1) |
---|
24 | |
---|
25 | # Ouverture de l'image fits en argument |
---|
26 | hdulist = pyfits.open(args[0]) |
---|
27 | scidata = hdulist[0].data |
---|
28 | |
---|
29 | # suppression prescan/overscan/bord de plage |
---|
30 | |
---|
31 | gauche = scidata[:2048,50:1074] |
---|
32 | droite = scidata[:2048,1086:2110] |
---|
33 | |
---|
34 | # Suppression du fond selon moyenne des overscans |
---|
35 | |
---|
36 | if options.nobias : |
---|
37 | print "No bias substraction" |
---|
38 | else: |
---|
39 | bias_gauche = mean(scidata[:2048,:50])-10 |
---|
40 | bias_droite = mean(scidata[:2048,2110:])-10 |
---|
41 | print "Warning ! bias removed (%f / %f) " % (bias_gauche, bias_droite) |
---|
42 | gauche -= bias_gauche |
---|
43 | droite -= bias_droite |
---|
44 | |
---|
45 | scidata = numpy.hstack((gauche,droite)) |
---|
46 | dim = scidata.shape |
---|
47 | |
---|
48 | # Pixel min = 0 |
---|
49 | scidata = numpy.where(scidata<0,0,scidata) |
---|
50 | |
---|
51 | prihdr = hdulist[0].header |
---|
52 | prihdr.add_history('pre.py V'+VERSION) |
---|
53 | prihdr.add_history('Suppression os/ps') |
---|
54 | |
---|
55 | # Ajout du WCS |
---|
56 | prihdr.update('CRPIX1',1024,'crpix1') |
---|
57 | prihdr.update('CRPIX2',1024,'crpix2') |
---|
58 | prihdr.update('CRVAL1',0,'crval1') |
---|
59 | prihdr.update('CRVAL2',0,'crval2') |
---|
60 | prihdr.update('CD1_1',0,'crdelt1') |
---|
61 | prihdr.update('CD1_2',1.0593,'crdelt2') |
---|
62 | prihdr.update('CD2_1',-1.0593,'crota1') |
---|
63 | prihdr.update('CD2_2',0.0,'crota2') |
---|
64 | prihdr.update('CTYPE1',' ','ctype1') |
---|
65 | prihdr.update('CTYPE2',' ','ctype2') |
---|
66 | |
---|
67 | |
---|
68 | hdulist[0].data = scidata |
---|
69 | hdulist.writeto(args[1],clobber=True) |
---|
70 | |
---|
71 | |
---|
72 | hdulist.close() |
---|