astropy

How to merge two table with pyfits?

淺唱寂寞╮ 提交于 2019-12-23 19:52:06
问题 I am using Python 2.7.10 And pyfits 3.3. Earlier, I have used the following code to merge two tables. However, now I am getting some errors t1 = pyfits.open(table1)[1].columns t2 = pyfits.open(table2)[1].columns new_columns = t1 + t2 hdu = pyfits.BinTableHDU.from_columns(new_columns) hdu.writeto(outtable) The error is: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/vvikraman/anaconda2/lib/python2.7/site-packages/pyfits/hdu/table.py", line 116, in from

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

Python astropy: convert velocities from ECEF to J2000 coordinate system

夙愿已清 提交于 2019-12-13 15:24:38
问题 I've written a code to transform the coordinates from Earth fixed system to inertial frame using astropy: from astropy import coordinates as coord from astropy import units as u from astropy.time import Time from astropy import time now = Time('2018-03-14 23:48:00') # position of satellite in GCRS or J20000 ECI: xyz=[-6340.40130292,3070.61774516,684.52263588] cartrep = coord.CartesianRepresentation(*xyz, unit=u.km) gcrs = coord.ITRS(cartrep, obstime=now) itrs = gcrs.transform_to(coord.GCRS

How to covert np.ndarray into astropy.coordinates.Angle class?

旧巷老猫 提交于 2019-12-12 03:36:44
问题 What is the quickest/most efficient way to convert a np.ndarray (importing numpy as np) into the astropy.coordinates.Angle class? I am having trouble keeping it as np.ndarray because the .wrap_at() operation will not work. 回答1: What exactly is your intention? np.asarray is quite ambiguous. If you are dealing with np.ndarray it is quite easy: from astropy.coordinates import Angle import astropy.units as u import numpy as np angles = np.array([100,200,300,400]) angles_quantity = a * u.degree #

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 sort through a list of observable coordinates?

岁酱吖の 提交于 2019-12-11 14:10:59
问题 I am struggling to find the best way of removing unwanted targets from a list of coordinates. My coordinates (Ra, Dec) are formed using astropy.coordinates.SkyCoord but I have a large number of un-observable targets that are too low in declination, so what I want to do is sort through my list and remove all targets with a declination lower than -10 degrees for example (as my telescope is in the northern hemisphere). This is the line of my code that produces the list, its called radecs for

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

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