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
7namespace Isis {
21 NormModel(pvl, pmodel, amodel) {
22 PvlGroup &algo = pvl.findObject("NormalizationModel")
23 .findGroup("Algorithm", Pvl::Traverse);
24 // Set default value
25 SetNormPharef(0.0);
26 SetNormIncref(0.0);
27 SetNormEmaref(0.0);
28
29 // Get value from user
30 if(algo.hasKeyword("Incref")) {
31 SetNormIncref(algo["Incref"]);
32 }
33
34 if(algo.hasKeyword("Pharef")) {
35 SetNormPharef(algo["Pharef"]);
36 } else {
38 }
39
40 if(algo.hasKeyword("Emaref")) {
41 SetNormEmaref(algo["Emaref"]);
42 }
43
44 // First-time setup:
45 // Calculate normalization at standard conditions
46 GetPhotoModel()->SetStandardConditions(true);
47 p_normPsurfref = GetPhotoModel()->CalcSurfAlbedo(p_normPharef, p_normIncref, p_normEmaref);
48 GetPhotoModel()->SetStandardConditions(false);
49
50 // Get reference hemispheric albedo
51 GetAtmosModel()->GenerateAhTable();
52
53 p_normAhref = (GetAtmosModel()->AtmosAhSpline()).Evaluate(p_normIncref, NumericalApproximation::Extrapolate);
54
55 p_normMunotref = cos((PI / 180.0) * p_normIncref);
56
57 // Now calculate atmosphere at standard conditions
58 GetAtmosModel()->SetStandardConditions(true);
59 GetAtmosModel()->CalcAtmEffect(p_normPharef, p_normIncref, p_normEmaref,
63 GetAtmosModel()->SetStandardConditions(false);
64 }
65
83 void AlbedoAtm::NormModelAlgorithm(double phase, double incidence, double emission,
84 double demincidence, double dememission, double dn,
85 double &albedo, double &mult, double &base) {
86 static double psurf;
87 static double ahInterp;
88 static double munot;
89 double pstd;
90 double trans;
91 double trans0;
92 double transs;
93 double rho;
94 double dpo;
95 double q;
96 double dpm;
97 double firsterm;
98 double secondterm;
99 double thirdterm;
100 double fourthterm;
101 double fifthterm;
102
103 static double old_phase = -9999;
104 static double old_incidence = -9999;
105 static double old_emission = -9999;
106 static double old_demincidence = -9999;
107 static double old_dememission = -9999;
108
109 if (old_phase != phase || old_incidence != incidence || old_emission != emission ||
110 old_demincidence != demincidence || old_dememission != dememission) {
111
112 psurf = GetPhotoModel()->CalcSurfAlbedo(phase, demincidence,
113 dememission);
114
115 ahInterp = (GetAtmosModel()->AtmosAhSpline()).Evaluate(incidence, NumericalApproximation::Extrapolate);
116
117 munot = cos(incidence * (PI / 180.0));
118
119 old_phase = phase;
120 old_incidence = incidence;
121 old_emission = emission;
122 old_demincidence = demincidence;
123 old_dememission = dememission;
124 }
125
126 GetAtmosModel()->CalcAtmEffect(phase, incidence, emission, &pstd, &trans, &trans0, &p_normSbar,
127 &transs);
128
129 // With model at actual geometry, calculate rho from dn
130 dpo = dn - pstd;
131 dpm = (psurf - ahInterp * munot) * trans0;
132 q = ahInterp * munot * trans + GetAtmosModel()->AtmosAb() * p_normSbar * dpo + dpm;
133
134 if(dpo <= 0.0 && GetAtmosModel()->AtmosNulneg()) {
135 rho = 0.0;
136 }
137 else {
138 firsterm = GetAtmosModel()->AtmosAb() * p_normSbar;
139 secondterm = dpo * dpm;
140 thirdterm = firsterm * secondterm;
141 fourthterm = pow(q, 2.0) - 4.0 * thirdterm;
142
143 if(fourthterm < 0.0) {
144 QString msg = "Square root of negative (math) encountered";
145 throw IException(IException::Unknown, msg, _FILEINFO_);
146 }
147 else {
148 fifthterm = q + sqrt(fourthterm);
149 }
150
151 rho = 2 * dpo / fifthterm;
152 }
153
154 // Now use rho and reference geometry to calculate output dnout
155 if((1.0 - rho * GetAtmosModel()->AtmosAb()*p_normSbar) <= 0.0) {
156 QString msg = "Divide by zero (math) encountered";
157 throw IException(IException::Unknown, msg, _FILEINFO_);
158 }
159 else {
160 albedo = p_normPstdref + rho * (p_normAhref * p_normMunotref *
161 p_normTransref / (1.0 - rho * GetAtmosModel()->AtmosAb() *
164 }
165 }
166
176 void AlbedoAtm::SetNormPharef(const double pharef) {
177 if(pharef < 0.0 || pharef >= 180.0) {
178 QString msg = "Invalid value of normalization pharef [" +
179 toString(pharef) + "]";
180 throw IException(IException::User, msg, _FILEINFO_);
181 }
182
183 p_normPharef = pharef;
184 }
185
195 void AlbedoAtm::SetNormIncref(const double incref) {
196 if(incref < 0.0 || incref >= 90.0) {
197 QString msg = "Invalid value of normalization incref [" +
198 toString(incref) + "]";
199 throw IException(IException::User, msg, _FILEINFO_);
200 }
201
202 p_normIncref = incref;
203 }
204
214 void AlbedoAtm::SetNormEmaref(const double emaref) {
215 if(emaref < 0.0 || emaref >= 90.0) {
216 QString msg = "Invalid value of normalization emaref [" +
217 toString(emaref) + "]";
218 throw IException(IException::User, msg, _FILEINFO_);
219 }
220
221 p_normEmaref = emaref;
222 }
223}
224
225extern "C" Isis::NormModel *AlbedoAtmPlugin(Isis::Pvl &pvl, Isis::PhotoModel &pmodel, Isis::AtmosModel &amodel) {
226 return new Isis::AlbedoAtm(pvl, pmodel, amodel);
227}
Albedo normalization with atmosphere.
Definition AlbedoAtm.h:38
double p_normSbar
???
Definition AlbedoAtm.h:78
void SetNormIncref(const double incref)
Set the normalization function parameter.
double p_normMunotref
???
Definition AlbedoAtm.h:74
double p_normTrans0ref
???
Definition AlbedoAtm.h:76
double p_normPharef
The reference phase angle.
Definition AlbedoAtm.h:69
double p_normPstdref
???
Definition AlbedoAtm.h:72
void SetNormPharef(const double pharef)
Set parameters needed for albedo normalization.
void SetNormEmaref(const double emaref)
Set the normalization function parameter.
double p_normEmaref
The reference emission angle.
Definition AlbedoAtm.h:71
double p_normTransref
???
Definition AlbedoAtm.h:75
AlbedoAtm(Pvl &pvl, PhotoModel &pmodel, AtmosModel &amodel)
Constructs AlbedoAtm object using a Pvl, PhotoModel, and AtmosModel.
Definition AlbedoAtm.cpp:20
double p_normPsurfref
???
Definition AlbedoAtm.h:68
virtual void NormModelAlgorithm(double pha, double inc, double ema, double dn, double &albedo, double &mult, double &base)
Performs the normalization.
Definition AlbedoAtm.h:56
double p_normTranss
???
Definition AlbedoAtm.h:77
double p_normAhref
???
Definition AlbedoAtm.h:73
double p_normIncref
The reference incidence angle.
Definition AlbedoAtm.h:70
Isotropic atmos scattering model.
Definition AtmosModel.h:60
Isis exception class.
Definition IException.h:91
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition IException.h:118
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
NormModel(Pvl &pvl, PhotoModel &pmodel)
Create a NormModel object.
Definition NormModel.cpp:23
@ Extrapolate
Evaluate() attempts to extrapolate if a is outside of the domain. This is only valid for NumericalApp...
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition PvlObject.h:274
@ Traverse
Search child objects.
Definition PvlObject.h:158
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
const double PI
The mathematical constant PI.
Definition Constants.h:40