<p>I'm not sure what your end goal is, but I think your easiest option is to use astropy.</p>
<pre><code>import astropy.io.fits
import astropy.wcs

hdu_list = astropy.io.fits.open(&quot;/path/to/your/file.fits&quot;)

# Assuming your WCS header is the first header in the file
header = hdu_list[0].header

# Construct the WCS object
wcs = astropy.wcs.WCS(header)

# Drop the last two axes
wcs_new = WCS.dropaxis(2).dropaxis(1)

print(wcs)
</code></pre>
<p>Lots more information can be found on the documentation for <a href="https://docs.astropy.org/en/stable/wcs/index.html" rel="nofollow noreferrer">astropy.wcs</a></p>

CC BY-SA 4.0
2023-01-25T04:04:56.900Z
Thank you Roy. I was using astropy. I managed to just call the first array of WCS and use it for further analysis.
SlightDecoy
CC BY-SA 4.0
2023-01-24T05:03:35.447Z
2023-01-24T05:03:35.447Z
Roy Smart
<p>I have three WCS axes in a FITS image. I want to slice the axes and use only the first one. Note that though there are three axes, the WCS is superimposable. So there is no worry about a shift in WCS due to my selection of a particular axis.</p>
<p>I am attaching the description of WCS axes as well.</p>
<pre><code>Number of WCS axes: 3
CTYPE : 'RA---TAN'  'DEC--TAN'  ''  
CRVAL : 181.6023  63.6321  0.0  
CRPIX : 128.5  128.5  0.0  
CD1_1 CD1_2 CD1_3  : -0.000138888888888889  0.0  0.0  
CD2_1 CD2_2 CD2_3  : 0.0  0.000138888888888889  0.0  
CD3_1 CD3_2 CD3_3  : 0.0  0.0  1.0  
NAXIS : 256  256  3
</code></pre>

<python><fits><fits-header><wcs>
How to slice WCS in a FITS file?
SlightDecoy
# How to slice WCS in a FITS file?

(Asked by: username_0 on 2023-01-20)

I have three WCS axes in a FITS image. I want to slice the axes and use only the first one. Note that though there are three axes, the WCS is superimposable. So there is no worry about a shift in WCS due to my selection of a particular axis.
I am attaching the description of WCS axes as well.
Number of WCS axes: 3
CTYPE : 'RA---TAN'  'DEC--TAN'  ''  
CRVAL : 181.6023  63.6321  0.0  
CRPIX : 128.5  128.5  0.0  
CD1_1 CD1_2 CD1_3  : -0.000138888888888889  0.0  0.0  
CD2_1 CD2_2 CD2_3  : 0.0  0.000138888888888889  0.0  
CD3_1 CD3_2 CD3_3  : 0.0  0.0  1.0  
NAXIS : 256  256  3

**Tags:** python, fits, fits-header, wcs

---

## 1 answers

### Answer by username_1 on 2023-01-24. Score: 0 | Accepted answer

I'm not sure what your end goal is, but I think your easiest option is to use astropy.
import astropy.io.fits
import astropy.wcs

hdu_list = astropy.io.fits.open("/path/to/your/file.fits")

# Assuming your WCS header is the first header in the file
header = hdu_list[0].header

# Construct the WCS object
wcs = astropy.wcs.WCS(header)

# Drop the last two axes
wcs_new = WCS.dropaxis(2).dropaxis(1)

print(wcs)

Lots more information can be found on the documentation for astropy.wcs

> **Comments:**
> **username_0**: Thank you Roy. I was using astropy. I managed to just call the first array of WCS and use it for further analysis.  

---

