Re: FITS WCS routines [message #72216] |
Sat, 21 August 2010 12:50 |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Aug 20, 9:09 am, Jeremy Bailin <astroco...@gmail.com> wrote:
> On Aug 19, 4:49 pm, wlandsman <wlands...@gmail.com> wrote:
>
>
>
>
>
>> On Aug 19, 3:51 pm, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>>> Does anyone know of a good IDL implementation or wrapper of up-to-date
>>> routines to deal with world coordinate systems in FITS files? The ones
>>> in the astronomy library aren't sufficient - in particular, I need
>>> something that can deal with a TNX coordinate system (tangent point
>>> plane with distortions).
>
>> Well, to be fair, there is no established standard yet for
>> representing distortions within FITS. (There is a draft standard
>> that has been in the works for at least 10 years -- but nobody uses
>> it ( see Paper IV inhttp://www.atnf.csiro.au/people/mcalabre/WCS/index.html)
>
>> The TNX distortion keywords and convention were created by the IRAF
>> software group (http://fits.gsfc.nasa.gov/registry/tnx.html). I
>> have implemented a more popular distortion convention -- the Simple
>> Imaging Polynomial or SIP (http://fits.gsfc.nasa.gov/registry/sip.html) in the Astronomy
>> Library. Unfortunately, that won't help you if you are given files
>> using the TNX keywords.
>
>> I think I once saw IDL code for parsing the TNX keywords but I can't
>> remember where just now. Perhaps someone else will have idea. --
>> Wayne
>
> Yeah, I thought about putting "standard" in quotes. ;-)
>
> Right now my tentative solution is to get IDL to write an IRAF script
> that uses wcsctran to do the coordinate transformation, spawn IRAF to
> run the script, and then read in the transformed coordinates. Which is
> not exactly elegant.
>
> The other solution is to take my current FITS file, use IRAF to
> reproject it into an undistorted tangent plane projection, and then
> use that reprojected image with XYAD etc. But for various reasons I'm
> suspicious about what's happening in that projection step, so I'd
> rather be able to operate on the original image.
>
> -Jeremy.
In case anyone's interested, here's some wrappers I just wrote to the
WCStools sky2xy and xy2sky commands that seem to do the trick.
Requires the astronomy library and a couple of the UWashington
routines in addition, of course, to WCStools.
-Jeremy.
;+
; NAME:
; SKY2XY
;
; PURPOSE:
; Converts between sky coordinates and pixel coordinates of a FITS
image
; using the WCSTOOLS sky2xy routine. Useful for images with WCS
keywords
; that are not implemented in the astronomy library (such as the
TNX
; convention for distortions).
;
; CATEGORY:
; Astro
;
; CALLING SEQUENCE:
; Result = SKY2XY(Filename, Ra, Dec)
;
; INPUTS:
; Filename: Name of FITS file that contains the WCS to use.
;
; Ra: Vector of right ascensions. Assumed to be in decimal
degrees unless
; /STRING is set.
;
; Dec: Vector of declinations. Assumed to be in decimal degrees
unless
; /STRING is set.
;
; OPTIONAL INPUTS:
; /STRING: Ra and Dec are strings in HH:MM:SS, DD:MM:SS format.
;
; OUTPUTS:
; The function returns a structure with fields .X and .Y which are
arrays
; containing the x and y pixel values.
;
; NOTES:
; Requires WCSTOOLS to be installed. Edit the wcstoolsdir= line
near the
; top of the function to point to the location that the binary
sky2xy and
; xy2sky files are located.
;
; EXAMPLE:
; FIXME
;
; MODIFICATION HISTORY:
; Written by: Jeremy Bailin
; 20 August 2010 Initial release
;
;-
function sky2xy, fitsfile, ra, dec, string=stringp
wcstoolslib='/Users/jbailin/src/wcstools-3.8.1/bin'
astrolib
skyfile=tmpfile('tmp','dat',4)
xyfile=tmpfile('tmp','dat',4)
if ~keyword_set(stringp) then begin
radec, ra, dec, rahr, ramn, rasc, dede, demn, desc
forprint, rahr, ramn, rasc, dede, demn, desc, format='(%"%02d:%02d:
%06.3f %+3d:%02d:%06.3f")', $
textout=skyfile, /nocomment
endif else begin
forprint, ra, dec, textout=skyfile, format='(%"%s %s")', /nocomment
endelse
spawn, wcstoolslib+'/sky2xy '+fitsfile+' @'+skyfile+' > '+xyfile
readcol, xyfile, x, y, format='x,x,x,x,f,f'
file_delete, skyfile, xyfile
return, {x:x, y:y}
end
;+
; NAME:
; XY2SKY
;
; PURPOSE:
; Converts between pixel coordinates of a FITS image and sky
coordinates
; using the WCSTOOLS xy2sky routine. Useful for images with WCS
keywords
; that are not implemented in the astronomy library (such as the
TNX
; convention for distortions).
;
; CATEGORY:
; Astro
;
; CALLING SEQUENCE:
; Result = XY2SKY(Filename, X, Y)
;
; INPUTS:
; Filename: Name of FITS file that contains the WCS to use.
;
; X: Vector of x coordinates.
;
; Y: Vector of y coordinates.
;
; OPTIONAL INPUTS:
; /STRING: Output strings of HH:MM:SS and DD:MM:SS format.
;
; OUTPUTS:
; The function returns a structure with fields .RA and .DEC which
are arrays
; containing the RA and Dec values in decimal degrees (or in
strings,
; if /STRING is set).
;
; NOTES:
; Requires WCSTOOLS to be installed. Edit the wcstoolsdir= line
near the
; top of the function to point to the location that the binary
sky2xy and
; xy2sky files are located. Also requires the UWashington TMPFILE
and
; DIR_EXIST routines.
;
; EXAMPLE:
; FIXME
;
; MODIFICATION HISTORY:
; Written by: Jeremy Bailin
; 20 August 2010 Initial release
;
;-
function xy2sky, fitsfile, x, y, string=stringp
wcstoolslib='/Users/jbailin/src/wcstools-3.8.1/bin'
astrolib
skyfile=tmpfile('tmp','dat',4)
xyfile=tmpfile('tmp','dat',4)
forprint, x, y, textout=xyfile, /nocomment
spawn, wcstoolslib+'/xy2sky '+fitsfile+' @'+xyfile+' > '+skyfile
readcol, skyfile, ra, dec, format='a,a,x,x,x'
file_delete, xyfile, skyfile
if ~keyword_set(stringp) then begin
ra = 15. * tenv(ra)
dec = tenv(dec)
endif
return, {ra:ra, dec:dec}
end
|
|
|