OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
rpt_noise.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <libgen.h>
3 #include "l1stat.h"
4 #include "l1stat_proto.h"
5 extern int32 stat_status;
6 extern char bad_stat_str[320];
7 
8 #define DETAIL_PRT 0 /* 1 to print detail, 0 to not print detail */
9 
10 void rpt_noise(int32 sdfid, int16 dtynum, int32 nscans, int32 nsamp,
11  int *spike_cnt, float *line_sd, float pct_noise_thresh,
12  float pct_encrypt_thresh)
13 /*******************************************************************
14 
15  rpt_noise
16 
17  purpose: get information from 5 other SDSes that flag noise in
18  the data, combine it with the spike count and std deviation
19  computed from the chk_count routine and decide if this dataset
20  has too much noise to just pass
21 
22  Returns type: void - none
23 
24  Parameters: (in calling order)
25  Type Name I/O Description
26  ---- ---- --- -----------
27  int32 sdfid I SD interface ID
28  int16 dtynum I data type number (not used now)
29  int32 nscans I # lines in dataset
30  int32 nsamp I # samples / line
31  int * spike_cnt I size nscans by 8 array of
32  spike counts found
33  float * line_sd I size nscans by 8 array of
34  std deviations found
35  float pct_noise_thresh I reporting limit for % of
36  noisey lines
37  float pct_encrypt_thresh I reporting limit for % of
38  encrypted lines
39 
40  access spike_cnt and line_sd to get band b, line l with
41  index = b * nrec + l
42 
43  Modification history:
44  Programmer Date Description of change
45  ---------- ---- ---------------------
46  W. Robinson 31-Jul-1998 Original development
47  W. Robinson 24-Oct-2001 have input noise report thresholds
48 
49  *******************************************************************/ {
50  int irec, ibnd, icode;
51  int16 *s_satp, *s_zerop, *dark_rest, *start_syn, *stop_syn;
52  int32 *msec;
53  int16 code_start_syn[8] = {1023, 0, 1023, 0, 1023, 0, 1023, 0}, c_start_syn[8];
54  int16 code_stop_syn[8] = {1023, 1023, 0, 0, 1023, 1023, 0, 0}, c_stop_syn[8];
55  float s_zerop_thresh[8] = {0., 0., 0., 0., 0.0016, 0.008, 0.016, 0.008};
56  /* this is fraction of # pixels with 0 counts and corresponds
57  to 0, 0, 0, 0, 2, 10, 20, 10 for 1285 pixels (in a HRPT) */
58  int32 start[3], edge[3], encrypt_cnt, ds_noise_cnt, lin_prob_cnt,
59  s_satp_bad, s_zerop_bad, dark_rest_bad, start_syn_bad,
60  stop_syn_bad, sum_spikes;
61  /* normal noisey line threshold = 80, encrypted: 70. now have as inputs */
62  float pct_noise, pct_encrypt;
63  double pct_s_satp = 0., pct_s_zerop = 0., pct_dark_rest = 0.,
64  pct_start_syn = 0., pct_stop_syn = 0.;
65  char str[12];
66 
67  /*
68  * set up the start and stop sync to check using the code and data type
69  */
70  if ((dtynum == IGC) || (dtynum == TDI) || (dtynum == SOL)) {
71  for (ibnd = 0; ibnd < 7; ibnd++) {
72  c_start_syn[ibnd] = 1023 - code_start_syn[ibnd];
73  c_stop_syn[ibnd] = 1023 - code_stop_syn[ibnd];
74  }
75  } else {
76  for (ibnd = 0; ibnd < 7; ibnd++) {
77  c_start_syn[ibnd] = code_start_syn[ibnd];
78  c_stop_syn[ibnd] = code_stop_syn[ibnd];
79  }
80  }
81 
82  /*
83  * allocate the space needed for the 5 arrays
84  */
85  if ((s_satp = (int16 *) malloc(8 * nscans * sizeof ( int16)))
86  == NULL) {
87  printf("\n*****rpt_noise: program error, unable to allocate s_satp space\n");
89  return;
90  }
91  if ((s_zerop = (int16 *) malloc(8 * nscans * sizeof ( int16)))
92  == NULL) {
93  printf("\n*****rpt_noise: program error, unable to allocate s_zerop space\n");
95  return;
96  }
97  if ((dark_rest = (int16 *) malloc(8 * nscans * sizeof ( int16)))
98  == NULL) {
99  printf("\n*****rpt_noise: program error, unable to allocate dark_rest space\n");
100  stat_status = stat_status | 1;
101  return;
102  }
103  if ((start_syn = (int16 *) malloc(8 * nscans * sizeof ( int16)))
104  == NULL) {
105  printf("\n*****rpt_noise: program error, unable to allocate start_syn space\n");
106  stat_status = stat_status | 1;
107  return;
108  }
109  if ((stop_syn = (int16 *) malloc(8 * nscans * sizeof ( int16)))
110  == NULL) {
111  printf("\n*****rpt_noise: program error, unable to allocate stop_syn space\n");
112  stat_status = stat_status | 1;
113  return;
114  }
115 
116  /*
117  * for other tests, get msec also (for line id)
118  */
119  if ((msec = (int32 *) malloc(nscans * sizeof ( int32)))
120  == NULL) {
121  printf("\n*****rpt_noise: program error, unable to allocate msec space\n");
122  stat_status = stat_status | 1;
123  return;
124  }
125 
126  /*
127  * read the arrays from the L1 dataset
128  */
129  start[0] = start[1] = start[2] = 0;
130  edge[0] = nscans;
131  edge[1] = 8;
132  edge[2] = 0;
133 
134  if (rdslice(sdfid, "s_satp", start, edge, (void *) s_satp) < 0) {
135  stat_status = stat_status | 1;
136  printf("\n*****rpt_noise: program error, unable to read s_satp\n");
137  return;
138  }
139 
140  if (rdslice(sdfid, "s_zerop", start, edge, (void *) s_zerop) < 0) {
141  stat_status = stat_status | 1;
142  printf("\n*****rpt_noise: program error, unable to read s_zerop\n");
143  return;
144  }
145 
146  if (rdslice(sdfid, "dark_rest", start, edge, (void *) dark_rest) < 0) {
147  stat_status = stat_status | 1;
148  printf("\n*****rpt_noise: program error, unable to read dark_rest\n");
149  return;
150  }
151 
152  if (rdslice(sdfid, "start_syn", start, edge, (void *) start_syn) < 0) {
153  stat_status = stat_status | 1;
154  printf("\n*****rpt_noise: program error, unable to read start_syn\n");
155  return;
156  }
157 
158  if (rdslice(sdfid, "stop_syn", start, edge, (void *) stop_syn) < 0) {
159  stat_status = stat_status | 1;
160  printf("\n*****rpt_noise: program error, unable to read stop_syn\n");
161  return;
162  }
163 
164  edge[0] = nscans;
165  edge[1] = 0;
166  edge[2] = 0;
167  if (rdslice(sdfid, "msec", start, edge, (void *) msec) < 0) {
168  stat_status = stat_status | 1;
169  printf("\n*****rpt_noise: program error, unable to read stop_syn\n");
170  return;
171  }
172 
173  /*
174  * initialize some values for the entire dataset
175  */
176  encrypt_cnt = 0;
177  ds_noise_cnt = 0;
178 
179  /*
180  * print heading for line-by-line report (if enabled)
181  */
182 
183  if (DETAIL_PRT) {
184  printf("\n\nLine-by-line report of noise and noise type found\n");
185  printf("line # bands # bands # bands w # bad strt # bad stop std dev # spikes msec line\n");
186  printf(" # saturated zero high dark sync wds/7 sync wds/7 band 1 all bnds tag type\n");
187  printf("---- --------- ------- --------- ---------- ---------- ------- -------- -------- ----\n");
188  }
189 
190  /*
191  * loop through the records and get onfo on each one
192  */
193  for (irec = 0; irec < nscans; irec++) {
194  /*
195  * initialize counts for each line
196  */
197  lin_prob_cnt = 0;
198  s_satp_bad = 0;
199  s_zerop_bad = 0;
200  dark_rest_bad = 0;
201  start_syn_bad = 0;
202  stop_syn_bad = 0;
203  sum_spikes = 0;
204 
205  /*
206  * loop through each band or sync word (only 7 checked for sync words )
207  */
208  for (ibnd = 0; ibnd < 8; ibnd++) {
209  if (*(s_satp + ibnd + 8 * irec) != 0) {
210  s_satp_bad++;
211  lin_prob_cnt++;
212  }
213  if ((float) *(s_zerop + ibnd + 8 * irec) / nsamp
214  > *(s_zerop_thresh + ibnd)) {
215  s_zerop_bad++;
216  lin_prob_cnt++;
217  }
218  if (*(dark_rest + ibnd + 8 * irec) > 30) {
219  dark_rest_bad++;
220  lin_prob_cnt++;
221  }
222  if (ibnd < 7) /* only check the 1st 7 words for the sync */ {
223  if (*(start_syn + ibnd + 8 * irec) != *(c_start_syn + ibnd)) {
224  start_syn_bad++;
225  lin_prob_cnt++;
226  }
227  if (*(stop_syn + ibnd + 8 * irec) != *(c_stop_syn + ibnd)) {
228  stop_syn_bad++;
229  lin_prob_cnt++;
230  }
231  }
232  sum_spikes += *(spike_cnt + ibnd + 8 * irec);
233  } /* end band (word) loop, report the line results */
234 
235  if (DETAIL_PRT) {
236  printf("%4d%10d%9d%11d%12d%12d%9.2f%10d%9d", irec, s_satp_bad,
237  s_zerop_bad, dark_rest_bad, start_syn_bad, stop_syn_bad,
238  *(line_sd + 8 * irec), sum_spikes, *(msec + irec));
239  }
240 
241  /*
242  * need to add the line type at the end
243  */
244  if (*(line_sd + 8 * irec) > 220.) {
245  if (DETAIL_PRT) {
246  printf(" **** Encrypted line\n");
247  }
248  encrypt_cnt++;
249  ds_noise_cnt++;
250  } else if (lin_prob_cnt > 0) {
251  if (DETAIL_PRT) {
252  printf(" ** Noisey line\n");
253  }
254  ds_noise_cnt++;
255  } else {
256  if (DETAIL_PRT) {
257  printf(" Good line\n");
258  }
259  }
260 
261  /*
262  * count the occurences of each of the 5 SDS violations
263  * (make into percentages at the end)
264  */
265  if (s_satp_bad > 0) pct_s_satp++;
266  if (s_zerop_bad > 0) pct_s_zerop++;
267  if (dark_rest_bad > 0) pct_dark_rest++;
268  if (start_syn_bad > 0) pct_start_syn++;
269  if (stop_syn_bad > 0) pct_stop_syn++;
270 
271  } /* end record loop, time for the final reconing */
272 
273  /*
274  * report percentages of the 5 sdses violated
275  */
276  printf("\n\n#Noise report summary\n\n");
277  printf("# --- Percentage bad lines ---\n");
278  printf("# bands bands bands w bad strt bad stop \n");
279  printf("# saturated zero high dark sync wds/7 sync wds/7 \n");
280  printf("# --------- ------- --------- ---------- ---------- \n");
281  printf("# %10.2f%9.2f%11.2f%12.2f%12.2f\n\n",
282  (100. * pct_s_satp / nscans), (100. * pct_s_zerop / nscans),
283  (100. * pct_dark_rest / nscans), (100. * pct_start_syn / nscans),
284  (100. * pct_stop_syn / nscans));
285 
286  printf("\n\n#total # lines: %9d # with noise: %9d # encrypted: %d\n",
287  nscans, ds_noise_cnt, encrypt_cnt);
288  pct_noise = 100. * (float) ds_noise_cnt / nscans;
289  pct_encrypt = 100. * (float) encrypt_cnt / nscans;
290  printf
291  (" %9.2f %% %9.2f %%\n\n\n",
292  pct_noise, pct_encrypt);
293  /*
294  * add the encryption and noise reports also
295  */
296  printf("\n\n#Mnemonic Code %% lines %% threshold\n");
297  printf(" -------- ---- ------- -----------\n");
298  if ((dtynum == GAC) || (dtynum == LAC) || (dtynum == HRPT)) {
299  icode = 0;
300  if (pct_encrypt > pct_encrypt_thresh) {
301  printf("#*** dataset failed due to > %7.2f %% encryption noise\n",
302  pct_encrypt_thresh);
303  stat_status = stat_status | 2;
304  icode = 1;
305  sprintf(str, "ENCRYPT ");
306  if (strlen(bad_stat_str) <= 300)
307  strcat(bad_stat_str, str);
308  }
309  printf("ENCRYPT %2d %7.2f %7.2f\n", icode, pct_encrypt,
310  pct_encrypt_thresh);
311  icode = 0;
312  if (pct_noise > pct_noise_thresh) {
313  printf("#*** dataset failed due to > %7.2f %% general noise\n",
314  pct_noise_thresh);
315  stat_status = stat_status | 2;
316  icode = 1;
317  sprintf(str, "NOISE ");
318  if (strlen(bad_stat_str) <= 300)
319  strcat(bad_stat_str, str);
320  }
321  printf("NOISE %2d %7.2f %7.2f\n\n", icode,
322  pct_noise, pct_noise_thresh);
323  } else {
324  printf("ENCRYPT N/A %7.2f %7.2f\n", pct_encrypt,
325  pct_encrypt_thresh);
326  printf("NOISE N/A %7.2f %7.2f\n\n",
327  pct_noise, pct_noise_thresh);
328  }
329  /*
330  * make a 1 line mnemonic version for easy auto-pull-out
331  */
332  printf("\n\n#1 line version for auto-identification\n");
333  printf("\n#Mnemonic Code noise encrypt sat zero dark start stop\n");
334  printf("#----------------------------------------------------------------------------\n");
335  if ((dtynum == GAC) || (dtynum == LAC) || (dtynum == HRPT)) {
336  printf("L1NOISE %2d%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f\n",
337  icode, pct_noise, pct_encrypt, (100. * pct_s_satp / nscans),
338  (100. * pct_s_zerop / nscans), (100. * pct_dark_rest / nscans),
339  (100. * pct_start_syn / nscans), (100. * pct_stop_syn / nscans));
340  } else {
341  printf("L1NOISE N/A%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f\n",
342  pct_noise, pct_encrypt, (100. * pct_s_satp / nscans),
343  (100. * pct_s_zerop / nscans), (100. * pct_dark_rest / nscans),
344  (100. * pct_start_syn / nscans), (100. * pct_stop_syn / nscans));
345  }
346 
347  free(s_satp);
348  free(s_zerop);
349  free(dark_rest);
350  free(start_syn);
351  free(stop_syn);
352 
353  /*
354  * that's all
355  */
356  return;
357 }
integer, parameter int16
Definition: cubeio.f90:3
char bad_stat_str[320]
Definition: l1stat_chk.c:11
int32 rdslice(int32 sdfid, char *name, int32 *start, int32 *edge, void *buf)
Definition: stat_chk_utl.c:94
#define TDI
Definition: l1stat.h:39
#define NULL
Definition: decode_rs.h:63
void rpt_noise(int32 sdfid, int16 dtynum, int32 nscans, int32 nsamp, int *spike_cnt, float *line_sd, float pct_noise_thresh, float pct_encrypt_thresh)
Definition: rpt_noise.c:10
int16_t * dark_rest
Definition: l1a_seawifs.c:89
int32 * msec
Definition: l1_czcs_hdf.c:31
#define GAC
Definition: l1stat.h:33
#define LAC
Definition: l1stat.h:34
#define DETAIL_PRT
Definition: rpt_noise.c:8
#define IGC
Definition: l1stat.h:38
#define HRPT
Definition: l1stat.h:35
#define SOL
Definition: l1stat.h:37
int32 stat_status
Definition: l1stat_chk.c:8
const char * str
Definition: l1c_msi.cpp:35