MsPASS C++ API  2.4.1.dev4+g92330b7a
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 */
39
44 // virtual mspass::TimeSeries inverse_wavelet() = 0;
51};
52/* This enum is used internally to define the algorithm the processor is to run.
53I (glp) chose that approach over the inheritance approach used in the scalar
54methods as an artistic choice. It is a matter of opinion which approach
55is better. This makes one symbol do multiple things with changes done in
56the parameter setup as opposed to having to select the right symbolic name
57to construct. The main difference is it avoids the messy trampoline class
58needed with pybind11 to create wrappers for the python bindings.
59This enum will not be exposed to python as it is totally internal to the
60CNR3CDecon class.
61*/
62enum class CNR3C_algorithms {
63 generalized_water_level,
64 colored_noise_damping,
65 undefined
66};
93// class CNR3CDecon : public mspass::FFTDeconOperator
94class CNR3CDecon : public Base3CDecon, public FFTDeconOperator {
95public:
97 CNR3CDecon();
109 CNR3CDecon(const CNR3CDecon &parent);
111 ~CNR3CDecon();
113 CNR3CDecon &operator=(const CNR3CDecon &parent);
145 void loaddata(mspass::seismic::Seismogram &d, const int wcomp,
146 const bool loadnoise = false);
163 void loaddata(mspass::seismic::Seismogram &d, const bool loadnoise = false);
239 /* These same names are used in ScalarDecon but we don't inherit them
240 here because this algorithm is 3C data centric there is a collision
241 with the ScalarDecon api because of it. */
243
265
294
295private:
296 CNR3C_algorithms algorithm;
297 bool taper_data; // Set false only if none specified
298 double operator_dt; // Data must match this sample interval
299 /* Expected time window size in samples
300 (computed from processing_window and operator dt)*/
301 int winlength;
302 double decon_bandwidth_cutoff;
303 /* Added Dec 2021 - this defines the upper starting frequency used for
304 the EstimateBandwith function. */
305 double fhs;
306 /* Defines relative time time window - ignored if length of input is
307 consistent with number of samples expected in this window */
308 mspass::algorithms::TimeWindow processing_window;
312 MTPowerSpectrumEngine signalengine, waveletengine;
313 MTPowerSpectrumEngine dnoise_engine, wnoise_engine;
314 ShapingWavelet shapingwavelet;
315 /* This contains the noise power spectrum to use for regularization
316 of the inverse. It should normally be created from a longer window
317 than the data.
318 */
320 /* This contains the power spectrum of the data used to estimate
321 snr-based QC estimates. It can be the same as the data but
322 not necessarily.
323 */
325 /* Because of the design of the algorithm we also have to save a power
326 spectral estimate for the wavelet and data signals. We use those when
327 automatic bandwidth adjustment is enabled.*/
330 /* Cached data to be deconvolved - result of loaddata methds*/
332 /* Cached wavelet for deconvolution - result of loadwavelet*/
334 /* As the name suggest we allow different tapers for data and wavelet */
335 std::shared_ptr<mspass::algorithms::BasicTaper> wavelet_taper;
336 std::shared_ptr<mspass::algorithms::BasicTaper> data_taper;
337 /* For the colored noise damping algorithm the damper is frequency dependent.
338 The same issue in water level that requires a floor on the water level
339 applies to damping. We use noise_floor to create a lower bound on
340 damper values. Note the damping constant at each frequency is
341 damp*noise except where noise is below noise_floor defined relative to
342 maximum noise value where it is set to n_peak*noise_floor*damp. */
343 double damp, noise_floor;
344 /* This algorithm uses a mix of damping and water level. Above this floor,
345 which acts a bit like a water level, no regularization is done. If
346 snr is less than this value we regularize with damp*noise_amplitude.
347 Note the noise_floor parameter puts a lower bound on the frequency dependent
348 regularization. If noise amplitude (not power) is less than noise_floor
349 the floor is set like a water level as noise_max*noise_level.*/
350 double snr_regularization_floor;
351 /* this parameter does a similar thing to regularization floor but is
352 by the bandwidth estimation algorithm to define the edge of the working
353 frequency band. */
354 double snr_bandwidth;
355 // ComplexArray winv;
356 /* winv is in FFTDeconOperator*/
357 ComplexArray ao_fft;
360 /* We cache wavelet snr time series as it is more efficiently computed during
361 the process routine and then used in (optional) qc methods */
362 std::vector<double> wavelet_snr;
363 /* SNR bandbwidth estimates count frequencies with snr above this value */
364 double band_snr_floor;
365 /* This array stores snr band fractions for each component.*/
366 double signal_bandwidth_fraction[3];
367 double peak_snr[3];
368 double regularization_bandwidth_fraction;
369 void read_parameters(const mspass::utility::AntelopePf &pf);
370 int TestSeismogramInput(mspass::seismic::Seismogram &d, const int comp,
371 const bool loaddata);
372 void compute_gwl_inverse();
373 void compute_gdamp_inverse();
375 ThreeCPower(const mspass::seismic::Seismogram &d);
376 void update_shaping_wavelet(
378};
379} // namespace mspass::algorithms::deconvolution
380
381#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::seismic::Seismogram process()=0
Apply the loaded 3C deconvolution operator.
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
Return the actual output of the deconvolution operator.
Colored Noise Regularized 3C Deconvolution opertor.
Definition CNR3CDecon.h:94
mspass::seismic::TimeSeries output_shaping_wavelet()
Return the output shaping wavelet.
Definition CNR3CDecon.h:249
mspass::seismic::Seismogram process()
Apply the loaded 3C deconvolution operator.
Definition CNR3CDecon.cc:792
~CNR3CDecon()
Definition CNR3CDecon.cc:307
mspass::seismic::TimeSeries actual_output()
Return the actual output of the deconvolution operator.
Definition CNR3CDecon.cc:925
mspass::seismic::PowerSpectrum data_spectrum()
Definition CNR3CDecon.h:293
mspass::seismic::TimeSeries inverse_wavelet(double tshift)
Return a FIR represention of the inverse filter.
Definition CNR3CDecon.cc:966
mspass::utility::Metadata QCMetrics()
Return appropriate quality measures.
Definition CNR3CDecon.cc:989
mspass::seismic::TimeSeries resolution_kernel()
Alias for actual_output using inverse-theory terminology.
Definition CNR3CDecon.h:262
mspass::seismic::TimeSeries ideal_output()
Definition CNR3CDecon.cc:917
mspass::seismic::PowerSpectrum data_noise_spectrum()
Definition CNR3CDecon.h:289
void loadnoise_wavelet(const mspass::seismic::TimeSeries &n)
Load noise data for wavelet directly.
Definition CNR3CDecon.cc:595
mspass::seismic::PowerSpectrum wavelet_spectrum()
Definition CNR3CDecon.h:291
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:378
void loadwavelet(const mspass::seismic::TimeSeries &w)
Load data defining the wavelet to use for deconvolution.
Definition CNR3CDecon.cc:479
void loadnoise_data(const mspass::seismic::Seismogram &n)
Load noise data directly.
Definition CNR3CDecon.cc:576
CNR3CDecon & operator=(const CNR3CDecon &parent)
Definition CNR3CDecon.cc:266
void change_parameters(const mspass::utility::BasicMetadata &md)
Change the setup of the operator on the fly.
Definition CNR3CDecon.cc:71
mspass::seismic::PowerSpectrum wavelet_noise_spectrum()
Definition CNR3CDecon.h:287
CNR3CDecon()
Definition CNR3CDecon.cc:43
Interfacing object to ease conversion between FORTRAN and C++ complex.
Definition ComplexArray.h:41
Object to hold components needed in all fft based decon algorithms.
Definition FFTDeconOperator.h:21
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
Type-safe metadata container used throughout MsPASS.
Definition Metadata.h:101