Isis 3 Programmer Reference
MinnaertEmpirical.cpp
1 #include <cmath>
2 #include "MinnaertEmpirical.h"
3 #include "IException.h"
4 
5 namespace Isis {
6  MinnaertEmpirical::MinnaertEmpirical(Pvl &pvl) : PhotoModel(pvl) {
7  PvlGroup &algo = pvl.findObject("PhotometricModel")
8  .findGroup("Algorithm", Pvl::Traverse);
9  // There are no default values for the Minnaert Empirical function; if user
10  // does not provide information, then an exception is thrown
11  if (algo.hasKeyword("PhaseList")) {
12  SetPhotoPhaseList(algo["PhaseList"]);
13  } else {
14  std::string msg = "The empirical Minnaert phase list was not provided by user";
15  throw IException(IException::User, msg, _FILEINFO_);
16  }
17  if (algo.hasKeyword("KList")) {
18  SetPhotoKList(algo["KList"]);
19  } else {
20  std::string msg = "The empirical Minnaert k exponent list was not provided by user";
21  throw IException(IException::User, msg, _FILEINFO_);
22  }
23  if (algo.hasKeyword("PhaseCurveList")) {
24  SetPhotoPhaseCurveList(algo["PhaseCurveList"]);
25  } else {
26  std::string msg = "The empirical Minnaert phase brightness list was not provided by user";
27  throw IException(IException::User, msg, _FILEINFO_);
28  }
29 
30  // Make sure all the vectors are the same size
31  p_photoPhaseAngleCount = (int)p_photoPhaseList.size();
32 
33  if (p_photoPhaseAngleCount != (int)p_photoKList.size()) {
34  std::string msg = "Number of empirical Minnaert k list values must be equal";
35  msg += "to number of phase angles provided";
36  throw IException(IException::User, msg, _FILEINFO_);
37  }
38 
39  if (p_photoPhaseAngleCount != (int)p_photoPhaseCurveList.size()) {
40  std::string msg = "Number of empirical Minnaert phase curve list values must be equal";
41  msg += "to number of phase angles provided";
42  throw IException(IException::User, msg, _FILEINFO_);
43  }
44 
45  // Create Cubic piecewise linear splines
46  p_photoKSpline.Reset();
48  p_photoKSpline.AddData(p_photoPhaseList,p_photoKList);
49  p_photoKSpline.SetCubicClampedEndptDeriv(1.0e30,1.0e30);
50  p_photoBSpline.Reset();
52  p_photoBSpline.AddData(p_photoPhaseList,p_photoPhaseCurveList);
53  p_photoBSpline.SetCubicClampedEndptDeriv(1.0e30,1.0e30);
54  }
55 
56  MinnaertEmpirical::~MinnaertEmpirical() {
57  p_photoKSpline.Reset();
58  p_photoBSpline.Reset();
59  p_photoPhaseList.clear();
60  p_photoKList.clear();
61  p_photoPhaseCurveList.clear();
62  }
63 
73  void MinnaertEmpirical::SetPhotoPhaseList(QString phasestrlist) {
74  double phaseangle;
75  IString strlist(phasestrlist);
76  p_photoPhaseList.clear();
77 
78  while (strlist.length()) {
79  phaseangle = strlist.Token(",");
80  if (phaseangle < 0.0 || phaseangle > 180.0) {
81  std::string msg = "Invalid value of empirical Minnaert phase angle list value [" +
82  IString(phaseangle) + "]";
84  }
85  p_photoPhaseList.push_back(phaseangle);
86  }
87  }
88 
98  void MinnaertEmpirical::SetPhotoKList(QString kstrlist) {
99  double kvalue;
100  IString strlist(kstrlist);
101  p_photoKList.clear();
102 
103  while (strlist.length()) {
104  kvalue = strlist.Token(",");
105  if (kvalue < 0.0) {
106  std::string msg = "Invalid value of Minnaert k list value [" +
107  IString(kvalue) + "]";
109  }
110  p_photoKList.push_back(kvalue);
111  }
112  }
113 
121  void MinnaertEmpirical::SetPhotoPhaseCurveList(QString phasecurvestrlist) {
122  double phasecurve;
123  IString strlist(phasecurvestrlist);
124  p_photoPhaseCurveList.clear();
125 
126  while (strlist.length()) {
127  phasecurve = strlist.Token(",");
128  p_photoPhaseCurveList.push_back(phasecurve);
129  }
130  }
131 
132  double MinnaertEmpirical::PhotoModelAlgorithm(double phase, double incidence,
133  double emission) {
134  static double pht_minnaert_empirical;
135  double incrad;
136  double emarad;
137  double munot;
138  double mu;
139  double kInterpolated = 0;
140  double bInterpolated = 0;
141 
142  static double old_phase = -9999;
143  static double old_incidence = -9999;
144  static double old_emission= -9999;
145 
146  // Don't need to do anything if the photometric angles are the same as before
147  if (old_phase == phase && old_incidence == incidence && old_emission == emission) {
148  return pht_minnaert_empirical;
149  }
150 
151  old_incidence = incidence;
152  old_emission = emission;
153 
154  incrad = incidence * Isis::PI / 180.0;
155  emarad = emission * Isis::PI / 180.0;
156  munot = cos(incrad);
157  mu = cos(emarad);
158 
159  if (phase != old_phase) {
160  kInterpolated = p_photoKSpline.Evaluate(phase, NumericalApproximation::Extrapolate);
161  bInterpolated = p_photoBSpline.Evaluate(phase, NumericalApproximation::Extrapolate);
162  old_phase = phase;
163  }
164 
165  if(munot <= 0.0 || mu <= 0.0 || incidence == 90.0 ||
166  emission == 90.0) {
167  pht_minnaert_empirical = 0.0;
168  }
169  else if(kInterpolated == 1.0) {
170  pht_minnaert_empirical = munot * bInterpolated;
171  }
172  else {
173  pht_minnaert_empirical = bInterpolated * munot * pow((munot * mu), (kInterpolated - 1.0));
174  }
175 
176  return pht_minnaert_empirical;
177  }
178 }
179 
180 extern "C" Isis::PhotoModel *MinnaertEmpiricalPlugin(Isis::Pvl &pvl) {
181  return new Isis::MinnaertEmpirical(pvl);
182 }
void SetPhotoKList(QString kstrlist)
Set the empirical Minnaert function K exponent list.
const double PI
The mathematical constant PI.
Definition: Constants.h:56
void SetPhotoPhaseCurveList(QString phasecurvestrlist)
Set the empirical Minnaert function phase curve list.
Search child objects.
Definition: PvlObject.h:170
virtual double PhotoModelAlgorithm(double phase, double incidence, double emission)
Return photometric phase angle list.
double Evaluate(const double a, const ExtrapType &etype=ThrowError)
Calculates interpolated or extrapolated value of tabulated data set for given domain value...
IString Token(const IString &separator)
Returns the first token in the IString.
Definition: IString.cpp:912
void Reset()
Resets the state of the object.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
void SetCubicClampedEndptDeriv(const double yp1, const double ypn)
Sets the values for the first derivatives of the endpoints of the data set.
Cubic Spline interpolation with clamped boundary conditions.
Container for cube-like labels.
Definition: Pvl.h:135
void SetInterpType(NumericalApproximation::InterpType itype)
Sets interpolation type.
void AddData(const double x, const double y)
Add a datapoint to the set.
Isis exception class.
Definition: IException.h:107
Adds specific functionality to C++ strings.
Definition: IString.h:181
void SetPhotoPhaseList(QString phasestrlist)
Set the empirical Minnaert function phase angle list.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Empirical Minnaert photometric model Derive model albedo using phase dependent Minnaert equation and ...
Evaluate() attempts to extrapolate if a is outside of the domain. This is only valid for NumericalApp...