OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
anal_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 
7 void anal_noise(int32 rec, int32 nrec, int32 nscans, int32 nsamp,
8  int32 nbands, int16 *i16buf, int *spike_cnt, float *line_sd,
9  int32_t *cnt_coin_jmp, int32_t *jmp_hist)
10 /*******************************************************************
11 
12  anal_noise
13 
14  purpose: check a buffer of level-1a data line by line and band by band
15  to see if there is evidence of spike noise or an encrypted line
16  only information is generated. later, this will get combined
17  with checks of other SDS data to evaluate the total noise
18 
19  Returns type: void - none
20 
21  Parameters: (in calling order)
22  Type Name I/O Description
23  ---- ---- --- -----------
24  int32 rec I line # of this current
25  batch of level-1a lines
26  int32 nrec I # of lines in this array
27  int32 nscans I total # scan lines
28  int32 nsamp I # pixels per line
29  int32 nbands I # of bands
30  int16 * i16buf I line by pixel by band
31  array of raw counts
32  int * spike_cnt O line by band array of
33  spike count
34  float * line_sd O line by band array of
35  std deviation for line
36  int32_t * cnt_coin_jmp O size 8 count of co-incidences
37  (# times 1-8 bands for a
38  pixel are on at once)
39  int32_t * jmp_hist O size 1024 histogram
40  of jump size
41 
42  access spike_cnt and line_sd to get band b, line l with
43  index = b * nrec + l
44 
45  Modification history:
46  Programmer Date Description of change
47  ---------- ---- ---------------------
48  W. Robinson 31-Jul-1998 Original development
49 
50  *******************************************************************/ {
51  int rec_num, irec, ibnd, ipix;
52  short *spike_jmp, pixm1, pix, pixp1, isum;
53  double apx, sum, sumsq, pix_jmp, sd;
54  float jfact = 1.3; /* 1.3 for HRPT, 5 for GAC? It seems that GAC
55  and HRPT still get 'spikes' for good, cloud pix,
56  so usefullness may be limited at this time */
57  int32_t neighbor_diff;
58 
59  if ((spike_jmp = (short *) malloc(nbands * nsamp * sizeof ( short)))
60  == NULL) {
61  printf("\n*****anal_noise: program error, unable to allocate space\n");
63  } else {
64  /*
65  * loop through the lines in this batch
66  */
67  rec_num = rec;
68 
69  for (irec = 0; irec < nrec; irec++, rec_num++) {
70  for (ibnd = 0; ibnd < nbands; ibnd++) {
71  /*
72  * Locate the spikes. The general idea is to see if a pixel
73  * is wildly different from it's next store neighbors
74  * a band-dependent minimum excursion will be imposed (to avoid
75  * classifying noise jumps as a spike) and a maximun
76  * neighbor change will also be imposed (to avois electronics
77  * overshoot points)
78  */
79  sum = 0.;
80  sumsq = 0.;
81  for (ipix = 1; ipix < (nsamp - 1); ipix++) {
82  pixm1 = *(i16buf + ibnd + nbands * ((ipix - 1) + nsamp * irec));
83  pix = *(i16buf + ibnd + nbands * (ipix + nsamp * irec));
84  pixp1 = *(i16buf + ibnd + nbands * ((ipix + 1) + nsamp * irec));
85  neighbor_diff = abs(pixm1 - pixp1);
86  pix_jmp = fabs(pix - (pixm1 + pixp1) / 2.);
87  /*
88  * do not do points that have a large neighbor jump or a small
89  * pixel jump
90  */
91 
92  *(spike_jmp + ibnd + nbands * ipix) = 0;
93  if (pix_jmp > 15 && neighbor_diff < 200) {
94  if (pix_jmp > jfact * neighbor_diff) {
95  (*(spike_cnt + ibnd + nbands * rec_num))++;
96  *(spike_jmp + ibnd + nbands * ipix) = pix_jmp;
97  /*
98  printf( "rec: %d, pix: %d, bnd: %d, jump: %f\n",
99  rec_num, ipix, ibnd, pix_jmp );
100  */
101  if (pix_jmp < 1024)
102  (*(jmp_hist + (int) pix_jmp))++;
103  }
104  }
105  /*
106  * accumulate the sum and sum square for the statistics
107  */
108  apx = (double) pix;
109  sum += apx;
110  sumsq += apx * apx;
111  } /* end pixel loop */
112  /*
113  * compute the standard deviation for the line and band
114  */
115  sd = sumsq / nsamp - sum * sum / (nsamp * nsamp);
116  sd = (sd > 0) ? sqrt(sd) : 0.;
117  *(line_sd + ibnd + nbands * (rec_num)) = (float) sd;
118  /*
119  printf( "rec: %d, bnd: %d, sd: %f\n", irec, ibnd, sd );
120  */
121  } /* end band loop */
122  /*
123  * find frequency of pops occuring at same pixel
124  */
125  for (ipix = 1; ipix < nsamp - 1; ipix++) {
126  isum = 0;
127  for (ibnd = 0; ibnd < nbands; ibnd++) {
128  if (*(spike_jmp + ibnd + nbands * ipix) > 0)
129  isum++;
130  }
131  if (isum > 0) {
132  /*
133  printf( "rec: %d, pix: %d, co-incident jumps: %d\n",
134  irec, ipix, isum );
135  */
136  (* (cnt_coin_jmp + isum - 1))++;
137  }
138  }
139  } /* end record loop */
140  /*
141  * remove space for spike jumps
142  */
143  free(spike_jmp);
144  }
145 }
integer, parameter int16
Definition: cubeio.f90:3
#define NULL
Definition: decode_rs.h:63
unsigned long long sumsq(signed short *in, int cnt)
int32 stat_status
Definition: l1stat_chk.c:8
integer, parameter double
int32_t nbands
#define fabs(a)
Definition: misc.h:93
void anal_noise(int32 rec, int32 nrec, int32 nscans, int32 nsamp, int32 nbands, int16 *i16buf, int *spike_cnt, float *line_sd, int32_t *cnt_coin_jmp, int32_t *jmp_hist)
Definition: anal_noise.c:7
#define abs(a)
Definition: misc.h:90