source: cherche_centre/03_suppr_fond.py

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

ajout scripts centrage

  • Property svn:executable set to *
File size: 1.0 KB
Line 
1#!/bin/env python
2# encoding: utf-8
3
4import pyfits
5from optparse import OptionParser
6
7import numpy
8from scipy import *
9
10parser = OptionParser()
11
12(options, args) = parser.parse_args ()
13
14if (len(args) != 2):
15    print "Usage : suppr_fond.py input.fits output.fits"
16    exit(1)
17
18# E# Ouverture de l'image fits en argument
19hdulist = pyfits.open(args[0])
20scidata = hdulist[0].data
21
22if (scidata.shape != (2048,2048)):
23    print "Erreur ! l'image ne fait pas 2048 x 2048 !"
24    exit(2)
25
26# Estimation fond (4 coins)
27tf = 256 # taille fenetre fond, en pix
28fond_bas = .5 * (mean(scidata[:tf,:tf]) + mean(scidata[:tf,2048-tf:]))
29fond_haut= .5 * (mean(scidata[2048-tf:,:tf]) + mean(scidata[2048-tf:,2048-tf:]))
30
31a = float(fond_haut - fond_bas) / (2048-tf)
32b = fond_haut - a * (2048 - tf/2.)
33
34fond=numpy.zeros((2048,2048))
35
36for i in range(2048):
37    fond[i,:] = a * i + b
38
39
40scidata -= fond
41
42prihdr = hdulist[0].header
43prihdr.add_history('Suppression fond gradient vertical')
44
45hdulist[0].data = scidata
46hdulist.writeto(args[1],clobber=True)
47
48
49hdulist.close()
Note: See TracBrowser for help on using the repository browser.