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

27 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-01 07:19 +0000

1##################### generated by xml-casa (v2) from imval.xml ##################### 

2##################### 1d88123b4a2ed930af9fa51382cba5b9 ############################## 

3from __future__ import absolute_import 

4import numpy 

5from casatools.typecheck import CasaValidator as _val_ctor 

6_pc = _val_ctor( ) 

7from casatools.coercetype import coerce as _coerce 

8from casatools.errors import create_error_string 

9from .private.task_imval import imval as _imval_t 

10from casatasks.private.task_logging import start_log as _start_log 

11from casatasks.private.task_logging import end_log as _end_log 

12from casatasks.private.task_logging import except_log as _except_log 

13 

14class _imval: 

15 """ 

16 imval ---- Get the data value(s) and/or mask value in an image. 

17 

18 --------- parameter descriptions --------------------------------------------- 

19 

20 imagename Name of the input image 

21 region Region selection. Empty string (default) means use rules for box/chans/stokes specification. 

22 box Rectangular region(s) to select in direction plane. Empty string (default) means use the reference pixel. 

23 chans Channels to use. Default is to use all channels. 

24 stokes Stokes planes to use. Planes specified must be contiguous. Default is to use all Stokes planes. 

25 RETURNS void 

26 

27 --------- examples ----------------------------------------------------------- 

28 

29  

30 The data point(s) to be retrieved are those found in the specified 

31 region, which may be: 

32 1. A region file or text string, with the following caveat: 

33 * If the specified region is complex (eg, a union or intersection of multiple regions, 

34 only the first simple region in this set is used. 

35 * If the region is not rectangular, then the rectangular region that circumscribes the 

36 specified region (ie the bounding box) is used to retrieve values, since the returned 

37 arrays must be rectangular. The resulting mask values in this case are the result of 

38 anding the image mask values with the specified region mask values, eg 

39 if a pixel falls outside the specified region but within the bounding box, its returned 

40 mask value will be false even if its image mask value is true. 

41 2. A region specified by a set of rectangular 

42 pixel coordinates, the channel ranges and/or the Stokes. 

43  

44 For directed output, run as 

45 myoutput = imval() 

46  

47  

48 Keyword arguments: 

49 imagename -- Name of input image 

50 Default: none; Example: imagename='ngc5921_task.im' 

51 region -- Region selection. Empty string (default) means use rules for box/chans/stokes specification. 

52 Example: region='myimage.im.rgn' 

53 region='region1' 

54 box -- Rectangular region to select in direction plane. Empty string (default) means use the reference pixel. 

55 Default: '' (referencepixel values for the Directional coord); 

56 Example: box='10,10,50,50' 

57 box = '10,10,30,30,35,35,50,50' (two boxes) 

58 chans -- Channels to use. Default is to use all channels. 

59 stokes -- Stokes planes to use. Planes specified must be contiguous. Default is to use all Stokes planes. 

60 Example: stokes='IQUV'; 

61 stokes='I,Q' 

62  

63 General procedure: 

64  

65 1. Specify inputs, then 

66  

67 2. myoutput = imval() 

68 or specify inputs directly in calling sequence to task 

69 myoutput = imsval(imagename='image.im', etc) 

70  

71 3. myoutput['KEYS'] will contain the result associated with any 

72 of the keys given below 

73  

74 KEYS CURRENTLY AVAILABLE 

75 blc - absolute PIXEL coordinate of the bottom left corner of 

76 the bounding box surrounding the selected region 

77 trc - the absolute PIXEL coordinate of the top right corner 

78 of the bounding box surrOunding the selected region 

79 axes - List the data stored in each axis of the data block. 

80 unit - unit of the returned data values. 

81 data - data value(s) found in the given region 

82 mask - mask value(s) found in the given region. See important 

83 note above regarding returned mask values for 

84 non-rectangular regions. 

85  

86 NOTE: The data returned is in the same order as it is internally 

87 stored, typically RA, DEC, spectral, stokes. Also both the data 

88 and mask values are returned as Python Numpy arrays, for more 

89 information on how to manipulate them see 

90 http://numpy.scipy.org/#array_interface 

91  

92  

93 Additional Examples 

94 # The value and mask value at a single point (5,17,2,Q) 

95 imval( 'myImage', box='5,5,17,17', chans=2, stokes='Q' ) 

96  

97 # Select and report on two box regions 

98 # box 1, bottom-left coord is 2,3 and top-right coord is 14,15 

99 # box 2, bottom-left coord is 30,31 and top-right coord is 42,43 

100 # Note that only the boxes for the 

101 imval( 'myImage', box='2,3,14,15;30,31,42,43' ) 

102  

103 # Select the same two box regions but only channels 4 and 5 

104 imval( 'myImage', box='2,3,14,15;30,31,42,43', chan='4~5' ) 

105  

106 # Select all channels greater the 20 as well as channel 0. 

107 # Then the mean and standard deviation are printed 

108 # Note that the data returned is a Python numpy array which 

109 # has built in operations such as min, max, and means as 

110 # demonstrated here. 

111 results = imval( 'myImage', chans='>20;0' ) 

112 imval_data=results['data'] 

113 mask=results['mask'] 

114 # holds the absolute coordinates of the associated pixels in imval_data 

115 coords = results['coords'] 

116 print "Data max: ", imval_data.max(), " mean is ", imval_data.mean() 

117 swapped_data=imval_data.swapaxes(0,2) 

118 swapped_mask=mask.swapaxes(0,2) 

119 print "Data values for 21st channel: n", swapped_data[0] 

120 print "Mask values for 21st channel: n", swapped_mask[0] 

121 

122 

123 """ 

124 

125 _info_group_ = """analysis, information""" 

126 _info_desc_ = """Get the data value(s) and/or mask value in an image.""" 

127 

128 def __call__( self, imagename='', region='', box='', chans='', stokes='' ): 

129 schema = {'imagename': {'type': 'cReqPath', 'coerce': _coerce.expand_path}, 'region': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'box': {'type': 'cStr', 'coerce': _coerce.to_str}, 'chans': {'type': 'cStr', 'coerce': _coerce.to_str}, 'stokes': {'type': 'cStr', 'coerce': _coerce.to_str}} 

130 doc = {'imagename': imagename, 'region': region, 'box': box, 'chans': chans, 'stokes': stokes} 

131 assert _pc.validate(doc,schema), create_error_string(_pc.errors) 

132 _logging_state_ = _start_log( 'imval', [ 'imagename=' + repr(_pc.document['imagename']), 'region=' + repr(_pc.document['region']), 'box=' + repr(_pc.document['box']), 'chans=' + repr(_pc.document['chans']), 'stokes=' + repr(_pc.document['stokes']) ] ) 

133 task_result = None 

134 try: 

135 task_result = _imval_t( _pc.document['imagename'], _pc.document['region'], _pc.document['box'], _pc.document['chans'], _pc.document['stokes'] ) 

136 except Exception as exc: 

137 _except_log('imval', exc) 

138 raise 

139 finally: 

140 task_result = _end_log( _logging_state_, 'imval', task_result ) 

141 return task_result 

142 

143imval = _imval( ) 

144