<p>I think the best option is to just change line 3 to:</p>
<pre><code>wcs2d = wcs1[:, :, 0]
</code></pre>
<p>But if you really want to use <a href="https://docs.astropy.org/en/stable/api/astropy.wcs.WCS.html#astropy.wcs.WCS.slice" rel="nofollow noreferrer"><code>astropy.wcs.WCS.slice()</code></a> you need to change the argument to a tuple</p>
<pre><code>wcs2d = wcs1.slice((slice(None), slice(None), 0))
</code></pre>

CC BY-SA 4.0
2023-11-19T03:08:16.113Z
2023-11-19T03:08:16.113Z
Roy Smart
<p>My code：</p>
<pre><code>import os
import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
from reproject import reproject_interp
from reproject.mosaicking import reproject_and_coadd
from astropy.wcs import WCS
from spectral_cube import SpectralCube as sc
hdu = fits.open('/media/ljy/PS2000/TEST/GALFA_HI_RA+DEC_004.00+10.35_N.fits')[0]
wcs1 = WCS(hdu.header)
wcs2d = wcs1.slice(slice(None), slice(None), 0)
wcs2d
</code></pre>
<p>The Error:---------------------------------------------------------------------------</p>
<pre><code>TypeError                                 Traceback (most recent call last)
Cell In[6], line 3
      1 hdu = fits.open('/media/ljy/PS2000/TEST/GALFA_HI_RA+DEC_004.00+10.35_N.fits')[0]
      2 wcs1 = WCS(hdu.header)
----&gt; 3 wcs2d = wcs1.slice(slice(None), slice(None), 0)
      4 wcs2d

TypeError: WCS.slice() takes from 2 to 3 positional arguments but 4 were given
</code></pre>
<p>about the wcs.slice function,i try again and again.But it does not work.</p>

<radio-astronomy>
Type Error： WCS.slice() takes from 2 to 3 positional arguments but 4 were given
柳吉羽
# Type Error： WCS.slice() takes from 2 to 3 positional arguments but 4 were given

(Asked by: username_0 on 2023-11-19)

My code：
import os
import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
from reproject import reproject_interp
from reproject.mosaicking import reproject_and_coadd
from astropy.wcs import WCS
from spectral_cube import SpectralCube as sc
hdu = fits.open('/media/ljy/PS2000/TEST/GALFA_HI_RA+DEC_004.00+10.35_N.fits')[0]
wcs1 = WCS(hdu.header)
wcs2d = wcs1.slice(slice(None), slice(None), 0)
wcs2d

The Error:---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[6], line 3
      1 hdu = fits.open('/media/ljy/PS2000/TEST/GALFA_HI_RA+DEC_004.00+10.35_N.fits')[0]
      2 wcs1 = WCS(hdu.header)
----> 3 wcs2d = wcs1.slice(slice(None), slice(None), 0)
      4 wcs2d

TypeError: WCS.slice() takes from 2 to 3 positional arguments but 4 were given

about the wcs.slice function,i try again and again.But it does not work.

**Tags:** radio-astronomy

---

## 1 answers

### Answer by username_1 on 2023-11-19. Score: 3

I think the best option is to just change line 3 to:
wcs2d = wcs1[:, :, 0]

But if you really want to use astropy.wcs.WCS.slice() you need to change the argument to a tuple
wcs2d = wcs1.slice((slice(None), slice(None), 0))


---

