LCOV - code coverage report
Current view: top level - mstransform/TVI - UVContSubResult.cc (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 61 61 100.0 %
Date: 2023-10-25 08:47:59 Functions: 2 2 100.0 %

          Line data    Source code
       1             : //# UVContSubResult.h: implementation of the UVContSubResult class
       2             : //#
       3             : //#  CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
       4             : //#  Copyright (C) Associated Universities, Inc. Washington DC, USA 2021, All rights reserved.
       5             : //#  Copyright (C) European Southern Observatory, 2021, All rights reserved.
       6             : //#
       7             : //#  This library is free software; you can redistribute it and/or
       8             : //#  modify it under the terms of the GNU Lesser General Public
       9             : //#  License as published by the Free software Foundation; either
      10             : //#  version 2.1 of the License, or (at your option) any later version.
      11             : //#
      12             : //#  This library is distributed in the hope that it will be useful,
      13             : //#  but WITHOUT ANY WARRANTY, without even the implied warranty of
      14             : //#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             : //#  Lesser General Public License for more details.
      16             : //#
      17             : //#  You should have received a copy of the GNU Lesser General Public
      18             : //#  License along with this library; if not, write to the Free Software
      19             : //#  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      20             : //#  MA 02111-1307  USA
      21             : //# $Id: $
      22             : 
      23             : #include <mstransform/TVI/UVContSubResult.h>
      24             : 
      25             : using namespace casacore;
      26             : 
      27             : namespace casa { //# NAMESPACE CASA - BEGIN
      28             : 
      29             : namespace vi { //# NAMESPACE VI - BEGIN
      30             : 
      31        3422 : void UVContSubResult::addOneFit(int field, int scan, int spw, int pol, Complex chiSquared)
      32             : {
      33        3422 :     auto &polRes = accum[field][scan][spw];
      34        3422 :     auto resIt = polRes.find(pol);
      35        3422 :     if (resIt == polRes.end()) {
      36         360 :         FitResultAcc fitResult;
      37         360 :         fitResult.count = 1;
      38         360 :         fitResult.chiSqAvg = chiSquared;
      39         360 :         fitResult.chiSqMin = chiSquared;
      40         360 :         fitResult.chiSqMax = chiSquared;
      41         360 :         polRes.emplace(pol, fitResult);
      42             :     } else {
      43        3062 :         auto &fitResult = resIt->second;
      44        3062 :         fitResult.count++;
      45        6124 :         fitResult.chiSqAvg += (chiSquared - fitResult.chiSqAvg) /
      46        3062 :             static_cast<float>(fitResult.count);
      47        3062 :         if (chiSquared < fitResult.chiSqMin)
      48         134 :             fitResult.chiSqMin = chiSquared;
      49        3062 :         if (chiSquared > fitResult.chiSqMax)
      50         128 :             fitResult.chiSqMax = chiSquared;
      51             :     }
      52        3422 : }
      53             : 
      54             : /*
      55             :  * Produces a record from information accumulated for every fit that
      56             :  * is calculated by the UVContSub TVI (addOneFit()). This is used at
      57             :  * the moment to hold basic goodness-of-fit information. The record
      58             :  * produced by this function is meant to be returned as result by the
      59             :  * UVContSub TVI and can be returned by the uvcontsub task. The result
      60             :  * record/dictionary would look like:
      61             :  *
      62             :  * {'description': 'summary of data fitting results in uv-continuum subtraction',
      63             :  *    'goodness_of_fit': {'field': {'0': {'scan': {'3': {'spw': {'0':
      64             :  *             {'polarization': {'0': {'chi_squared': {'average': {'imag': 0.0001153,
      65             :  *                                                                'real': 0.0001143},
      66             :  *                                                     'max': {'imag': 0.0001199,
      67             :  *                                                             'real': 0.0001255},
      68             :  *                                                     'min': {'imag': 0.0001117,
      69             :  *                                                             'real': 0.0001069}},
      70             :  *                                     'count': 16},
      71             :  *                               '1': {'chi_squared': {'average': {'imag': 0.0001143,
      72             :  *                                                                 'real': 0.0001150},
      73             :  * ...
      74             :  *
      75             :  * @retunrs record of results accumulated by the UVContSub TVI throughout iterations
      76             :  */
      77          44 : Record UVContSubResult::getAccumulatedResult() const
      78             : {
      79          88 :     Record fieldRec;
      80          99 :     for (const auto fieldIt : accum) {
      81         110 :         Record srec;
      82         123 :         for (const auto scanIt : fieldIt.second) {
      83         136 :             Record sprec;
      84         211 :             for (const auto spwIt : scanIt.second) {
      85         286 :                 Record polrec;
      86         503 :                 for (const auto polIt : spwIt.second) {
      87         360 :                     const auto fitResult = polIt.second;
      88         720 :                     Record avg;
      89         360 :                     avg.define("real", fitResult.chiSqAvg.real());
      90         360 :                     avg.define("imag", fitResult.chiSqAvg.imag());
      91         720 :                     Record min;
      92         360 :                     min.define("real", fitResult.chiSqMin.real());
      93         360 :                     min.define("imag", fitResult.chiSqMin.imag());
      94         720 :                     Record max;
      95         360 :                     max.define("real", fitResult.chiSqMax.real());
      96         360 :                     max.define("imag", fitResult.chiSqMax.imag());
      97         720 :                     Record chisq;
      98         360 :                     chisq.defineRecord("average", avg);
      99         360 :                     chisq.defineRecord("min", min);
     100         360 :                     chisq.defineRecord("max", max);
     101             : 
     102         360 :                     Record stats;
     103         360 :                     stats.defineRecord("chi_squared", chisq);
     104         360 :                     stats.define("count", (unsigned int)fitResult.count);
     105         360 :                     polrec.defineRecord(std::to_string(polIt.first), stats);
     106             :                 }
     107         143 :                 Record polTop;
     108         143 :                 polTop.defineRecord("polarization", polrec);
     109         143 :                 sprec.defineRecord(std::to_string(spwIt.first), polTop);
     110             :             }
     111          68 :             Record spwTop;
     112          68 :             spwTop.defineRecord("spw", sprec);
     113          68 :             srec.defineRecord(std::to_string(scanIt.first), spwTop);
     114             :         }
     115          55 :         Record scanTop;
     116          55 :         scanTop.defineRecord("scan", srec);
     117          55 :         fieldRec.defineRecord(std::to_string(fieldIt.first), scanTop);
     118             :     }
     119          88 :     Record gof;
     120          44 :     gof.defineRecord("field", fieldRec);
     121             : 
     122          44 :     Record uvcont;
     123          44 :     uvcont.defineRecord("goodness_of_fit", gof);
     124          44 :     uvcont.define("description",
     125             :                   "summary of data fitting results in uv-continuum subtraction");
     126          88 :     return uvcont;
     127             : }
     128             : 
     129             : } //# NAMESPACE VI - END
     130             : 
     131             : } //# NAMESPACE CASA - END

Generated by: LCOV version 1.16