NASA Logo
Ocean Color Science Software

ocssw V2022
sst_cloud_mask_utils.cpp
Go to the documentation of this file.
2 #include "d3940tref.h"
3 
4 namespace envset {
6  if (const char *env_p = std::getenv("OCDATAROOT")) {
7  return env_p;
8  }
9  std::cerr << "--Error-: OCDATAROOT env variable NOT found; exiting ..." << std::endl;
10  exit(EXIT_FAILURE);
11  return "";
12  }
13 
14 }
15 
16 namespace cldmsk {
17  std::vector<float> month_data_; // month_data;
18  std::vector<float> &month_data() { return month_data_; }
19 
21  for (const auto &sens_data: all_sensors) {
22  if (sens_data.second.count(key) > 0)
23  return sens_data.first;
24  }
25  std::cerr << "--Error-: Sensor is Not Found; Currently, the code process only VIIRS and MODIS; exiting ... "
26  << std::endl;
27  exit(EXIT_FAILURE);
28  return "";
29  }
30 
31  float btrefdiffv6(int32_t ip, float BT39, float BT40, const l1str *l1rec, int fullscanpix) {
32  float diff;
33  float satzdir;
34  float senz;
35  float tref;
36  satzdir = (l1rec->pixnum[ip] < fullscanpix / 2) ? -1.0 : 1.0;
37  senz = l1rec->senz[ip] * satzdir;
38  tref = linterp(sza, trefv6, NSENZ, senz);
39  diff = BT39 - BT40 - tref;
40  return (diff);
41  }
42 
43  void get_var_mask(int *mask, const l1str &l1str, size_t npix, int nbands, int ib, get_valid get_mask) {
44  for (size_t i = 0; i < npix; i++) {
45  mask[i] = get_mask(l1str, i, nbands, ib);
46  }
47  }
48 
49  void get_var_vals(float *BT, const l1str &l1str, size_t npix, int nbands, int ib, get_value get_val) {
50  for (size_t i = 0; i < npix; i++) {
51  BT[i] = get_val(l1str, i, nbands, ib);
52  }
53  }
54 
55  void get_window_1D_max(float *maxs_1d, const float *inp1d, const int *mask1d, size_t npix, size_t radius) {
56  for (size_t i_p = 0; i_p < npix; i_p++) {
57  maxs_1d[i_p] = BAD_FLT;
58  const size_t i_p_s = std::max(0, (int) i_p - (int) radius);
59  const size_t i_p_e = std::min(npix - 1, i_p + radius);
60  for (size_t i = i_p_s; i <= i_p_e; i++) {
61  if (mask1d[i]) {
62  const float val = inp1d[i];
63  if (val > maxs_1d[i_p]) {
64  maxs_1d[i_p] = val;
65  }
66  }
67  }
68  }
69  }
70 
71  void
72  get_total_2d_max(float *max_global, const float *inp2d, size_t npix, size_t nscan, size_t center, size_t radius) {
73  const size_t i_q_s = std::max(0, (int) center - (int) radius);
74  const size_t i_q_e = std::min(nscan - 1, center + radius);
75  for (size_t i_p = 0; i_p < npix; i_p++) {
76  max_global[i_p] = BAD_FLT;
77  for (size_t i_q = i_q_s; i_q <= i_q_e; i_q++) {
78  const size_t ind = i_p + i_q * npix;
79  const float val = inp2d[ind];
80  if (val > max_global[i_p]) {
81  max_global[i_p] = val;
82  }
83  }
84  }
85  }
86 
87  void get_window_1D_min(float *mins_1d, const float *inp1d, const int *mask1d, size_t npix, size_t radius) {
88  const float max_possible_val = std::abs(BAD_FLT);
89  for (size_t i_p = 0; i_p < npix; i_p++) {
90  mins_1d[i_p] = max_possible_val;
91  const size_t i_p_s = std::max(0, (int) i_p - (int) radius);
92  const size_t i_p_e = std::min(npix - 1, i_p + radius);
93  for (size_t i = i_p_s; i <= i_p_e; i++) {
94  if (mask1d[i]) {
95  const float val = inp1d[i];
96  if (val < mins_1d[i_p]) {
97  mins_1d[i_p] = val;
98  }
99  }
100  }
101  }
102  }
103 
104  void
105  get_total_2d_min(float *min_global, const float *inp2d, size_t npix, size_t nscan, size_t center, size_t radius) {
106  const size_t i_q_s = std::max(0, (int) center - (int) radius);
107  const size_t i_q_e = std::min(nscan - 1, center + radius);
108  const float max_possible_val = std::abs(BAD_FLT);
109  for (size_t i_p = 0; i_p < npix; i_p++) {
110  min_global[i_p] = max_possible_val;
111  for (size_t i_q = i_q_s; i_q <= i_q_e; i_q++) {
112  const size_t ind = i_p + i_q * npix;
113  const float val = inp2d[ind];
114  if (val < min_global[i_p]) {
115  min_global[i_p] = val;
116  }
117  }
118  }
119  }
120 
121  void get_std_box(const float *inp2d, const int *mask2d, size_t npix, size_t nscan, size_t radius_x, size_t radius_y,
122  float *out, size_t center, l1qstr *l1qrec) {
123  std::vector<double> sums(npix * nscan, 0.0);
124  std::vector<double> sums2(npix * nscan, 0.0);
125  std::vector<size_t> counts(npix * nscan, 0);
126  for (size_t i_q = 0; i_q < nscan; i_q++) {
127  for (size_t i_p = 0; i_p < npix; i_p++) {
128  const size_t i_p_s = std::max(0, (int) i_p - (int) radius_x);
129  const size_t i_p_e = std::min(npix - 1, i_p + radius_x);
130  const size_t ind = i_p + i_q * npix;
131  for (size_t i = i_p_s; i <= i_p_e; i++) {
132  const size_t index = i + i_q * npix;
133  if (mask2d[index]) {
134  sums.at(ind) += (inp2d[index]);
135  sums2.at(ind) += (inp2d[index]) * (inp2d[index]);
136  counts.at(ind) += 1;
137  }
138  }
139  }
140  }
141  const size_t i_q_s = std::max(0, (int) center - (int) radius_y);
142  const size_t i_q_e = std::min(nscan - 1, center + radius_y);
143  for (size_t i_p = 0; i_p < npix; i_p++) {
144  double sum_local = 0.0f;
145  double sum_local2 = 0.0f;
146  size_t count_local = 0;
147  for (size_t i_q = i_q_s; i_q <= i_q_e; i_q++) {
148  const size_t ind = i_p + i_q * npix;
149  count_local += counts.at(ind);
150  sum_local += sums.at(ind);
151  sum_local2 += sums2.at(ind);
152  }
153  if (count_local > 2) {
154  double diff = (sum_local2 - sum_local * sum_local / (int) count_local) / ((int) count_local - 1);
155  if (diff <= 0) {
156  out[i_p] = BAD_FLT;
157  } else {
158  out[i_p] = std::sqrt(diff);
159  }
160  } else {
161  out[i_p] = BAD_FLT;
162  }
163  }
164  }
165 
166  void read_sst_bands(const std::string &sat, std::unordered_map<std::string, int> &bands) {
167  for (const auto &var_pair: bands_set.at(sat)) {
168  const std::string key = var_pair.first;
169  const int value = var_pair.second;
171  }
172  }
173 }
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT the first two or last two tables respectively will be used for the interpolation If there is only one LUT in the set of it will be treated as a constant LUT The manner in which Earth View data is checked for saturation was changed Previously the raw Earth View DNs and Space View DNs were checked against the lookup table values contained in the table dn_sat The change made is to check the raw Earth and Space View DNs to be sure they are less than the maximum saturation value and to check the Space View subtracted Earth View dns against a set of values contained in the new lookup table dn_sat_ev The metadata configuration and ASSOCIATEDINSTRUMENTSHORTNAME from the MOD02HKM product The same metatdata with extensions and were removed from the MOD021KM and MOD02OBC products ASSOCIATEDSENSORSHORTNAME was set to MODIS in all products These changes are reflected in new File Specification which users may consult for exact the pow functions were eliminated in Emissive_Cal and Emissive bands replaced by more efficient code Other calculations throughout the code were also made more efficient Aside from a few round off there was no difference to the product The CPU time decreased by about for a day case and for a night case A minor bug in calculating the uncertainty index for emissive bands was corrected The frame index(0-based) was previously being used the frame number(1-based) should have been used. There were only a few minor changes to the uncertainty index(maximum of 1 digit). 3. Some inefficient arrays(Sigma_RVS_norm_sq) were eliminated and some code lines in Preprocess_L1A_Data were moved into Process_OBCEng_Emiss. There were no changes to the product. Required RAM was reduced by 20 MB. Now
int32 value
Definition: Granule.c:1235
real, dimension(fnm) tref
bool(* get_valid)(const l1str &, int, int, int)
These are used to scale the SD before writing it to the HDF4 file The default is and which means the product is not scaled at all Since the product is usually stored as a float inside of this is a way to write the float out as a integer l2prod min
void get_window_1D_min(float *mins_1d, const float *inp1d, const int *mask1d, size_t npix, size_t radius)
the same as get_window_1D_max but for min
const std::unordered_map< std::string, const std::unordered_map< std::string, int > > bands_set
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed as required for compatibility with version of the SDP toolkit Corrected test output file names to end in out
Definition: HISTORY.txt:422
float(* get_value)(const l1str &, int, int, int)
read l1rec
void read_sst_bands(const std::string &sat, std::unordered_map< std::string, int > &bands)
uint8 * counts
Definition: l1_czcs_hdf.c:30
int32 nscan
Definition: l1_czcs_hdf.c:19
std::string get_ocdata_root()
Returns OCDATAROOT.
@ string
std::string get_sensor(int key)
Get the sensor string.
int bindex_get(int32_t wave)
Definition: windex.c:45
float linterp(float xin[], float yin[], int32_t nin, float xout)
Definition: lspline.c:59
Contains supportive functions and constants.
void get_window_1D_max(float *maxs_1d, const float *inp1d, const int *mask1d, size_t npix, size_t radius)
Compute max values within a 1D window in one line in a queue.
a context in which it is NOT documented to do so subscript which cannot be easily calculated when extracting TONS attitude data from the Terra L0 files Corrected several defects in extraction of entrained ephemeris and and as HDF file for both the L1A and Geolocation enabling retrieval of South Polar DEM data Resolved Bug by changing to opent the geolocation file only after a successful read of the L1A and also by checking for fatal errors from not restoring C5 and to report how many of those high resolution values were water in the new WaterPresent SDS Added valid_range attribute to Land SeaMask Changed to bilinearly interpolate the geoid_height to remove artifacts at one degree lines Made corrections to const qualification of pointers allowed by new version of M API library Removed casts that are no longer for same not the geoid Corrected off by one error in calculation of high resolution offsets Corrected parsing of maneuver list configuration parameter Corrected to set Height SDS to fill values when geolocation when for elevation and land water mask
Definition: HISTORY.txt:114
void get_total_2d_min(float *min_global, const float *inp2d, size_t npix, size_t nscan, size_t center, size_t radius)
the same as get_total_2d_max but for min
subroutine diff(x, conec, n, dconecno, dn, dconecmk, units, u, inno, i, outno, o, input, deriv)
Definition: ffnet.f:205
std::vector< float > & month_data()
month variable for the desicion tree traversal
#define BT
Definition: st_lt.h:10
def center
Definition: sort_gring.py:68
std::vector< float > month_data_
#define BAD_FLT
Definition: jplaeriallib.h:19
int32_t nbands
void get_std_box(const float *inp2d, const int *mask2d, size_t npix, size_t nscan, size_t radius_x, size_t radius_y, float *out, size_t center, l1qstr *l1qrec)
Compute standard deviation in a window.
void get_total_2d_max(float *max_global, const float *inp2d, size_t npix, size_t nscan, size_t center, size_t radius)
Get the max value of center line with 2D sliding window using a 1D max queue computed with get_window...
#define NSENZ
Definition: d3940tref.h:3
float btrefdiffv6(int32_t ip, float BT39, float BT40, const l1str *l1rec, int fullscanpix)
Legacy BT diff test with interpolation adjutment.
void get_var_mask(int *mask, const l1str &l1str, size_t npix, int nbands, int ib, get_valid get_mask)
Get the mask (line) of a BT.
void radius(double A)
Definition: proj_report.c:132
#define abs(a)
Definition: misc.h:90
int i
Definition: decode_rs.h:71
const std::unordered_map< std::string, std::unordered_set< int > > all_sensors
void get_var_vals(float *BT, const l1str &l1str, size_t npix, int nbands, int ib, get_value get_val)
the same as get_var_mask but gets values
int npix
Definition: get_cmp.c:28
l2prod max