source: datared/pre.py

Last change on this file was 11, checked in by meynadie, 16 years ago

Mise au point pre.py

  • Property svn:executable set to *
File size: 1.7 KB
Line 
1#!/bin/env python
2# coding: utf-8
3
4VERSION='1.2'
5
6# Version 1.2 : partie droite débute à 1086 et non 1087
7
8import pyfits
9from optparse import OptionParser
10
11import numpy
12from scipy import *
13
14parser = OptionParser()
15parser.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
21if (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
26hdulist = pyfits.open(args[0])
27scidata = hdulist[0].data
28
29# suppression prescan/overscan/bord de plage
30
31gauche = scidata[:2048,50:1074]
32droite = scidata[:2048,1086:2110]
33
34# Suppression du fond selon moyenne des overscans
35
36if options.nobias :
37    print "No bias substraction"
38else:
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
45scidata = numpy.hstack((gauche,droite))
46dim = scidata.shape
47
48# Pixel min = 0
49scidata = numpy.where(scidata<0,0,scidata)
50
51prihdr = hdulist[0].header
52prihdr.add_history('pre.py V'+VERSION)
53prihdr.add_history('Suppression os/ps')
54
55# Ajout du WCS
56prihdr.update('CRPIX1',1024,'crpix1')
57prihdr.update('CRPIX2',1024,'crpix2')
58prihdr.update('CRVAL1',0,'crval1')
59prihdr.update('CRVAL2',0,'crval2')
60prihdr.update('CD1_1',0,'crdelt1')
61prihdr.update('CD1_2',1.0593,'crdelt2')
62prihdr.update('CD2_1',-1.0593,'crota1')
63prihdr.update('CD2_2',0.0,'crota2')
64prihdr.update('CTYPE1',' ','ctype1')
65prihdr.update('CTYPE2',' ','ctype2')
66
67
68hdulist[0].data = scidata
69hdulist.writeto(args[1],clobber=True)
70
71
72hdulist.close()
Note: See TracBrowser for help on using the repository browser.