casa
$Rev:20696$
|
00001 # 00002 # This file was generated using xslt from its XML file 00003 # 00004 # Copyright 2009, Associated Universities Inc., Washington DC 00005 # 00006 import sys 00007 import os 00008 from casac import * 00009 import string 00010 from taskinit import casalog 00011 #from taskmanager import tm 00012 import task_imtrans 00013 def imtrans(imagename='', outfile='', order='', wantreturn=True): 00014 00015 """Reorder image axes 00016 PARAMETER SUMMARY 00017 imagename Name of the input image 00018 outfile Name of output CASA image. If blank, no disk image is written. 00019 order Output axes mapping 00020 wantreturn Return an image tool referencing the transposed image? 00021 00022 This task reorders (transposes) the axes in the input image to the specified 00023 order. The associated pixel values and coordinate system are transposed. 00024 00025 If the outfile parameter is empty, only a temporary image is created; no output image 00026 is written to disk. The temporary image can be captured in the returned value (assuming 00027 wantreturn is true). 00028 00029 The order parameter describes the mapping of the input axes to the output axes. 00030 It can be one of three types: a non-negative integer, a string, or a list of 00031 strings. If a string or non-negative integer, it should contain 00032 zero-based digits describing the new order of the input axes. It must 00033 contain the same number of (unique) digits as the number of input axes. For example, 00034 specifying reorder="1032" or reorder=1032 for a four axes image maps input axes 00035 1, 0, 3, 2 to output axes 0, 1, 2, 3. In the case of order being a nonnegative integer 00036 and the zeroth axis in the input being mapped to zeroth axis in the output, the zeroth 00037 digit is implicitly understood to be 0 so that to transpose an image where one would 00038 use a string order="0321", one could equivalently specify an int order=321. 00039 Because of ambiguity for axes numbers greater than nine, using string or integer order 00040 specifications cannot handle images containing more than 10 axes. 00041 The order parameter can also be specified as a list of strings which uniquely match, 00042 ignoring case, the first characters of the image axis names (ia.coordsys().names()). 00043 So to reorder an image with right ascension, declination, and frequency axes, one could 00044 specify order=["d", "f", "r"] or equivalently ["decl", "frequ", "right a"]. Note that 00045 specifying "ra" for the right ascension axis will result in an error because "ra" does 00046 not match the first two characters of right ascension. 00047 Axes can be simultaneously inverted in cases where order is a string or an array of 00048 strings by specifying negative signs in front of the axis/axes to be inverted. So, 00049 in a 4-D image, order="-10-3-2" maps input axes 1, 0, 3, 2 to output axes 0, 1, 2, 3 00050 and reverses the direction and values of input axes 1, 3, and 2. 00051 EXAMPLE: 00052 # Swap the stokes and spectral axes in an RA-Dec-Stokes-Frequency image 00053 imagename = "myim.im" 00054 outfile = "outim.im" 00055 order = "0132" 00056 imtrans() 00057 00058 # or 00059 00060 outfile = "myim_2.im" 00061 order = 132 00062 imtrans() 00063 00064 # or 00065 00066 outfile = "myim_3.im" 00067 order = ["r", "d", "f", "s"] 00068 imtrans() 00069 00070 # or 00071 00072 utfile = "myim_4.im" 00073 order = ["rig", "declin", "frequ", "stok"] 00074 imtrans() 00075 00076 00077 """ 00078 00079 # 00080 # The following is work around to avoid a bug with current python translation 00081 # 00082 mytmp = {} 00083 00084 mytmp['imagename'] = imagename 00085 mytmp['outfile'] = outfile 00086 mytmp['order'] = order 00087 mytmp['wantreturn'] = wantreturn 00088 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00089 trec = casac.utils().torecord(pathname+'imtrans.xml') 00090 00091 casalog.origin('imtrans') 00092 if trec.has_key('imtrans') and casac.utils().verify(mytmp, trec['imtrans']) : 00093 result = task_imtrans.imtrans(imagename, outfile, order, wantreturn) 00094 00095 else : 00096 result = False 00097 return result