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

27 statements  

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

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

2##################### d38b54a6ac9dbd28160cf0da65ac9bcc ############################## 

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_imsubimage import imsubimage as _imsubimage_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 _imsubimage: 

15 """ 

16 imsubimage ---- Create a (sub)image from a region of the image 

17 

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

19 

20 imagename Input image name. Default is unset. 

21 outfile Output image name. Default is unset. 

22 box Rectangular region to select in direction plane. Default is to use the entire direction plane. 

23 region Region selection. Default is to use the full image. 

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

25 stokes Stokes planes to use. Default is to use all Stokes planes. 

26 mask Mask to use. Default is none. 

27 dropdeg Drop degenerate axes 

28 overwrite Overwrite (unprompted) pre-existing output file? 

29 verbose Post additional informative messages to the logger 

30 stretch Stretch the mask if necessary and possible? 

31 keepaxes If dropdeg=True, these are the degenerate axes to keep. Nondegenerate axes are implicitly always kept. 

32 RETURNS image 

33 

34 --------- examples ----------------------------------------------------------- 

35 

36  

37 PARAMETER SUMMARY 

38 imagename Name of the input image 

39 outfile Name of output file. Must be specified. 

40 box Rectangular region to select in direction plane. 

41 for details. Default is to use the entire direction plane. 

42 region Region selection. Default is to use 

43 the full image. 

44 chans Channels to use. Default is to use 

45 all channels. 

46 stokes Stokes planes to use. Default is to 

47 use all Stokes planes. 

48 mask Mask to use. Default ("") is none. 

49 dropdeg If True, all degenerate axes in the input image will be excluded in the output image. 

50 overwrite If True, a pre-existing file of the same name as outfile will be overwritten. 

51 verbose Post additional informative messages to the logger. 

52 stretch Stretch the input mask if necessary and possible. Only used if a mask is specified. 

53  

54 keepaxes If dropdeg=True, these are the degenerate axes to keep. Nondegenerate axes are 

55 implicitly always kept. 

56  

57  

58 OVERVIEW 

59  

60 This task copies all or part of the image to a new image specified by outfile. 

61 Both float and complex valued images are supported. 

62  

63 Sometimes it is useful to drop axes of length one (degenerate axes). 

64 Set {stfaf dropdeg} equal to True if you want to do this. 

65  

66 The output mask is the combination (logical OR) of the default input 

67 pixelmask (if any) and the OTF mask. Any other input pixelmasks 

68 will not be copied. Use function maskhandler if you 

69 need to copy other masks too. 

70  

71 If the mask has fewer dimensions than the image and if the shape 

72 of the dimensions the mask and image have in common are the same, 

73 the mask will automatically have the missing dimensions added so 

74 it conforms to the image. 

75  

76 If stretch is true and if the number of mask dimensions is less than 

77 or equal to the number of image dimensions and some axes in the 

78 mask are degenerate while the corresponding axes in the image are not, 

79 the mask will be stetched in the degenerate dimensions. For example, 

80 if the input image has shape [100, 200, 10] and the input 

81 mask has shape [100, 200, 1] and stretch is true, the mask will be 

82 stretched along the third dimension to shape [100, 200, 10]. However if 

83 the mask is shape [100, 200, 2], stretching is not possible and an 

84 error will result. 

85  

86 EXAMPLES 

87  

88 # make a subimage containing only channels 4 to 6 of the original image, 

89 imsubimage(imagename="my.im", outfile="first.im", chans="4~6") 

90  

91 # Same as above command, just specifying chans in an alternate, more verbose 

92 # way 

93 imsubimage(imagename="my.im", outfile="second.im", chans="range=[4pix,6pix]") 

94  

95 # Same as the above command, but even more verbose way of specifying the spectral 

96 # selection. Assumes the direction axes are axes numbers 0 and 1. 

97 ia.open("my.im") 

98 shape = ia.shape() 

99 axes = ia.coordsys().names() 

100 ia.done() 

101 xmax = shape[axes.index("Right Ascension")] - 1 

102 ymax = shape[axes.index("Declination")] - 1 

103 reg = "box[[0pix,0pix],[" + str(xmax) + "pix, " + str(ymax) + "pix]] range=[4pix,6pix]" 

104 imsubimage(imagename="my.im", outfile="third.im", region=reg) 

105  

106 # As an example of the usage of the keepaxes parameter, consider an image 

107 # that has axes RA, Dec, Stokes, and Freq. The Stokes and Freq axes are both 

108 # degenerate while the RA and Dec axes are not, and it is desired to make a 

109 # subimage in which the Stokes axis is discarded. The following command will 

110 # accomplish that. 

111 imsubimage(imagename="my.im", outfile="discarded_stokes.im", dropdeg=True, keepaxes=[3]) 

112 

113 

114 """ 

115 

116 _info_group_ = """analysis""" 

117 _info_desc_ = """Create a (sub)image from a region of the image""" 

118 

119 def __call__( self, imagename='', outfile='', box='', region='', chans='', stokes='', mask='', dropdeg=False, overwrite=False, verbose=True, stretch=False, keepaxes=[ ] ): 

120 schema = {'imagename': {'type': 'cReqPath', 'coerce': _coerce.expand_path}, 'outfile': {'type': 'cStr', 'coerce': _coerce.to_str}, 'box': {'type': 'cStr', 'coerce': _coerce.to_str}, 'region': {'type': 'cStr', 'coerce': _coerce.to_str}, 'chans': {'type': 'cStr', 'coerce': _coerce.to_str}, 'stokes': {'type': 'cStr', 'coerce': _coerce.to_str}, 'mask': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'dropdeg': {'type': 'cBool'}, 'overwrite': {'type': 'cBool'}, 'verbose': {'type': 'cBool'}, 'stretch': {'type': 'cBool'}, 'keepaxes': {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}} 

121 doc = {'imagename': imagename, 'outfile': outfile, 'box': box, 'region': region, 'chans': chans, 'stokes': stokes, 'mask': mask, 'dropdeg': dropdeg, 'overwrite': overwrite, 'verbose': verbose, 'stretch': stretch, 'keepaxes': keepaxes} 

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

123 _logging_state_ = _start_log( 'imsubimage', [ 'imagename=' + repr(_pc.document['imagename']), 'outfile=' + repr(_pc.document['outfile']), 'box=' + repr(_pc.document['box']), 'region=' + repr(_pc.document['region']), 'chans=' + repr(_pc.document['chans']), 'stokes=' + repr(_pc.document['stokes']), 'mask=' + repr(_pc.document['mask']), 'dropdeg=' + repr(_pc.document['dropdeg']), 'overwrite=' + repr(_pc.document['overwrite']), 'verbose=' + repr(_pc.document['verbose']), 'stretch=' + repr(_pc.document['stretch']), 'keepaxes=' + repr(_pc.document['keepaxes']) ] ) 

124 task_result = None 

125 try: 

126 task_result = _imsubimage_t( _pc.document['imagename'], _pc.document['outfile'], _pc.document['box'], _pc.document['region'], _pc.document['chans'], _pc.document['stokes'], _pc.document['mask'], _pc.document['dropdeg'], _pc.document['overwrite'], _pc.document['verbose'], _pc.document['stretch'], _pc.document['keepaxes'] ) 

127 except Exception as exc: 

128 _except_log('imsubimage', exc) 

129 raise 

130 finally: 

131 task_result = _end_log( _logging_state_, 'imsubimage', task_result ) 

132 return task_result 

133 

134imsubimage = _imsubimage( ) 

135