OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
glint.c
Go to the documentation of this file.
1 #include "l12_proto.h"
2 
3 /* ============================================================================
4 
5 c This corrects the sunglint contamination reflectances in the
6 c SeaWiFS 8 bands using the Cox & Munk model for the ocean
7 c sun glitter radiance distribution as function of the sea surface
8 c wind.
9 c
10 c Inputs:
11 c num_iter, I, --- iteration number in the atmospheric corrections.
12 c nband, I, --- number of bands for the sensor (e.g., 8 for SeaWiFS).
13 c glint_coef, R, --- glitter radiance (F0=1) from Cox & Munk.
14 c air_mass, R, --- airmass value.
15 c mu0, R, --- cosine of the solar zenith angle.
16 c taur(nband), R, --- Rayleigh optical thicknesses.
17 c taua(nband), R, --- retrieved aerosol optical thicknesses.
18 c La(nband), R, --- aerosol reflectances at 8 SeaWiFS bands.
19 c Output:
20 c TLg(nband), R, --- sunglint radiances at 8 SeaWiFS bands.
21 c Credits:
22 c Written by
23 c Menghua Wang
24 c UMBC, Code 970.2, NASA/GSFC, Greenbelt, MD
25 c 10-7-1999
26 c
27 c Modification History
28 c - Modified to return glint radiance at TOA rather than to
29 c correct an input reflectance. Bryan Franz, 14 October 1999.
30 c - Added low rhoa enhancements from M. Wang, 28 November 1999.
31 c - Added a check and necessary correction to make sure there is
32 c no over-correction, i.e., there is no pixel lost due to sun
33 c glint corrections. Menghua Wang, 2-18-00
34 c ============================================================================= */
35 
36 static float taua_est(float x) {
37  return (-0.8 - 0.4 * log(x));
38 };
39 
40 void glint_rad(int32_t iter, int32_t nband, int32_t nir_s, int32_t nir_l,
41  float glint_coef, float airmass,
42  float mu0, float F0[], float taur[], float taua[], float La[], float TLg[]) {
43  static float pi = PI;
44  static float glint_min = GLINT_MIN;
45  static float taua_min = 0.08;
46  static float taua_ave = 0.1;
47  static float rhoa_min = 0.01;
48  static float rhoa_min2 = 0.008;
49  static int32_t iter_max = 2;
50  static float rfac = 0.8;
51 
52  int32_t ib;
53  float taua_c;
54  float refl_test;
55  float taua_ave2;
56  float fac;
57 
58 
59  /* If the number of iterations exceeds the maximum, we just return. This assumes */
60  /* that the calling routine saved the TLg from the previous iteration. If the glint */
61  /* coefficient is very low, return 0. */
62 
63  if (iter > iter_max)
64  return;
65 
66  else if (glint_coef <= glint_min)
67  for (ib = 0; ib < nband; ib++)
68  TLg[ib] = 0.0;
69 
70  else {
71 
72  refl_test = pi / mu0 * (La[nir_l] / F0[nir_l] - glint_coef * exp(-(taur[nir_l] + taua_ave) * airmass));
73 
74  if (refl_test <= rhoa_min)
75  taua_ave2 = taua_est(10. * MAX(refl_test, 0.0001));
76  else
77  taua_ave2 = taua_ave;
78 
79  for (ib = nband - 1; ib >= 0; ib--) {
80 
81  if (iter <= 1)
82  taua_c = taua_ave2;
83  else if (taua[nir_l] <= taua_min)
84  taua_c = taua_est(taua[nir_l]);
85  else
86  taua_c = taua[ib];
87 
88  /* Check for over-correction */
89  if (ib == nir_l)
90  refl_test = pi / mu0 * (La[ib] / F0[ib] - glint_coef * exp(-(taur[ib] + taua_c) * airmass));
91 
92  if (refl_test <= rhoa_min2)
93  TLg[ib] = F0[ib] * glint_coef * exp(-(taur[ib] + 1.5 * taua_c) * airmass);
94  else
95  TLg[ib] = F0[ib] * glint_coef * exp(-(taur[ib] + taua_c) * airmass);
96  }
97 
98 
99  /* Make sure there is no over-correction */
100  if (La[nir_l] > 0.0 && La[nir_s] > 0.0) {
101  fac = MAX(TLg[nir_l] / La[nir_l], TLg[nir_s] / La[nir_s]);
102  if (fac >= rfac) {
103  for (ib = 0; ib < nband; ib++) {
104  TLg[ib] = rfac * TLg[ib] / fac;
105  }
106 
107  }
108 
109  }
110 
111  }
112 }
113 
114 
115 
116 
117 
118 
#define MAX(A, B)
Definition: swl0_utils.h:26
map< string, float > F0
Definition: DDSensor.cpp:39
const double pi
void glint_rad(int32_t iter, int32_t nband, int32_t nir_s, int32_t nir_l, float glint_coef, float airmass, float mu0, float F0[], float taur[], float taua[], float La[], float TLg[])
Definition: glint.c:40
#define fac
#define PI
Definition: l3_get_org.c:6
#define GLINT_MIN
Definition: l1.h:59
int32_t nband
float mu0