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