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

33 statements  

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

1 

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

3# task_specfit.py 

4# 

5# Copyright (C) 2008, 2009 

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# Fit 1 dimensional gaussians and/or polynomial 

35# </summary> 

36# 

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

38# </reviewed> 

39# 

40# <prerequisite> 

41# <ul> 

42# 

43# </ul> 

44# </prerequisite> 

45# 

46# <etymology> 

47# specfit => spec(trum) fit(ter) 

48# but in general it can be used for any image axis 

49# </etymology> 

50# 

51# <synopsis> 

52# specfit fits models to 1-d profiles. It is built on top of ia.fitprofile() 

53# </synopsis>  

54# 

55# <example> 

56# specfit(imagename="myline.im", ngauss=2, poly=3, model="mymodel.im", multi=true, residual="myresid.im") 

57# 

58# </example> 

59# 

60# <motivation> 

61# To make users happy, cf https://bugs.aoc.nrao.edu/browse/CAS-607 

62# </motivation> 

63# 

64 

65########################################################################### 

66 

67import sys 

68import glob 

69import time 

70 

71from casatools import image 

72from casatasks import casalog 

73 

74from .ialib import write_image_history, get_created_images 

75 

76 

77def specfit( 

78 imagename, box, region, chans, stokes, axis, mask, ngauss, 

79 poly, estimates, minpts, multifit, model, residual, amp, amperr, 

80 center, centererr, fwhm, fwhmerr, integral, integralerr, wantreturn, 

81 stretch, logresults, pampest, pcenterest, pfwhmest, pfix, 

82 gmncomps, gmampcon, gmcentercon, gmfwhmcon, gmampest, gmcenterest, 

83 gmfwhmest, gmfix, logfile, append, pfunc, goodamprange, goodcenterrange, 

84 goodfwhmrange, sigma, outsigma 

85): 

86 casalog.origin('specfit') 

87 retval = None 

88 myia = image() 

89 myia.dohistory(False) 

90 try: 

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

92 raise Exception("Cannot create image analysis tool using " + imagename) 

93 

94 target_time = time.time() 

95 retval = myia.fitprofile( 

96 box=box, region=region, chans=chans, 

97 stokes=stokes, axis=axis, mask=mask, 

98 ngauss=ngauss, poly=poly, 

99 estimates=estimates, minpts=minpts, 

100 multifit=multifit, model=model, 

101 residual=residual, amp=amp, amperr=amperr, 

102 center=center, centererr=centererr, 

103 fwhm=fwhm, fwhmerr=fwhmerr, 

104 integral=integral, integralerr=integralerr, 

105 stretch=stretch, logresults=logresults, 

106 pampest=pampest, pcenterest=pcenterest, 

107 pfwhmest=pfwhmest, pfix=pfix, 

108 gmncomps=gmncomps, gmampcon=gmampcon, 

109 gmcentercon=gmcentercon, gmfwhmcon=gmfwhmcon, 

110 gmampest=gmampest, gmcenterest=gmcenterest, 

111 gmfwhmest=gmfwhmest, gmfix=gmfix, logfile=logfile, 

112 append=append, pfunc=pfunc, goodamprange=goodamprange, 

113 goodcenterrange=goodcenterrange, goodfwhmrange=goodfwhmrange, 

114 sigma=sigma, outsigma=outsigma 

115 ) 

116 

117 try: 

118 param_names = specfit.__code__.co_varnames[:specfit.__code__.co_argcount] 

119 local_vars = locals( ) 

120 param_vals = [local_vars[p] for p in param_names] 

121 

122 ims = [model, residual] 

123 for x in [amp, amperr, center, centererr, fwhm, fwhmerr, integral, integralerr]: 

124 if x: 

125 ims.extend(get_created_images(x, target_time)) 

126 for im in ims: 

127 write_image_history(im, sys._getframe().f_code.co_name,param_names, param_vals, casalog) 

128 

129 except Exception as instance: 

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

131 

132 finally: 

133 myia.done() 

134 if (wantreturn): 

135 return retval 

136 if (retval): 

137 del retval