def test_add_stokes(ndim): wcs = WCS(naxis=ndim) for ii in range(ndim + 1): outwcs = add_stokes_axis_to_wcs(wcs, ii) assert outwcs.wcs.naxis == ndim + 1 assert outwcs.wcs.ctype[ii] == 'STOKES' assert outwcs.wcs.cname[ii] == 'STOKES'
fitsimage=pa + line + '_fullchannelflux9.fits', overwrite=True) exportfits(imagename=tppr + '_regrid9.spw' + spw + '.I.sd.image', fitsimage=tppr + '_regrid9.spw' + spw + '.I.sd.fits', overwrite=True) #with spectralcube multiply the flux and sd flux = SpectralCube.read(pa + line + '_fullchannelflux9.fits') flux.allow_huge_operations = True sd = SpectralCube.read(tppr + '_regrid9.spw' + spw + '.I.sd.fits') sd.allow_huge_operations = True end = flux * sd #need to add a 4th axis - Stokes and modify the headers to match the ones of the original sd file hdu = fits.PrimaryHDU(end.filled_data[:].value.reshape((1, ) + end.shape), header=add_stokes_axis_to_wcs(end.wcs, 3).to_header()) a = SpectralCube.read(tppr + '.spw' + spw + '.I.sd.fits') hdu.header['BUNIT'] = 'Jy/beam' hdu.header['BMAJ'] = a.header['BMAJ'] hdu.header['BMIN'] = a.header['BMIN'] hdu.header['BPA'] = a.header['BPA'] hdu.header['BZERO'] = a.header['BZERO'] hdu.header['BSCALE'] = a.header['BSCALE'] hdu.header['BTYPE'] = a.header['BTYPE'] hdu.header['TELESCOP'] = a.header['TELESCOP'] hdu.header['INSTRUME'] = a.header['INSTRUME'] hdu.header['OBSERVER'] = a.header['OBSERVER'] hdu.header['TIMESYS'] = a.header['TIMESYS'] hdu.header['OBSDEC'] = a.header['OBSDEC']