Page 1 of 1

Adding a new product in SeaDAS

Posted: Fri Apr 13, 2018 1:00 am America/New_York
by alakes
I am trying to implement Shanmugam, 2011 chl ABI algorithm as a new product in SeaDAS. It is already integrated in get_chl.c but I want to try it to add as a different product so that in future I can add any product of my interest.

The following executable c code is in file get_INCOIS_ChlAbi.c :
#include <stdlib.h>
#include <math.h>
#include "l12_proto.h"

/* ---------------------------------------------------------------------------------------------------------------------------- */
/* Implementation of ABI Chlorophyll (Shanmugam, 2011)                                                                          */
/* ---------------------------------------------------------------------------------------------------------------------------- */

void get_chl_shanmugam(l2str *l2rec, float prod[])
    static float minval=0.001, maxval=100;
    static long   ip, ipb;
    float chl, chl1, chl2, chl3, chl4, chl5, chl6, chl7, Z;
    float nLw1, nLw2, nLw3;
    static long ib1 =-1, ib2 = -1, ib3 =-1;

    ib1 = bindex_get(443);
    ib2 = bindex_get(488);
    ib3 = bindex_get(547);

    if (ib1 < 0 || ib2 < 0 || ib3 < 0) {
        printf("chl_abi is not compatible with this sensor. \n");
        printf("Check get_INCOIS_HAB.c\n");
        } else {
            printf("Calculating chl_abi using %7.2f %7.2f %7.2f\n",l2rec->fwave[ib1],l2rec->fwave[ib2],l2rec->fwave[ib3]);

   for (ip=0; ip<l2rec->npix; ip++) {

       ipb = l2rec->nbands*ip;

       nLw1 = l2rec->nLw[ipb+ib1]; //443nm
       nLw2 = l2rec->nLw[ipb+ib2]; //488nm
       nLw3 = l2rec->nLw[ipb+ib3]; //547nm

       if (nLw1 >-10.0){                               //condition to avoid negative nLw
          chl1 = ((nLw2/nLw3)-nLw1)/((nLw2/nLw3)+nLw1);
          chl2 = pow(10.0,chl1);
          chl3 = (((nLw1*nLw2)/47.0)*((nLw1*nLw2)/(nLw3*nLw3)));
          chl4 = chl2*chl3;
          chl5 = 0.1403*(pow(chl4,(-0.572)));
          chl6 = pow(chl5,1.056);
          Z = pow(98,1.056);
          chl7 = chl6/(chl6+Z);
          chl = 125.0*chl7;
/* ---------------------------------------------------------------------------------------------------------------------------- */

In l2prod.h I have added the following:
                                                      #define CAT_Checking            322

In prodgen.c I have added the following:
                                                                  case CAT_Checking:
                                                                          get_chl_shanmugam(l2rec, fbuf);`
                                                                          pbuf = (VOIDP) fbuf;

In l12_proto.h I have added the following:
                                                                 void  get_chl_shanmugam (l2str *l2rec, float prod[]);

In product.xml I have added the following:

        <product name="HAB_INCOIS">
                <units>mg m^-3</units>
                <algorithm name="Checking">
                        <description>Chlorophyll Concentration in mg m^-3, ABI Algorithm</description>
                        <reference>Shanmugam P. (2011), A new bio-optical algorithm for the remote sensing of algal blooms in complex ocean waters, Journal of Geophysical Research, 116(C4), C04016. doi:10.1029/2010JC006796</reference>

I have added get_INCOIS_ChlAbi.c to add_executable of all the tools, i.e. l2gen, l3gen etc in the CMakeLists.txt

l2gen and other tool are built successfully and installed successfully using make, make install. Then I run l2gen and got the following results for chl_abi(already implemented in SeaDAS) and HAB_INCOIS_Checking (the newly added one).
(I have reprojected the output file manually) .

Please find image for chl_abi here.

Please find image for HAB_INCOIS_Checking here.

The figure should be same. Can anybody suggest where I am messing up?

Thanks in advance.

Adding a new product in SeaDAS

Posted: Sat Apr 14, 2018 7:06 pm America/New_York
by OB.DAAC - SeanBailey
The image looks like you have an indexing issue.  I would run l2gen in a debugger and step through the get_chl_shanmugam function.
You could also compare the logic to that of a similar function - one like get_depth.c  (BTW, since ib{1-3} are static, you should wrap the binindex_get calls in a "firstCall" block to prevent unnecessarily recomputing them)


Adding a new product in SeaDAS

Posted: Wed Apr 18, 2018 3:19 am America/New_York
by alakes
Thanks Sean, I will check.

Adding a new product in SeaDAS

Posted: Wed Apr 18, 2018 10:42 am America/New_York
by nrl7331
Your data product returns a float, but you've set the data type to short in your product.xml.