Bonjour je suis actuellement en projet de dut informatique et je programme en python3 et je doit dans mon application modifier le header mais ce la me provoque cette erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
Exception in Tkinter callback
Traceback (most recent call last):
  File "/home/rozenn/anaconda3/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
    return self.func(*args)
  File "/home/rozenn/Documents/cours/DeuxiemeAnnée/Projet de sythese/test/header.py", line 134, in valider
    with fits.open(ModifHeader.file_image, 'update') as f:
  File "/home/rozenn/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 151, in fitsopen
    lazy_load_hdus, **kwargs)
  File "/home/rozenn/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 390, in fromfile
    lazy_load_hdus=lazy_load_hdus, **kwargs)
  File "/home/rozenn/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 1064, in _readfrom
    read_one = hdulist._read_next_hdu()
  File "/home/rozenn/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 1139, in _read_next_hdu
    hdu = _BaseHDU.readfrom(fileobj, **kwargs)
  File "/home/rozenn/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/base.py", line 328, in readfrom
    **kwargs)
  File "/home/rozenn/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/base.py", line 475, in _readfrom_internal
    size = hdu.size
  File "/home/rozenn/anaconda3/lib/python3.7/site-packages/astropy/io/fits/hdu/base.py", line 951, in size
    size = abs(bitpix) * gcount * (pcount + size) // 8
TypeError: bad operand type for abs(): 'str'
Voici le code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 
classModifHeader:
# constructeur
header_info =""
file_image = ""
def__init__(self):
"le constructeur"
 
defpopup(self, headerTest, fileImage):
"""affiche dans une deuxieme fenetre le header
 
Parameters
----------
self :
headerTest : string
le header
fileImage : string
le chemin du fichier fit
"""
ModifHeader.file_image = fileImage
fInfos = Toplevel() # Popup -> Toplevel()
fInfos.title('Modifier header')
fInfos.config( bg="black")
cadre = Frame(fInfos, borderwidth=1,bg="black")
cadre.pack(fill=BOTH)
#le label contenant les info
scrollbarY = Scrollbar(cadre, activebackground ="white", bg="black", cursor="double_arrow", highlightbackground = "black", troughcolor ="black")
scrollbarY.pack(side=RIGHT, fill=Y)
scrollbarX = Scrollbar(cadre, orient='horizontal', activebackground ="white", bg="black", cursor="double_arrow", highlightbackground = "black", troughcolor ="black")
scrollbarX.pack(side=BOTTOM, fill=X)
ModifHeader.header_info = Text(cadre, bg="black",fg="white", cursor="xterm", insertbackground="white", undo="true", wrap='none', yscrollcommand=scrollbarY.set, xscrollcommand=scrollbarX.set)
 
scrollbarX.config(command=ModifHeader.header_info.xview)
ModifHeader.header_info.insert('1.0', repr(headerTest))
ModifHeader.header_info.pack(padx=10,pady=10)
#les bouton qui sont dans une frame
boutons = Frame(fInfos,borderwidth=1,bg="black")
boutons.pack(padx=10,pady=10,fill=X)
annuler = Button(boutons, text='Annuler',bg="black",fg="white", command=fInfos.destroy)
annuler.pack(side=RIGHT,padx=10,pady=10)
valider = Button(boutons, text='Valider',bg="black",fg="white", command=ModifHeader.valider)
valider.pack(side=LEFT,padx=10,pady=10)
 
defvalider():
"""Pour modifier le header
 
Parameters
----------
 
"""
contents = ModifHeader.header_info.get('1.0','end')#recupere le text ecrit par l'utilisateur
while( contents.find('\n') != -1):
posLigne = contents.find('\n') #recupeere ligne par ligne les information
ligne = contents[0:posLigne]
contents= contents[posLigne+1:len(contents)]
nom = ligne[0: (ligne.find("=")-1)]
contenu = ligne [(ligne.find("=")+1): len(ligne)]
#permet d'enregistrer mais ne marche pas
with fits.open(ModifHeader.file_image, 'update') as f:
for hdu in f:
hdu.header[nom]=contenu
showerror("header erreur", "Cette fonctionalité n'est pas disponible")


La fonction popup est appeler par la fenêtre redescente en passant par paramétre
hd.afficheHeaders(fits.open(file_image)) et file_image


pour info :file_image = filedialog.askopenfilename(initialdir=os.path.dirname(__file__) , filetypes = [("Fit(s) files", ("*.fit","*.fits")), ("Fits file", "*.fits"), ("Fit file", "*.fit")])

Si vous avez besoin de plus d'info pour m'aider hésiter pas merci d'avance pour votre reponse