Index: /cherche_centre/00_traiter_tout_dat.py
===================================================================
--- /cherche_centre/00_traiter_tout_dat.py	(revision 28)
+++ /cherche_centre/00_traiter_tout_dat.py	(revision 28)
@@ -0,0 +1,54 @@
+#!/bin/env python
+# coding: utf-8
+
+import glob
+import os
+import subprocess as sp
+import sys
+import datetime
+
+pwd = sys.path[0]
+
+log = open("./05_resultat.txt",'w')
+
+threshold = 0.5
+width = 5
+
+outs = "# %s\n" % (datetime.datetime.now().isoformat())
+log.write(outs)
+outs = "# Nom Fichier / rayon x / centre x / rayon y / centre y / intensitÃ© centrale / '*' si problÃšme\n"
+log.write(outs)
+outs = "# Seuil dÃ©tection bord (par rapport au max) = %f\n" % (threshold) 
+log.write(outs)
+outs = "# largeur fenÃªtre pour intensitÃ© moyenne au centre = %f\n" % (2*width +1) 
+log.write(outs)
+
+log.flush()
+
+for filename in glob.glob("*.dat"):
+    print filename
+    # On obtient le "basename" (i.e. le nom de fichier moins '.dat')
+    bn = filename[:-4]
+    os.system('python %s/01_pyraw2fits.py -n %s' % (pwd,
+                                                    filename))
+    os.system('python %s/02_prepare.py %s %s' % (pwd,
+                                                 bn+'.fits',
+                                                 bn+'_02.fits'))
+    os.system('python %s/03_suppr_fond.py %s %s' % (pwd,
+                                                    bn+'_02.fits',
+                                                    bn+'_03.fits'))
+    buf = sp.Popen('python %s/04_cherche_centre.py -t %f -w %i %s' %\
+                   (pwd,
+                    threshold,
+                    width,
+                    bn+'_03.fits'),
+                   shell=True,
+                   stdout=log)
+    # Le lignes suivantes effacent les fichiers gÃ©nÃ©rÃ©s
+    # Commenter si besoin
+    # os.remove(bn+'.fits')
+    os.remove(bn+'_02.fits')
+    # os.remove(bn+'_03.fits')
+    
+log.close()
+
Index: /cherche_centre/01_pyraw2fits.py
===================================================================
--- /cherche_centre/01_pyraw2fits.py	(revision 28)
+++ /cherche_centre/01_pyraw2fits.py	(revision 28)
@@ -0,0 +1,249 @@
+#!/usr/bin/python
+# -*- coding: iso-8859-1 -*-
+# Un utilitaire pour transformer les données CCD PICARD en images fits
+# Frédéric Meynadier /  Service d'Aéronomie, Mai 2008
+
+VERSION='2.0'
+
+
+import pyfits
+import Tkinter
+from Tkconstants import END
+import numpy
+
+from optparse import OptionParser
+import datetime
+import time
+
+def raw2fits(InputFilename,headers,comments):
+    OutputFilename = InputFilename.replace('.dat','.fits')
+
+    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')
+
+    for item in headers:
+        prihdr.update(item['key'],item['value'],item['comment'])
+
+    for item in comments:
+        prihdr.add_comment(item)
+
+    of = OutputFilename
+
+    hdu.writeto(of,clobber=True)
+
+
+class simpleapp_tk(Tkinter.Tk):
+    def __init__(self,parent):
+        Tkinter.Tk.__init__(self,parent)
+        self.parent = parent
+        self.initialize()
+
+    def initialize(self):
+        self.grid()
+
+        self.labelexptimeVariable = Tkinter.StringVar()
+        self.labelexptimeVariable.set("Temps de pose (s) :")
+        labelexptime = Tkinter.Label(self,textvariable=self.labelexptimeVariable, anchor="w")
+        labelexptime.grid(column=0,columnspan=2,row=1)
+
+        self.exptimeVariable = Tkinter.StringVar()
+        self.exptime = Tkinter.Entry(self,textvariable=self.exptimeVariable)
+        self.exptime.grid(column=0,columnspan=2,row=2,sticky='EW')
+        self.exptimeVariable.set(u"")
+        
+
+        self.labelrf1Variable = Tkinter.StringVar()
+        self.labelrf1Variable.set("RF1 :")
+        labelrf1 = Tkinter.Label(self,textvariable=self.labelrf1Variable,
+                                 anchor="w")
+        labelrf1.grid(column=0,row=3)
+
+        self.rf1 = Tkinter.Listbox(self,height=5,width=8,exportselection=0)
+        self.rf1.pack()
+        for item in ['trou',
+                     '535',
+                     '607',
+                     '215',
+                     '782']:
+            self.rf1.insert(END,item)
+        self.rf1.grid(column=0,row=4)
+        
+        self.labelrf2Variable = Tkinter.StringVar()
+        self.labelrf2Variable.set("RF2 :")
+        labelrf2 = Tkinter.Label(self,textvariable=self.labelrf2Variable,
+                                 anchor="w")
+        labelrf2.grid(column=1,row=3)
+
+        self.rf2 = Tkinter.Listbox(self,height=5,width=8,exportselection=0)
+        self.rf2.pack()
+        for item in ['535h',
+                     'trou',
+                     'dioptre',
+                     'lentille',
+                     '393']:
+            self.rf2.insert(END,item)
+        self.rf2.grid(column=1,row=4)
+
+        self.labelcommentVariable = Tkinter.StringVar()
+        self.labelcommentVariable.set("commentaire :")
+        labelcomment = Tkinter.Label(self,textvariable=self.labelcommentVariable, anchor="w")
+        labelcomment.grid(column=0,columnspan=2,row=5)
+
+        self.commentVariable = Tkinter.StringVar()
+        self.comment = Tkinter.Entry(self,textvariable=self.commentVariable)
+        self.comment.grid(column=0,columnspan=2,row=6,sticky='EW')
+        self.commentVariable.set(u"")
+
+
+        self.labelnameVariable = Tkinter.StringVar()
+        self.labelnameVariable.set("Nom du fichier :")
+        label = Tkinter.Label(self,textvariable=self.labelnameVariable,
+                              anchor="w")
+        label.grid(column=0,row=7,columnspan=2,sticky='EW')
+
+        self.entryVariable = Tkinter.StringVar()
+        self.entry = Tkinter.Entry(self,textvariable=self.entryVariable)
+        self.entry.grid(column=0,columnspan=2,row=8,sticky='EW')
+        self.entry.bind("<Return>", self.OnPressEnter)
+        self.entryVariable.set(u"")
+
+
+
+
+
+        button = Tkinter.Button(self,
+                                text="Convertir en fits",
+                                command=self.OnButtonClick)
+        button.grid(column=0,columnspan=2,row=9)
+
+        self.labelVariable = Tkinter.StringVar()
+        label = Tkinter.Label(self,textvariable=self.labelVariable,
+                              anchor="w",fg="white",bg="blue")
+        label.grid(column=0,row=10,columnspan=2,sticky='EW')
+        self.labelVariable.set(u"")
+
+
+
+        self.grid_columnconfigure(0,weight=1)
+        self.resizable(True,False)
+        self.update()
+        self.geometry(self.geometry())
+        self.entry.focus_set()
+        self.entry.selection_range(0, Tkinter.END)
+
+
+    def CommonAction(self):
+        rf1setting = self.rf1.get(self.rf1.curselection()[0])
+        rf2setting = self.rf2.get(self.rf2.curselection()[0])
+
+        exptime = self.exptimeVariable.get()
+        if (exptime == ''):
+            exptime = 0.
+        
+        InputFilename = self.entryVariable.get()
+        print InputFilename
+        OutputFilename = InputFilename.replace(".dat",".fits")
+        self.labelVariable.set("Ecriture de " + OutputFilename)
+        headers=[]
+        headers.append({'key':'EXPTIME',
+                        'value':float(exptime),
+                        'comment':'Temps de pose'})
+        headers.append({'key':'RF1FILT',
+                        'value':rf1setting,
+                        'comment':'filtre roue 1'})
+        headers.append({'key':'RF2FILT',
+                        'value':rf2setting,
+                        'comment':'filtre roue 2'})
+        headers.append({'key':'CNVDATE',
+                        'value':datetime.date.today().isoformat(),
+                        'comment':'Date de la conversion fits'})
+        headers.append({'key':'CNVTIME',
+                        'value':time.strftime("%H:%M:%S"),
+                        'comment':'Heure de la conversion fits'})
+
+
+        comments=[]
+        commentaire = self.commentVariable.get()
+        if (commentaire != '') :
+            comments.append(commentaire)
+        raw2fits(InputFilename,headers,comments)
+        
+        
+    def OnButtonClick(self):
+        self.CommonAction()
+        self.entry.focus_set()
+        self.entry.selection_range(0, Tkinter.END)
+
+    def OnPressEnter(self,event):
+        self.CommonAction()
+        self.entry.focus_set()
+        self.entry.selection_range(0, Tkinter.END)
+
+
+        
+
+if __name__ == "__main__":
+
+    parser = OptionParser()
+    parser.add_option("-n","--nogui",action="store_true",
+                      dest="nogui", default=False,
+                      help="command line only, no gui")
+                      
+    (options, args) = parser.parse_args ()
+
+    if options.nogui:
+        InputFilename=args[0]
+        headers=[]
+        comments=[]
+        raw2fits(InputFilename,headers,comments)
+
+    else:
+        app = simpleapp_tk(None)
+        app.title('raw2fits')
+        app.mainloop()
+
+
+
Index: /cherche_centre/02_prepare.py
===================================================================
--- /cherche_centre/02_prepare.py	(revision 28)
+++ /cherche_centre/02_prepare.py	(revision 28)
@@ -0,0 +1,72 @@
+#!/bin/env python
+# coding: utf-8
+
+VERSION='1.2'
+
+# Version 1.2 : partie droite dÃ©bute Ã  1086 et non 1087
+
+import pyfits
+from optparse import OptionParser
+
+import numpy
+from scipy import *
+
+parser = OptionParser()
+parser.add_option("-n","--nobias",action="store_true",
+                  dest="nobias", default=False,
+                  help="no suppression of the bias (based on overscans)")
+
+(options, args) = parser.parse_args ()
+
+if (len(args) !=2) :
+    print "Usage : pre.py [-n --nobias] input.fits output.fits"
+    exit(1)
+
+# Ouverture de l'image fits en argument
+hdulist = pyfits.open(args[0])
+scidata = hdulist[0].data
+
+# suppression prescan/overscan/bord de plage
+
+gauche = scidata[:2048,50:1074]
+droite = scidata[:2048,1086:2110]
+
+# Suppression du fond selon moyenne des overscans
+
+if options.nobias :
+    print "No bias substraction"
+else:
+    bias_gauche = mean(scidata[:2048,:50])-10
+    bias_droite = mean(scidata[:2048,2110:])-10
+    print "Warning ! bias removed (%f / %f) " % (bias_gauche, bias_droite)
+    gauche -= bias_gauche
+    droite -= bias_droite
+
+scidata = numpy.hstack((gauche,droite))
+dim = scidata.shape
+
+# Pixel min = 0
+scidata = numpy.where(scidata<0,0,scidata)
+
+prihdr = hdulist[0].header
+prihdr.add_history('pre.py V'+VERSION)
+prihdr.add_history('Suppression os/ps')
+
+# Ajout du WCS
+prihdr.update('CRPIX1',1024,'crpix1')
+prihdr.update('CRPIX2',1024,'crpix2')
+prihdr.update('CRVAL1',0,'crval1')
+prihdr.update('CRVAL2',0,'crval2')
+prihdr.update('CD1_1',0,'crdelt1')
+prihdr.update('CD1_2',1.0593,'crdelt2')
+prihdr.update('CD2_1',-1.0593,'crota1')
+prihdr.update('CD2_2',0.0,'crota2')
+prihdr.update('CTYPE1',' ','ctype1')
+prihdr.update('CTYPE2',' ','ctype2')
+
+
+hdulist[0].data = scidata
+hdulist.writeto(args[1],clobber=True)
+
+
+hdulist.close()
Index: /cherche_centre/03_suppr_fond.py
===================================================================
--- /cherche_centre/03_suppr_fond.py	(revision 28)
+++ /cherche_centre/03_suppr_fond.py	(revision 28)
@@ -0,0 +1,49 @@
+#!/bin/env python
+# encoding: utf-8
+
+import pyfits
+from optparse import OptionParser
+
+import numpy
+from scipy import *
+
+parser = OptionParser()
+
+(options, args) = parser.parse_args ()
+
+if (len(args) != 2):
+    print "Usage : suppr_fond.py input.fits output.fits"
+    exit(1)
+
+# E# Ouverture de l'image fits en argument
+hdulist = pyfits.open(args[0])
+scidata = hdulist[0].data
+
+if (scidata.shape != (2048,2048)):
+    print "Erreur ! l'image ne fait pas 2048 x 2048 !"
+    exit(2)
+
+# Estimation fond (4 coins)
+tf = 256 # taille fenetre fond, en pix
+fond_bas = .5 * (mean(scidata[:tf,:tf]) + mean(scidata[:tf,2048-tf:]))
+fond_haut= .5 * (mean(scidata[2048-tf:,:tf]) + mean(scidata[2048-tf:,2048-tf:]))
+
+a = float(fond_haut - fond_bas) / (2048-tf)
+b = fond_haut - a * (2048 - tf/2.)
+
+fond=numpy.zeros((2048,2048))
+
+for i in range(2048):
+    fond[i,:] = a * i + b
+
+
+scidata -= fond
+
+prihdr = hdulist[0].header
+prihdr.add_history('Suppression fond gradient vertical')
+
+hdulist[0].data = scidata
+hdulist.writeto(args[1],clobber=True)
+
+
+hdulist.close()
Index: /cherche_centre/04_cherche_centre.py
===================================================================
--- /cherche_centre/04_cherche_centre.py	(revision 28)
+++ /cherche_centre/04_cherche_centre.py	(revision 28)
@@ -0,0 +1,100 @@
+#!/bin/env python
+# encoding: utf-8
+
+import pyfits
+from optparse import OptionParser
+
+import numpy
+from scipy import *
+
+parser = OptionParser()
+
+parser.add_option("-t","--threshold",dest="threshold", default=0.5,
+                  help="threshold for edge detection (relative to max, default 0.5)")
+
+parser.add_option("-w","--width",dest="hw_fen_int", default=5,
+                  help="window for measuring central intensity, size will be 2*hw_fen_int+1")
+
+(options, args) = parser.parse_args ()
+
+if (len(args) != 1):
+    print "Usage : cherche_centre.py [-t threshold] [-w width] image.fits"
+    exit(1)
+
+
+# Ouverture de l'image fits en argument
+hdulist = pyfits.open(args[0])
+scidata = hdulist[0].data
+
+
+# Estimation fond (4 coins)
+tf = 256 # taille fond, en pix
+fond_bas = .5 * (mean(scidata[:tf,:tf]) + mean(scidata[:tf,2048-tf:]))
+fond_haut= .5 * (mean(scidata[2048-tf:,:tf]) + mean(scidata[2048-tf:,2048-tf:]))
+
+
+if (abs(fond_haut - fond_bas) > .5 * (fond_haut + fond_bas) ):
+    print "Ereur : offsets dÃ©sÃ©quilibrÃ©s. Corriger le fond."
+    exit(3)
+
+def filtre_median(profil,hw):
+    tmp = numpy.zeros(2048)
+    for i in range(hw,2048-hw-1):
+        tmp[i] = median(profil[i-hw:i+hw+1])
+    return tmp
+
+# Moyenne suivant lignes et colonnes
+moyenne_h = filtre_median(sum(scidata, axis=0) / 2048.,5) 
+moyenne_v = filtre_median(sum(scidata, axis=1) / 2048.,5)
+
+
+
+of = open("profils"+args[0][:-5]+".csv",'w')
+for i in range(2048):
+    of.write("%4i %f %f\n" % (i, moyenne_h[i], moyenne_v[i]))
+of.close()
+
+def get_rayon_centre(profil):
+    # DÃ©termination du seuil, ici 10%
+    seuil = max(profil) * float(options.threshold)
+    # MÃ©thode bÃªte
+    bord1 = 0
+    for i in range(2047):
+        if ((profil[i] < seuil) and (profil[i+1] >= seuil)):
+            bord1 = i
+
+    bord2 = 2048
+    for i in range(2047,1,-1):
+        if((profil[i] < seuil) and (profil[i-1] >= seuil)):
+            bord2 = i
+
+    flag=""
+    if ((bord1 == 0) or (bord2 == 2048)) :
+        flag = "*"
+        print "Attention ! un seul bord dÃ©tectÃ© !"
+        rayon = 0
+        centre = 0
+    else:
+        rayon = (bord2 - bord1) / 2.
+        centre = (bord1 + bord2) / 2.
+    return (rayon,centre,flag)
+
+
+(rayon_h,centre_h,flag) = get_rayon_centre(moyenne_h)
+(rayon_v,centre_v,flag) = get_rayon_centre(moyenne_v)
+
+
+hw_fen_int = int(options.hw_fen_int)
+
+int_centre = sum(sum(scidata[int(centre_v)-hw_fen_int:int(centre_v)+hw_fen_int+1,
+                             int(centre_h)-hw_fen_int:int(centre_h)+hw_fen_int+1]))/((2*hw_fen_int + 1)**2)
+                             
+
+
+print "%13s %4i %6.1f %4i %6.1f %6.0f %1s" % (args[0],
+                                              rayon_h,
+                                              centre_h+1, # fits commence Ã  1
+                                              rayon_v,
+                                              centre_v+1, # fits commence Ã  1
+                                              int_centre,
+                                              flag)
Index: /mire/mire.sex
===================================================================
--- /mire/mire.sex	(revision 27)
+++ /mire/mire.sex	(revision 28)
@@ -16,5 +16,5 @@
 THRESH_TYPE      RELATIVE       # threshold type: RELATIVE (in sigmas)
                                 # or ABSOLUTE (in ADUs)
