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-12-11 20:54:31 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         247 : std::shared_ptr<const std::map<uInt, String>> ImageCollapserData::funcNameMap() {
      15         247 :         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         247 :         return _funcNameMap;
      36             : }
      37             : 
      38         247 : std::shared_ptr<const std::map<uInt, String>> ImageCollapserData::minMatchMap() {
      39         247 :         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         247 :         return _minMatchMap;
      60             : }
      61             : 
      62         247 : ImageCollapserData::AggregateType ImageCollapserData::aggregateType(
      63             :         const String& aggString
      64             : ) {
      65         247 :         ThrowIf (
      66             :                 aggString.empty(),
      67             :                 "Aggregate function name is not specified and it must be."
      68             :         );
      69         247 :         String agg = aggString;
      70         247 :         agg.downcase();
      71         247 :         auto funcNamePtr = funcNameMap();
      72         247 :         auto minMatch = minMatchMap();
      73        1209 :         for (const auto& p: *minMatch) {
      74        1208 :             auto key = p.first;
      75        1208 :             auto minMatch = p.second;
      76        1208 :             auto funcName = (*funcNamePtr).at(key);
      77        1208 :             if (
      78        1208 :                 agg.startsWith(minMatch)
      79        1208 :                 && funcName.startsWith(agg)
      80             :             ) {
      81         492 :                 return (AggregateType)key;
      82             :             }
      83        1454 :         }
      84           1 :         ThrowCc("Unknown aggregate function specified by " + aggString);
      85         249 : }
      86             : 
      87             : std::shared_ptr<const std::set<ImageCollapserData::AggregateType>>
      88         337 : ImageCollapserData::aggTypesSupportedDegenAxes() {
      89         337 :     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         337 :     return _degenAxesSupported;
     105             : }
     106             : 
     107             : 
     108             : }

Generated by: LCOV version 1.16