NASA Logo
Ocean Color Science Software

ocssw V2022
get_hyper_vi.cpp
Go to the documentation of this file.
1 
8 #include "l12_proto.h"
9 #include "vegetation_indices.h"
10 
20 void get_pri(l1str *l1rec, float pri[]) {
21  int32_t num_pixels = l1rec->npix;
22  int32_t pixel_idx = -0;
23  int32_t band_idx = -0;
24  double rhos_530 = -0.0;
25  double rhos_570 = -0.0;
26 
27  static uint idx_530 = bindex_get(530);
28  static uint idx_570 = bindex_get(570);
29  std::vector<double> rhos_values;
30 
31  for (pixel_idx = 0; pixel_idx < num_pixels; pixel_idx++) {
32  pri[pixel_idx] = UNDEFINED;
33  band_idx = l1rec->l1file->nbands * pixel_idx;
34 
35  rhos_530 = l1rec->rhos[band_idx + idx_530];
36  rhos_570 = l1rec->rhos[band_idx + idx_570];
37 
38  // Pixel attributes and metadata
39  if (!rhos_values.empty())
40  rhos_values.clear();
41  rhos_values.push_back(rhos_530);
42  rhos_values.push_back(rhos_570);
43  double pixel_elevation = l1rec->dem[pixel_idx];
44  double pixel_mask = l1rec->flags[pixel_idx] & LAND_MASK;
45 
46  if (invalid_pixel(pixel_elevation, pixel_mask, rhos_values.data(), rhos_values.size())) {
47  l1rec->flags[pixel_idx] |= PRODFAIL;
48  continue;
49  }
50 
51  float pri_val = (rhos_530 - rhos_570) / (rhos_530 + rhos_570);
52  pri[pixel_idx] = clamp(pri_val, VI_MINVAL, VI_MAXVAL);
53  }
54 }
55 
64 void get_cire(l1str *l1rec, float cire[]) {
65  int32_t num_pixels = l1rec->npix;
66  int32_t pixel_idx = -0;
67  int32_t band_idx = -0;
68  double rhos_800 = -0.0;
69  double rhos_705 = -0.0;
70 
71  static uint idx_800 = bindex_get(800);
72  static uint idx_705 = bindex_get(705);
73  std::vector<double> rhos_values;
74 
75  for (pixel_idx = 0; pixel_idx < num_pixels; pixel_idx++) {
76  cire[pixel_idx] = UNDEFINED;
77  band_idx = l1rec->l1file->nbands * pixel_idx;
78 
79  rhos_800 = l1rec->rhos[band_idx + idx_800];
80  rhos_705 = l1rec->rhos[band_idx + idx_705];
81 
82  // Pixel attributes and metadata
83  if (!rhos_values.empty())
84  rhos_values.clear();
85 
86  rhos_values.push_back(rhos_800);
87  rhos_values.push_back(rhos_705);
88  double pixel_elevation = l1rec->dem[pixel_idx];
89  double pixel_mask = l1rec->flags[pixel_idx] & LAND_MASK;
90 
91  if (invalid_pixel(pixel_elevation, pixel_mask, rhos_values.data(), rhos_values.size())) {
92  l1rec->flags[pixel_idx] |= PRODFAIL;
93  continue;
94  }
95 
96  float cire_val = (rhos_800 / rhos_705) - 1;
97  cire[pixel_idx] = clamp(cire_val, VI_MINVAL, VI_MAXVAL);
98  }
99 }
100 
110 void get_car(l1str *l1rec, float car[]) {
111  int32_t num_pixels = l1rec->npix;
112  int32_t pixel_idx = -0;
113  int32_t band_idx = -0;
114  double rhos_495 = -0.0;
115  double rhos_705 = -0.0;
116  double rhos_800 = -0.0;
117 
118  static uint idx_495 = bindex_get(495);
119  static uint idx_705 = bindex_get(705);
120  static uint idx_800 = bindex_get(800);
121  std::vector<double> rhos_values;
122 
123  for (pixel_idx = 0; pixel_idx < num_pixels; pixel_idx++) {
124  car[pixel_idx] = UNDEFINED;
125  band_idx = l1rec->l1file->nbands * pixel_idx;
126 
127  rhos_495 = l1rec->rhos[band_idx + idx_495];
128  rhos_705 = l1rec->rhos[band_idx + idx_705];
129  rhos_800 = l1rec->rhos[band_idx + idx_800];
130 
131  // Pixel attributes and metadata
132  if (!rhos_values.empty())
133  rhos_values.clear();
134 
135  rhos_values.push_back(rhos_495);
136  rhos_values.push_back(rhos_705);
137  rhos_values.push_back(rhos_800);
138  double pixel_elevation = l1rec->dem[pixel_idx];
139  double pixel_mask = l1rec->flags[pixel_idx] & LAND_MASK;
140 
141  if (invalid_pixel(pixel_elevation, pixel_mask, rhos_values.data(), rhos_values.size())) {
142  l1rec->flags[pixel_idx] |= PRODFAIL;
143  continue;
144  }
145 
146  float car_val = ((1 / rhos_495) - (1 / rhos_705)) * rhos_800;
147  car[pixel_idx] = clamp(car_val, VI_MINVAL, VI_MAXVAL);
148  }
149 }
150 
160 void get_ari(l1str *l1rec, float ari[]) {
161  int32_t num_pixels = l1rec->npix;
162  int32_t pixel_idx = -0;
163  int32_t band_idx = -0;
164  double rhos_550 = -0.0;
165  double rhos_705 = -0.0;
166  double rhos_800 = -0.0;
167 
168  static uint idx_550 = bindex_get(550);
169  static uint idx_705 = bindex_get(705);
170  static uint idx_800 = bindex_get(800);
171 
172  std::vector<double> rhos_values;
173 
174  for (pixel_idx = 0; pixel_idx < num_pixels; pixel_idx++) {
175  ari[pixel_idx] = UNDEFINED;
176  band_idx = l1rec->l1file->nbands * pixel_idx;
177 
178  rhos_550 = l1rec->rhos[band_idx + idx_550];
179  rhos_705 = l1rec->rhos[band_idx + idx_705];
180  rhos_800 = l1rec->rhos[band_idx + idx_800];
181 
182  // Pixel attributes and metadata
183  if (!rhos_values.empty())
184  rhos_values.clear();
185 
186  rhos_values.push_back(rhos_550);
187  rhos_values.push_back(rhos_705);
188  rhos_values.push_back(rhos_800);
189  double pixel_elevation = l1rec->dem[pixel_idx];
190  double pixel_mask = l1rec->flags[pixel_idx] & LAND_MASK;
191 
192  if (invalid_pixel(pixel_elevation, pixel_mask, rhos_values.data(), rhos_values.size())) {
193  l1rec->flags[pixel_idx] |= PRODFAIL;
194  continue;
195  }
196 
197  float ari_val = ((1 / rhos_550) - (1 / rhos_705)) * rhos_800;
198  ari[pixel_idx] = clamp(ari_val, VI_MINVAL, VI_MAXVAL);
199  }
200 }
201 
211 int get_hyper_vi(l1str *l1rec, int product_number, float product[]) {
212  switch (product_number) {
213  case CAT_pri:
215  break;
216  case CAT_cire:
218  break;
219  case CAT_car:
221  break;
222  case CAT_ari:
224  break;
225  default:
226  printf("Error in %s; Unknown product specifier: %d\n", __FILE__, product_number);
227  exit(FATAL_ERROR);
228  }
229  return (EXIT_SUCCESS);
230 }
void get_car(l1str *l1rec, float car[])
#define EXIT_SUCCESS
Definition: GEO_basic.h:72
#define CAT_ari
Definition: l2prod.h:560
int get_hyper_vi(l1str *l1rec, int product_number, float product[])
void get_ari(l1str *l1rec, float ari[])
read l1rec
#define PRODFAIL
Definition: l2_flags.h:41
#define CAT_cire
Definition: l2prod.h:558
#define VI_MAXVAL
int bindex_get(int32_t wave)
Definition: windex.c:45
bool invalid_pixel(double pixel_elevation, double pixel_mask, double rhos_values[], int len_rhos_values)
Check pixel attributes for validity.
#define LAND_MASK
#define CAT_car
Definition: l2prod.h:559
#define FATAL_ERROR
Definition: swl0_parms.h:5
void get_pri(l1str *l1rec, float pri[])
#define UNDEFINED
void get_cire(l1str *l1rec, float cire[])
float clamp(float pixel_value, int minimum, int maximum)
Clamp the value of a pixel between minval and maxval.
#define VI_MINVAL
#define CAT_pri
Definition: l2prod.h:557
HISTORY txt for MOD_PR01(step one of PGE01) History follows the following convention needed due to new Aqua ReprocessingActual and the expected LUT revision number from PCF Changed to use PGE version for ProductionHistory Added Archive including ProcessingEnvironment Corrected handling of bad to resovle GSFcd02514 Changed to check staged LUT revision number versus the expected LUT revision number from thereby resolving defect report MODxl02056 This change also avoids the memory access violation reported in MODur00039 Changed the way output arrays were initialized with fill to be more but placed into the L1A output product and thought of as valid packets These packets had an invalid frame count in them and since only the last valid packet of any specific type gets it frame count data written to the output product
Definition: HISTORY.txt:176