[RESOLU] Python - Problème - WCS avec un fichier calibré par Prism

Le fil de ce forum est dédié aux fonctions d'observatoire virtuel comme Colibri, ou SAMP.
On trouvera ici des tutos.
Répondre
Marc DELDEM
Messages : 1304
Enregistré le : 20 juin 2009, 01:01

[RESOLU] Python - Problème - WCS avec un fichier calibré par Prism

Message par Marc DELDEM »

Bonsoir les utilisateurs de Python,

J'ai un problème.
Si je pars d'une image CPA qui a été calibrée en astrométrie par Prism, puis je la converties en FITS.
Autant quand j'ouvre l'image FITS dans Aladin, tout fonctionne, Aladin voit bien que l'image est calibrée en astrométrie.

Mais si j'essaye de faire le code python ci-dessous, cela plante au niveau du constructeur WCS :

Code : Tout sélectionner

from astropy.io import fits
from astropy.wcs import WCS
from astropy.coordinates import SkyCoord


filename = "./data/t_PNV J06483343+0656236-001.fits"
print(f"\nTraitement de {filename}")

# https://www.aavso.org/vsx/index.php?view=detail.top&oid=399830
# PNV J06483343+0656236
# J2000.0 : 06 48 33.47 +06 56 23.2 (102.13946 +6.93978)
ra = 102.13946
dec = +6.93978
target_coord = SkyCoord(ra, dec, frame='icrs', unit='deg')

with fits.open(filename) as hdul:
    data = hdul[0].data
    header = hdul[0].header

wcs = WCS(header)
x_target, y_target = wcs.world_to_pixel(target_coord)
print(f"\nTarget: X={x_target}, Y={y_target}")

