LCOV - code coverage report
Current view: top level - imageanalysis/ImageAnalysis - ImageCollapserData.cc (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 73 73 100.0 %
Date: 2023-10-25 08:47:59 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         232 : std::shared_ptr<const std::map<uInt, String>> ImageCollapserData::funcNameMap() {
      15         232 :         if (! _funcNameMap) {
      16           2 :                 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             :         }
      35         232 :         return _funcNameMap;
      36             : }
      37             : 
      38         232 : std::shared_ptr<const std::map<uInt, String>> ImageCollapserData::minMatchMap() {
      39         232 :         if (! _minMatchMap) {
      40           2 :                 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             :         }
      59         232 :         return _minMatchMap;
      60             : }
      61             : 
      62         232 : ImageCollapserData::AggregateType ImageCollapserData::aggregateType(
      63             :         const String& aggString
      64             : ) {
      65         232 :         ThrowIf (
      66             :                 aggString.empty(),
      67             :                 "Aggregate function name is not specified and it must be."
      68             :         );
      69         464 :         String agg = aggString;
      70         232 :         agg.downcase();
      71         464 :         auto funcNamePtr = funcNameMap();
      72         464 :         auto minMatch = minMatchMap();
      73        1134 :         for (const auto& p: *minMatch) {
      74        1133 :             auto key = p.first;
      75        1133 :             auto minMatch = p.second;
      76        1133 :             auto funcName = (*funcNamePtr).at(key);
      77        1133 :             if (
      78        1133 :                 agg.startsWith(minMatch)
      79        1133 :                 && funcName.startsWith(agg)
      80             :             ) {
      81         462 :                 return (AggregateType)key;
      82             :             }
      83             :         }
      84           1 :         ThrowCc("Unknown aggregate function specified by " + aggString);
      85             : }
      86             : 
      87             : std::shared_ptr<const std::set<ImageCollapserData::AggregateType>>
      88         322 : ImageCollapserData::aggTypesSupportedDegenAxes() {
      89         322 :     if (! _degenAxesSupported) {
      90           2 :         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             :     }
     104         322 :     return _degenAxesSupported;
     105             : }
     106             : 
     107             : 
     108             : }

Generated by: LCOV version 1.16