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

Generated by: LCOV version 1.16