1 | #!/bin/env python |
---|
2 | # coding: utf-8 |
---|
3 | |
---|
4 | VERSION='1.0' |
---|
5 | |
---|
6 | import pyfits |
---|
7 | from optparse import OptionParser |
---|
8 | |
---|
9 | import numpy |
---|
10 | |
---|
11 | |
---|
12 | parser = 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 | |
---|
21 | |
---|
22 | #print len(options.keys()) |
---|
23 | |
---|
24 | |
---|
25 | NX = 2160 |
---|
26 | NY = 2053 |
---|
27 | |
---|
28 | # Ouverture de l'image en mode lecture binaire (windows) |
---|
29 | try: |
---|
30 | f= open(options.InputFilename,'rb') |
---|
31 | except IOError : |
---|
32 | print "Impossible d'ouvrir l'image" |
---|
33 | exit (1) |
---|
34 | |
---|
35 | # Creation de l'array d'entiers non signés + byteswap |
---|
36 | a = numpy.fromfile(file=f, dtype=numpy.uint16, count=-1) |
---|
37 | a.byteswap(True) |
---|
38 | f.close() |
---|
39 | |
---|
40 | # dispatch des parties du binaire + conversion en signed int |
---|
41 | gauche = numpy.cast[numpy.int16](a[NX*NY/2:NX*NY]-32768) |
---|
42 | droite = numpy.cast[numpy.int16](a[:NX*NY/2]-32768) |
---|
43 | observables = numpy.cast[numpy.int16](a[-5:-1]-32768) |
---|
44 | |
---|
45 | # Construction de l'image (flip de la partie droite) |
---|
46 | b=numpy.empty(NX,dtype=numpy.int16) |
---|
47 | gauche.resize(NY,NX/2) |
---|
48 | droite.resize(NY,NX/2) |
---|
49 | b = numpy.hstack((gauche,numpy.fliplr(droite))) |
---|
50 | |
---|
51 | |
---|
52 | # Creation de l'objet fits |
---|
53 | hdu = pyfits.PrimaryHDU(b) |
---|
54 | hdulist = pyfits.HDUList([hdu]) |
---|
55 | |
---|
56 | prihdr = hdulist[0].header |
---|
57 | |
---|
58 | prihdr.update('BSCALE',1,'scale') |
---|
59 | prihdr.update('BZERO',32768,'origin of the scale') |
---|
60 | |
---|
61 | |
---|
62 | prihdr.update('OBS1',observables[0],'Observable 1') |
---|
63 | prihdr.update('OBS2',observables[1],'Observable 2') |
---|
64 | prihdr.update('OBS3',observables[2],'Observable 3') |
---|
65 | prihdr.update('OBS4',observables[3],'Observable 4') |
---|
66 | prihdr.update('Conv','pyraw2fits','Logiciel de conversion utilise') |
---|
67 | prihdr.update('ConvVer',VERSION,'Version de raw2fits') |
---|
68 | |
---|
69 | |
---|
70 | of = options.OutputFilename |
---|
71 | |
---|
72 | hdu.writeto(of,clobber=True) |
---|