Isis 3 Programmer Reference
MoonAlbedo.cpp
1 #include <cmath>
2 #include "MoonAlbedo.h"
3 #include "SpecialPixel.h"
4 #include "IException.h"
5 
6 #define MIN(x,y) (((x) < (y)) ? (x) : (y))
7 #define MAX(x,y) (((x) > (y)) ? (x) : (y))
8 
9 namespace Isis {
10  MoonAlbedo::MoonAlbedo(Pvl &pvl, PhotoModel &pmodel) :
11  NormModel(pvl, pmodel) {
12  PvlGroup &algo = pvl.findObject("NormalizationModel")
13  .findGroup("Algorithm", Pvl::Traverse);
14  // Set default values
15  SetNormD(0.14);
16  SetNormE(-0.4179);
17  SetNormF(0.55);
18  SetNormG2(0.02);
19  SetNormXmul(1.0);
20  SetNormWl(p_normWavelength);
21  SetNormH(0.048);
22  SetNormBsh1(0.08);
23  SetNormXb1(-0.0817);
24  SetNormXb2(0.0081);
25 
26  // Get values from user
27  if(algo.hasKeyword("D")) {
28  SetNormD(algo["D"]);
29  }
30 
31  if(algo.hasKeyword("Wl")) {
32  SetNormWl(algo["Wl"]);
33  }
34 
35  if(algo.hasKeyword("E")) {
36  SetNormE(algo["E"]);
37  }
38  else {
39  if(p_normWl < 1.0) {
40  p_normE = -0.3575 * p_normWl - 0.0607;
41  }
42  else {
43  p_normE = -0.4179;
44  }
45  }
46 
47  if(algo.hasKeyword("F")) {
48  SetNormF(algo["F"]);
49  }
50 
51  if(algo.hasKeyword("G2")) {
52  SetNormG2(algo["G2"]);
53  }
54  else {
55  if(p_normWl < 1.0) {
56  p_normG2 = -0.9585 * p_normWl + 0.98;
57  }
58  else {
59  p_normG2 = 0.02;
60  }
61  }
62 
63  if(algo.hasKeyword("Xmul")) {
64  SetNormXmul(algo["Xmul"]);
65  }
66 
67  if(algo.hasKeyword("H")) {
68  SetNormH(algo["H"]);
69  }
70 
71  if(algo.hasKeyword("Bsh1")) {
72  SetNormBsh1(algo["Bsh1"]);
73  }
74  else {
75  p_normBsh1 = 19.89 - 59.58 * p_normWl + 59.86 * pow(p_normWl, 2) -
76  20.09 * pow(p_normWl, 3);
77  if(p_normBsh1 < 0.0) {
78  p_normBsh1 = 0.0;
79  }
80  }
81 
82  if(algo.hasKeyword("Xb1")) {
83  SetNormXb1(algo["Xb1"]);
84  }
85 
86  if(algo.hasKeyword("Xb2")) {
87  SetNormXb2(algo["Xb2"]);
88  }
89 
90  // Initialize values that will be needed to normalize to a
91  // Buratti function at phase = 2.0 degrees
92  p_normF1 = 1.0 - p_normF;
93  double g1 = p_normD * 0.1 + p_normE;
94  double g1sq = g1 * g1;
95  p_normG2sq = p_normG2 * p_normG2;
96  double c30 = cos(30.0 * Isis::PI / 180.0);
97  if(1.0 + g1sq + 2.0 * g1 *c30 <= 0.0) {
98  std::string msg = "Error while initializing Buratti function";
99  throw IException(IException::Unknown, msg, _FILEINFO_);
100  }
101  double pg130 = p_normF1 * (1.0 - g1sq) / (pow((1.0 + g1sq + 2.0 * g1 * c30), 1.5));
102  if(1.0 + p_normG2sq + 2.0 * p_normG2 *c30 <= 0.0) {
103  std::string msg = "Error while initializing Buratti function";
104  throw IException(IException::Unknown, msg, _FILEINFO_);
105  }
106  double pg230 = p_normF * (1.0 - p_normG2sq) / (pow((1.0 + p_normG2sq + 2.0 * p_normG2 * c30), 1.5));
107  if(p_normBsh1 < 0.0) p_normBsh1 = 0.0;
108  if(1.0 + tan(15.0 * Isis::PI / 180.0) / p_normH == 0.0) {
109  std::string msg = "Error while initializing Buratti function";
110  throw IException(IException::Unknown, msg, _FILEINFO_);
111  }
112  double bshad30 = 1.0 + p_normBsh1 / (1.0 + tan(15.0 * Isis::PI / 180.0) / p_normH);
113  p_normPg30 = (pg130 + pg230) * bshad30;
114  p_normBc1 = p_normXb1 + p_normXb2 * p_normWl;
115  p_normFbc3 = 1.0 + p_normBc1 * 2.0;
116  if(p_normFbc3 == 0.0) {
117  std::string msg = "Error while initializing Buratti function";
118  throw IException(IException::Unknown, msg, _FILEINFO_);
119  }
120  p_normC3 = cos(2.0 * Isis::PI / 180.0);
121  if(1.0 + p_normG2sq + 2.0 * p_normG2 *p_normC3 <= 0.0) {
122  std::string msg = "Error while initializing Buratti function";
123  throw IException(IException::Unknown, msg, _FILEINFO_);
124  }
125  p_normPg32 = p_normF * (1.0 - p_normG2sq) / (pow((1.0 + p_normG2sq + 2.0 * p_normG2 * p_normC3), 1.5));
126  if(1.0 + tan(Isis::PI / 180.0) / p_normH == 0.0) {
127  std::string msg = "Error while initializing Buratti function";
128  throw IException(IException::Unknown, msg, _FILEINFO_);
129  }
130  p_normBshad3 = 1.0 + p_normBsh1 / (1.0 + tan(Isis::PI / 180.0) / p_normH);
131  }
132 
133  void MoonAlbedo::NormModelAlgorithm(double phase, double incidence, double emission,
134  double demincidence, double dememission, double dn,
135  double &albedo, double &mult, double &base) {
136  double a;
137  double cosa;
138  double pg2;
139  double bshad;
140  double r;
141  double g1;
142  double g1sq;
143  double pg1;
144  double pg;
145  double fbc;
146  double pg31;
147  double pg3;
148 
149  a = GetPhotoModel()->CalcSurfAlbedo(phase, demincidence, dememission);
150 
151  if(a != 0.0) {
152  cosa = cos(phase * Isis::PI / 180.0);
153  if(1.0 + p_normG2sq + 2.0 * p_normG2 *cosa <= 0.0) {
154  albedo = NULL8;
155  return;
156  }
157  pg2 = p_normF * (1.0 - p_normG2sq) / (pow((1.0 + p_normG2sq + 2.0 * p_normG2 * cosa), 1.5));
158  if(1.0 + tan(phase * .5 * Isis::PI / 180.0) / p_normH == 0.0) {
159  albedo = NULL8;
160  return;
161  }
162  bshad = 1.0 + p_normBsh1 / (1.0 + tan(phase * .5 * Isis::PI / 180.0) / p_normH);
163  r = dn * p_normXmul;
164  // Estimate the albedo at 0.1, then iterate
165  albedo = 0.1;
166  for(int i = 0; i < 6; i++) {
167  g1 = p_normD * albedo + p_normE;
168  g1sq = g1 * g1;
169  if(1.0 + g1sq + 2.0 * g1 *cosa <= 0.0) {
170  albedo = NULL8;
171  return;
172  }
173  pg1 = p_normF1 * (1.0 - g1sq) / (pow((1.0 + g1sq + 2.0 * g1 * cosa), 1.5));
174  pg = (pg1 + pg2) * bshad;
175  if(phase <= 2.0) {
176  fbc = 1.0 + p_normBc1 * phase;
177  if(1.0 + g1sq + 2.0 * g1 *p_normC3 <= 0.0) {
178  albedo = NULL8;
179  return;
180  }
181  pg31 = p_normF1 * (1.0 - g1sq) / (pow((1.0 + g1sq + 2.0 * g1 * p_normC3), 1.5));
182  pg3 = (pg31 + p_normPg32) * p_normBshad3;
183  pg = fbc * (pg3 / p_normFbc3);
184  }
185  if(pg == 0.0) {
186  albedo = NULL8;
187  return;
188  }
189  albedo = r * a * p_normPg30 / pg;
190  }
191  }
192  else {
193  albedo = NULL8;
194  return;
195  }
196  }
197 
205  void MoonAlbedo::SetNormD(const double d) {
206  p_normD = d;
207  }
208 
217  void MoonAlbedo::SetNormWl(const double wl) {
218  p_normWl = wl;
219  }
220 
228  void MoonAlbedo::SetNormE(const double e) {
229  p_normE = e;
230  }
231 
239  void MoonAlbedo::SetNormF(const double f) {
240  p_normF = f;
241  }
242 
250  void MoonAlbedo::SetNormG2(const double g2) {
251  p_normG2 = g2;
252  }
253 
261  void MoonAlbedo::SetNormXmul(const double xmul) {
262  p_normXmul = xmul;
263  }
264 
272  void MoonAlbedo::SetNormH(const double h) {
273  if(h == 0.0) {
274  std::string msg = "Invalid value of normalization h [" +
275  IString(h) + "]";
277  }
278 
279  p_normH = h;
280  }
281 
289  void MoonAlbedo::SetNormBsh1(const double bsh1) {
290  if(bsh1 < 0.0) {
291  std::string msg = "Invalid value of normalization bsh1 [" +
292  IString(bsh1) + "]";
294  }
295 
296  p_normBsh1 = bsh1;
297  }
298 
306  void MoonAlbedo::SetNormXb1(const double xb1) {
307  p_normXb1 = xb1;
308  }
309 
317  void MoonAlbedo::SetNormXb2(const double xb2) {
318  p_normXb2 = xb2;
319  }
320 }
321 
322 extern "C" Isis::NormModel *MoonAlbedoPlugin(Isis::Pvl &pvl, Isis::PhotoModel &pmodel) {
323  return new Isis::MoonAlbedo(pvl, pmodel);
324 }
void SetNormWl(const double wl)
Set the albedo dependent phase function normalization parameter.
Definition: MoonAlbedo.cpp:217
double CalcSurfAlbedo(double pha, double inc, double ema)
Calculate the surface brightness using photometric angle information.
Definition: PhotoModel.cpp:171
void SetNormXmul(const double xmul)
Set the albedo dependent phase function normalization parameter.
Definition: MoonAlbedo.cpp:261
void SetNormD(const double d)
Set parameters needed for albedo dependent phase function normalization for the Moon.
Definition: MoonAlbedo.cpp:205
const double PI
The mathematical constant PI.
Definition: Constants.h:56
Search child objects.
Definition: PvlObject.h:170
void SetNormXb1(const double xb1)
Set the albedo dependent phase function normalization parameter.
Definition: MoonAlbedo.cpp:306
void SetNormBsh1(const double bsh1)
Set the albedo dependent phase function normalization parameter.
Definition: MoonAlbedo.cpp:289
#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
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:134
void SetNormF(const double f)
Set the albedo dependent phase function normalization parameter.
Definition: MoonAlbedo.cpp:239
Container for cube-like labels.
Definition: Pvl.h:135
void SetNormG2(const double g2)
Set the albedo dependent phase function normalization parameter.
Definition: MoonAlbedo.cpp:250
void SetNormE(const double e)
Set the albedo dependent phase function normalization parameter.
Definition: MoonAlbedo.cpp:228
void SetNormXb2(const double xb2)
Set the albedo dependent phase function normalization parameter.
Definition: MoonAlbedo.cpp:317
void SetNormH(const double h)
Set the albedo dependent phase function normalization parameter.
Definition: MoonAlbedo.cpp:272
Isis exception class.
Definition: IException.h:107
Adds specific functionality to C++ strings.
Definition: IString.h:181
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Albedo dependent phase function normalization for the Moon.
Definition: MoonAlbedo.h:41