#!/bin/env python # coding: utf-8 VERSION='1.0' import pyfits from optparse import OptionParser import numpy parser = OptionParser() ##parser.add_option("-i","--input",dest="InputFilename", ## help="Input filename (required)", metavar="RAWIMAGE") ##parser.add_option("-o","--output",dest="OutputFilename", ## help="Output Filename (required)", metavar="FITSIMAGE") (options, args) = parser.parse_args () InputFilename = args[0] OutputFilename = InputFilename.replace('.dat','.fits') print InputFilename, OutputFilename #print len(options.keys()) NX = 2160 NY = 2053 # Ouverture de l'image en mode lecture binaire (windows) try: f= open(InputFilename,'rb') except IOError : print "Impossible d'ouvrir l'image" exit (1) # Creation de l'array d'entiers non signés + byteswap a = numpy.fromfile(file=f, dtype=numpy.uint16, count=-1) a.byteswap(True) f.close() # dispatch des parties du binaire + conversion en signed int gauche = numpy.cast[numpy.int16](a[NX*NY/2:NX*NY]-32768) droite = numpy.cast[numpy.int16](a[:NX*NY/2]-32768) observables = numpy.cast[numpy.int16](a[-5:-1]-32768) # Construction de l'image (flip de la partie droite) b=numpy.empty(NX,dtype=numpy.int16) gauche.resize(NY,NX/2) droite.resize(NY,NX/2) b = numpy.hstack((gauche,numpy.fliplr(droite))) # Creation de l'objet fits hdu = pyfits.PrimaryHDU(b) hdulist = pyfits.HDUList([hdu]) prihdr = hdulist[0].header prihdr.update('BSCALE',1,'scale') prihdr.update('BZERO',32768,'origin of the scale') prihdr.update('OBS1',observables[0],'Observable 1') prihdr.update('OBS2',observables[1],'Observable 2') prihdr.update('OBS3',observables[2],'Observable 3') prihdr.update('OBS4',observables[3],'Observable 4') prihdr.update('Conv','pyraw2fits','Logiciel de conversion utilise') prihdr.update('ConvVer',VERSION,'Version de raw2fits') of = OutputFilename hdu.writeto(of,clobber=True)