OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
setflags_l1.c
Go to the documentation of this file.
1 #include "l1.h"
2 
3 void l1_mask_set(l1str *l1rec, int32_t ip) {
4  l1rec->mask[ip] = (l1_input->landmask && l1rec->land [ip]) ||
5  (l1_input->bathmask && l1rec->swater [ip]) ||
6  (l1_input->cloudmask && l1rec->cloud [ip]) ||
7  (l1_input->glintmask && l1rec->glint [ip]) ||
8  (l1_input->stlightmask && l1rec->stlight[ip]) ||
9  (l1_input->satzenmask && l1rec->senzmax[ip]) ||
10  (l1_input->sunzenmask && l1rec->solzmax[ip]) ||
11  (l1_input->hiltmask && l1rec->hilt [ip]) ||
12  (l1rec->filter[ip]) ||
13  (l1rec->navfail[ip]);
14 }
15 
16 int setflags(l1str *l1rec) {
17  static float pi = PI;
18  static float radeg = RADEG;
19  static int firstCall = 1;
20 
21  static int ib412;
22  static int ib555;
23  static int ib670;
24  static int ib865;
25  static int ibcloud;
26 
27  int32_t evalmask = l1_input->evalmask;
28  float mu0;
29  int32_t ip;
30  float albedo;
31  filehandle *l1file = l1rec->l1file;
32  int32_t nwave = l1file->nbands;
33 
34  if (firstCall) {
35  firstCall = 0;
36  ib412 = windex(412., l1file->fwave, nwave);
37  ib555 = windex(550., l1file->fwave, nwave);
38  ib670 = windex(670., l1file->fwave, nwave);
39  ib865 = windex(865., l1file->fwave, nwave);
40  ibcloud = windex(l1_input->cloud_wave, l1file->fwave, nwave);
41 
42  printf("\nUsing %6.1f nm channel for cloud flagging over water.\n", l1file->fwave[ibcloud]);
43  printf("Using %6.1f nm channel for cloud flagging over land.\n\n", l1file->fwave[ib412]);
44 
45  }
46 
47  /* */
48  /* Now set flags for each pixel */
49  /* */
50  for (ip = 0; ip < l1rec->npix; ip++) {
51 
52  mu0 = cos(l1rec->solz[ip] / radeg);
53 
54  /* Check view angle limits */
55  if (l1rec->senz[ip] > l1_input->satzen) {
56  l1rec->senzmax[ip] = ON;
57  }
58  if (l1rec->solz[ip] > l1_input->sunzen) {
59  l1rec->solzmax[ip] = ON;
60  }
61 
62 
63  /* Check for glint */
64  if (!l1rec->land[ip] && l1rec->solz[ip] < SOLZNIGHT) {
65  if (l1rec->glint_coef[ip] > l1_input->glint) {
66  l1rec->glint[ip] = ON;
67  }
68  }
69 
70 
71  /* Check for clouds (daytime only) */
72  if (l1rec->solz[ip] < SOLZNIGHT) {
73 
74  if (!l1rec->land[ip]) {
75  l1rec->cloud_albedo[ip] = l1rec->rhos[ip * nwave + ibcloud]
76  - l1rec->TLg[ip * nwave + ibcloud] * pi / mu0 / l1rec->Fo[ibcloud];
77  albedo = l1_input->albedo;
78  } else {
79  l1rec->cloud_albedo[ip] = l1rec->rhos[ip * nwave + ib412];
80  albedo = l1_input->albedo * 4.0;
81  }
82  // If cloud mask file is there, use that
83  if ( l1_input->cld_msk_file[0]) {
84  char cld_category;
85  l1rec->cloud[ip] = get_sdps_cld_mask( l1rec, ip, &cld_category );
86  } else {
87  // use all other standard cloud data
88  if ((evalmask & MODCLOUD) != 0) {
89  l1rec->cloud[ip] = get_cldmask(l1rec, ip);
90  } else {
91  if (l1rec->cloud_albedo[ip] > albedo)
92  l1rec->cloud[ip] = ON;
93  }
94  /* Eval switch to enable spectral cloud test, recover bright water */
95  if ((l1_input->cloud_eps > 0.0) != 0) {
96  float min_cld_rhos = 1.0;
97  float max_cld_rhos = 1.0;
98  float cld_rhos_ratio = 0.0;
99  if (l1rec->cloud[ip] == ON && !l1rec->land[ip] && l1rec->cloud_albedo[ip] < albedo * 10) {
100  min_cld_rhos = MIN(MIN(MIN(
101  l1rec->rhos[ip * nwave + ib865],
102  l1rec->rhos[ip * nwave + ib670]),
103  l1rec->rhos[ip * nwave + ib555]),
104  l1rec->rhos[ip * nwave + ib412]);
105  max_cld_rhos = MAX(MAX(MAX(
106  l1rec->rhos[ip * nwave + ib865],
107  l1rec->rhos[ip * nwave + ib670]),
108  l1rec->rhos[ip * nwave + ib555]),
109  l1rec->rhos[ip * nwave + ib412]);
110  if (min_cld_rhos > 0.0) {
111  cld_rhos_ratio = max_cld_rhos / min_cld_rhos;
112  if (cld_rhos_ratio > l1_input->cloud_eps && (evalmask & MODCLOUD) == 0)
113  l1rec->cloud[ip] = OFF;
114  }
115  }
116  }
117  }
118 
119  }
120 
121  /* Set masking */
122  l1_mask_set(l1rec, ip);
123 
124  }
125 
126  return (1);
127 }
128 
129 void setflagbits_l1(int level, l1str *l1rec, int32_t ipix) {
130  int32_t npix, spix, epix;
131  int32_t ip, ib, iw;
132  int32_t nwave;
133 
134  if (l1rec == NULL) {
135  printf("-E- %s line %d: attempt to set flags from NULL L1 record.\n",
136  __FILE__, __LINE__);
137  exit(FATAL_ERROR);
138  }
139 
140  npix = l1rec->npix;
141  nwave = l1rec->l1file->nbands;
142 
143  if (ipix < 0) {
144  spix = 0;
145  epix = npix - 1;
146  } else {
147  spix = ipix;
148  epix = ipix;
149  }
150 
151  /* Level-0, Level-1A flag bits (require readl1) */
152  if (level == 0) {
153  for (ip = spix; ip <= epix; ip++) {
154  if (l1rec->hilt [ip]) l1rec->flags[ip] |= HILT;
155  if (l1rec->stlight[ip]) l1rec->flags[ip] |= STRAYLIGHT;
156  if (l1rec->navfail[ip]) l1rec->flags[ip] |= NAVFAIL;
157  if (l1rec->navwarn[ip]) l1rec->flags[ip] |= NAVWARN;
158  }
159  }
160  /* Level-1B flag bits (require loadl1) */
161  else if (level == 1) {
162  for (ip = spix; ip <= epix; ip++) {
163  if (l1rec->land [ip]) l1rec->flags[ip] |= LAND;
164  if (l1rec->swater [ip]) l1rec->flags[ip] |= COASTZ;
165  if (l1rec->cloud [ip]) l1rec->flags[ip] |= CLOUD;
166  if (l1rec->ice [ip]) l1rec->flags[ip] |= SEAICE;
167  if (l1rec->glint [ip]) l1rec->flags[ip] |= HIGLINT;
168  if (l1rec->solzmax[ip]) l1rec->flags[ip] |= HISOLZEN;
169  if (l1rec->senzmax[ip]) l1rec->flags[ip] |= HISATZEN;
170  if (l1rec->filter [ip]) l1rec->flags[ip] |= FILTER;
171  if (l1rec->glint_coef[ip] > GLINT_MIN)
172  l1rec->flags[ip] |= MODGLINT;
173  for (iw = 0; iw < nwave; iw++) {
174  ib = iw;
175  if (l1rec->dpol[ip * nwave + ib] > l1_input->hipol) {
176  l1rec->flags[ip] |= HIPOL;
177  break;
178  }
179  }
180  }
181 
182  } else {
183  printf("-E- %s line %d: attempt to set l1 flags at bogus level %d.\n",
184  __FILE__, __LINE__, level);
185  exit(FATAL_ERROR);
186  }
187 }
188 
int32 l1file(int32 sdfid, int32 *nsamp, int32 *nscans, int16 *dtynum)
Definition: l1stat_chk.c:586
#define MAX(A, B)
Definition: swl0_utils.h:26
char get_cldmask(l1str *l1rec, int32_t ip)
Definition: cloud_flag.c:280
#define MIN(x, y)
Definition: rice.h:169
#define OFF
Definition: l1.h:42
#define HISOLZEN
Definition: l2_flags.h:23
#define MODGLINT
Definition: l2_flags.h:31
#define NULL
Definition: decode_rs.h:63
read l1rec
#define STRAYLIGHT
Definition: l2_flags.h:19
const double pi
#define ON
Definition: l1.h:43
void l1_mask_set(l1str *l1rec, int32_t ip)
Definition: setflags_l1.c:3
#define PI
Definition: l3_get_org.c:6
#define GLINT_MIN
Definition: l1.h:59
#define FILTER
Definition: l2_flags.h:37
l1_input_t * l1_input
Definition: l1_options.c:9
int setflags(l1str *l1rec)
Definition: setflags_l1.c:16
#define FATAL_ERROR
Definition: swl0_parms.h:5
#define COASTZ
Definition: l2_flags.h:17
int get_sdps_cld_mask(l1str *l1rec, int32_t ip, char *cld_category)
Definition: cloud_flag.c:5
#define CLOUD
Definition: l2_flags.h:20
#define RADEG
Definition: czcs_ctl_pt.c:5
#define LAND
Definition: l2_flags.h:12
#define HILT
Definition: l2_flags.h:15
#define SOLZNIGHT
Definition: l1.h:57
#define HISATZEN
Definition: l2_flags.h:16
level
Definition: mapgen.py:186
#define SEAICE
Definition: l2_flags.h:35
#define MODCLOUD
Definition: l1.h:73
#define HIPOL
Definition: l2_flags.h:40
int32 spix
Definition: l1_czcs_hdf.c:21
int windex(float wave, float twave[], int ntwave)
Definition: windex.c:73
#define HIGLINT
Definition: l2_flags.h:14
float mu0
int32 epix
Definition: l1_czcs_hdf.c:23
void setflagbits_l1(int level, l1str *l1rec, int32_t ipix)
Definition: setflags_l1.c:129
#define NAVWARN
Definition: l2_flags.h:27
int npix
Definition: get_cmp.c:27
#define NAVFAIL
Definition: l2_flags.h:36