Le résultat :
Traitement de ./data/t_PNV J06483343+0656236-001.fits
WARNING: VerifyWarning: Verification reported errors: [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PPLATESD' is not FITS standard (invalid value string: 'TRUE / PRISM plate solved'). Fixed 'PPLATESD' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Note: astropy.io.fits uses zero-based indexing.
[astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'P3DSPHER' is not FITS standard (invalid value string: 'TRUE / PRISM 3Dspheric_Astrom'). Fixed 'P3DSPHER' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PRA_REF' is not FITS standard (invalid value string: '3FFC84C2485B57CF / plate solved RA'). Fixed 'PRA_REF' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PDEC_REF' is not FITS standard (invalid value string: 'BFBF0819A0AC1814 / plate solved DEC'). Fixed 'PDEC_REF' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PRADIUSX' is not FITS standard (invalid value string: '40F63E9408C1C96F / plate solved X Radius'). Fixed 'PRADIUSX' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PRADIUSY' is not FITS standard (invalid value string: '40F63E9408C1C96F / plate solved Y Radius'). Fixed 'PRADIUSY' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PCYASTRO' is not FITS standard (invalid value string: '407FE00000000000 / plate solved Y pos'). Fixed 'PCYASTRO' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLRA1' is not FITS standard (invalid value string: 'BFB306E2AD3D1170'). Fixed 'PSOLRA1' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLDC1' is not FITS standard (invalid value string: '3FEF8876D68DB0A1'). Fixed 'PSOLDC1' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLX1' is not FITS standard (invalid value string: '3FAE620D78121C0B'). Fixed 'PSOLX1' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLY1' is not FITS standard (invalid value string: 'BFEFC1FF4E3735E6'). Fixed 'PSOLY1' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLRA2' is not FITS standard (invalid value string: 'BF8F5D47C76F3821'). Fixed 'PSOLRA2' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLDC2' is not FITS standard (invalid value string: '3FEFCAE9E624DBED'). Fixed 'PSOLDC2' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLX2' is not FITS standard (invalid value string: '3F8FC5437C255C77'). Fixed 'PSOLX2' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLY2' is not FITS standard (invalid value string: '3FF019B699A6582F'). Fixed 'PSOLY2' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLRA3' is not FITS standard (invalid value string: '3FEFC9872E726F73'). Fixed 'PSOLRA3' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLDC3' is not FITS standard (invalid value string: '3F900098E27EFC13'). Fixed 'PSOLDC3' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLX3' is not FITS standard (invalid value string: '3FF01A6BD7B1576A'). Fixed 'PSOLX3' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLY3' is not FITS standard (invalid value string: 'BF9035E76C5C844D'). Fixed 'PSOLY3' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLRA4' is not FITS standard (invalid value string: '3EA46ED2A193B119'). Fixed 'PSOLRA4' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLDC4' is not FITS standard (invalid value string: '3E8A388F23141392'). Fixed 'PSOLDC4' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLX4' is not FITS standard (invalid value string: 'BEA5F6364856AB40'). Fixed 'PSOLX4' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLY4' is not FITS standard (invalid value string: 'BE898273C6FC5F6F'). Fixed 'PSOLY4' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLRA5' is not FITS standard (invalid value string: '3EA4CCB2321DD486'). Fixed 'PSOLRA5' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLDC5' is not FITS standard (invalid value string: '3E7C0C10FDC53788'). Fixed 'PSOLDC5' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLX5' is not FITS standard (invalid value string: 'BEA4EBEAC95C8504'). Fixed 'PSOLX5' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLY5' is not FITS standard (invalid value string: 'BE791EBC3B1F78F2'). Fixed 'PSOLY5' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLRA6' is not FITS standard (invalid value string: 'BE98621155843865'). Fixed 'PSOLRA6' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLDC6' is not FITS standard (invalid value string: '3E6A89498FE3AF28'). Fixed 'PSOLDC6' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLX6' is not FITS standard (invalid value string: '3E9846366F2464C4'). Fixed 'PSOLX6' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: VerifyWarning: Card 'PSOLY6' is not FITS standard (invalid value string: 'BE70E8BF6C33B2A8'). Fixed 'PSOLY6' card to meet the FITS standard. [astropy.io.fits.verify]
WARNING: FITSFixedWarning: CDELTM1 = 0.009000000000 /Size of a pixel (x) in mm
keyword looks very much like CDELTia but isn't. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: CDELTM2 = 0.009000000000 /Size of a pixel (y) in mm
keyword looks very much like CDELTia but isn't. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: 'datfix' made the change 'Set MJD-OBS to 60709.811355 from DATE-OBS'. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: 'unitfix' made the change 'Changed units:
'DEG' -> 'deg',
'DEG' -> 'deg'. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: 'celfix' made the change 'Invalid parameter value'. [astropy.wcs.wcs]
Traceback (most recent call last):
File "I:\DEV\DEV_PYTHON\Test_Aperture_Photometry\test_wcs.py", line 20, in <module>
wcs = WCS(header)
^^^^^^^^^^^
File "I:\DEV\DEV_PYTHON\Test_Aperture_Photometry\.venv\Lib\site-packages\astropy\wcs\wcs.py", line 598, in __init__
self.wcs.set()
ValueError: ERROR 5 in wcsset() at line 2868 of file cextern\wcslib\C\wcs.c:
Invalid parameter value.
ERROR 4 in linset() at line 767 of file cextern\wcslib\C\lin.c:
Failed to initialize distortion functions.
ERROR 3 in dssset() at line 2748 of file cextern\wcslib\C\dis.c:
Coefficient scale for DSS on axis 1 is zero..

Donc j'imagine qu'il y a des éléments qui ne vont pas dans l'entête FITS de Prism au niveau des données de la calibration astrométrique.

Si quelqu'un a déjà résolu le problème, je suis preneur.

Remarque :
Pour le moment, dans mon script Python, je suis obligé de refaire une calibration astrométrique en appelant Astrometry.net pour que cela fonctionne.
C'est quand même balo, surtout qu'Aladin lui gère bien ça.

Merci
Marc
Modifié en dernier par Marc DELDEM le 19 avr. 2025, 21:39, modifié 1 fois.
Marc DELDEM
Messages : 1304
Enregistré le : 20 juin 2009, 01:01

Re: Python - Problème - WCS avec un fichier calibré par Prism

Message par Marc DELDEM »

OK j'ai trouvé la solution ici : https://github.com/astropy/astropy/issu ... 1788210651

Il faut retirer de l'entête les mots clés suivants :
- XPIXELSZ
- YPIXELSZ
- CDELTM1
- CDELTM2

Code : Tout sélectionner

from astropy.io import fits
from astropy.wcs import WCS
from astropy.coordinates import SkyCoord


filename = "./data/t_PNV J06483343+0656236-001.fits"
print(f"\nTraitement de {filename}")

# https://www.aavso.org/vsx/index.php?view=detail.top&oid=399830
# PNV J06483343+0656236
# J2000.0 : 06 48 33.47 +06 56 23.2 (102.13946 +6.93978)
ra = 102.13946
dec = +6.93978
target_coord = SkyCoord(ra, dec, frame='icrs', unit='deg')

with fits.open(filename) as hdul:
    data = hdul[0].data
    header = hdul[0].header

# Should remove the following keywords otherwise WCS is crashing
# see https://github.com/astropy/astropy/issues/15558#issuecomment-1788210651
header.remove('XPIXELSZ')
header.remove('YPIXELSZ')
header.remove('CDELTM1')
header.remove('CDELTM2')

wcs = WCS(header)
x_target, y_target = wcs.world_to_pixel(target_coord)
print(f"\nTarget: X={x_target}, Y={y_target}")
Et le résultat :
Traitement de ./data/t_PNV J06483343+0656236-001.fits
[...des warnings ...]
Target: X=716.8293268648144, Y=492.2710332509236
Maintenant que j'ai la solution, cela m'a rappelé un truc et en recherchant sur le forum, bingo, le sujet avait déjà été traité :
viewtopic.php?t=2979

J'aurai du chercher plus efficacement sur le forum...

Marc
Répondre