-DETECT_THRESH    10            # <sigmas> or <threshold>,<ZP> in mag.arcsec-2
+DETECT_THRESH    5             # <sigmas> or <threshold>,<ZP> in mag.arcsec-2
 ANALYSIS_THRESH  10            # <sigmas> or <threshold>,<ZP> in mag.arcsec-2
  
@@ -61,5 +61,5 @@
 MAG_GAMMA        4.0            # gamma of emulsion (for photographic scans)
 GAIN             0.0            # detector gain in e-/ADU
-PIXEL_SCALE      0.944          # size of pixel in arcsec (0=use FITS WCS info)
+PIXEL_SCALE      0              # size of pixel in arcsec (0=use FITS WCS info)
  
 #------------------------- Star/Galaxy Separation ----------------------------
Index: /mire/mire.sh
===================================================================
--- /mire/mire.sh	(revision 27)
+++ /mire/mire.sh	(revision 28)
@@ -21,4 +21,5 @@
 CATALOG=$(basename $1 .fits).cat
 OUTPUT_FITS=$(basename $1 .fits)_sf.fits
+OUTPUT_RING=$(basename $1 .fits).ring
 
 if test $skip_sextractor == false
@@ -33,5 +34,5 @@
 echo "Mesures gÃ©omÃ©triques..."
 OUTPUT_FILENAME=$(basename $1 .fits).mes
