1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
.help skywcs Oct00 xtools
.ih
NAME
skywcs -- sky coordinates package
.ih
SYNOPSIS
.nf
stat = sk_decwcs (ccsystem, mw, coo, imcoo)
stat = sk_decwstr (ccsystem, coo, imcoo)
stat = sk_decim (im, wcs, mw, coo)
sk_enwcs (coo, ccsystem, maxch)
newcoo = sk_copy (coo)
sk_iiprint (label, imagesys, mw, coo)
sk_iiwrite (fd, label, imagesys, mw, coo)
[id]val = sk_stat[id] (coo, param)
sk_stats (coo, param, str, maxch)
sk_set[id] (coo, param, [id]val)
sk_sets (coo, param, str)
sk_ultran (incoo, outcoo, ilng, ilat, olng, olat, npts)
sk_lltran (incoo, outoo, ilng, ilat, ipmlng, ipmlat, px, rv,
olng, olat)
sk_equatorial (incoo, outcoo, ilng, ilat, ipmlng, ipmlat, px,
rv, olng, olat)
sk_saveim (coo, mw, im)
sk_close (coo)
.fi
.ih
DESCRIPTION
The skywcs package contains a simple set of routines for managing
sky coordinate information and for transforming from one sky coordinate
system to another. The sky coordinate system is defined either by a system
name, e.g. "J2000", "galactic", etc. or by an image system name, e.g.
"dev$ypix" or "dev$ypix world".
The skywcs routine are layered on the Starlink Positional Astronomy library
SLALIB which is installed in the IRAF MATH package. Type "help slalib
option=sys" for more information about SLALIB.
.ih
NOTES
An "include <skywcs.h>" statement must be included in the calling program
to make the skywcs package parameter definitions visible to the calling
program.
The sky coordinate descriptor is created with a call to one of the sk_decwcs
sk_decwstr or sk_imwcs routines. If the source of sky coordinate descriptor
is an image then an IRAF MWCS descriptor will be returned with the sky
oordinate descriptor. The sky coordinate descriptor is freed with a
call to sk_close. A separate call to mw_close must be made to free the
MWCS descriptor if one was allocated.
By default the main skywcs coordinate transformation routine sk_ultran
assumes that the input and output sky coordinates are in hours and degrees
if the input and output coordinate systems are equatorial, otherwise the
coordinates are assumed to be in degrees and degrees. The default input and
output sky coordinate units can be reset with calls to sk_seti. Two lower level
coordinate transformations for handling proper motions sk_lltran and
sk_equatorial are also available. These routines expect the input and output
coordinates and proper motions to be in radians.
Calling programs working with both sky coordinate and MWCS descriptors
need to be aware that the MWCS routines assume that all sky coordinates
must be input in degrees and will be output in degrees and adjust their
code accordingly.
The skywcs routine sk_saveim can be used to update an image header.
.ih
EXAMPLES
.nf
Example 1: Convert from B1950 coordinates to J2000 coordinates.
include <skywcs.h>
....
# Open input coordinate system.
instat = sk_decwstr ("B1950", incoo, NULL)
if (instat == ERR) {
call sk_close (incoo)
return
}
# Open output coordinate system.
outstat = sk_decwstr ("J2000", outcoo, NULL)
if (outstat == ERR) {
call sk_close (outcoo)
return
}
# Do the transformation assuming the input coordinates are in hours
# and degrees. The output coordinates will be in hours and degrees
# as well.
call sk_ultran (incoo, outcoo, rain, decin, raout, decout, npts)
# Close the coordinate descriptors.
call sk_close (incoo)
call sk_close (outcoo)
...
Example 2: Repeat example 1 but convert to galactic coordinates.
include <skywcs.h>
....
# Open the input coordinate system.
instat = sk_decwstr ("B1950", incoo, NULL)
if (instat == ERR) {
call sk_close (incoo)
return
}
# Open the output coordinate system.
outstat = sk_decwstr ("galactic", outcoo, NULL)
if (outstat == ERR) {
call sk_close (outcoo)
return
}
# Do the transformation assuming the input coordinates are in hours and
# degrees. The output coordinates will be in degrees and degrees.
call sk_ultran (incoo, outcoo, rain, decin, raout, decout, npts)
# Close the coordinate descriptors.
call sk_close (incoo)
call sk_close (outcoo)
...
Example 3: Convert a grid of pixel coordinates in the input image to the
equivalent pixel coordinate in the output image using the
image world coordinate systems to connect the two.
include <skywcs.h>
....
# Mwref will be defined because the input system is an image.
refstat = sk_decwcs ("refimage logical", mwref, refcoo, NULL)
if (refstat == ERR || mwref == NULL) {
if (mwref != NULL)
call mw_close (mwref)
call sk_close (refcoo)
return
}
# Set the reference coordinate descriptor so it expects input in degrees
# and degrees.
call sk_seti (refcoo, S_NLNGUNUTS, SKY_DEGREES)
call sk_seti (refcoo, S_NLATUNUTS, SKY_DEGREES)
# Mwout will be defined because the output system is an image.
outstat = sk_decwcs ("image logical", mwout, outcoo, NULL)
if (outstat == ERR || mwout == NULL) {
if (mwout != NULL)
call mw_close (mwout)
call sk_close (outcoo)
call mw_close (mwref)
call sk_close (refcoo)
return
}
# Set the output coordinate descriptor so it will output coordinates
# in degrees and degrees.
call sk_seti (outcoo, S_NLNGUNUTS, SKY_DEGREES)
call sk_seti (outcoo, S_NLATUNUTS, SKY_DEGREES)
# Compute pixel grid in refimage and store coordinate in the arrays
# xref and yref.
npts = 0
do j = 1, IM_LEN(im,2), 100 {
do i = 1, IM_LEN(im,1), 100 {
npts = npts + 1
xref[npts] = i
yref[npts] = j
}
}
# Convert xref and yref to celestial coordinates raref and decref using
# mwref. The output coordinates will be in degrees and degrees.
ctref = mw_sctran (mwref, "logical", "world", 03B)
do i = 1, npts
call mw_c2trand (ctref, xref[i], yref[i], raref[i], decref[i])
call ct_free (ctref)
# Convert the reference celestial coordinates to the output celestial
# coordinate system using the coordinate descriptors.
call sk_ultran (refcoo, outcoo, raref, decref, raout, decout, npts)
# Convert the output celestial coordinates to pixel coordinates in
# the other image using mwout.
ctout = mw_sctran (mwout, "world", "logical", 03B)
do i = 1, npts
call mw_c2trand (ctout, raout[i], decout[i], xout[i], yout[i])
call ct_free (ctout)
# Print the input and output pixel coordinates.
do i = 1, npts {
call printf ("%10.3f %10.3f %10.3f %10.3f\n")
call pargd (xref[i])
call pargd (yref[i])
call pargd (xout[i])
call pargd (yout[i])
}
# Tidy up.
call mw_close (mwref)
call mw_close (mwout)
call sk_close (refcoo)
call sk_close (outcoo)
Example 4: Convert a 2D image with an J2000 tangent plane projection
wcs to the equivalent galactic wcs. The transformation
requires a shift in origin and a rotation. Assume that the ra
axis is 1 and the dec axis is 2. The details of how to compute
the rotation are not shown here. See the imcctran task for details.
include <mwset.h>
include <skywcs.h>
...
# Open image.
im = immap (image, READ_WRITE, 0)
# Open the image coordinate system.
instat = sk_decim (im, "logical", mwin, cooin)
if (instat == ERR || mwin == NULL) {
...
call sk_close (cooin)
...
}
# Get the dimensions of the mwcs descriptor. This should be 2.
ndim = mw_ndim (mwin, MW_NPHYSDIM)
# Get the default coordinates to degrees and degreees.
call sk_seti (cooin, S_NLNGUNITS, SKY_DEGREES)
call sk_seti (cooin, S_NATGUNITS, SKY_DEGREES)
# Open the output coordinate system. Mwout is NULL because this system
# is not an image.
outstat = sk_decwstr ("galactic", mwout, cooout, cooin)
if (outstat == ERR) {
...
call sk_close (outstat)
...
}
# Make a copy of the mwcs descriptor.
mwout = mw_newcopy (mwin)
# Allocate space for the r and w vectors and cd matrix.
call malloc (r, ndim, TY_DOUBLE)
call malloc (w, ndim, TY_DOUBLE)
call malloc (cd, ndim * ndim, TY_DOUBLE)
call malloc (newcd, ndim * ndim, TY_DOUBLE)
# Assume for simplicty that the MWCS LTERM is the identify transform.
# so we don't have to worry about it. Get the WTERM which consists
# of r the reference point in pixels, w the reference point in degrees,
# and the cd matrix in degrees per pixel.
call mw_gwtermd (mwin, Memd[r], Memd[w], Memd[cd], ndim)
# Convert the world coordinates zero point. The pixel zero point
# remains the same.
tilng = Memd[w]
tilat = Memd[w+1]
call sk_ultran (incoo, outcoo, tilng, tilat, tolng, tolat, 1)
Memd[w] = tolng
Memd[w+1] = tolat
# Figure out how much to rotate the coordinate system and edit the
# compute a new CD matrix. Call it newcd.
...
# Enter the new CD matrix and zero point.
call mw_swterm (mwout, Memd[r], Memd[w], Memd[newcd], ndim)
# Update the header.
call sk_saveim (cooout, mwout, im)
call mw_saveim (mwout, im)
...
# Tidy up.
call mfree (r, TY_DOUBLE)
call mfree (w, TY_DOUBLE)
call mfree (cd, TY_DOUBLE)
call mfree (newcd, TY_DOUBLE)
call mw_close (mwin)
call mw_close (mwout)
call sk_close (cooin)
call sk_close (cooout)
call imunmap (im)
.fi
.endhelp
|