Go to the documentation of this file.
13 static int32_t idx_band_swir = -1;
15 static int idx_multiband_nir;
16 static int idx_nir_min =
BAD_INT;
17 static int idx_nir_max =
BAD_INT;
19 static int32_t num_bands;
31 int32_t idx_pixel = -0, idx_band = -0;
32 float rhos_nir = -0.0, rhos_swir = -0.0;
35 if (idx_nir_max < 0 || idx_nir_min < 0 || idx_band_swir < 0) {
36 printf(
"NDWI requires NIR bands between 670 and 875, and at 1250 nm");
40 for (idx_pixel = 0; idx_pixel <
l1rec->npix; idx_pixel++) {
42 idx_band =
l1rec->l1file->nbands * idx_pixel;
47 float *start_of_rhos_nir = &
l1rec->rhos[idx_band + idx_nir_min];
48 int nir_band_width = idx_nir_max - idx_nir_min + 1;
54 rhos_nir =
l1rec->rhos[idx_band + idx_multiband_nir];
56 rhos_swir =
l1rec->rhos[idx_band + idx_band_swir];
59 double pixel_elevation =
l1rec->dem[idx_pixel];
61 double rhos_vals[] = {rhos_nir, rhos_swir};
62 int len =
sizeof(rhos_vals) /
sizeof(rhos_vals[0]);
64 if (
invalid_pixel(pixel_elevation, pixel_mask, rhos_vals, len)) {
69 float ndwi_value = (rhos_nir - rhos_swir) / (rhos_nir + rhos_swir);
80 num_bands =
l1rec->l1file->nbands;
82 static bool first_call =
true;
float average_rhos_values(float rhos_values[], size_t length)
Get the average of rho_s values from a hyperspectral measurement to approximate a multi-band measurem...
int bindex_get(int32_t wave)
bool invalid_pixel(double pixel_elevation, double pixel_mask, double rhos_values[], int len_rhos_values)
Check pixel attributes for validity.
bool instrument_is_hyperspectral(int32_t num_bands)
void get_ndwi(l1str *l1rec, float prod[])
Main entry point for getting NDWI.
float clamp(float pixel_value, int minimum, int maximum)
Clamp the value of a pixel between minval and maxval.
void calculate_ndwi(l1str *l1rec, float ndwi[])