LCOV - code coverage report
Current view: top level - imageanalysis/ImageAnalysis - ImageCollapserData.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 78 78 100.0 %
Date: 2025-08-06 00:27:07 Functions: 4 4 100.0 %

          Line data    Source code
       1             : #include <imageanalysis/ImageAnalysis/ImageCollapserData.h>
       2             : 
       3             : #include <casacore/casa/BasicSL/String.h>
       4             : #include <casacore/casa/Exceptions/Error.h>
       5             : 
       6             : using namespace casacore;
       7             : namespace casa {
       8             : 
       9             : std::shared_ptr<std::map<uInt, String>> ImageCollapserData::_funcNameMap = nullptr;
      10             : std::shared_ptr<std::map<uInt, String>> ImageCollapserData::_minMatchMap = nullptr;
      11             : std::shared_ptr<std::set<ImageCollapserData::AggregateType>>
      12             : ImageCollapserData::_degenAxesSupported = nullptr;
      13             : 
      14         258 : std::shared_ptr<const std::map<uInt, String>> ImageCollapserData::funcNameMap() {
      15         258 :         if (! _funcNameMap) {
      16           5 :                 std::map<uInt, String> ref;
      17           5 :                 ref[(uInt)FLUX] = "flux";
      18           5 :                 ref[(uInt)MADM] = "madm";
      19           5 :                 ref[(uInt)MAX] = "max";
      20           5 :                 ref[(uInt)MEAN] = "mean";
      21           5 :                 ref[(uInt)MEDIAN] = "median";
      22           5 :                 ref[(uInt)MIN] = "min";
      23           5 :                 ref[(uInt)NPTS] = "npts";
      24           5 :                 ref[(uInt)RMS] = "rms";
      25           5 :                 ref[(uInt)SQRTSUM] = "sqrtsum";
      26           5 :                 ref[(uInt)SQRTSUM_NPIX_BEAM] = "sqrtsum_npix_beam";
      27           5 :                 ref[(uInt)SQRTSUM_NPIX] = "sqrtsum_npix";
      28           5 :                 ref[(uInt)STDDEV] = "stddev";
      29           5 :                 ref[(uInt)SUM] = "sum";
      30           5 :                 ref[(uInt)VARIANCE] = "variance";
      31           5 :                 ref[(uInt)XMADM] = "xmadm";
      32           5 :                 ref[(uInt)ZERO] = "zero";
      33           5 :                 _funcNameMap.reset(new std::map<uInt, String>(ref));
      34           5 :         }
      35         258 :         return _funcNameMap;
      36             : }
      37             : 
      38         258 : std::shared_ptr<const std::map<uInt, String>> ImageCollapserData::minMatchMap() {
      39         258 :         if (! _minMatchMap) {
      40           5 :                 std::map<uInt, String> ref;
      41           5 :                 ref[(uInt)FLUX] = "f";
      42           5 :                 ref[(uInt)MADM] = "mad";
      43           5 :                 ref[(uInt)MAX] = "max";
      44           5 :                 ref[(uInt)MEAN] = "mea";
      45           5 :                 ref[(uInt)MEDIAN] = "med";
      46           5 :                 ref[(uInt)MIN] = "mi";
      47           5 :                 ref[(uInt)NPTS] = "n";
      48           5 :                 ref[(uInt)RMS] = "r";
      49           5 :                 ref[(uInt)SQRTSUM] = "sqrtsum";
      50           5 :                 ref[(uInt)SQRTSUM_NPIX_BEAM] = "sqrtsum_npix_beam";
      51           5 :                 ref[(uInt)SQRTSUM_NPIX] = "sqrtsum_npix";
      52           5 :                 ref[(uInt)STDDEV] = "st";
      53           5 :                 ref[(uInt)SUM] = "su";
      54           5 :                 ref[(uInt)VARIANCE] = "v";
      55           5 :                 ref[(uInt)XMADM] = "x";
      56           5 :                 ref[(uInt)ZERO] = "z";
      57           5 :                 _minMatchMap.reset(new std:: map<uInt, String>(ref));
      58           5 :         }
      59         258 :         return _minMatchMap;
      60             : }
      61             : 
      62         258 : ImageCollapserData::AggregateType ImageCollapserData::aggregateType(
      63             :         const String& aggString
      64             : ) {
      65         258 :         ThrowIf (
      66             :                 aggString.empty(),
      67             :                 "Aggregate function name is not specified and it must be."
      68             :         );
      69         258 :         String agg = aggString;
      70         258 :         agg.downcase();
      71         258 :         auto funcNamePtr = funcNameMap();
      72         258 :         auto minMatch = minMatchMap();
      73        1264 :         for (const auto& p: *minMatch) {
      74        1263 :             auto key = p.first;
      75        1263 :             auto minMatch = p.second;
      76        1263 :             auto funcName = (*funcNamePtr).at(key);
      77        1263 :             if (
      78        1263 :                 agg.startsWith(minMatch)
      79        1263 :                 && funcName.startsWith(agg)
      80             :             ) {
      81         514 :                 return (AggregateType)key;
      82             :             }
      83        1520 :         }
      84           1 :         ThrowCc("Unknown aggregate function specified by " + aggString);
      85         260 : }
      86             : 
      87             : std::shared_ptr<const std::set<ImageCollapserData::AggregateType>>
      88         348 : ImageCollapserData::aggTypesSupportedDegenAxes() {
      89         348 :     if (! _degenAxesSupported) {
      90           9 :         std::set<AggregateType> ref;
      91           9 :         ref.insert(MADM);
      92           9 :         ref.insert(MAX);
      93           9 :         ref.insert(MEAN);
      94           9 :         ref.insert(MEDIAN);
      95           9 :         ref.insert(MIN);
      96           9 :         ref.insert(NPTS);
      97           9 :         ref.insert(RMS);
      98           9 :         ref.insert(STDDEV);
      99           9 :         ref.insert(SUM);
     100           9 :         ref.insert(VARIANCE);
     101           9 :         ref.insert(XMADM);
     102           9 :         _degenAxesSupported.reset(new std::set<AggregateType>(ref));
     103           9 :     }
     104         348 :     return _degenAxesSupported;
     105             : }
     106             : 
     107             : 
     108             : }

Generated by: LCOV version 1.16