source: pyraw2fits/pyraw2fits_old.py @ 26

Last change on this file since 26 was 6, checked in by meynadie, 12 years ago

Ajout d'un GUI, sauvegarde de l'ancien dans old

  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#!/bin/env python
2# coding: utf-8
3
4VERSION='1.0'
5
6import pyfits
7from optparse import OptionParser
8
9import numpy
10
11
12parser = OptionParser()
13##parser.add_option("-i","--input",dest="InputFilename",
14##                  help="Input filename (required)", metavar="RAWIMAGE")
15##parser.add_option("-o","--output",dest="OutputFilename",
16##                  help="Output Filename (required)", metavar="FITSIMAGE")
17
18
19(options, args) = parser.parse_args ()
20
21InputFilename = args[0]
22OutputFilename = InputFilename.replace('.dat','.fits')
23
24print InputFilename, OutputFilename
25
26#print len(options.keys())
27
28
29NX = 2160
30NY = 2053
31
32# Ouverture de l'image en mode lecture binaire (windows)
33try:
34    f= open(InputFilename,'rb')
35except IOError :
36    print "Impossible d'ouvrir l'image"
37    exit (1)
38
39# Creation de l'array d'entiers non signés + byteswap
40a = numpy.fromfile(file=f, dtype=numpy.uint16, count=-1)
41a.byteswap(True)
42f.close()
43
44# dispatch des parties du binaire + conversion en signed int
45gauche = numpy.cast[numpy.int16](a[NX*NY/2:NX*NY]-32768)
46droite = numpy.cast[numpy.int16](a[:NX*NY/2]-32768)
47observables = numpy.cast[numpy.int16](a[-5:-1]-32768)
48
49# Construction de l'image (flip de la partie droite)
50b=numpy.empty(NX,dtype=numpy.int16)
51gauche.resize(NY,NX/2)
52droite.resize(NY,NX/2)
53b = numpy.hstack((gauche,numpy.fliplr(droite)))
54
55
56# Creation de l'objet fits
57hdu = pyfits.PrimaryHDU(b)
58hdulist = pyfits.HDUList([hdu])
59
60prihdr = hdulist[0].header
61
62prihdr.update('BSCALE',1,'scale')
63prihdr.update('BZERO',32768,'origin of the scale')
64
65
66prihdr.update('OBS1',observables[0],'Observable 1')
67prihdr.update('OBS2',observables[1],'Observable 2')
68prihdr.update('OBS3',observables[2],'Observable 3')
69prihdr.update('OBS4',observables[3],'Observable 4')
70prihdr.update('Conv','pyraw2fits','Logiciel de conversion utilise')
71prihdr.update('ConvVer',VERSION,'Version de raw2fits')
72
73
74of = OutputFilename
75
76hdu.writeto(of,clobber=True)
Note: See TracBrowser for help on using the repository browser.