NASA Logo
Ocean Color Science Software

ocssw V2022
vegetation_indices.c
Go to the documentation of this file.
1 
8 #include "vegetation_indices.h"
9 #include <math.h>
10 
11 #define NUM_BANDS_TO_BE_HYPERSPECTRAL 50
12 
13 // Band constants for use with hyperspectral instuments
14 const int32_t blu_min = 459; // blue band boundary for hyperspectral instruments
15 const int32_t blu_max = 479; // blue band boundary for hyperspectral instruments
16 const int32_t red_min = 620; // red band boundary for hyperspectral instruments
17 const int32_t red_max = 670; // red band boundary for hyperspectral instruments
18 const int32_t nir_min = 841; // near infrared band boundary for hyperspectral instruments
19 const int32_t nir_max = 876; // near infrared band boundary for hyperspectral instruments
20 const int32_t grn_min = 480; // green band boundary for hyperspectral instruments
21 const int32_t grn_max = 537; // green band boundary for hyperspectral instruments
22 const int32_t modis_b4_min = 545; // MODIS Green
23 const int32_t modis_b4_max = 565; // MODIS Green
24 const int32_t modis_b11_min = 526; // MODIS Green
25 const int32_t modis_b11_max = 536; // MODIS Green
26 
27 float average_rhos_values(float rhos_values[], size_t length) {
28  double sum = 0;
29  for (int i = 0; i < length; i++) {
30  sum += rhos_values[i];
31  }
32  return (sum / length);
33 }
34 
35 bool invalid_pixel(double pixel_elevation, double pixel_mask, double rhos_values[], int len_rhos_values) {
36  if (pixel_elevation <= MIN_PIXEL_ELEVATION || pixel_mask == 0)
37  return true;
38 
39  for (int idx_rhos = 0; idx_rhos < len_rhos_values; idx_rhos++) {
40  double rho_s = rhos_values[idx_rhos];
41  if (rho_s < 0.0 || rho_s > 1.0)
42  return true;
43  }
44 
45  // Nothing wrong found
46  return false;
47 }
48 
49 float clamp(float pixel_value, int minimum, int maximum) {
50  return fmin(fmax(pixel_value, minimum), maximum);
51 }
52 
53 bool instrument_is_hyperspectral(int32_t num_bands) {
54  return num_bands > NUM_BANDS_TO_BE_HYPERSPECTRAL;
55 }
const int32_t modis_b11_min
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...
const int32_t blu_min
const int32_t modis_b11_max
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)
const int32_t red_min
const int32_t modis_b4_max
const int32_t grn_min
const int32_t grn_max
const int32_t red_max
#define NUM_BANDS_TO_BE_HYPERSPECTRAL
const int32_t nir_min
const int32_t modis_b4_min
const int32_t nir_max
float clamp(float pixel_value, int minimum, int maximum)
Clamp the value of a pixel between minval and maxval.
int i
Definition: decode_rs.h:71
#define MIN_PIXEL_ELEVATION
const int32_t blu_max