l2gen algorithm - source code error

Use this Forum to find information on, or ask a question about, NASA Earth Science data.
Post Reply
cortivo
Posts: 20
Joined: Thu Mar 20, 2014 9:42 am America/New_York
Answers: 0

l2gen algorithm - source code error

by cortivo » Tue May 30, 2023 3:31 pm America/New_York

Hi.
I was looking at the source codes of l2gen algorithm on page: https://oceancolor.gsfc.nasa.gov/docs/ocssw/get__chl_8c_source.html
At this part of the code

252 float chl_oci(l2str *l2rec, float Rrs[]) {
253 static float t1 = 0.25;
254 static float t2 = 0.35;
255
256 float chl1 = chlbad;
257 float chl2 = chlbad;
258 float chl = chlbad;
259
260 chl1 = chl_hu(l2rec, Rrs);
261 if (chl1 <= t1)
262 chl = chl1;
263 else {
264 chl2 = get_chl_ocx(l2rec, Rrs);
265 if (chl2 > 0.0) {
266 if (chl1 >= t2)
267 chl = chl2;
268 else {
269 chl = chl1 * (t2 - chl1) / (t2 - t1)
270 + chl2 * (chl1 - t1) / (t2 - t1);
271 }
272 }
273 }
274
275 return (chl);
276 }
in line 266 (bold) is it right compare chl1 >= t2 ?? At this point the right way should not be: chl2 >= t2?

Tags:

lmckinna
Posts: 15
Joined: Sun Jul 29, 2007 11:20 pm America/New_York
Answers: 0

Re: l2gen algorithm - source code error

by lmckinna » Tue May 30, 2023 8:21 pm America/New_York

Hi Cortivo,

The code looks correct to me. In l2gen's function chl_oci, chl_hu (per Hu et al 2012) is denoted as chl1 and chl_ocx (band ratio) is denoted as chl2.

The decision point in the function chl_oci that selects chl_hu, chl_ocx, or a blend of the two, is dependent only the magnitude of chl_hu (i.e., chl1).

See Equation 5 in Hu et al (2012) to confirm:https://doi.org/10.1029/2011JC007395

Please note, the thresholds t1 and t2 originally published are slightly different to those used in l2gen.

Cheers,
Lachlan

OB General Science - guoqingw
Subject Matter Expert
Subject Matter Expert
Posts: 77
Joined: Fri Jun 03, 2022 10:54 am America/New_York
Answers: 0
Location: NASA GSFC
Been thanked: 1 time
Contact:

Re: l2gen algorithm - source code error

by OB General Science - guoqingw » Wed May 31, 2023 8:52 am America/New_York

Lachlan is correct. chl1 is the chlorophyll estimated using CI algorithm (the parameters are from Hu et al. 2019) which performs better for low values. Here it was used to find the upper limit for the blending of CI and OCx algorithm to make sure low values are estimated using CI algorithm.
Last edited by OB General Science - guoqingw on Thu Jun 01, 2023 10:58 am America/New_York, edited 1 time in total.

cortivo
Posts: 20
Joined: Thu Mar 20, 2014 9:42 am America/New_York
Answers: 0

Re: l2gen algorithm - source code error

by cortivo » Wed May 31, 2023 5:04 pm America/New_York

Hello,

Let me explain the following calculations ...
Lets consider (Rrs) for Modis/Aqua. Calculations follow https://oceancolor.gsfc.nasa.gov/atbd/chlor_a/#sec_2 (Algorithm Description)
t1 = 0.25
t2 = 0.35

Reflectances:
R1 = 0.006004000856137 (443)
R2 = 0.004496000859945 (488)
R3 = 0.003296000862974 (547)
R4 = 0.002744000864368 (555)
R5 = 0.000502000870028 (667)

1) Calculate CI according to CI = R4-[R1+(555-443)/(667-443)*(R5-R1)]=-5.0900e-04
2) a0ci = -0.4287 e a1ci = 230.47 => chl1 = chlor_a = 10^(a0ci+a1ci*CI) = 0.2844400 > t1 and therefore the "if" at line 261 it is false (see source code) and "else" at line 263 becomes true and line 264 is performed.

3) Following item 2 of the description on https://oceancolor.gsfc.nasa.gov/atbd/chlor_a/#sec_2 we must perform the chl_ocx calculations.
4) According Table 1 on that page: Rrs(443>488)/Rrs547 with coefficients a(0,1,2,3,4)=[0.26294; -2.64669; 1.28364; 1.08209; -1.76828] and so R = log10(max([R1,R2]/R3)) = 0.2605. According to the polynomial approximation chl2 = chlor_a = 0.469525.

Now lets go back to the source code. At line 264 we obtain, according the above calculations, chlor_a = chl2 = 0.469525. As this value is > 0.0 the "if" at line 265 becomes true. Therefore, the next line (266) is evaluated. However here we have a "problem" (maybe...).

Note that chl1 = 0.2844400 which is greater then t1 but not greater then t2 and so the "if" at line 266 is false because chl1 is less then t2. So "else" at line 268 is performed and a blend chlorophyll is calculated. On the other hand, we have chl2 = 0.469525 which is >= t2.

I think that we must use chl=0.469525 as the correct value and not a blended value (as the algorithm will calculate and give as the answer)....
(See explanation on https://oceancolor.gsfc.nasa.gov/atbd/chlor_a/#sec_2 after Table 1
For chlorophyll retrievals below 0.25 mg m-3, the CI algorithm is used.
For chlorophyll retrievals above 0.35 mg m-3, the OCx algorithm is used.
In between these values, the CI and OCx algorithm are blended using a weighted approach where:
)
Sorry if my logic isn't true and in this case why we must use a blended value and not the chl2=chlor_a=0.469525 given by chl_ocx??

Thank you in advance.

I considered lambda=667 on the CI equation because Modis/Aqua do not have 670. But if consider lambda=670 and R5 we get chl1 = 0.27900. Which does not chance the explanation above about source code.

Fabio.

OB.DAAC - SeanBailey
User Services
User Services
Posts: 1464
Joined: Wed Sep 18, 2019 6:15 pm America/New_York
Answers: 1
Been thanked: 4 times

Re: l2gen algorithm - source code error

by OB.DAAC - SeanBailey » Wed May 31, 2023 5:58 pm America/New_York

Fabio,

When the Hu algorithm is above 0.25 mg m^-3, but below 0.35 mg m^-3, we blend Hu with OCx. As Lachlan pointed out:
The decision point in the function chl_oci that selects chl_hu, chl_ocx, or a blend of the two, is dependent only the magnitude of chl_hu (i.e., chl1).

The code is correct.

Sean

Post Reply