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_imcollapse 00013 def imcollapse(imagename='', function='', axes=[0], outfile='', box='', region='', chans='', stokes='', mask='', wantreturn=False, overwrite=False, stretch=False): 00014 00015 """Collapse image along one axis, aggregating pixel values along that axis. 00016 PARAMETER SUMMARY 00017 imagename Name of the input (CASA, FITS, MIRIAD) image 00018 function Function used to compute aggregation of pixel values along the collapsed 00019 axis. Supported functions are max, mean, median, min, rms, stdev, 00020 sum, variance. Minimum match is supported for the function parameter (eg, 00021 function="r" will compute the rms of the pixel values). 00022 axis Zero-based axis number(s) or minimal match strings to compress. 00023 outfile Name of output CASA image. If not specified, no image is written 00024 but an image analysis tool which references the output image is returned. 00025 overwrite If output file is specified, controls if an already existing file by the 00026 same name can be overwritten. If true, the user is not prompted, the file 00027 if it exists is automatically overwritten. 00028 box Direction plane box specification, "blcx, blcy, trcx, trcy". Only one box 00029 may be specified. If not specified, region is used if specified. If region 00030 is also not specified, entire directional plane unioned with any chans and 00031 stokes specification determines the region. 00032 region Region specification. See help par.region. Default is to not use a region. 00033 chans Optional contiguous frequency channel number specification. Not used if 00034 region is specified. Default is all channels. 00035 stokes Contiguous stokes planes specification. Not used if region is specified. 00036 Default is all stokes. 00037 mask Mask to use. See help par.mask. Default is none. 00038 stretch Stretch the input mask if necessary and possible. Only used if a mask is specified. 00039 See help par.stretch. 00040 wantreturn If true, return an image analysis tool referencing the collapsed image, if 00041 false, return false. 00042 00043 This task collapses an image along a specified axis or set of axes of N pixels to a single pixel on each 00044 specified axis. It computes the specified aggregate function for pixel values along the specified axes 00045 and places those values in the single remaining plane of those axes in the output image. It returns 00046 an image analysis tool containing the newly created collapsed image if wantreturn=True. Choices of 00047 aggregate functions are: max, mean, median, min, rms, stdev, sum, variance. Minimal unique match is 00048 supported for the function parameter (eg, function="r" will compute the rms of the pixel values, "med" 00049 will compute the median). 00050 00051 Axes can be specified as a single integer or array of integers indicating the zero-based axes along 00052 which to collapse the image. Axes may also be specified as a single or array of strings which minimally 00053 and uniquely match (ignoring case) world axes names in the image (eg "dec" or ["ri, "d"] for 00054 collapsing along the declination axis or along the right ascension and declination axes, respectively). 00055 00056 If outfile is not specified (or contains only white spaces), no image is written but, if wantreturn=True, 00057 the collapsed image is still able to be accessed via the returned image analysis tool which references 00058 the collpased image. If the returned object is not wanted it should still be captured and deleted via its 00059 done() method. If this is not done, there is no gaurantee for when the python garbage collector will delete 00060 it. If the returned object is wanted, it should be deleted as soon as possible for the same reasons, eg 00061 00062 collapsed_image = imcollapse(..., wantreturn=T) 00063 # do things (or not) with collapsed_image and when done with object, do 00064 collapsed_image.done() 00065 00066 The reference pixel of the collapsed axis is set to 0 and its reference value is set to the mean 00067 of the the first and last values of that axis in the specified region of the input image. 00068 00069 # myimage.im is a 512x512x128x4 (ra,dec,freq,stokes) image 00070 imagename = "myimage.im" 00071 # collapse a subimage of it along its spectral axis avoiding the 8 edge 00072 # channels at each end of the band, computing the mean value of the pixels 00073 # resulting image is 256x256x1x4 in size. 00074 outfile="collapse_spec_mean.im" 00075 function="mean" 00076 axis=2 00077 box="127,127,383,383" 00078 chans="8~119" 00079 collapsed = imcollapse(imagename=imagename, outfile=outfile, function=function, axes=axis, box=box, chans=chans, wantreturn=True) 00080 # manipulate collapsed 00081 collapsed.done() 00082 T 00083 00084 """ 00085 00086 # 00087 # The following is work around to avoid a bug with current python translation 00088 # 00089 mytmp = {} 00090 00091 mytmp['imagename'] = imagename 00092 mytmp['function'] = function 00093 mytmp['axes'] = axes 00094 mytmp['outfile'] = outfile 00095 mytmp['box'] = box 00096 mytmp['region'] = region 00097 mytmp['chans'] = chans 00098 mytmp['stokes'] = stokes 00099 mytmp['mask'] = mask 00100 mytmp['wantreturn'] = wantreturn 00101 mytmp['overwrite'] = overwrite 00102 mytmp['stretch'] = stretch 00103 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00104 trec = casac.utils().torecord(pathname+'imcollapse.xml') 00105 00106 casalog.origin('imcollapse') 00107 if trec.has_key('imcollapse') and casac.utils().verify(mytmp, trec['imcollapse']) : 00108 result = task_imcollapse.imcollapse(imagename, function, axes, outfile, box, region, chans, stokes, mask, wantreturn, overwrite, stretch) 00109 00110 else : 00111 result = False 00112 return result