-python $PATH_TO_MIRE/process.py -c $CATALOG -r $2 -o $OUTPUT_FITS -m $OUTPUT_FILENAME -t $3
+python $PATH_TO_MIRE/process.py -c $CATALOG -r $2 -o $OUTPUT_FITS -m $OUTPUT_FILENAME -t $3 --ring $OUTPUT_RING
 
 
Index: /mire/mire_all.sh
===================================================================
--- /mire/mire_all.sh	(revision 27)
+++ /mire/mire_all.sh	(revision 28)
@@ -14,4 +14,5 @@
 
 rm -f collect
+rm -f *.mes
 for file in *_0.fits; do
     if test $skip_sextractor == true
@@ -24,4 +25,3 @@
     done;
 
-
-
+moyenne_ring.py > moyenne_ring
Index: /mire/process.py
===================================================================
--- /mire/process.py	(revision 27)
+++ /mire/process.py	(revision 28)
@@ -24,4 +24,7 @@
                   default="output.mes",
                   help="Name of the output measurement file")
+parser.add_option("--ring",dest="ring",
+                  default="output.ring",
+                  help="Name of the output measurement file")
 parser.add_option("-t","--timing",dest="timing",
                   help="Name of the input timing file")
@@ -84,11 +87,16 @@
     for source in catalog:
         pos_source = array([source['X_IMAGE'],source['Y_IMAGE']])
