Status: offline
Registered: 09/30/2005
Posts: 4040
|
[Moderator's Note: Forwarded from story posting]
qphot outputs an invalid floating-point number (such as "-299866.375-58") when the coordinates of the object to be measured fall considerably off (\$this->_split2($m[0])= ~100 degrees) the FITS image. This may cause applications that expect a standard-conforming value to fail. For example, Python raises ValueError (invalid literal for float()) when we attempt to convert them to float.
In order to help reproduce the problem, the following Python code uses PyRAF to measure an object incrementally farther from the center of a FITS image. As the output illustrates, the value of xcenter breaks about 100 degrees off the image, giving a positive value (when it should be negative) with what seems to be an exponent where the letter is missing.
---------------------------------------------------------------------
#! /usr/bin/env python
import pyraf.iraf
from pyraf.iraf import digiphot, apphot
import atexit
import os
import tempfile
def get_output_coords(img_path, ra, dec):
""" Run IRAF's qphot on (ra, dec), return (xcenter, ycenter) """
fd, coords_path = tempfile.mkstemp(suffix = '.coords')
os.write(fd, "{0:.5f} {1:.5f}n".format(ra, dec))
os.close(fd)
with tempfile.NamedTemporaryFile(suffix = '.qphot') as fd:
qphot_output = fd.name
with tempfile.NamedTemporaryFile(suffix = '.txdump') as fd:
txdump_output = fd.name
atexit.register(os.unlink, coords_path)
atexit.register(os.unlink, qphot_output)
atexit.register(os.unlink, txdump_output)
apphot.qphot(img_path,
cbox = 0,
aperture = 11,
annulus = 13,
dannulus = 8,
coords = coords_path,
output = qphot_output,
exposure = 'EXPTIME',
wcsin = 'world',
interactive = 'no')
pyraf.iraf.txdump(qphot_output,
fields = 'xcenter,ycenter',
Stdout = txdump_output,
expr = 'yes')
with open(txdump_output, 'rt') as fd:
return fd.readline().split()
if __name__ == "__main__":
path = "ferM_4436sa.fits"
ra, dec = 65.991667, 24.963778
print "Image center: ({0}, {1}) [RA, DEC]".format(ra, dec)
while ra <= 360:
xcenter, ycenter = get_output_coords(path, ra, dec)
print "{0} --> xcenter = {1}".format(ra, xcenter)
float(xcenter)
ra += 1
---------------------------------------------------------------------
Image center: (65.991667, 24.963778) [RA, DEC]
65.991667 --\$this->_split2($m[0]) xcenter = -299.940
66.991667 --\$this->_split2($m[0]) xcenter = -7579.813
67.991667 --\$this->_split2($m[0]) xcenter = -14863.232
68.991667 --\$this->_split2($m[0]) xcenter = -22153.457
69.991667 --\$this->_split2($m[0]) xcenter = -29453.758
70.991667 --\$this->_split2($m[0]) xcenter = -36767.426
71.991667 --\$this->_split2($m[0]) xcenter = -44097.777
72.991667 --\$this->_split2($m[0]) xcenter = -51448.160
[...]
162.991667 --\$this->_split2($m[0]) xcenter = -5457173.00264
163.991667 --\$this->_split2($m[0]) xcenter = -6703824.50330
164.991667 --\$this->_split2($m[0]) xcenter = -8691652.00435
165.991667 --\$this->_split2($m[0]) xcenter = -12364481.0630
166.991667 --\$this->_split2($m[0]) xcenter = -21450586.0111
167.991667 --\$this->_split2($m[0]) xcenter = -81586672.0431
168.991667 --\$this->_split2($m[0]) xcenter = 44982164.00-24
Traceback (most recent call last):
File "./xcenter-bug.py", line 54, in
float(xcenter)
ValueError: invalid literal for float(): 44982164.00-24
|