[AstroPy] AstroPy Digest, Vol 161, Issue 5

Harry Ferguson ferguson at stsci.edu
Thu Feb 13 16:11:12 EST 2020


If you would like to record the mapping from pixels to angular size in your FITS
header, that’s what “world coordinate systems” are for. There are some instructions
at https://docs.astropy.org/en/stable/wcs/.

This can get very arcane, but for your simple application, ifthe third axis
is redshift, you could do something like:

from astropy.io<http://astropy.io> import fits
from astropy.wcs import WCS

myarray = np.ones((200,200,300),dtype=np.float64)   # Your 3D array

w = WCS(naxis=3)
w.wcs.crpix = (100,100,150) # Reference pixel at the center
w.wcs.crval = (30.,60.,1.0) # centered at RA=30 deg, Dec=60 deg, redshift z=1.0
w.wcs.ctype = ('RA---TAN','DEC--TAN','ZOPT')
w.wcs.cunit = ('deg','deg’,'')

# Increments 1 arc second per pixel in the spatial dimensions and delta_z = 0.1 in redshift
w.wcs.pc = [[1/3600.,0.,0.],
            [0,1/3600.,0.],
            [0,0,0.01]]

hdu = fits.PrimaryHDU(myarray, header=w.to_header())
hdu.writeto('myfile.fits')

If you display myfile.fits in ds9 you should get slider for the redshift axis, labeled
with redshift, and the coordinate info should show RA & Dec.


Dr. Henry C. Ferguson
Space Telescope Science Institute
3700 San Martin Drive, Baltimore, MD 21218
Phone: (410) 338-5098
www.stsci.edu/~ferguson<http://www.stsci.edu/~ferguson>



On Feb 13, 2020, at 12:00 PM, astropy-request at python.org<mailto:astropy-request at python.org> wrote:

External Email - Use Caution

Send AstroPy mailing list submissions to
       astropy at python.org<mailto: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<mailto:astropy-request at python.org>

You can reach the person managing the list at
       astropy-owner at python.org<mailto: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<mailto:m.shemuni at gmail.com>>
To: Astronomical Python mailing list <astropy at python.org<mailto: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<mailto: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<http://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<mailto: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<mailto: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<mailto:AstroPy at python.org>
https://mail.python.org/mailman/listinfo/astropy


------------------------------

End of AstroPy Digest, Vol 161, Issue 5
***************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20200213/21a1296a/attachment-0001.html>


More information about the AstroPy mailing list