[AstroPy] AstroPy Digest, Vol 161, Issue 5
Mihai Cara
mihail.cara at gmail.com
Thu Feb 13 13:13:58 EST 2020
Because you mentioned "pixel size in arcsec", I assume you are interested in creating images with valid WCS object. In that case, follow instructions in https://docs.astropy.org/en/stable/wcs/index.html#building-a-wcs-structure-programmatically to create a WCS object ("w") and to create a FITS HDU object. The only difference from the example is in the last statement. Instead of
hdu = fits.PrimaryHDU(header=header)
assuming "data" is the numpy array with your data and "slice" is the slice number (0-indexed), you should do:
hdu = fits.PrimaryHDU(data=data[:, :, slice], header=header)
Then write this HDU to a file:
hdu.writeto('slice_name.fits')
Mihai
On 2/13/20, 12:02 PM, "astropy-bounces+mihail.cara=gmail.com at python.org on behalf of astropy-request at python.org" <astropy-bounces+mihail.cara=gmail.com at python.org on behalf of astropy-request at python.org> wrote:
Send AstroPy mailing list submissions to
astropy at python.org
To subscribe or unsubscribe via the World Wide Web, visit
https://mail.python.org/mailman/listinfo/astropy
or, via email, send a message with subject or body 'help' to
astropy-request at python.org
You can reach the person managing the list at
astropy-owner at python.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of AstroPy digest..."
Today's Topics:
1. Re: Making fits images with given angular size and pixel
resolution (Mohammad Shameoni Niaei)
----------------------------------------------------------------------
Message: 1
Date: Thu, 13 Feb 2020 08:33:48 +0300
From: Mohammad Shameoni Niaei <m.shemuni at gmail.com>
To: Astronomical Python mailing list <astropy at python.org>
Subject: Re: [AstroPy] Making fits images with given angular size and
pixel resolution
Message-ID:
<CAAXud8MOvYQgS2CwNKQ9cBZXvbLqHthN_O08H=zzwwx6+v2U4w at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
You're looking for "writeto" method. Here a simple script:
from astropy.io import fits as fts
>
> dest = "/Output/file"
>
> fits_file = "/Input/file"
>
> hdu = fts.open(fits_file, "readonly")
>
> header = hdu[0].header
> data = hdu[0].data
>
> #
> #Do something to data
> #
>
> fts.writeto(dest, data, header=header)
>
On Wed, Feb 12, 2020 at 5:50 PM AISHRILA MAZUMDER <aishri0208 at gmail.com>
wrote:
> Hello,
>
> I have a numpy 3D array of size (200,200,300). The third axis is the
> redshift (frequency) axis, and the first two axes are coordinates in Mpc.
> Now I have converted the Mpc values to angular separation using
> cosmological calculations, and I have determined the pixel size in arcsec.
> I want to know if its possible to make a fits image out of this 3D array
> using the pixel size and angular size in Astropy. I could not find any
> method of doing this hence I am writing this email. The image (which is a
> single slice along z axis) should look like image.png attached with this
> email.
>
> Thank you in advance,
>
> best regards,
> Aishrila Mazumder
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
--
Mohammad SHAMEONI NIAEI
Astronomer / Software Specialist
Astrofizik Ara?t?rma ve Uygulama Merkezi (ATASAM),
Yakutiye, ERZURUM/T?RK?YE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20200213/dedbc231/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
AstroPy mailing list
AstroPy at python.org
https://mail.python.org/mailman/listinfo/astropy
------------------------------
End of AstroPy Digest, Vol 161, Issue 5
***************************************
More information about the AstroPy
mailing list