comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: FITS WCS routines
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: FITS WCS routines [message #72216] Sat, 21 August 2010 12:50
Jeremy Bailin is currently offline  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
Re: FITS WCS routines [message #72242 is a reply to message #72216] Fri, 20 August 2010 06:09 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
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.
Re: FITS WCS routines [message #72246 is a reply to message #72242] Thu, 19 August 2010 14:02 Go to previous message
Chris[7] is currently offline  Chris[7]
Messages: 4
Registered: August 2010
Junior Member
I would also love to see the IDL astro WCS procedures handle
N-dimensional (or at least 3 dimensional) image arrays. I've had to
write clumsy wrappers to extract coordinate information from spectral
data cubes.

chris


On 8/19/10 10:49 AM, wlandsman 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 in
> http://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
Re: FITS WCS routines [message #72247 is a reply to message #72246] Thu, 19 August 2010 13:49 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
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 in
http://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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: PLOTS and the new PLOT
Next Topic: Open webpage

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:45:42 PDT 2025

Total time taken to generate the page: 0.00470 seconds