LCOV - code coverage report
Current view: top level - mstransform/TVI - UVContSubResult.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 66 0.0 %
Date: 2024-10-12 00:35:29 Functions: 0 2 0.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           0 : void UVContSubResult::addOneFit(int field, int scan, int spw, int pol, Complex chiSquared)
      32             : {
      33           0 :     auto &polRes = accum[field][scan][spw];
      34           0 :     auto resIt = polRes.find(pol);
      35           0 :     if (resIt == polRes.end()) {
      36           0 :         FitResultAcc fitResult;
      37           0 :         fitResult.count = 1;
      38           0 :         fitResult.chiSqAvg = chiSquared;
      39           0 :         fitResult.chiSqMin = chiSquared;
      40           0 :         fitResult.chiSqMax = chiSquared;
      41           0 :         polRes.emplace(pol, fitResult);
      42             :     } else {
      43           0 :         auto &fitResult = resIt->second;
      44           0 :         fitResult.count++;
      45           0 :         fitResult.chiSqAvg += (chiSquared - fitResult.chiSqAvg) /
      46           0 :             static_cast<float>(fitResult.count);
      47           0 :         if (chiSquared < fitResult.chiSqMin)
      48           0 :             fitResult.chiSqMin = chiSquared;
      49           0 :         if (chiSquared > fitResult.chiSqMax)
      50           0 :             fitResult.chiSqMax = chiSquared;
      51             :     }
      52           0 : }
      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           0 : Record UVContSubResult::getAccumulatedResult() const
      78             : {
      79           0 :     Record fieldRec;
      80           0 :     for (const auto fieldIt : accum) {
      81           0 :         Record srec;
      82           0 :         for (const auto scanIt : fieldIt.second) {
      83           0 :             Record sprec;
      84           0 :             for (const auto spwIt : scanIt.second) {
      85           0 :                 Record polrec;
      86           0 :                 for (const auto polIt : spwIt.second) {
      87           0 :                     const auto fitResult = polIt.second;
      88           0 :                     Record avg;
      89           0 :                     avg.define("real", fitResult.chiSqAvg.real());
      90           0 :                     avg.define("imag", fitResult.chiSqAvg.imag());
      91           0 :                     Record min;
      92           0 :                     min.define("real", fitResult.chiSqMin.real());
      93           0 :                     min.define("imag", fitResult.chiSqMin.imag());
      94           0 :                     Record max;
      95           0 :                     max.define("real", fitResult.chiSqMax.real());
      96           0 :                     max.define("imag", fitResult.chiSqMax.imag());
      97           0 :                     Record chisq;
      98           0 :                     chisq.defineRecord("average", avg);
      99           0 :                     chisq.defineRecord("min", min);
     100           0 :                     chisq.defineRecord("max", max);
     101             : 
     102           0 :                     Record stats;
     103           0 :                     stats.defineRecord("chi_squared", chisq);
     104           0 :                     stats.define("count", (unsigned int)fitResult.count);
     105           0 :                     polrec.defineRecord(std::to_string(polIt.first), stats);
     106           0 :                 }
     107           0 :                 Record polTop;
     108           0 :                 polTop.defineRecord("polarization", polrec);
     109           0 :                 sprec.defineRecord(std::to_string(spwIt.first), polTop);
     110           0 :             }
     111           0 :             Record spwTop;
     112           0 :             spwTop.defineRecord("spw", sprec);
     113           0 :             srec.defineRecord(std::to_string(scanIt.first), spwTop);
     114           0 :         }
     115           0 :         Record scanTop;
     116           0 :         scanTop.defineRecord("scan", srec);
     117           0 :         fieldRec.defineRecord(std::to_string(fieldIt.first), scanTop);
     118           0 :     }
     119           0 :     Record gof;
     120           0 :     gof.defineRecord("field", fieldRec);
     121             : 
     122           0 :     Record uvcont;
     123           0 :     uvcont.defineRecord("goodness_of_fit", gof);
     124           0 :     uvcont.define("description",
     125             :                   "summary of data fitting results in uv-continuum subtraction");
     126           0 :     return uvcont;
     127           0 : }
     128             : 
     129             : } //# NAMESPACE VI - END
     130             : 
     131             : } //# NAMESPACE CASA - END

Generated by: LCOV version 1.16