# Fits file and WCS issue

**URL:** <https://community.openastronomy.org/t/fits-file-and-wcs-issue/678>\
**Category:** Astropy\
**Created:** [May 27, 2023, 1:52pm UTC](https://community.openastronomy.org/t/fits-file-and-wcs-issue/678 "2023-05-27T13:52:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ngc2218](https://avatars.discourse-cdn.com/v4/letter/n/71e660/32.png) [@ngc2218](https://community.openastronomy.org/u/ngc2218)\
**Post date:** [May 27, 2023, 1:52pm UTC](https://community.openastronomy.org/t/fits-file-and-wcs-issue/678/1 "2023-05-27T13:52:23Z")

</div>

Hello,  
I’ve been trying a simple example with a fits file like this:

```auto
from astropy import wcs
from astropy.io import fits

# Load the FITS hdulist using astropy.io.fits
hdulist = fits.open('abell.fits')

# Parse the WCS keywords in the primary HDU
w = wcs.WCS(hdulist[0].header)

# Print out the "name" of the WCS, as defined in the FITS header
print(w.wcs.name)

# Print out all of the settings that were parsed from the header
w.wcs.print_contents()

```

And I get an error:

```auto
ValueError Traceback (most recent call last)
Cell In[34], line 8
      5 hdulist = fits.open('abell.fits')
      7 # Parse the WCS keywords in the primary HDU
----> 8 w = wcs.WCS(hdulist[0].header)
     10 # Print out the "name" of the WCS, as defined in the FITS header
     11 print(w.wcs.name)

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\astropy\wcs\wcs.py:612, in WCS. __init__ (self, header, fobj, key, minerr, relax, naxis, keysel, colsel, fix, translate_units, _do_set)
    609 self.fix(translate_units=translate_units)
    611 if _do_set:
--> 612 self.wcs.set()
    614 for fd in close_fds:
    615 fd.close()

ValueError: ERROR 5 in wcsset() at line 2775 of file cextern\wcslib\C\wcs.c:
Invalid parameter value.
ERROR 4 in linset() at line 737 of file cextern\wcslib\C\lin.c:
Failed to initialize distortion functions.
ERROR 3 in dssset() at line 2697 of file cextern\wcslib\C\dis.c:
Coefficient scale for DSS on axis 1 is zero..

```

Part of my fits header:

```auto
OBJCTRA = '16 35 53.453 ' /Object Right Ascension (J2000)                  
OBJCTDEC= '+66 14 01.11 ' /Object Declinaison (J2000)                      
RA = 2.48972721654300130E+002 /Telescope RA                                
DEC = 6.62336441336017145E+001 /Telescope DEC                               
CRVAL1 = 2.48972721654300130E+002 /approx coord. in RA                         
CRVAL2 = 6.62336441336017145E+001 /approx coord. in DEC                        
CDELT1 = 2.57895481677548606E-004 /ScaleX in deg/pix                           
CDELT2 = 2.57895481677548606E-004 /ScaleY in deg/pix

```

Any idea how to remedy this?

As an update, I solved the image using [astrometry.net](http://astrometry.net) and downloaded the new fits file with all WCS data added.  
Still doesn’t work.

```auto
from astropy import wcs
from astropy.io import fits

# Load the FITS hdulist using astropy.io.fits
img = fits.open('abell_solved_wcs.fits')

# Parse the WCS keywords in the primary HDU
w = wcs.WCS(img[0].header,img)

```

Error:

```auto
ValueError: ERROR 5 in wcsset() at line 2775 of file cextern\wcslib\C\wcs.c:
Invalid parameter value.
ERROR 4 in linset() at line 737 of file cextern\wcslib\C\lin.c:
Failed to initialize distortion functions.
ERROR 3 in dssset() at line 2697 of file cextern\wcslib\C\dis.c:
Coefficient scale for DSS on axis 1 is zero..

```

---

<div class="post-metadata">

**Author:** ![hamogu](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/hamogu/32/93_2.png) [@hamogu](https://community.openastronomy.org/u/hamogu)\
**Post date:** [June 10, 2023, 11:51pm UTC](https://community.openastronomy.org/t/fits-file-and-wcs-issue/678/2 "2023-06-10T23:51:05Z")

</div>

That could be a bug in astropy, or it could be an error in your fits file. I can’t say from the few lines of the fits header that you posted. Could you make the complete file available somewhere, e.g. Dropbix, Google drive etc. so that I can download it and look at the entire header?
