CalibrationStats.hpp
1 #ifndef OPALS_CALIBRATION_STATS_HPP_INCLUDED
2 #define OPALS_CALIBRATION_STATS_HPP_INCLUDED
3 
4 #pragma once
5 
6 #include <opals/config.hpp>
7 #include <opals/Vector.hpp>
8 #include <opals/Path.hpp>
9 #include <opals/CustomOptionType.hpp>
10 
11 namespace opals {
12 
13  /// \brief CalibrationRegion stores calibration results of a single region based on a single ODM file.
14  ///
15  /// The id of the object corresponds to the polygon id within the calRegionFile (see ModuleRadioCal). The filename of the ODM from which the points were selected for calibration
16  /// is stored in the Filename member. Area contains the 2d area of the corresponding region. Details on the point counter can be found in the corresponding member description.
17  ///
18  class OPALS_API CalibrationRegion
19  {
20  public:
23 
24  void reset();
25 
26  bool isSetId() const;
27  bool isSetFilename() const;
28  bool isSetArea() const;
29  bool isSetPtsInRegion() const;
30  bool isSetPtsFiltered() const;
31  bool isSetPtsNoNormal() const;
32  bool isSetPtsExceededMaxSigma() const;
33  bool isSetPtsMultiEchos() const;
34  bool isSetPtsCalibrated() const;
35  bool isSetMean() const;
36  bool isSetStdDev() const;
37  bool isSetMedian() const;
38 
39  int64_t getId() const;
40  opals::Path getFilename() const;
41  double getArea() const;
42  int64_t getPtsInRegion() const;
43  int64_t getPtsFiltered() const;
44  int64_t getPtsNoNormal() const;
45  int64_t getPtsExceededMaxSigma() const;
46  int64_t getPtsMultiEchos() const;
47  int64_t getPtsCalibrated() const;
48  double getMean() const;
49  double getStdDev() const;
50  double getMedian() const;
51 
52  void setId(const int64_t& id);
53  void setFilename(const opals::Path& filename);
54  void setArea(const double &area);
55  void setPtsInRegion(const int64_t &pts);
56  void setPtsFiltered(const int64_t &pts);
57  void setPtsNoNormal(const int64_t &pts);
58  void setPtsExceededMaxSigma(const int64_t &pts);
59  void setPtsMultiEchos(const int64_t &pts);
60  void setPtsCalibrated(const int64_t &pts);
61  void setMean(const double &mean);
62  void setStdDev(const double &stdDev);
63  void setMedian(const double &median);
64 
65  String logCalibrationRegion() const; ///< for xml output
66 
67  protected:
68  int64_t _id;
69  opals::Path _filename;
70  double _area;
71  int64_t _ptsInRegion; ///< total number of points in the region
72  int64_t _ptsFiltered; ///< number of points that were filtered and therefore ignored for calibration constant estimation
73  int64_t _ptsNoNormal; ///< number of points that didn't have a normal vector information (ignored for calibration constant estimation)
74  int64_t _ptsExceededMaxSigma; ///< number of points that exceeded the max sigma threshold of its normal vector (ignored for calibration constant estimation)
75  int64_t _ptsMultiEchos; ///< number of multi echo points (ignored for calibration constant estimation)
76  int64_t _ptsCalibrated; ///< number of points that were used for calibration constant estimation
77 
78  double _mean;
79  double _stdDev;
80  double _median;
81  };
82 
83  /// \brief A CalibrationEntry object stores statistics and results of one calibration constant estimation.
84  ///
85  /// ModuleRadioCal estimates the calibration constant based on (multiple) defined regions with known reflectivity. For each region
86  /// a CalibrationRegion object is added to the region vector. The accumulated results of the regions are then stored within the object
87  /// itself. In case the splitByAttribute parameter was set for ModuleRadioCal run, the corresponding attribute value is also stored. If
88  /// the attribute is empty (isSetAttribute() == false) the object is considered as the default entry object.
89  ///
90  class OPALS_API CalibrationEntry
91  {
92  public:
94 
97 
98  void reset();
99 
100  bool isSetAttribute() const;
101  bool isSetPtsCalibrated() const;
102  bool isSetCalibrationConst() const;
103  bool isSetRegions() const;
104 
105  int64_t getAttribute() const;
106  int64_t getPtsCalibrated() const; ///< sum of calibrated points in all regions
107  double getCalibrationConst() const;
108  RegionVector getRegions() const;
109 
110  void setAttribute(const int64_t& attribute);
111  void setPtsCalibrated(const int64_t &pts);
112  void setCalibrationConst(const double& cal);
113  void setRegions(const RegionVector& regions);
114 
115  double computeWeightedMeanOfMedians() const; ///< computes the point weighted average of the median of all regions
116 
117  String logCalibrationEntry() const; ///< for xml output
118 
119  protected:
120  int64_t _attribute;
121  int64_t _ptsCalibrated;
122  double _calibrationConst;
123  RegionVector _regions;
124  };
125 
126  /// \class CalibrationStats
127  /// A CalibrationStats object stores full calibration results and statistics.
128  /** The object basically stores a vector of calibrations entries. Each entry corresponds to calibration constant estimation. In case only one calibration constant was estimated (standard), the vector has only one element. */
129  /** If ModuleRadioCal was run with splitByAttribute parameter,
130  an element for each unique attribute value is added to the entry vector. It is possible to store one default entry
131  (CalibrationEntry::isSetAttribute() == false) which is used for calibrating points that do not have an attribute matching element in the
132  entry vector
133 
134  The class provides three different string to object parser:
135  - a simple single real value parser -> creates default entry with the given calibration constant
136  - attribute-calibr.constant-matrix parser: "[[attr1 cal.const1] [attr2 cal.const2] ... ]" or "[[default.cal.const] [attr1 cal.const1] [attr2 cal.const2] ... ]"
137  - full syntax parser -> parses object to string representation. example:
138  "CalibrationEntry[Attribute[-15] PtsCalibrated[108] CalibrationConst[764.450] Regions[ CalibrationRegion[ Id[600001] Area[0.275] ...] ] ]"
139 
140  \author JO
141  \date 27.06.2018
142  */
143  class OPALS_API CalibrationStats : public CustomOptionType<CalibrationStats>
144  {
145  public:
147 
149  CalibrationStats(double singleCalValue); ///< create an object based on a single calibration constant
150  ~CalibrationStats();
151 
152  void reset(); ///< reset object (removes all entries)
153 
154  bool isSetEntries() const;
155  EntryVector getEntries() const;
156  void setEntries(const EntryVector &entries);
157 
158  int getDefaultCalibrationConstIndex() const; ///< get index of default calibration constant (-1 if no default calibration constant is set)
159  double computeDefaultCalibrationConst() const; ///< compute a default calibration constant (point count weighted average of all calibration constants)
160 
161  String logCalibrationStats() const; ///< for xml output
162 
163  static bool exportsPythonType();
164  static const char * help();
165  static const char * syntax();
166 
167  protected:
168  EntryVector _entries;
169  };
170 }
171 
172 #endif //OPALS_CALIBRATION_STATS_HPP_INCLUDED