Isis 3 Programmer Reference
AlbedoAtm.cpp
1 #include <cmath>
2 #include "AlbedoAtm.h"
3 #include "NumericalApproximation.h"
4 #include "IException.h"
5 #include "IString.h"
6 
7 #define MIN(x,y) (((x) < (y)) ? (x) : (y))
8 #define MAX(x,y) (((x) > (y)) ? (x) : (y))
9 
10 namespace Isis {
23  AlbedoAtm::AlbedoAtm(Pvl &pvl, PhotoModel &pmodel, AtmosModel &amodel) :
24  NormModel(pvl, pmodel, amodel) {
25  PvlGroup &algo = pvl.findObject("NormalizationModel")
26  .findGroup("Algorithm", Pvl::Traverse);
27  // Set default value
28  SetNormPharef(0.0);
29  SetNormIncref(0.0);
30  SetNormEmaref(0.0);
31 
32  // Get value from user
33  if(algo.hasKeyword("Incref")) {
34  SetNormIncref(algo["Incref"]);
35  }
36 
37  if(algo.hasKeyword("Pharef")) {
38  SetNormPharef(algo["Pharef"]);
39  } else {
41  }
42 
43  if(algo.hasKeyword("Emaref")) {
44  SetNormEmaref(algo["Emaref"]);
45  }
46 
47  // First-time setup:
48  // Calculate normalization at standard conditions
49  GetPhotoModel()->SetStandardConditions(true);
51  GetPhotoModel()->SetStandardConditions(false);
52 
53  // Get reference hemispheric albedo
54  GetAtmosModel()->GenerateAhTable();
55 
57 
58  p_normMunotref = cos((PI / 180.0) * p_normIncref);
59 
60  // Now calculate atmosphere at standard conditions
61  GetAtmosModel()->SetStandardConditions(true);
65  &p_normTranss);
66  GetAtmosModel()->SetStandardConditions(false);
67  }
68 
86  void AlbedoAtm::NormModelAlgorithm(double phase, double incidence, double emission,
87  double demincidence, double dememission, double dn,
88  double &albedo, double &mult, double &base) {
89  static double psurf;
90  static double ahInterp;
91  static double munot;
92  double pstd;
93  double trans;
94  double trans0;
95  double transs;
96  double rho;
97  double dpo;
98  double q;
99  double dpm;
100  double firsterm;
101  double secondterm;
102  double thirdterm;
103  double fourthterm;
104  double fifthterm;
105 
106  static double old_phase = -9999;
107  static double old_incidence = -9999;
108  static double old_emission = -9999;
109  static double old_demincidence = -9999;
110  static double old_dememission = -9999;
111 
112  if (old_phase != phase || old_incidence != incidence || old_emission != emission ||
113  old_demincidence != demincidence || old_dememission != dememission) {
114 
115  psurf = GetPhotoModel()->CalcSurfAlbedo(phase, demincidence,
116  dememission);
117 
118  ahInterp = (GetAtmosModel()->AtmosAhSpline()).Evaluate(incidence, NumericalApproximation::Extrapolate);
119 
120  munot = cos(incidence * (PI / 180.0));
121 
122  old_phase = phase;
123  old_incidence = incidence;
124  old_emission = emission;
125  old_demincidence = demincidence;
126  old_dememission = dememission;
127  }
128 
129  GetAtmosModel()->CalcAtmEffect(phase, incidence, emission, &pstd, &trans, &trans0, &p_normSbar,
130  &transs);
131 
132  // With model at actual geometry, calculate rho from dn
133  dpo = dn - pstd;
134  dpm = (psurf - ahInterp * munot) * trans0;
135  q = ahInterp * munot * trans + GetAtmosModel()->AtmosAb() * p_normSbar * dpo + dpm;
136 
137  if(dpo <= 0.0 && GetAtmosModel()->AtmosNulneg()) {
138  rho = 0.0;
139  }
140  else {
141  firsterm = GetAtmosModel()->AtmosAb() * p_normSbar;
142  secondterm = dpo * dpm;
143  thirdterm = firsterm * secondterm;
144  fourthterm = pow(q, 2.0) - 4.0 * thirdterm;
145 
146  if(fourthterm < 0.0) {
147  QString msg = "Square root of negative (math) encountered";
149  }
150  else {
151  fifthterm = q + sqrt(fourthterm);
152  }
153 
154  rho = 2 * dpo / fifthterm;
155  }
156 
157  // Now use rho and reference geometry to calculate output dnout
158  if((1.0 - rho * GetAtmosModel()->AtmosAb()*p_normSbar) <= 0.0) {
159  QString msg = "Divide by zero (math) encountered";
161  }
162  else {
163  albedo = p_normPstdref + rho * (p_normAhref * p_normMunotref *
164  p_normTransref / (1.0 - rho * GetAtmosModel()->AtmosAb() *
167  }
168  }
169 
179  void AlbedoAtm::SetNormPharef(const double pharef) {
180  if(pharef < 0.0 || pharef >= 180.0) {
181  QString msg = "Invalid value of normalization pharef [" +
182  toString(pharef) + "]";
184  }
185 
186  p_normPharef = pharef;
187  }
188 
198  void AlbedoAtm::SetNormIncref(const double incref) {
199  if(incref < 0.0 || incref >= 90.0) {
200  QString msg = "Invalid value of normalization incref [" +
201  toString(incref) + "]";
203  }
204 
205  p_normIncref = incref;
206  }
207 
217  void AlbedoAtm::SetNormEmaref(const double emaref) {
218  if(emaref < 0.0 || emaref >= 90.0) {
219  QString msg = "Invalid value of normalization emaref [" +
220  toString(emaref) + "]";
222  }
223 
224  p_normEmaref = emaref;
225  }
226 }
227 
228 extern "C" Isis::NormModel *AlbedoAtmPlugin(Isis::Pvl &pvl, Isis::PhotoModel &pmodel, Isis::AtmosModel &amodel) {
229  return new Isis::AlbedoAtm(pvl, pmodel, amodel);
230 }
double p_normAhref
???
Definition: AlbedoAtm.h:89
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
double CalcSurfAlbedo(double pha, double inc, double ema)
Calculate the surface brightness using photometric angle information.
Definition: PhotoModel.cpp:171
void SetNormPharef(const double pharef)
Set parameters needed for albedo normalization.
Definition: AlbedoAtm.cpp:179
void SetNormEmaref(const double emaref)
Set the normalization function parameter.
Definition: AlbedoAtm.cpp:217
const double PI
The mathematical constant PI.
Definition: Constants.h:56
virtual void SetStandardConditions(bool standard)
Used to calculate atmosphere at standard conditions.
Definition: AtmosModel.cpp:492
double p_normIncref
The reference incidence angle.
Definition: AlbedoAtm.h:86
void CalcAtmEffect(double pha, double inc, double ema, double *pstd, double *trans, double *trans0, double *sbar, double *transs)
Calculate the atmospheric scattering effect using photometric angle information.
Definition: AtmosModel.cpp:469
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:286
Search child objects.
Definition: PvlObject.h:170
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
double p_normPstdref
???
Definition: AlbedoAtm.h:88
void SetNormIncref(const double incref)
Set the normalization function parameter.
Definition: AlbedoAtm.cpp:198
NumericalApproximation AtmosAhSpline()
If GenerateAhTable() has been called this returns a clamped cubic spline of the data set (p_atmosIncT...
Definition: AtmosModel.h:199
AlbedoAtm(Pvl &pvl, PhotoModel &pmodel, AtmosModel &amodel)
Constructs AlbedoAtm object using a Pvl, PhotoModel, and AtmosModel.
Definition: AlbedoAtm.cpp:23
Isotropic atmos scattering model.
Definition: AtmosModel.h:76
double p_normTransref
???
Definition: AlbedoAtm.h:91
double p_normPharef
The reference phase angle.
Definition: AlbedoAtm.h:85
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
double p_normSbar
???
Definition: AlbedoAtm.h:94
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
double p_normTranss
???
Definition: AlbedoAtm.h:93
Container for cube-like labels.
Definition: Pvl.h:135
double p_normMunotref
???
Definition: AlbedoAtm.h:90
double p_normTrans0ref
???
Definition: AlbedoAtm.h:92
double p_normEmaref
The reference emission angle.
Definition: AlbedoAtm.h:87
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
double AtmosAb() const
Return atmospheric Ab value.
Definition: AtmosModel.h:155
void GenerateAhTable()
This method computes the values of the atmospheric Ah table and sets the properties of the atmospheri...
Definition: AtmosModel.cpp:531
Albedo normalization with atmosphere.
Definition: AlbedoAtm.h:54
Evaluate() attempts to extrapolate if a is outside of the domain. This is only valid for NumericalApp...
double p_normPsurfref
???
Definition: AlbedoAtm.h:84
virtual void NormModelAlgorithm(double pha, double inc, double ema, double dn, double &albedo, double &mult, double &base)
Performs the normalization.
Definition: AlbedoAtm.h:72
virtual void SetStandardConditions(bool standard)
Sets whether standard conditions will be used.
Definition: PhotoModel.cpp:44