[AstroPy] Format of a FITS-LDAC file
evert.rol at gmail.com
Tue Jun 13 06:08:21 EDT 2017
Your assumption is correct: the data attribute of hdulist is a (binary) table; a record array in numpy, essentially. It just contains the original header.
I'm not familiar with LDAC (and it appears strange to me that one puts a header into the data section of a HDU when an actual header is available; perhaps someone else can clarify that), but judging from what you have listed, you'd probably want to add or replace the essential WCS keywords (from wcs.header) into that table.
Given that the contents of hdulist.data is just an array of the full 80-chars header lines, you may need to perform some manual string searching to find the relevant keywords (str.startswith(...) is probably a convenient method to use), while simply stepping through the individual entries of the data array.
I see that your wcs solution uses SIP. Note that, as far as I'm aware, SExtractor, and probably SCAMP and other related utilities, don't deal with these nth order corrections. Perhaps that has changed, but I've always had to update SExtractor astrometry output after the fact, to correct for SIP corrections (and similarly, I have avoided using SCAMP).
> I need to make a FITS-LDAC file for the SCAMP program.
> Normally this file is made with the Sextractor program but this time I am
> calculating the star positions outside Sextractor, within Python.
> I am using a FITS-LDAC file made with Sextractor as a template so that I do not
> need to make eveything from scratch. Let's open the FITS-LDAC template:
> >>> from astropy.io import fits
> >>> hdulist=fits.open('LDAC-template.fits')
> >>> hdulist.info()
> Filename: LDAC-template.fits
> No. Name Type Cards Dimensions Format
> 0 PRIMARY PrimaryHDU 4 ()
> 1 LDAC_IMHEAD BinTableHDU 12 1R x 1C [17760A]
> 2 LDAC_OBJECTS BinTableHDU 57 1762R x 13C [1J, 1E, 1E, 1J, 1D, 1D, 1E, 1E, 1E, 1I, 1I, 1J, 1E]
> So there are three HDU objects.
> The hdulist includes the positions and fluxes of the stars. I am able to replace
> hdulist with a binary table HDU object made with the BinTableHDU.from_columns
> The problem is hdulist which includes the astrometry of the image.
> The content of hdulist:
> >>> hdulist.header
> XTENSION= 'BINTABLE' / THIS IS A BINARY TABLE (FROM THE LDACTOOLS)
> BITPIX = 8 /
> NAXIS = 2 /
> NAXIS1 = 17760 / BYTES PER ROW
> NAXIS2 = 1 / NUMBER OF ROWS
> PCOUNT = 0 / RANDOM PARAMETER COUNT
> GCOUNT = 1 / GROUP COUNT
> TFIELDS = 1 / FIELDS PER ROWS
> EXTNAME = 'LDAC_IMHEAD' / TABLE NAME
> TTYPE1 = 'Field Header Card'
> TFORM1 = '17760A '
> TDIM1 = '(80, 222)'
> >>> hdulist.data
> FITS_rec([ (chararray([ 'SIMPLE = T /,
> 'BITPIX = -32 / Number of bits per data pixel',
> 'NAXIS = 2 / Number of data axes',
> 'NAXIS1 = 8736 /',
> ... many fits keywords...
> 'SEXDWSCL= 0.000000000000E+00 / Detection-weight re-scaling factor',
> dtype=[('Field Header Card', 'S80', (222,))])
> I need to replace hdulist.data with a header that I read from a separate
> FITS-file. The header includes astrometry made with www.astrometry.net.
> Lets open that file:
> >>> wcs = fits.open('wcs.fits')
> >>> wcs.header
> SIMPLE = T / Standard FITS file
> BITPIX = 8 / ASCII or bytes array
> NAXIS = 0 / Minimal header
> EXTEND = T / There may be FITS ext
> WCSAXES = 2 / no comment
> CTYPE1 = 'RA---TAN-SIP' / TAN (gnomic) projection + SIP distortions
> CTYPE2 = 'DEC--TAN-SIP' / TAN (gnomic) projection + SIP distortions
> EQUINOX = 2000.0 / Equatorial coordinates definition (yr)
> LONPOLE = 180.0 / no comment
> LATPOLE = 0.0 / no comment
> CRVAL1 = 304.317023912 / RA of reference point
> CRVAL2 = 45.3045531672 / DEC of reference point
> CRPIX1 = 4123.62069546 / X reference pixel
> CRPIX2 = 3118.81777021 / Y reference pixel
> CUNIT1 = 'deg ' / X pixel scale units
> CUNIT2 = 'deg ' / Y pixel scale units
> CD1_1 = 0.000187351090429 / Transformation matrix
> CD1_2 = 3.58456619667E-06 / no comment
> CD2_1 = 3.68116182084E-06 / no comment
> CD2_2 = -0.000187399195345 / no comment
> ... many fits keywords ...
> ** The problem is: how do I replace record array hdulist.data with another
> array made from wcs.header or how to remove/update keywords in hdulist.data ? **
> I am confused about the format of hdulist.data, is it some kind of record array ?
> Thanks for your help, Kimmo Lehtinen
> AstroPy mailing list
> AstroPy at python.org
More information about the AstroPy