fits

Write 3d Numpy array to FITS file with Astropy

a 夏天 提交于 2019-12-11 02:59:51
问题 I have a 3D NumPy array (i.e. (10, 256, 256)) representing 256x256 images. I would like to write this array to a FITS file using astropy.io.fits so that I can open the file using ds9 -mecube and move through the frames. My attempt is shown below export_array = numpy.array(images) #Create an array from a list of images print export_array.shape ## (10, 256, 256) hdu = fits.PrimaryHDU(export_array) hdulist = fits.HDUList([hdu]) hdulist.writeto(out_file_name) hdulist.close() This will give me a

astropy.io fits efficient element access of a large table

依然范特西╮ 提交于 2019-12-10 11:26:37
问题 I am trying to extract data from a binary table in a FITS file using Python and astropy.io. The table contains an events array with over 2 million events. What I want to do is store the TIME values of certain events in an array, so I can then do analysis on that array. The problem I have is that, whereas in fortran (using FITSIO) the same operation takes maybe a couple of seconds on a much slower processor, the exact same operation in Python using astropy.io is taking several minutes. I would

re-sizing a fits image in python

做~自己de王妃 提交于 2019-12-08 08:54:07
问题 I have 5 astronomy images in python, each for a different wavelength, therefore they are of different angular resolutions and grid sizes and in order to compare them so that i can create temperature maps i need them to be the same angular resolution and grid size. I have managed to Gaussian convolve each image to the same angular resolution as the worst one, however i am having trouble finding a method to re-grid each image in python and wondered if anyone knew how to go about doing this? I

Median combining fits images in python

陌路散爱 提交于 2019-12-04 20:39:53
问题 I have three fits images in the form of 2D numpy arrays. I want to median combine them, that is, generate an output array in which each pixel is the median of the same pixel in the three input arrays. This can be done easily on IRAF using imcombine. Is there a way to do this on Python without looping through the entire array and taking the median of each pixel? 回答1: The easiest way to do this is: Stack the 2d arrays to form a 3d array Compute the median using numpy.median passing axis=0 to

Adding a new column to a FITS file via python

若如初见. 提交于 2019-12-04 05:29:06
问题 I have created an array named distance that contains 1242 values. I want to add this array as the 11th column in an already existing FITS file that contains 10 columns. I am using pyfits. I tried pyfits.append(filename, distance) which showed no errors but did not add my column to the FITS file. Any suggestions?? 回答1: Finally they released an updated library that allows the modification of a table extension in a human way! Last release of FITSIO. You can easily add a column with a code

Median combining fits images in python

喜欢而已 提交于 2019-12-03 12:54:32
I have three fits images in the form of 2D numpy arrays. I want to median combine them, that is, generate an output array in which each pixel is the median of the same pixel in the three input arrays. This can be done easily on IRAF using imcombine. Is there a way to do this on Python without looping through the entire array and taking the median of each pixel? The easiest way to do this is: Stack the 2d arrays to form a 3d array Compute the median using numpy.median passing axis=0 to compute along the dimension of stacking. You're essentially computing an element-wise median. Here's a simple

Astropy Fits: How to write out a table with rows sliced out?

人走茶凉 提交于 2019-12-02 02:14:33
I'm currently working with some fits tables and I'm having trouble with outputting in Astropy.io.fits. Essentially, I am slicing out a bunch of rows that have data for objects I'm not interested in, but when I save the new table all of those rows have magically reappeared. For example: import astropy.io.fits as fits import numpy as np hdu = fits.open('some_fits_file.fits')[1].data sample_slice = [True True True False False True] hdu_sliced = hdu[sample_slice] Now my naive mind expects that "hdu" has 6 rows and hdu_sliced has 4 rows, which is what you would get if you used np.size(). So if I

Astropy Fits: How to write out a table with rows sliced out?

佐手、 提交于 2019-12-02 02:07:43
问题 I'm currently working with some fits tables and I'm having trouble with outputting in Astropy.io.fits. Essentially, I am slicing out a bunch of rows that have data for objects I'm not interested in, but when I save the new table all of those rows have magically reappeared. For example: import astropy.io.fits as fits import numpy as np hdu = fits.open('some_fits_file.fits')[1].data sample_slice = [True True True False False True] hdu_sliced = hdu[sample_slice] Now my naive mind expects that

Find physical coordinates of a pixel in a fits file with python

痴心易碎 提交于 2019-12-01 04:05:48
I am tying to get the physical sky coordinates of a given pixel from within a python script. I would like to use astropy's WCS, but I'll do anything from within python. I have tried these two snippets of code. from astropy.io import fits from astropy.wcs import WCS def astropymethod1(img): # from http://astropy.readthedocs.org/en/latest/wcs/ w = WCS(img) lon, lat = w.all_pix2world( 100., 100., 1) print lon, lat def astropymethod2(img): # from http://astropy.readthedocs.org/en/latest/wcs/ hdu = fits.open(img) w = WCS(hdu[0].header) lon, lat = w.wcs_pix2world(100., 100., 1) print lon, lat The

Find physical coordinates of a pixel in a fits file with python

我怕爱的太早我们不能终老 提交于 2019-12-01 01:43:20
问题 I am tying to get the physical sky coordinates of a given pixel from within a python script. I would like to use astropy's WCS, but I'll do anything from within python. I have tried these two snippets of code. from astropy.io import fits from astropy.wcs import WCS def astropymethod1(img): # from http://astropy.readthedocs.org/en/latest/wcs/ w = WCS(img) lon, lat = w.all_pix2world( 100., 100., 1) print lon, lat def astropymethod2(img): # from http://astropy.readthedocs.org/en/latest/wcs/ hdu