version  0.0.1
Defines the C++ API for MsPASS
GeneralIterDecon.h
1 #ifndef __SIIMPLE_GENERAL_ITER_DECON__
2 #define __SIIMPLE_GENERAL_ITER_DECON__
3 #include <vector>
4 #include "mspass/algorithms/deconvolution/ComplexArray.h"
5 #include "mspass/algorithms/deconvolution/ScalarDecon.h"
6 #include "mspass/algorithms/deconvolution/FFTDeconOperator.h"
7 #include "mspass/algorithms/TimeWindow.h"
8 #include "mspass/utility/dmatrix.h"
9 #include "mspass/utility/Metadata.h"
10 #include "mspass/utility/AntelopePf.h"
11 #include "mspass/seismic/CoreTimeSeries.h"
12 #include "mspass/seismic/Seismogram.h"
13 namespace mspass::algorithms::deconvolution{
14 /* Wang's original version allowed XCORR here - dropped for now as this
15 code assumes the decon produces a zero phase ideal output while in every
16 case the original XCORR iterative method uses the raw wavelet and cross
17 correlation. */
18 
19 enum IterDeconType {WATER_LEVEL,LEAST_SQ,MULTI_TAPER};
21 {
22 public:
25  int col;
27  double u[3];
29  double amp;
30  /* This is the primary constructor for oneo of thise. In the iterative
31  sequnce of generalized iterative decon we find the column with maximum
32  amplitude and point this constructor at the right column. The
33  parent dmatrix is then updated subtracting the inverse wavelet at
34  this lag. */
38  ThreeCSpike(const ThreeCSpike& parent);
41  ThreeCSpike& operator=(const ThreeCSpike& parent);
42 };
68 {
69 public:
78  GeneralIterDecon(const GeneralIterDecon &parent);
79  void changeparameter(const mspass::utility::Metadata &md) {
80  this->preprocessor->changeparameter(md);
81  };
90  void process();
93  mspass::seismic::CoreTimeSeries ideal_output() {
94  return this->preprocessor->ideal_output();
95  };
97  return this->preprocessor->actual_output();
98  };
100  return this->preprocessor->inverse_wavelet();
101  };
103  return this->preprocessor->inverse_wavelet(t0parent);
104  };
106 private:
107  /* These are data at different stages of process. d_all is the
108  largest signal window that is assumed to have been initialized by the
109  load method for this object. d_decon is the
110  result of apply the preprocessor (signal processing) deconvolution to
111  all three components. d_decon is computed from d, which is a windowed
112  version of the input data received by the load method. It have a
113  time duration less than or at least equal to that of d_all.
114  r is the residual, which is accumulated during the iterative method.
115  The time duraction of r is the same as d. It is initalized by
116  convolving the inverse filter with d_all.
117  n is the noise data. It should normally be at least as long a d_all*/
118  mspass::seismic::CoreSeismogram d_all,d_decon,r,n;
119  /* We save the set of data lengths for clarity and a minor bit efficiency.
120  ndwin is the number of samples in d_all and r.
121  nnwin is the number of samples in n.
122  nfft is the size of d_decon */
123  int ndwin, nnwin,nfft;
124  /* this is the time shift in sample applied by preprocessor*/
125  int time_shift;
126  /* Save the TimeWindow objects hat define the extent of d_all, d_decon,
127  and n. Some things need at least some of these downstream */
128  mspass::algorithms::TimeWindow dwin, nwin, fftwin;
131  int noise_component;
135  std::list<ThreeCSpike> spikes;
142  std::vector<double> lag_weights;
143  /* This vector contains the function time shifted and added to lag_weights
144  vector after each iteration. */
145  std::vector<double> wtf;
146  int nwtf; //size of wtf - cached because wtf is inside the deepest loop
147 
148  /* This is a pointer to the BasicDeconOperator class used for preprocessing
149  Classic use of inheritance to simplify the api. */
150  ScalarDecon *preprocessor;
151 
152  /* This defines a shaping wavelet applied to output. The inverse filter
153  preprocessing algorithm is assumed to have it's own embedded shaping wavelet.
154  i.e. this is the wavelet convolved with the output spike sequence. */
155  ShapingWavelet shapingwavelet;
156  /* This parameter is set in the constructor. It would normally be half the length
157  of the fir representation of the inverse wavelet. (winv_fir below)*/
158  int wavelet_pad;
167  std::vector<double> winv_fir, actual_o_fir;
168  int actual_o_0; //offset from sample zero for zero lag position
169  IterDeconType decon_type;
170  /* This is called by the constructor to create the wtf penalty function */
171  void construct_weight_penalty_function(const mspass::utility::Metadata& md);
177  void update_residual_matrix(ThreeCSpike spk);
184  void update_lag_weights(int col);
190  double compute_resid_linf_floor();
193  bool has_not_converged();
194  /* These are convergence attributes. lw_inf indicates Linf norm of
195  lag_weight array, lw_l2 is L2 metric of lag_weight, resid_inf is Linf
196  norm of residual vector, and resid_l2 is L2 of resid matrix. prev
197  modifier means the size of that quantity in the previous iteration. initial
198  means initial value at the top of the loop.*/
199  double lw_linf_initial, lw_linf_prev;
200  double lw_l2_initial, lw_l2_prev;
201  double resid_linf_initial, resid_linf_prev;
202  double resid_l2_initial, resid_l2_prev;
203  /* These are convergence paramwters for the different tests */
204  int iter_count, iter_max; // actual iteration count and ceiling to break loop
205  /*lw metrics are scaled with range of 0 to 1. l2 gets scaled by number of
206  points and so can use a similar absolute scale. */
207  double lw_linf_floor, lw_l2_floor;
208  /* We use a probability level to define the floor Linf of the residual
209  matrix. For L2 we use the conventional fractional improvment metric. */
210  double resid_linf_prob, resid_linf_floor;
211  double resid_l2_tol;
212 
213 
214  /* DEBUG attributes and methods. These should be deleted after testing. */
215  std::vector<double> lw_linf_history,lw_l2_history,resid_l2_history,resid_linf_history;
216  void print_convergence_history(std::ostream& ofs)
217  {
218  ofs << "lw_inf lw_l2 resid_l2, resid_linf"<<std::endl;
219  for(int i=0; i<iter_count; ++i)
220  {
221  if(i<lw_linf_history.size())
222  {
223  ofs<<lw_linf_history[i]<<" ";
224  }
225  else
226  {
227  ofs<<"xxxx " ;
228  }
229  if(i<lw_l2_history.size())
230  {
231  ofs<<lw_l2_history[i]<<" ";
232  }
233  else
234  {
235  ofs<<"xxxx " ;
236  }
237  if(i<resid_linf_history.size())
238  {
239  ofs<<resid_linf_history[i]<<" ";
240  }
241  else
242  {
243  ofs<<"xxxx " ;
244  }
245  if(i<resid_l2_history.size())
246  {
247  ofs<<resid_l2_history[i]<<" ";
248  }
249  else
250  {
251  ofs<<"xxxx " ;
252  }
253  ofs<<std::endl;
254  }
255  }
256 };
257 }
258 #endif
Defines a time window.
Definition: TimeWindow.h:14
Implements the Generalized Iterative Method of Wang and Pavlis.
Definition: GeneralIterDecon.h:68
mspass::seismic::CoreTimeSeries inverse_wavelet()
Return a FIR represention of the inverse filter.
Definition: GeneralIterDecon.h:99
mspass::seismic::CoreTimeSeries actual_output()
Definition: GeneralIterDecon.h:96
GeneralIterDecon(mspass::utility::AntelopePf &md)
Create an initialize an operator for subseqquent processing.
Definition: GeneralIterDecon.cc:55
mspass::utility::Metadata QCMetrics()
Return appropriate quality measures.
Definition: GeneralIterDecon.cc:736
Base class decon operator for single station 3C decon (receiver functions).
Definition: ScalarDecon.h:24
virtual mspass::seismic::CoreTimeSeries inverse_wavelet()=0
Return a FIR represention of the inverse filter.
virtual mspass::seismic::CoreTimeSeries actual_output()=0
Definition: GeneralIterDecon.h:21
double amp
Definition: GeneralIterDecon.h:29
double u[3]
Definition: GeneralIterDecon.h:27
ThreeCSpike & operator=(const ThreeCSpike &parent)
Definition: ThreeCSpike.cc:27
int col
Definition: GeneralIterDecon.h:25
Vector (three-component) seismogram data object.
Definition: CoreSeismogram.h:40
Scalar time series data object.
Definition: CoreTimeSeries.h:18
C++ object version of a parameter file.
Definition: AntelopePf.h:62
Definition: Metadata.h:76
Lightweight, simple matrix object.
Definition: dmatrix.h:102