Source
1
-
<casaxml xsi:schemaLocation="http://casa.nrao.edu/schema/casa.xsd file:///opt/casa/code/xmlcasa/xml/casa.xsd" xmlns="http://casa.nrao.edu/schema/psetTypes.html" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2
-
3
-
<task type="function" name="imregrid" category="analysis">
4
-
<shortdescription>regrid an image onto a template image</shortdescription>
5
-
<description>
6
-
Imregrid will regrid an input image onto a new coordinate system from a template image
7
-
or to a new directional reference frame. If a template image is used, then the input and
8
-
template images must have the same coordinate structure.
9
-
</description>
10
-
<input>
11
-
<param type="path" name="imagename" mustexist="true"><shortdescription>Name of the source image</shortdescription><description>Name of the source image</description>
12
-
13
-
<value/>
14
-
</param>
15
-
<param type="any" name="template"><shortdescription>A dictionary, refcode, or name of an image that provides the output shape and coordinate system</shortdescription><description>A dictionary, refcode, or name of an image that provides the output shape and coordinate system</description>
16
-
<any type="variant"/>
17
-
18
-
<value type="string">get</value>
19
-
</param>
20
-
21
-
<param type="string" name="output"><shortdescription>Name for the regridded image</shortdescription><description>Name for the regridded image</description>
22
-
23
-
<value/>
24
-
</param>
25
-
26
-
<param type="bool" direction="in" name="asvelocity"><shortdescription>Regrid spectral axis in velocity space rather than frequency space?</shortdescription><description>Regrid spectral axis in velocity space rather than frequency space?</description>
27
-
28
-
<value>True</value>
29
-
</param>
30
-
<param type="intVec" direction="in" name="axes"><shortdescription>The pixel axes to regrid. -1 => all.</shortdescription><description>The pixel axes to regrid. -1 => all.</description>
31
-
32
-
<value><value>-1</value></value>
33
-
</param>
34
-
<param type="intVec" name="shape" subparam="true"><shortdescription>Shape of the output image. Only used if template is an image. If not specified (-1), the output image shape will be the same as the template image shape along the axes that are regridded and the same as input image shape along the axes which are not regridded.</shortdescription><description>Shape of the output image. Only used if template is an image. If not specified (-1), the output image shape will be the same as the template image shape along the axes that are regridded and the same as input image shape along the axes which are not regridded.</description>
35
-
36
-
<value><value>-1</value></value>
37
-
</param>
38
-
<param type="string" name="interpolation"><shortdescription>The interpolation method. One of "nearest", "linear", "cubic".</shortdescription><description>The interpolation method. One of "nearest", "linear", "cubic".</description>
39
-
40
-
<value>linear</value>
41
-
</param>
42
-
<param type="int" name="decimate"><shortdescription>Decimation factor for coordinate grid computation</shortdescription><description>Decimation factor for coordinate grid computation</description>
43
-
44
-
<value>10</value>
45
-
</param>
46
-
47
-
<param type="bool" name="replicate"><shortdescription>Replicate image rather than regrid?</shortdescription><description>Replicate image rather than regrid?</description>
48
-
49
-
<value>False</value>
50
-
</param>
51
-
52
-
<param type="bool" name="overwrite"><shortdescription>Overwrite (unprompted) pre-existing output file?</shortdescription><description>Overwrite (unprompted) pre-existing output file?</description>
53
-
54
-
<value>False</value>
55
-
</param>
56
-
<constraints>
57
-
<when param="template">
58
-
<notequals type="string" value="get">
59
-
<default param="shape"><value type="intVec"><value>-1</value></value></default>
60
-
</notequals>
61
-
</when>
62
-
</constraints>
63
-
</input>
64
-
<example>
65
-
The imregrid task currently finds the nearest input pixel center and interpolates to the output pixel center.
66
-
No averaging is done in any direction!
67
-
68
-
Imregrid will regrid an input image onto a new coordinate system from a template image
69
-
or to a new directional reference frame. If a template image is used, then the input and
70
-
template images must have the same coordinate structure.
71
-
72
-
Keyword arguments:
73
-
74
-
imagename Name of the source image that needs to be regridded. Must be specified.
75
-
example: imagename='orion.image'
76
-
template Dictionary, directional reference code, or imagename defining the new
77
-
shape and coordinate system, or 'get' to return the template
78
-
dictionary for imagename. Recognized directional reference codes are:
79
-
'J2000', 'B1950', 'B1950_VLA', 'GALACTIC', 'HADEC', 'AZEL',
80
-
'AZELSW', 'AZELNE', 'ECLIPTIC', 'MECLIPTIC', 'TECLIPTIC',
81
-
and 'SUPERGAL'.
82
-
default: 'get'; example: template='orion_j2000.im' (for a template image),
83
-
template='J2000' (to regrid the input image to J2000 coordinates).
84
-
shape Shape of the output image. Only used if template is an image.
85
-
If not specified (-1), the output image will be the same as the template image
86
-
shape along the axes which are regridded and the same as the input image shpae
87
-
along the axes which are not regridded. If specified and the axis ordering between
88
-
the input image and the template are not the same, the values in the array correspond
89
-
to the axis ordering of the input image; the output image will have the same axis
90
-
ordering as the input image. Ignored if template is set equal to a
91
-
reference code. If template is a dictionary, the output shape is
92
-
retrieved from the dictionary so the shape input parameter is ignored.
93
-
output Name for the regridded image. Must be specified.
94
-
example: imagename='orion_shifted.im'
95
-
asvelocity If True, regrid spectral axis with respect to velocity, not frequency. If False,
96
-
regrid with respect to frequency. default: True
97
-
axes The pixel axes to regrid. Default value [-1] => all except Stokes. Ignored
98
-
if template is set equal to a reference code (in which case only the directional
99
-
axes are regridded). If specified, this should
100
-
be provided as an array. example axes=[0,1] (only regrid the first two axes, which
101
-
are normally the directional axes).
102
-
interpolation The interpolation method. One of 'nearest', 'linear', 'cubic'.
103
-
decimate Decimation factor for coordinate grid computation
104
-
replicate Replicate image rather than regrid?
105
-
overwrite"> Overwrite (unprompted) pre-existing output file?
106
-
107
-
The new coordinate system is defined by the template parameter, which can be:
108
-
109
-
* a recognized directional reference frame string. This will rotate the image and the coordinate system so that
110
-
the new reference frame's axes are aligned to the cardinal directions (left-right, up-down).
111
-
Rotation occurs about the center direction pixel. If this pixel is not the reference pixel,
112
-
a temporary copy of the original image is created and the coordinate system is adjusted so
113
-
the center direction pixel is the reference pixel. The coordinate system of the input image
114
-
is not modified and the output image's reference direction pixel is the center pixel.
115
-
Note that the conversion between one frame and another in general becomes less accurate
116
-
as distance from the output image's reference pixel increases. Before the rotation occurs, the
117
-
image is padded with masked pixels to ensure that all good pixels are used in the rotation (ie the
118
-
corners of the image are not cropped after the rotation). After the image is rotated, any masked slices
119
-
remaining along the edges of the image in the directional coordinate are cropped, so that there are
120
-
no masked slices in the directional coordinate along the edges of the final image.
121
-
* a {'csys': [valid coordinate system dictionary], 'shap': [int array describing the output shape]} dictionary.
122
-
This is normally obtained by first running regrid with template='get'. In this case imregrid returns the
123
-
necessary dictionary.
124
-
* 'get', which does not regrid but returns the template dictionary
125
-
for imagename, suitable for modification and reuse (see the point immediately above), or
126
-
* the name of an image from which to get the coordinate system and shape.
127
-
The input and template images must have the same
128
-
coordinate structure.
129
-
130
-
Regridding of complex-valued images is supported. The real and imaginary parts are
131
-
regridded independently and the resulting regridded pixel values are combined to
132
-
form the regridded, complex-valued image.
133
-
134
-
The argument {\stfaf replicate} can be used to simply replicate pixels
135
-
rather than regridding them. Normally ({\stfaf replicate=F}), for every
136
-
output pixel, its world coordinate is computed and the corresponding
137
-
input pixel found (then a little interpolation grid is generated). If
138
-
you set {\stfaf replicate=T}, then what happens is that for every output
139
-
axis, a vector of regularly sampled input pixels is generated (based on
140
-
the ratio of the output and input axis shapes). So this just means the
141
-
pixels get replicated (by whatever interpolation scheme you use) rather
142
-
than regridded in world coordinate space. This process is much faster,
143
-
but its not a true world coordinate based regrid.
144
-
145
-
As decribed above, when {\stfaf replicate} is False, a coordinate is
146
-
computed for each output pixel; this is an expensive operation. The
147
-
argument {\stfaf decimate} allows you to decimate the computation of
148
-
that coordinate grid to a sparse grid, which is then filled in via fast
149
-
interpolation. The default for {\stfaf decimate} is 10. The number of
150
-
pixels per axis in the sparse grid is the number of output pixels for
151
-
that axis divided by the decimation factor. A factor of 10 does pretty
152
-
well. You may find that for very non-linear coordinate systems (e.g.
153
-
very close to the pole) that you have to reduce the decimation factor.
154
-
You may also have to reduce the decimation factor if the number of pixels
155
-
in the output image along an axis to be regridded is less than about 50, or
156
-
the output image may be completely masked.
157
-
158
-
If one of the axes to be regridded is a spectral axis and asvelocity=T,
159
-
the axis will be regridded to match the velocity, not the frequency,
160
-
coordinate of the template coordinate system. Thus the output pixel
161
-
values will correspond only to the velocity, not the frequency, of the
162
-
output axis.
163
-
164
-
A variety of interpolation schemes are provided (only
165
-
the first three characters to be specified). The cubic interpolation
166
-
is substantially slower than linear, and often the improvement is
167
-
modest. By default linear interpolation is used.
168
-
169
-
If an image has per-plane beams and one attempts to regrid the spectral axis,
170
-
an exception is thrown.
171
-
172
-
RULES USED FOR GENERATING OUTPUT IMAGES IN SPECIFIC CASES
173
-
174
-
There are numerous rules governing the shape and coordinate system of the output
175
-
image depending on the input image, template image, and wheher default values of the
176
-
axes and shape parameters are used. They are enumerated below.
177
-
178
-
NOTE: If you want to be certain of what type of output you will get, it is highly
179
-
recommended you specify both axes and shape to avoid any ambiguity.
180
-
181
-
1. Rules governing Stokes axes
182
-
1.1. If the input image has no stokes axis, then the output image will have no stokes axis.
183
-
1.2. If the input image has a stokes axis, but the template image/coordinate system does not,
184
-
and if the default value of the shape parameter is used or if shape is specified and the
185
-
specified value for the length stokes axis in equal to the length of the input image
186
-
stokes axis, then all stokes in the input
187
-
image will be present in the output image
188
-
1.3. If the input image has a stokes axis, but the template image/coordinate system does not,
189
-
and if the value of the shape parameter is specified but the length of the resulting stokes
190
-
axis is not equal to the length of the input image's stokes axis, a failure will occur.
191
-
1.4. If the input image has a stokes axis, if the template parameter is an image name, and if the
192
-
template image has a degenerate stokes axis, if the axes parameter is not specified or is specified
193
-
but does not contain the input stokes axis number, and if the shape parameter is not specified, then
194
-
all stokes planes in the input image will be present in the output image.
195
-
1.5. If the input image has a stokes axis, if the template parameter is an image name, and if the
196
-
template image has a degenerate stokes axis, if the axes parameter is not specified or is specified
197
-
but does not contain the input stokes axis number, if the shape parameter is specified, and if the
198
-
specified length of the stokes axis is not equal to the length of the input stokes axis, then
199
-
a failure will occur.
200
-
1.6. If the input image has a stokes axis, if the template parameter is an image name, if the
201
-
template image has a degenerate stokes axis, if the axes parameter is specified contains the
202
-
input stokes axis number, then use the applicable rule of rules 1.7. and 1.8. for the template
203
-
image having a nondegenerate stokes axis.
204
-
1.7. If the input image has a stokes axis, if the template parameter is an image name, if the
205
-
template image has a nondegenerate stokes axis, and if axes is not specified or if it is, it contains
206
-
the input stokes axis number, then only the stokes parameters common to both the input image and
207
-
the template image will be present in the output image. If the input image and the template image
208
-
have no common stokes parameters, failure will occur. If shape is specified and the length of the
209
-
specified stokes axis is not equal to the number of common stokes parameters in the input image and
210
-
the template image, then failure will result.
211
-
1.8. If the input image has a stokes axis, if the template parameter is an image name, if the
212
-
template image has a nondegenerate stokes axis, and if axes is specified but does not contain the input
213
-
image stokes axis number, then all stokes present in the input image will be present in the output image.
214
-
If shape is also specified but the length of the specified stokes axis does not equal the length of
215
-
the input stokes axis, then failure will result.
216
-
217
-
2. Rules governing spectral axes
218
-
In all cases, if the shape parameter is specified, the spectral axis length must be consistent with what
219
-
one would normally expect in the special cases, or a failure will result.
220
-
2.1. If the input image does not have a spectral axis, then the output image will not have a spectral axis.
221
-
2.2. If the input image has a degenerate spectral axis, if the template parameter is an image name, and if the
222
-
template image has a spectral axis, if axes is not specified or if it is and does not
223
-
contain the input image spectral axis number, then the spectral coordinate of the input image is copied
224
-
to the output image and the output image will have a degenerate spectral axis.
225
-
2.3. If the input image has a degenerate spectral axis, if the template parameter is an image name, and if the
226
-
template image has a spectral axis, if axes is specified and it
227
-
contains the input image spectral axis number, then the spectral coordinate of the template image is copied
228
-
to the output image. If shape is not specified, the output image will have the same number of channels
229
-
as the input image. If shape is specified, the output image will have the number of channels as specified
230
-
in shape for the spectral axis. In these cases, the pixel and mask values for all spectral hyperplanes
231
-
will be identical; the regridded single spectral plane is simply replicated n times, where n is the
232
-
number of channels in the output image.
233
-
2.4. If the input image has a spectral axis, if the template parameter is an image name, and if the
234
-
template image does not have a spectral axis, if axes is not specified or if it is and does not
235
-
contain the input image spectral axis number, then the spectral coordinate of the input image is copied
236
-
to the output image and the output image will have the same number of channels as the input image.
237
-
2.5. If the input image has a spectral axis, if the template parameter is an image name, if the
238
-
template image does not have a spectral axis, if axes is specified it
239
-
contains the input image spectral axis number, then failure will result.
240
-
2.6. If the input image has a spectral axis, if the template parameter is an image name, if the
241
-
template image has a degenerate spectral axis, and if axes is unspecified or if it is but does not
242
-
contain the spectral axis number of the input image, the spectral coordinate of the input image is
243
-
copied to the output image and the output image will have the same number of channels as the input
244
-
image.
245
-
2.7. If the input image has a spectral axis, if the template parameter is an image name, if the
246
-
template image has a nondegenerate spectral axis, and if axes is unspecified or if it is and
247
-
contains the spectral axis number of the input image, regrid the spectral axis of the input to
248
-
match the spectral axis of the template.
249
-
250
-
IMPORTANT NOTE ABOUT FLUX CONSERVATION
251
-
in general regridding is inaccurate for images that the angular resolution is poorly
252
-
sampled. A check is done for such cases and a warning message is emitted if a beam present.
253
-
However, no such check is done if there is no beam present. To add a restoring beam to
254
-
an image, use ia.setrestoringbeam().
255
-
256
-
Basic Examples
257
-
258
-
# Regrid an image to the "B1950" or "GALACTIC" coordinate systems
259
-
260
-
imregrid(imagename="input.image", output="output.image", template="B1950")
261
-
imregrid(imagename="input.image", output="output.image", template="GALACTIC")
262
-
263
-
Note that when regridding to another coordinate system in the manner above, if the
264
-
input image's direction coordinate is already in the frame specified by template,
265
-
a straight copy of the image is made. No regridding is actually done.
266
-
267
-
# Obtain a template dictionary from an image and then use it to regrid another image
268
-
269
-
temp_dict = imregrid(imagename="target.image", template="get")
270
-
imregrid(imagename="input.image", output="output.image", template=temp_dict)
271
-
272
-
In this example, the template="get" option is used in the first command in order to
273
-
characterize the desired shape and coordinate system used, and a new dictionary,
274
-
temp_dict, is generated accordingly. This is then used when performing the actual
275
-
regridding of input.image in the second command.
276
-
277
-
278
-
More Advanced Examples
279
-
280
-
It is also possible to directly use a template image for regridding with imregrid.
281
-
For this to work reliably and predictably, the dimensionality (i.e. which
282
-
dimensions are present in an image) and the axis ordering of the input image must
283
-
be the same. The type and ordering of the axes of both the input and template
284
-
images can (and should) first be examined using the CASA imhead task. Any
285
-
necessary reordering of axes can be performed using the CASA imtrans task.
286
-
287
-
Unless the user explicitly specifies which dimensions to regrid using the axes
288
-
parameter (see the following example), imregrid will also attempt to regrid
289
-
degenerate axes (i.e. image axes of length one pixel). Stokes axes are never
290
-
regridded.
291
-
292
-
In the case where template is an image name and the default value of shape is specified,
293
-
the output image's shape will be the same as the template image's shape along the axes which
294
-
are regridded and the same as the input image's shape along the axes which are not regridded.
295
-
So for example, if the input image has a shape of [20, 30, 40] and the template image has a shape
296
-
of [10, 40, 70] and only axes=[0, 1], the output image will have a shape of [10, 40, 40]. If axes=[2],
297
-
the output image will have a shape of [20, 30, 70].
298
-
299
-
# Regrid input.image by directly using target.image as a template
300
-
301
-
imregrid(imagename="input.image", output="output.image", template="target.image", shape=[500,500,40,1])
302
-
303
-
In this example, it is assumed that the axis order of the input image is of the
304
-
form (direction_x, direction_y, spectral, Stokes), where 'direction_x' and 'direction_y'
305
-
are the directional coordinates on the sky (in some reference frame),
306
-
'spectral' is a velocity/frequency axis, and 'Stokes' contains polarization
307
-
information. In this example, input.image might typically be a data cube of
308
-
shape [100, 100, 40, 1]. Note that the default value of asvelocity (True) will be used so that
309
-
the spectral axis will be regridded to the same velocity system as that of the template image.
310
-
311
-
312
-
# Regrid only the first two axes of an image
313
-
314
-
Firstly, the user should inspect the type and ordering of the axes with imhead,
315
-
and then correct with imtrans if necessary.
316
-
317
-
imregrid(imagename="input.image", output="output.image", template="target.image", axes=[0,1])
318
-
319
-
The above command will regrid only the first two axes (normally the directional axes) of input.image and
320
-
leave all other axes unchanged. The output image will have the shape of the template image along the regridded
321
-
axes [0, 1] and the shape of the input image along the other axes since the shape parameter was not
322
-
explicitly specified.
323
-
324
-
325
-
# Regrid the third axis, considering velocity rather than frequency units
326
-
327
-
imregrid(imagename="input.image", output="output.image", template="target.image", axes=[2], asvelocity=True)
328
-
329
-
This example regrids the spectral axis (zero-based axis number 2) with respect to velocity because the asvelocity parameter
330
-
has been set to True. This is useful when eg, regridding a cube containing one spectral line to match the velocity coordinate
331
-
of another cube containing a different spectral line.
332
-
333
-
334
-
# Regrid the third axis, considering velocity rather than frequency units but first set the rest frequency
335
-
336
-
imhead("input.image", mode="put", hdkey="restfreq", hdvalue="110GHz")
337
-
imregrid(imagename="input.image", output="output.image", template="target.image", axes=[2], asvelocity=True)
338
-
339
-
The first command in this example uses the imhead task to set the value of the
340
-
image rest frequency to a value of 110GHz in input.image. The following
341
-
imregrid command then performs a frequency units regridding only of the third
342
-
axis listed (zero-based axis) (2), taking account of the input.image rest frequency in the input file.
343
-
344
-
345
-
</example>
346
-
347
-
<returns>void</returns></task>
348
-
</casaxml>