fits

How to Create .fits file from numpy array

泪湿孤枕 提交于 2020-01-06 07:01:08
问题 I am currently trying to convert a .cr2 into .fits file. I am currently unable to create .fits as any file I create doesn't open or work because of the wrong shape of fits. I have tried using the solution Write 3d Numpy array to FITS file with Astropy but, still, it doesn't work. import numpy as np from astropy.io import fits im = imageio.imread(r'E:\FYP\cr.cr2', format="RAW-FI") a = np.array(im) print (a.shape) hdu = fits.PrimaryHDU(a) hdulist = fits.HDUList([hdu]) hdulist.writeto(r'E:\FYPcr

OSError 24 (Too many open files) when reading bunch of FITS with astropy.io

有些话、适合烂在心里 提交于 2020-01-03 11:51:28
问题 I’m trying to load into memory a few 2 000 FITS using astropy.io.fits : def readfits(filename): with fits.open(filename) as ft: # the fits contain a single HDU data = ft[0].data return data data_sci = [] for i in range(2000): data_sci.append(readfits("filename_{}.fits".format(i))) However, when reaching the 1015th file, OSError: [Errno 24] Too many open files is raised. I have the same issue with: def readfits(filename): ft = fits.open(filename) as ft: data = ft[0].data ft.close() return data

Add a column to fits file with Astropy

孤人 提交于 2019-12-23 02:48:20
问题 I have a fits files of event data, and I need to modify one of the tables by adding a new column of data derived by the data stored in a preexisting column of the same table. The problem I have is in closing the modified file. This is the code: data = fits.open(events, extname='events') t1 = data[1].data.field('time') table = Table.read(events, format='fits') t2 = Column(name='T2', data=t1) table.add_column(t2) How can I close the file writing on the same file as in input? If I try with table

Move the read files along with same named different format files

此生再无相见时 提交于 2019-12-13 04:17:01
问题 I have a file that contains lots of .fits and .dat files. First, I want them separated by a parameter and moved to another file(I have this part done). Then, the problem is there is a .dat file with exact same name for each .fits file (for example kkk.fits , kkk_trl.dat ) and I want the same named .dat file to move along with the .fits file together to the new folder. import os import glob import pyfits import shutil for fitsName in glob.glob('*.fits'): hdulist = pyfits.open(fitsName) hdu =

Converting ASCII Table to FITS image

可紊 提交于 2019-12-13 00:31:02
问题 I am a beginner in this domain. I have a text file having three columns: X, Y, Intensity at (X, Y). They are basically arrays (1X10000) each written out in a text files via python. To plot the dataset in python, I can simply use trisurf to achieve this. But for further processing, I need to create a fits image from it. How do I make FITS image (and NOT a simple FITS table) out of the this text file (through python or matlab will be preferable). 回答1: You should be able to do this mostly with

Plot several fields in an image

戏子无情 提交于 2019-12-11 19:32:25
问题 How would I plot several FITS fields in a single image ? Each FITS file covers a neighboring part of the sky. The data field of the HDU only contains the image. So to plot each image at the right coordinates, I need to get information from the header field. But how do I pass that information on the pyplot? I tried the following, using astropy.WCS so that the information from the headers be used in the plots import matplotlib.pyplot as plt from astropy.io import fits from astropy.wcs import

How to stop fits files from being imported upside down python

浪尽此生 提交于 2019-12-11 15:51:53
问题 When importing a fits image in python it gets imported upside down. This is the code i'm using: import numpy as np from astropy.io get fits import matplotlib.pyplot as plt im = fits.getdata('myimage.fits') plt.imshow(im, cmap='gray') plt.colorbar() Again I just want to view the image and it opens upside down. When I open it in an image viewer I have on my computer it looks fine so I know I didn't save it upside down. Is there any way to prevent this from happening? 回答1: You can specify the

How to stop Matplotlib from inverting fits files when plotting

强颜欢笑 提交于 2019-12-11 15:51:38
问题 I have an image but when I try to visualise it in mythic it plots upside-down. Is there any way to stop the imshow() function in matplotlib.pyplot from displaying images upside down. 来源: https://stackoverflow.com/questions/59072405/how-to-stop-matplotlib-from-inverting-fits-files-when-plotting

What does it mean that a card is fixed to meet FITS standard?

五迷三道 提交于 2019-12-11 11:24:43
问题 I am trying to use a FITS file. I have the following code: from astropy.io import fits from astropy.wcs import WCS hdul = fits.open(fitsfilename)[0] wcs = WCS(hdul.header) It gives me these warnings: WARNING: VerifyWarning: Verification reported errors: [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'A_2_0' is not FITS standard (invalid value string: '3.29341755408e-05'). Fixed 'A_2_0' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Note: astropy.io

c++ reading fits file using ccfits

与世无争的帅哥 提交于 2019-12-11 03:00:07
问题 So... can anyone see what I'm doing wrong here?!? I'm trying to read a *.fits file in C++ using CCfits following their example at http://heasarc.gsfc.nasa.gov/fitsio/CCfits/html/readimage.html. #include <iostream> #include <valarray> #include <CCfits/CCfits.h> #include <CCfits/PHDU.h> namespace fit = CCfits; int main(int argc, char * argv[]) { fit::FITS inFile( "../data/example/example.fits", fit::Read, true ); fit::PHDU & phdu = inFile.pHDU(); std::valarray<unsigned int> fitsImage; phdu.read