-        if ((modulus(rep[i,:] - pos_source)) < 5):
+        max_dist = 5 # pixels
+        if ((modulus(rep[i,:] - pos_source)) < max_dist):
+            max_dist = modulus(rep[i,:] - pos_source)
             detections +=1
             real_rep[i,:] = pos_source
-    if (detections !=1):
+    if (detections > 1):
         print "Attention ! ambiguÃ¯tÃ© pour repÃšre ",i,\
               ", nb de dÃ©tections :",detections
         
+    if (detections ==0):
+        print "Erreur ! Pas de dÃ©tection pour repÃšre ",i
+        exit (2)
 
 # DÃ©termination du centre : barycentre des 4 repÃšres
@@ -173,5 +181,5 @@
             if (nb_voisin > 0):
                 catalog[knot_idx]['MEAN_DIST_TO_NGBRS'] = float(distance)/weights
-                lookup_sources[i,j,3] = float(distance)/weights
+                lookup_sources[i,j,3] = 60./ (float(distance)/weights)
         
 cleaned_catalog = []
@@ -250,5 +258,5 @@
 
 a = lookup_sources[:,:,3]
-            
+
 hdu = pyfits.PrimaryHDU(a)
 hdulist = pyfits.HDUList([hdu])
@@ -268,11 +276,77 @@
 
 meas.write("# Moyenne des mesures /  Module vec_i /  Module vec_j / deltaT (min) / date\n")
