DP3
ParmValue.h
Go to the documentation of this file.
1 // ParmValue.h: A class containing the values of a parameter
2 //
3 // Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 
9 
10 #ifndef LOFAR_PARMDB_PARMVALUE_H
11 #define LOFAR_PARMDB_PARMVALUE_H
12 
13 #include "Grid.h"
14 #include "Axis.h"
15 
16 #include <casacore/casa/Arrays/Array.h>
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 namespace dp3 {
23 namespace parmdb {
24 
27 
29 
33 //
38 
39 class ParmValue {
40  public:
42  typedef std::shared_ptr<ParmValue> ShPtr;
43 
45  enum FunkletType {
47  Scalar = 0,
49  Polc = 1,
51  PolcLog = 2
52  };
53 
55  explicit ParmValue(double value = 0.);
56 
59 
61 
64 
66  void setScalar(double value);
67 
69  void setCoeff(const casacore::Array<double>&);
70 
73  void setScalars(const Grid&, const casacore::Array<double>&);
74 
78  void setErrors(const casacore::Array<double>&);
79 
82  unsigned int nx() const {
83  return static_cast<unsigned int>(itsValues.shape()[0]);
84  }
85  unsigned int ny() const {
86  return static_cast<unsigned int>(itsValues.shape()[1]);
87  }
89 
92  const casacore::Array<double>& getValues() const { return itsValues; }
93  casacore::Array<double>& getValues() { return itsValues; }
95 
97  const Grid& getGrid() const { return itsGrid; }
98 
100  bool hasErrors() const { return itsErrors != nullptr; }
101 
104  const casacore::Array<double>& getErrors() const { return *itsErrors; }
105  casacore::Array<double>& getErrors() { return *itsErrors; }
107 
110  int getRowId() const { return itsRowId; }
111  void setRowId(int rowId) { itsRowId = rowId; }
112  void clearRowId() { itsRowId = -1; }
114 
117  static casacore::Matrix<double> scale2(const casacore::Matrix<double>& coeff,
118  double offx, double offy,
119  double scalex, double scaley);
120 
124  bool rescale(double sx, double ex, double sy, double ey,
125  const Box& oldDomain);
126 
127  private:
129  void copyOther(const ParmValue& that);
130 
133  static void fillPascal(casacore::Matrix<double>& pascal, int order);
134 
135  // Data members.
136  Grid itsGrid;
137  casacore::Array<double> itsValues;
138  casacore::Array<double>* itsErrors;
139  int itsRowId;
140 };
141 
145 
147  public:
153  explicit ParmValueSet(const ParmValue& defaultValue = ParmValue(),
155  double perturbation = 1e-6, bool pertRel = true,
156  const Box& scaleDomain = Box());
157 
161  ParmValueSet(const Grid& domainGrid,
162  const std::vector<ParmValue::ShPtr>& values,
163  const ParmValue& defaultValue = ParmValue(),
165  double perturbation = 1e-6, bool pertRel = true);
166 
169 
172 
176  void setSolveGrid(const Grid& solveGrid);
177 
179  ParmValue::FunkletType getType() const { return itsType; }
180 
184  const casacore::Array<bool>& getSolvableMask() const {
185  return itsSolvableMask;
186  }
187  void setSolvableMask(const casacore::Array<bool>& mask) {
188  itsSolvableMask.assign(mask);
189  }
191 
193  double getPerturbation() const { return itsPerturbation; }
194 
196  bool getPertRel() const { return itsPertRel; }
197 
199  const Grid& getGrid() const { return itsDomainGrid; }
200 
202  unsigned int size() const { return itsValues.size(); }
203 
205  bool empty() const { return itsValues.size() == 0; }
206 
208  const ParmValue& getDefParmValue() const { return itsDefaultValue; }
209 
212  const Box& getScaleDomain() const { return itsScaleDomain; }
213  void setScaleDomain(const Box& domain) { itsScaleDomain = domain; }
215 
218  const ParmValue& getFirstParmValue() const;
219 
222  const ParmValue& getParmValue(int i) const { return *(itsValues[i]); }
223  ParmValue& getParmValue(int i) { return *(itsValues[i]); }
225 
231  bool isDirty() const { return itsDirty; }
232  void setDirty(bool dirty = true) { itsDirty = dirty; }
234 
235  private:
238  void createValues(const Grid& solveGrid);
239  void checkGrid(const Grid& solveGrid);
240  void addValues(const Grid& solveGrid);
241  void addCoeffValues(const Grid& solveGrid);
242  ParmValue::ShPtr copyParmCoeff(const ParmValue::ShPtr& pval);
244 
246  ParmValue::FunkletType itsType;
247  double itsPerturbation;
248  bool itsPertRel;
249  casacore::Array<bool> itsSolvableMask;
250  Grid itsDomainGrid;
251  std::vector<ParmValue::ShPtr> itsValues;
252  ParmValue itsDefaultValue;
253  Box itsScaleDomain;
254  bool itsDirty;
255 };
256 
258 
259 } // namespace parmdb
260 } // namespace dp3
261 
262 #endif
Classes representing a regular or irregular axis.
Class representing a regular or irregular 2-D grid.
Class representing a 2-dim box.
Definition: Box.h:36
The envelope class for a 2-D grid with regular or irregular axes. -.
Definition: Grid.h:83
A class holding information of multiple domains of a parameter. ParmValueSet holds the information of...
Definition: ParmValue.h:146
void setSolvableMask(const casacore::Array< bool > &mask)
Definition: ParmValue.h:187
ParmValueSet(const ParmValue &defaultValue=ParmValue(), ParmValue::FunkletType=ParmValue::Scalar, double perturbation=1e-6, bool pertRel=true, const Box &scaleDomain=Box())
const Grid & getGrid() const
Get access to the grid info, so a domain can be looked up.
Definition: ParmValue.h:199
bool empty() const
No ParmValues?
Definition: ParmValue.h:205
void setDirty(bool dirty=true)
Definition: ParmValue.h:232
unsigned int size() const
Get the nr of ParmValues.
Definition: ParmValue.h:202
ParmValueSet(const ParmValueSet &)
Copy constructor.
const ParmValue & getFirstParmValue() const
const ParmValue & getParmValue(int i) const
Definition: ParmValue.h:222
const ParmValue & getDefParmValue() const
Get the default ParmValue.
Definition: ParmValue.h:208
bool isDirty() const
Definition: ParmValue.h:231
const casacore::Array< bool > & getSolvableMask() const
Definition: ParmValue.h:184
void setScaleDomain(const Box &domain)
Definition: ParmValue.h:213
ParmValue & getParmValue(int i)
Definition: ParmValue.h:223
ParmValueSet(const Grid &domainGrid, const std::vector< ParmValue::ShPtr > &values, const ParmValue &defaultValue=ParmValue(), ParmValue::FunkletType type=ParmValue::Scalar, double perturbation=1e-6, bool pertRel=true)
void setSolveGrid(const Grid &solveGrid)
double getPerturbation() const
Get the perturbation value.
Definition: ParmValue.h:193
bool getPertRel() const
Is the perturbation relative or absolute?
Definition: ParmValue.h:196
ParmValue::FunkletType getType() const
Get the funklet type.
Definition: ParmValue.h:179
ParmValueSet & operator=(const ParmValueSet &)
Assignment.
const Box & getScaleDomain() const
Definition: ParmValue.h:212
A class containing the values of a parameter.
Definition: ParmValue.h:39
const Grid & getGrid() const
Get the grid.
Definition: ParmValue.h:97
const casacore::Array< double > & getValues() const
Definition: ParmValue.h:92
int getRowId() const
Definition: ParmValue.h:110
void setScalars(const Grid &, const casacore::Array< double > &)
casacore::Array< double > & getErrors()
Definition: ParmValue.h:105
ParmValue(const ParmValue &)
Copy constructor makes a deep copy.
std::shared_ptr< ParmValue > ShPtr
Define a shared pointer for this type.
Definition: ParmValue.h:42
FunkletType
Define the possible funklet types.
Definition: ParmValue.h:45
@ Scalar
A constant scalar.
Definition: ParmValue.h:47
@ Polc
A polynomial.
Definition: ParmValue.h:49
@ PolcLog
A polynomial of logs.
Definition: ParmValue.h:51
void clearRowId()
Definition: ParmValue.h:112
unsigned int ny() const
Definition: ParmValue.h:85
void setRowId(int rowId)
Definition: ParmValue.h:111
bool rescale(double sx, double ex, double sy, double ey, const Box &oldDomain)
static casacore::Matrix< double > scale2(const casacore::Matrix< double > &coeff, double offx, double offy, double scalex, double scaley)
ParmValue(double value=0.)
Construct with the given scalar value.
void setErrors(const casacore::Array< double > &)
void setScalar(double value)
Set as a single scalar value.
bool hasErrors() const
Are there errors? If false, the result of getErrors is undefined.
Definition: ParmValue.h:100
unsigned int nx() const
Definition: ParmValue.h:82
const casacore::Array< double > & getErrors() const
Definition: ParmValue.h:104
void setCoeff(const casacore::Array< double > &)
Set as an array of coefficients.
casacore::Array< double > & getValues()
Definition: ParmValue.h:93
ParmValue & operator=(const ParmValue &)
Assignment makes a deep copy.
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53