Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_spxfit.py: 14%
44 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 19:10 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 19:10 +0000
2##########################################################################
3# task_spxfit.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 spectral index like functions.
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# spxfit => sp(ectral) (inde)x fit(ter)
48# but in general it can be used for any image axis
49# </etymology>
50#
51# <synopsis>
52# spxfit fits models to 1-d profiles. It is built on top of ia.fitprofile()
53# </synopsis>
54#
55# <example>
56#
57# </example>
58#
59# <motivation>
60# To make users happy, cf https://bugs.aoc.nrao.edu/browse/CAS-3116
61# </motivation>
62#
64###########################################################################
65from casatools import image
66from casatasks import casalog
68from .ialib import write_image_history, get_created_images
69import sys
70import time
72def spxfit(
73 imagename, box, region, chans, stokes,
74 axis, mask, minpts, multifit, spxtype,
75 spxest, spxfix, div, spxsol, spxerr,
76 model, residual, wantreturn,
77 stretch, logresults, logfile, append,
78 sigma, outsigma
79):
80 casalog.origin('spxfit')
81 myia = image()
82 myia.dohistory(False)
83 retval = None
84 try:
85 if type(imagename) == list and len(imagename) > 1:
86 myia = myia.imageconcat(outfile="", infiles=imagename, axis=axis, relax=True)
87 else:
88 if type(imagename) == list and len(imagename) == 1:
89 imagename = imagename[0]
90 if (not myia.open(imagename)):
91 raise Exception("Cannot create image analysis tool using " + str(imagename))
92 sigmacopy = sigma
93 if type(sigma) == list and type(sigma) == str:
94 if len(sigma) == 1:
95 sigmacopy = sigma[0]
96 else:
97 sigia = myia.imageconcat(outfile="", infiles=sigma, axis=axis, relax=True)
98 sigmacopy = sigia.getchunk()
99 sigia.done()
100 target_time = time.time()
101 retval = myia.fitprofile(
102 box=box, region=region, chans=chans,
103 stokes=stokes, axis=axis, mask=mask,
104 minpts=minpts, ngauss=0, multifit=multifit,
105 spxtype=spxtype, spxest=spxest, spxfix=spxfix,
106 div=div, model=model, residual=residual,
107 stretch=stretch, logresults=logresults,
108 spxsol=spxsol, spxerr=spxerr, logfile=logfile,
109 append=append,
110 sigma=sigmacopy, outsigma=outsigma
111 )
112 try:
113 param_names = spxfit.__code__.co_varnames[:spxfit.__code__.co_argcount]
114 local_vars = locals( )
115 param_vals = [local_vars[p] for p in param_names]
116 ims = [model, residual]
117 for x in [spxsol, spxerr]:
118 if x:
119 ims.extend(get_created_images(x, target_time))
120 for im in ims:
121 write_image_history(
122 im, sys._getframe().f_code.co_name,
123 param_names, param_vals, casalog
124 )
125 except Exception as instance:
126 casalog.post("*** Error \'%s\' updating HISTORY" % (instance), 'WARN')
127 finally:
128 myia.done()
129 if (wantreturn):
130 return retval
131 if (retval):
132 del retval
133 return