-outs = "%7.4f %7.4f %7.4f %7.3f %s\n" % (sum(tmp)/len(tmp),
-                                         modulus(vec_i),
-                                         modulus(vec_j),
-                                         phase,
-                                         dt.isoformat())
+# transfo pixels / arcminutes -> mas / pixel
+moyenne_mesures = 60 * (1. / (sum(tmp)/len(tmp)))
+module_veci = 60 * (1. /  modulus(vec_i))
+module_vecj = 60 * (1. /  modulus(vec_j))
+
+outs = "%10.7f %10.7f %10.7f %7.3f %s\n" % (moyenne_mesures,
+                                            module_veci,
+                                            module_vecj,
+                                            phase,
+                                            dt.isoformat())
 meas.write(outs)
 
 meas.close()
 
+## Facteur d'Ã©chelle par rapport au centre du champ sur une couronne
+## reprÃ©sentative du diamÃštre solaire
+
+# Quel noeud est (Ã  peu prÃšs) au centre ?
+
+
+dist_mini = 2048
+i_centre = 0
+for i in range(len(cleaned_catalog)):
+    source = cleaned_catalog[i]
+    dist = modulus([source["X_IMAGE"] - 1024, source["Y_IMAGE"] - 1024])
+    if (dist < dist_mini):
+        dist_mini = dist
+        i_centre = i
+
+#print "Source au centre : ",cleaned_catalog[i_centre]
+
+# On parcourt une couronne de noeuds et on calcule le facteur d'Ã©chelle pour chacun
+
+rmin = 14 # en inter-noeud
+rmax = 18 # en inter-noeud
+
+source_centrale = cleaned_catalog[i_centre]
+
+couronne=[]
+
+for source in cleaned_catalog:
+    tmp = {}
+    dist_knots = modulus([source["I_GRID"] - source_centrale["I_GRID"],
+                          source["J_GRID"] - source_centrale["J_GRID"]])
+    x_rel = source["X_IMAGE"] - source_centrale["X_IMAGE"]
+    y_rel = source["Y_IMAGE"] - source_centrale["Y_IMAGE"]
+    dist_pix = modulus([x_rel,y_rel])
+    if ((dist_knots >= rmin) and (dist_knots <= rmax)):
+        tmp['ScFact'] = dist_knots * 60. / dist_pix # arcsec / pix
+        tmp['r'] = dist_pix
+        tmp['theta'] = math.atan(y_rel/x_rel)
+        if (x_rel < 0):
+            tmp['theta']+=math.pi
+        if (tmp['theta'] < 0):
+            tmp['theta'] += 2*math.pi
+        if (tmp['theta'] >= 2*math.pi):
+            tmp['theta'] -= 2*math.pi
+        couronne.append(tmp)
+
+output_couronne = file(options.ring,'w')
+
+outs = "# phase: %f date: %s\n" % (phase,
+                                 dt.isoformat())
+output_couronne.write(outs)
+
+for source in couronne:
+    outs = "%f %f %10.7f\n" % (source['r'],
+                               math.degrees(source['theta']),
+                               source['ScFact'])
+    output_couronne.write(outs)
+
+
+
+output_couronne.close()
+        
