Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_imcollapse.py: 19%

26 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-10-31 17:39 +0000

1 

2########################################################################## 

3# task_imcollapse.py 

4# 

5# Copyright (C) 2008, 2009, 2010 

6# Associated Universities, Inc. Washington DC, USA. 

7# 

8# This script is free software; you can redistribute it and/or modify it 

9# under the terms of the GNU Library General Public License as published by 

10# the Free Software Foundation; either version 2 of the License, or (at your 

11# option) any later version. 

12# 

13# This library is distributed in the hope that it will be useful, but WITHOUT 

14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 

15# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 

16# License for more details. 

17# 

18# You should have received a copy of the GNU Library General Public License 

19# along with this library; if not, write to the Free Software Foundation, 

20# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 

21# 

22# Correspondence concerning AIPS++ should be adressed as follows: 

23# Internet email: casa-feedback@nrao.edu. 

24# Postal address: AIPS++ Project Office 

25# National Radio Astronomy Observatory 

26# 520 Edgemont Road 

27# Charlottesville, VA 22903-2475 USA 

28# 

29# <author> 

30# Dave Mehringer 

31# </author> 

32# 

33# <summary> 

34# Task to collapse an image along a specified axis, 

35# computing a specified aggregate function of pixels along that axis 

36# </summary> 

37# 

38# <reviewed reviwer="" date="" tests="" demos=""> 

39# </reviewed> 

40# 

41# <prerequisite> 

42# <ul> 

43# 

44# </ul> 

45# </prerequisite> 

46# 

47# <etymology> 

48# imtrans => im(age) collapse 

49# </etymology> 

50# 

51# <synopsis> 

52# imtrans collapses an image along a specified axis. It is built on top of ia.collapse() 

53# </synopsis>  

54# 

55# <example> 

56# collapsed_image_tool = imcollapse(imagename="myim.im", outfile="collapsed.im", axis=2, function="variance", wantreturn=true) 

57# 

58# </example> 

59# 

60# <motivation> 

61# To make users happy (https://bugs.aoc.nrao.edu/browse/CAS-1222) 

62# and associated casacore class is prereq for specfit work 

63# </motivation> 

64# 

65 

66########################################################################### 

67 

68import sys 

69 

70from casatools import image 

71from casatasks import casalog 

72from .ialib import write_image_history 

73 

74def imcollapse( 

75 imagename=None, function=None, axes=None, outfile=None, box=None, 

76 region=None, chans=None, stokes=None, mask=None, 

77 overwrite=None, stretch=None 

78): 

79 casalog.origin('imcollapse') 

80 myia = image() 

81 outia = None 

82 try: 

83 if len(outfile) == 0: 

84 raise RuntimeError("outfile must be specified") 

85 myia.dohistory(False) 

86 if (not myia.open(imagename)): 

87 raise RuntimeError("Cannot create image analysis tool using " + imagename) 

88 outia = myia.collapse( 

89 function, axes, outfile, region, box, chans, 

90 stokes, mask, overwrite, stretch 

91 ) 

92 try: 

93 vars = locals() 

94 param_names = imcollapse.__code__.co_varnames[:imcollapse.__code__.co_argcount] 

95 param_vals = [vars[p] for p in param_names] 

96 write_image_history( 

97 outia, sys._getframe().f_code.co_name, 

98 param_names, param_vals, casalog 

99 ) 

100 except Exception as instance: 

101 casalog.post("*** Error \'%s\' updating HISTORY" % (instance), 'WARN') 

102 # returns None as per requirement 

103 finally: 

104 if myia: 

105 myia.done() 

106 if outia: 

107 outia.done()