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
10namespace Isis {
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);
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";
148 throw IException(IException::Unknown, msg, _FILEINFO_);
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";
160 throw IException(IException::Unknown, msg, _FILEINFO_);
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) + "]";
183 throw IException(IException::User, msg, _FILEINFO_);
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) + "]";
202 throw IException(IException::User, msg, _FILEINFO_);
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) + "]";
221 throw IException(IException::User, msg, _FILEINFO_);
222 }
223
224 p_normEmaref = emaref;
225 }
226}
227
228extern "C" Isis::NormModel *AlbedoAtmPlugin(Isis::Pvl &pvl, Isis::PhotoModel &pmodel, Isis::AtmosModel &amodel) {
229 return new Isis::AlbedoAtm(pvl, pmodel, amodel);
230}
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:23
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
NumericalApproximation AtmosAhSpline()
If GenerateAhTable() has been called this returns a clamped cubic spline of the data set (p_atmosIncT...
Definition AtmosModel.h:183
double AtmosAb() const
Return atmospheric Ab value.
Definition AtmosModel.h:139
void GenerateAhTable()
This method computes the values of the atmospheric Ah table and sets the properties of the atmospheri...
virtual void SetStandardConditions(bool standard)
Used to calculate atmosphere at standard conditions.
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.
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
@ Extrapolate
Evaluate() attempts to extrapolate if a is outside of the domain. This is only valid for NumericalApp...
double CalcSurfAlbedo(double pha, double inc, double ema)
Calculate the surface brightness using photometric angle information.
virtual void SetStandardConditions(bool standard)
Sets whether standard conditions will be used.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
@ 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