Skip to content
Snippets Groups Projects
Select Git revision
  • 2ae4762aa46ed8a3b6efd142dcb7d0b2f0a241b8
  • master default protected
  • gec-84-c-compiler-dependency
  • gec-50-only-test-plot-with-gtkmm
  • make-baseline-aoqplot-nicer
  • use-system-pybind11
  • fix-filterbank-imagesets
  • fix-drawing-large-images
  • allow-writing-to-filterbanksets
  • implement-nroamlize-bandpass-for-non-complex-data
  • support-multiple-pols-in-filterbank
  • solve-flipped-axis-crashes
  • improve-statistics-speed
  • avoid-deprecated-gtkmm
  • ast-1621-deprecated-deletetable
  • ast-1613-update-hdf5-url
  • rename-use-input-flags-variable
  • dockerfile-fix
  • open-correct-data-column
  • add-target-cpu
  • add-git-to-format-conatiner
  • v3.4.0
  • v3.3.0
  • v3.2.0
  • test-vx.y
  • v3.1.0
  • v3.0.0
  • v2.15.0
  • v2.14.0
  • v2.13.0
  • v2.12.1
  • v2.12.0
  • v2.11.0
  • v2.10.0
  • v2.9.0
  • v2.8.0
  • v2.7.0
  • v2.6.0
  • v2.5.0
  • v2.4.0
  • v2.3.0
41 results

aoqplotpagecontroller.cpp

Blame
  • user avatar
    André Offringa authored
    2ae4762a
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    aoqplotpagecontroller.cpp 4.80 KiB
    #include "aoqplotpagecontroller.h"
    
    #include "../twodimensionalplotpage.h"
    
    #include "../../quality/statisticsderivator.h"
    
    #include "../../util/logger.h"
    
    AOQPlotPageController::AOQPlotPageController()
        : _page(nullptr), _statCollection(nullptr) {}
    
    void AOQPlotPageController::UpdatePlot() {
      if (_page != nullptr) {
        updatePlotForSettings(_page->GetSelectedKinds(),
                              _page->GetSelectedPolarizations(),
                              _page->GetSelectedPhases());
      }
    }
    
    void AOQPlotPageController::updatePlotForSettings(
        const std::vector<QualityTablesFormatter::StatisticKind>& kinds,
        const std::set<SelectedPol>& pols, const std::set<PhaseType>& phases) {
      if (HasStatistics()) {
        _plot.Clear();
    
        std::map<std::string, int> units;
        for (const QualityTablesFormatter::StatisticKind k : kinds) {
          const std::string unit_str = StatisticsDerivator::GetUnits(k);
          std::map<std::string, int>::const_iterator iterator =
              units.find(unit_str);
          if (iterator == units.end()) {
            units.emplace(unit_str, units.size() % 2);
          }
        }
        _plot.Y2Axis().SetShow(false);
        int index = 0;
        for (const QualityTablesFormatter::StatisticKind k : kinds) {
          const std::string unit_str = StatisticsDerivator::GetUnits(k);
          const int axis_number = units.find(unit_str)->second;
          const bool multiple_units =
              units.size() > 3 || (units.size() > 2 && (axis_number % 2) == 0);
          XYPlotAxis& y_axis = axis_number == 1 ? _plot.Y2Axis() : _plot.YAxis();
          y_axis.SetShow(true);
          for (const SelectedPol p : pols) {
            for (const PhaseType ph : phases) {
              const std::string description =
                  multiple_units ? "Value"
                                 : StatisticsDerivator::GetDescWithUnits(k);
              plotStatistic(k, p, ph, index, description, axis_number == 1);
              ++index;
            }
          }
        }
    
        processPlot(_plot);
    
        if (_page != nullptr) {
          _page->Redraw();
        }
      }
    }
    
    double AOQPlotPageController::getValue(enum PhaseType phase,
                                           const std::complex<long double>& val) {
      switch (phase) {
        default:
        case AmplitudePhaseType:
          return sqrt(val.real() * val.real() + val.imag() * val.imag());
        case PhasePhaseType:
          return atan2(val.imag(), val.real());
        case RealPhaseType:
          return val.real();
        case ImaginaryPhaseType:
          return val.imag();
      }
    }
    
    void AOQPlotPageController::plotStatistic(
        QualityTablesFormatter::StatisticKind kind, SelectedPol pol,
        PhaseType phase, int lineIndex, const std::string& yDesc,
        bool second_axis) {
      const StatisticsDerivator derivator(*_statCollection);
      const size_t polCount = _statCollection->PolarizationCount();
      const std::map<double, DefaultStatistics>& statistics = getStatistics();
      std::ostringstream s;
      int polIndex = -1;
      s << StatisticsDerivator::GetDescription(kind);
      switch (pol) {
        case PolI:
          s << ", pol I";
          polIndex = 0;
          break;
        case PolPP:
          s << ", pol PP";
          polIndex = 0;
          break;
        case PolPQ:
          s << ", pol PQ";
          if (polCount == 4) polIndex = 1;
          break;
        case PolQP:
          s << ", pol QP";
          if (polCount == 4) polIndex = 2;
          break;
        case PolQQ:
          s << ", pol QQ";
          if (polCount == 4)
            polIndex = 3;
          else if (polCount == 2)
            polIndex = 1;
          break;
      }
      if (phase == RealPhaseType)
        s << " (real)";
      else if (phase == ImaginaryPhaseType)
        s << " (imag)";
      if (polIndex >= 0) {
        startLine(_plot, s.str(), lineIndex, yDesc, second_axis);
        for (std::map<double, DefaultStatistics>::const_iterator i =
                 statistics.begin();
             i != statistics.end(); ++i) {
          const double x = i->first;
          std::complex<long double> val;
    
          if (pol == PolI) {
            const std::complex<long double> valA =
                derivator.GetComplexStatistic(kind, i->second, 0);
            const std::complex<long double> valB =
                derivator.GetComplexStatistic(kind, i->second, polCount - 1);
            val = valA * 0.5l + valB * 0.5l;
          } else {
            val = derivator.GetComplexStatistic(kind, i->second, polIndex);
          }
          _plot.PushDataPoint(x, getValue(phase, val));
        }
      }
    }
    
    void AOQPlotPageController::SavePdf(
        const string& filename, QualityTablesFormatter::StatisticKind kind) {
      const std::vector<QualityTablesFormatter::StatisticKind> kinds{kind};
      const std::set<SelectedPol> pols{PolI};
      const std::set<PhaseType> phases{AmplitudePhaseType};
    
      updatePlotForSettings(kinds, pols, phases);
    
      _plot.SavePdf(filename);
    }
    
    void AOQPlotPageController::SetStatistics(
        const StatisticsCollection* statCollection,
        const std::vector<class AntennaInfo>& antennas) {
      processStatistics(statCollection, antennas);
    
      _statCollection = statCollection;
      UpdatePlot();
    }