version  0.0.1
Defines the C++ API for MsPASS
CNR3CDecon.h
1 #ifndef __CNR3C_DECON_H__
2 #define __CNR3C_DECON_H__
3 #include <vector>
4 #include <math.h>
5 #include "mspass/utility/AntelopePf.h"
6 #include "mspass/algorithms/deconvolution/FFTDeconOperator.h"
7 #include "mspass/algorithms/deconvolution/ShapingWavelet.h"
8 #include "mspass/algorithms/deconvolution/MTPowerSpectrumEngine.h"
9 #include "mspass/algorithms/amplitudes.h"
10 #include "mspass/algorithms/Taper.h"
11 #include "mspass/algorithms/TimeWindow.h"
12 #include "mspass/seismic/PowerSpectrum.h"
13 #include "mspass/seismic/TimeSeries.h"
14 #include "mspass/seismic/Seismogram.h"
15 namespace mspass::algorithms::deconvolution{
16 
20 {
21 public:
22  virtual ~Base3CDecon() {};
23  /*
24  virtual void change_parameters(const mspass::BasicMetadata &md)=0;
25  virtual void loaddata(mspass::Seismogram& d,const int comp)=0;
26  virtual void loadwavelet(const mspass::TimeSeries& w)=0;
27  */
28  /* \brief Return the ideal output of the deconvolution operator.
29 
30  All deconvolution operators have a implicit or explicit ideal output
31  signal. e.g. for a spiking Wiener filter it is a delta function with or
32  without a lag. For a shaping wavelt it is the time domain version of the
33  wavelet. */
34  virtual mspass::seismic::Seismogram process()=0;
42 
47  //virtual mspass::TimeSeries inverse_wavelet() = 0;
54 };
55 /* This enum is used internally to define the algorithm the processor is to run.
56 I (glp) chose that approach over the inheritance approach used in the scalar
57 methods as an artistic choice. It is a matter of opinion which approach
58 is better. This makes one symbol do multiple things with changes done in
59 the parameter setup as opposed to having to select the right symbolic name
60 to construct. The main difference is it avoids the messy trampoline class
61 needed with pybind11 to create wrappers for the python bindings.
62 This enum will not be exposed to python as it is totally internal to the
63 CNR3CDecon class.
64 */
65 enum class CNR3C_algorithms{
66  generalized_water_level,
67  colored_noise_damping,
68  undefined
69 };
96 //class CNR3CDecon : public mspass::FFTDeconOperator
97 class CNR3CDecon : public Base3CDecon, public FFTDeconOperator
98 {
99 public:
101  CNR3CDecon();
112  CNR3CDecon(const CNR3CDecon& parent);
114  ~CNR3CDecon();
115  CNR3CDecon& operator=(const CNR3CDecon& parent);
147  void loaddata(mspass::seismic::Seismogram& d, const int wcomp,const bool loadnoise=false);
162  void loaddata(mspass::seismic::Seismogram& d, const bool loadnoise=false);
234  /* These same names are used in ScalarDecon but we don't inherit them
235  here because this algorithm is 3C data centric there is a collision
236  with the ScalarDecon api because of it. */
237  mspass::seismic::Seismogram process();
238 
239  /* \brief Return the ideal output of the deconvolution operator.
240 
241  All deconvolution operators have a implicit or explicit ideal output
242  signal. e.g. for a spiking Wiener filter it is a delta function with or
243  without a lag. For a shaping wavelt it is the time domain version of the
244  wavelet. */
245  mspass::seismic::TimeSeries ideal_output();
253 
276  {
277  return psnoise;
278  };
281  {
282  return psnoise_data;
283  };
286  {
287  return pswavelet;
288  };
291  {
292  return pssignal;
293  };
294 private:
295  CNR3C_algorithms algorithm;
296  bool taper_data; //Set false only if none specified
297  double operator_dt; // Data must match this sample interval
298  /* Expected time window size in samples
299  (computed from processing_window and operator dt)*/
300  int winlength;
301  double decon_bandwidth_cutoff;
302  /* Added Dec 2021 - this defines the upper starting frequency used for
303  the EstimateBandwith function. */
304  double fhs;
305  /* Defines relative time time window - ignored if length of input is
306  consistent with number of samples expected in this window */
307  mspass::algorithms::TimeWindow processing_window;
308  mspass::algorithms::TimeWindow noise_window;
311  MTPowerSpectrumEngine signalengine,waveletengine;
312  MTPowerSpectrumEngine dnoise_engine, wnoise_engine;
313  ShapingWavelet shapingwavelet;
314  /* This contains the noise power spectrum to use for regularization
315  of the inverse. It should normally be created from a longer window
316  than the data.
317  */
319  /* This contains the power spectrum of the data used to estimate
320  snr-based QC estimates. It can be the same as the data but
321  not necessarily.
322  */
323  mspass::seismic::PowerSpectrum psnoise_data;
324  /* Because of the design of the algorithm we also have to save a power
325  spectral estimate for the wavelet and data signals. We use those when
326  automatic bandwidth adjustment is enabled.*/
329  /* Cached data to be deconvolved - result of loaddata methds*/
330  mspass::seismic::Seismogram decondata;
331  /* Cached wavelet for deconvolution - result of loadwavelet*/
333  /* As the name suggest we allow different tapers for data and wavelet */
334  std::shared_ptr<mspass::algorithms::BasicTaper> wavelet_taper;
335  std::shared_ptr<mspass::algorithms::BasicTaper> data_taper;
336  /* For the colored noise damping algorithm the damper is frequency dependent.
337  The same issue in water level that requires a floor on the water level
338  applies to damping. We use noise_floor to create a lower bound on
339  damper values. Note the damping constant at each frequency is
340  damp*noise except where noise is below noise_floor defined relative to
341  maximum noise value where it is set to n_peak*noise_floor*damp. */
342  double damp, noise_floor;
343  /* This algorithm uses a mix of damping and water level. Above this floor,
344  which acts a bit like a water level, no regularization is done. If
345  snr is less than this value we regularize with damp*noise_amplitude.
346  Note the noise_floor parameter puts a lower bound on the frequency dependent
347  regularization. If noise amplitude (not power) is less than noise_floor
348  the floor is set like a water level as noise_max*noise_level.*/
349  double snr_regularization_floor;
350  /* this parameter does a similar thing to regularization floor but is
351  by the bandwidth estimation algorithm to define the edge of the working
352  frequency band. */
353  double snr_bandwidth;
354  //ComplexArray winv;
355  /* winv is in FFTDeconOperator*/
356  ComplexArray ao_fft;
359  /* We cache wavelet snr time series as it is more efficiently computed during
360  the process routine and then used in (optional) qc methods */
361  std::vector<double> wavelet_snr;
362  /* SNR bandbwidth estimates count frequencies with snr above this value */
363  double band_snr_floor;
364  /* This array stores snr band fractions for each component.*/
365  double signal_bandwidth_fraction[3];
366  double peak_snr[3];
367  double regularization_bandwidth_fraction;
368  void read_parameters(const mspass::utility::AntelopePf& pf);
369  int TestSeismogramInput(mspass::seismic::Seismogram& d,const int comp,const bool loaddata);
370  void compute_gwl_inverse();
371  void compute_gdamp_inverse();
373  void update_shaping_wavelet(const mspass::algorithms::amplitudes::BandwidthData& bwd);
374 };
375 } // End namespace
376 
377 #endif
Defines a time window.
Definition: TimeWindow.h:14
Holds parameters defining a passband computed from snr.
Definition: amplitudes.h:275
Absract base class for algorithms handling full 3C data.
Definition: CNR3CDecon.h:20
virtual mspass::utility::Metadata QCMetrics()=0
Return appropriate quality measures.
virtual mspass::seismic::TimeSeries inverse_wavelet(double)=0
Return a FIR represention of the inverse filter.
virtual mspass::seismic::TimeSeries actual_output()=0
Colored Noise Regularized 3C Deconvolution opertor.
Definition: CNR3CDecon.h:98
~CNR3CDecon()
Definition: CNR3CDecon.cc:304
mspass::seismic::TimeSeries actual_output()
Definition: CNR3CDecon.cc:918
mspass::seismic::PowerSpectrum data_spectrum()
Definition: CNR3CDecon.h:290
mspass::seismic::TimeSeries inverse_wavelet(double tshift)
Return a FIR represention of the inverse filter.
Definition: CNR3CDecon.cc:955
mspass::utility::Metadata QCMetrics()
Return appropriate quality measures.
Definition: CNR3CDecon.cc:979
mspass::seismic::PowerSpectrum data_noise_spectrum()
Definition: CNR3CDecon.h:280
void loadnoise_wavelet(const mspass::seismic::TimeSeries &n)
Load noise data for wavelet directly.
Definition: CNR3CDecon.cc:577
mspass::seismic::PowerSpectrum wavelet_spectrum()
Definition: CNR3CDecon.h:285
void loaddata(mspass::seismic::Seismogram &d, const int wcomp, const bool loadnoise=false)
Load data with one component used as wavelet estimate.
Definition: CNR3CDecon.cc:374
void loadwavelet(const mspass::seismic::TimeSeries &w)
Load data defining the wavelet to use for deconvolution.
Definition: CNR3CDecon.cc:471
void loadnoise_data(const mspass::seismic::Seismogram &n)
Load noise data directly.
Definition: CNR3CDecon.cc:562
void change_parameters(const mspass::utility::BasicMetadata &md)
Change the setup of the operator on the fly.
Definition: CNR3CDecon.cc:60
mspass::seismic::PowerSpectrum wavelet_noise_spectrum()
Definition: CNR3CDecon.h:275
CNR3CDecon()
Definition: CNR3CDecon.cc:30
Object to hold components needed in all fft based decon algorithms.
Definition: FFTDeconOperator.h:19
Multittaper power spectral estimator.
Definition: MTPowerSpectrumEngine.h:28
Frequency domain shaping wavelet.
Definition: ShapingWavelet.h:19
Definition: PowerSpectrum.h:13
Implemntation of Seismogram for MsPASS.
Definition: Seismogram.h:15
Implemntation of TimeSeries for MsPASS.
Definition: TimeSeries.h:15
C++ object version of a parameter file.
Definition: AntelopePf.h:62
Abstract base class for Metadata concept.
Definition: BasicMetadata.h:15
Definition: Metadata.h:76