version  0.0.1
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
Public Member Functions | List of all members
mspass::algorithms::deconvolution::LeastSquareDecon Class Reference
Inheritance diagram for mspass::algorithms::deconvolution::LeastSquareDecon:
mspass::algorithms::deconvolution::FFTDeconOperator mspass::algorithms::deconvolution::ScalarDecon mspass::algorithms::deconvolution::BasicDeconOperator

Public Member Functions

 LeastSquareDecon (const LeastSquareDecon &parent)
 
 LeastSquareDecon (const mspass::utility::Metadata &md)
 
 LeastSquareDecon (const mspass::utility::Metadata &md, const std::vector< double > &wavelet, const std::vector< double > &data)
 
void changeparameter (const mspass::utility::Metadata &md)
 
void process ()
 
mspass::seismic::CoreTimeSeries actual_output ()
 Return the actual output of the deconvolution operator.
 
mspass::seismic::CoreTimeSeries inverse_wavelet (const double t0parent=0.0)
 Return a FIR respresentation of the inverse filter.
 
mspass::seismic::CoreTimeSeries inverse_wavelet ()
 Return default FIR represesentation of the inverse filter.
 
mspass::utility::Metadata QCMetrics ()
 Return appropriate quality measures.
 
- Public Member Functions inherited from mspass::algorithms::deconvolution::FFTDeconOperator
 FFTDeconOperator (const mspass::utility::Metadata &md)
 
 FFTDeconOperator (const FFTDeconOperator &parent)
 
FFTDeconOperatoroperator= (const FFTDeconOperator &parent)
 
void changeparameter (const mspass::utility::Metadata &md)
 
void change_size (const int nfft_new)
 
void change_shift (const int shift)
 
int get_size ()
 
int get_shift ()
 
int operator_size ()
 
int operator_shift ()
 
double df (const double dt)
 
mspass::seismic::CoreTimeSeries FourierInverse (const ComplexArray &winv, const ComplexArray &sw, const double dt, const double t0parent)
 Return inverse wavelet for Fourier methods.
 
- Public Member Functions inherited from mspass::algorithms::deconvolution::ScalarDecon
 ScalarDecon (const mspass::utility::Metadata &md)
 
 ScalarDecon (const std::vector< double > &d, const std::vector< double > &w)
 
 ScalarDecon (const ScalarDecon &parent)
 
int load (const std::vector< double > &wavelet, const std::vector< double > &data)
 Load all data required for decon.
 
int loaddata (const std::vector< double > &data)
 
int loadwavelet (const std::vector< double > &wavelet)
 
ScalarDeconoperator= (const ScalarDecon &parent)
 
std::vector< double > getresult ()
 
void changeparameter (const mspass::utility::Metadata &md)
 
void change_shaping_wavelet (const ShapingWavelet &nsw)
 
ShapingWavelet get_shaping_wavelet () const
 
mspass::seismic::CoreTimeSeries ideal_output ()
 

Additional Inherited Members

- Protected Attributes inherited from mspass::algorithms::deconvolution::FFTDeconOperator
int nfft
 
int sample_shift
 
gsl_fft_complex_wavetable * wavetable
 
gsl_fft_complex_workspace * workspace
 
ComplexArray winv
 
- Protected Attributes inherited from mspass::algorithms::deconvolution::ScalarDecon
std::vector< double > data
 
std::vector< double > wavelet
 
std::vector< double > result
 
ShapingWavelet shapingwavelet
 

Constructor & Destructor Documentation

◆ LeastSquareDecon() [1/3]

mspass::algorithms::deconvolution::LeastSquareDecon::LeastSquareDecon ( )
inline
15: FFTDeconOperator(), ScalarDecon() { damp = 1.0; };

◆ LeastSquareDecon() [2/3]

mspass::algorithms::deconvolution::LeastSquareDecon::LeastSquareDecon ( const LeastSquareDecon parent)
12 : FFTDeconOperator(parent), ScalarDecon(parent) {
13 damp = parent.damp;
14}

◆ LeastSquareDecon() [3/3]

mspass::algorithms::deconvolution::LeastSquareDecon::LeastSquareDecon ( const mspass::utility::Metadata md)
34 : FFTDeconOperator(md) {
35 try {
36 this->read_metadata(md);
37 } catch (...) {
38 throw;
39 }
40}

Member Function Documentation

◆ actual_output()

CoreTimeSeries mspass::algorithms::deconvolution::LeastSquareDecon::actual_output ( )
virtual

Return the actual output of the deconvolution operator.

The actual output is defined as w^-1*w and is compable to resolution kernels in linear inverse theory. Although not required we would normally expect this function to be peaked at 0. Offsets from 0 would imply a bias.

Implements mspass::algorithms::deconvolution::ScalarDecon.

121 {
122 try {
123 ComplexArray W(nfft, &(wavelet[0]));
124 gsl_fft_complex_forward(W.ptr(), 1, nfft, wavetable, workspace);
125 ComplexArray ao_fft;
126 ao_fft = winv * W;
127 /* We always apply the shaping wavelet - this perhaps should be optional
128 but probably better done with a none option for the shaping wavelet */
129 ao_fft = (*shapingwavelet.wavelet()) * ao_fft;
130 gsl_fft_complex_inverse(ao_fft.ptr(), 1, nfft, wavetable, workspace);
131 vector<double> ao;
132 ao.reserve(nfft);
133 for (int k = 0; k < ao_fft.size(); ++k)
134 ao.push_back(ao_fft[k].real());
135 /* We always shift this wavelet to the center of the data vector.
136 We handle the time through the CoreTimeSeries object. */
137 int i0 = nfft / 2;
138 ao = circular_shift(ao, i0);
139 CoreTimeSeries result(nfft);
140 /* Getting dt from here is unquestionably a flaw in the api, but will
141 retain for now. Perhaps should a copy of dt in the ScalarDecon object. */
142 double dt = this->shapingwavelet.sample_interval();
143
144 result.set_t0(-dt * ((double)i0));
145 result.set_dt(dt);
146 result.set_live();
147 result.set_npts(nfft);
148 result.set_tref(TimeReferenceType::Relative);
149 for (int k = 0; k < nfft; ++k)
150 result.s[k] = ao[k];
151 result.s = normalize<double>(result.s);
152 return result;
153 } catch (...) {
154 throw;
155 };
156}
ComplexArray * wavelet()
Definition ShapingWavelet.h:75

References mspass::seismic::CoreTimeSeries::s, mspass::seismic::CoreTimeSeries::set_dt(), mspass::seismic::BasicTimeSeries::set_live(), mspass::seismic::CoreTimeSeries::set_npts(), mspass::seismic::CoreTimeSeries::set_t0(), and mspass::seismic::BasicTimeSeries::set_tref().

◆ changeparameter()

void mspass::algorithms::deconvolution::LeastSquareDecon::changeparameter ( const mspass::utility::Metadata md)
virtual

Implements mspass::algorithms::deconvolution::BasicDeconOperator.

42 {
43 try {
44 this->read_metadata(md);
45 } catch (...) {
46 throw;
47 };
48}

◆ inverse_wavelet() [1/2]

CoreTimeSeries mspass::algorithms::deconvolution::LeastSquareDecon::inverse_wavelet ( )
virtual

Return default FIR represesentation of the inverse filter.

This is an overloaded version of the parameterized method. It is equivalent to this->inverse_wavelet(0.0,0.0);

Implements mspass::algorithms::deconvolution::ScalarDecon.

171 {
172 try {
173 return this->inverse_wavelet(0.0);
174 } catch (...) {
175 throw;
176 };
177}
mspass::seismic::CoreTimeSeries inverse_wavelet()
Return default FIR represesentation of the inverse filter.
Definition LeastSquareDecon.cc:171

◆ inverse_wavelet() [2/2]

CoreTimeSeries mspass::algorithms::deconvolution::LeastSquareDecon::inverse_wavelet ( const double  t0parent = 0.0)
virtual

Return a FIR respresentation of the inverse filter.

An inverse filter has an impulse response. For some wavelets this can be respresented by a FIR filter with finite numbers of coefficients. Since this is a Fourier method the best we can do is return the inverse fft of the regularized operator. The output usually needs to be phase shifted to be most useful. For typical seismic source wavelets that are approximately minimum phase the shift can be small, but for zero phase input it should be approximately half the window size. This method also has an optional argument for t0parent. Because this processor was written to be agnostic about a time standard it implicitly assumes time 0 is sample 0 of the input waveforms. If the original data have a nonzero start time this should be passed as t0parent or the output will contain a time shift of t0parent. Note that tshift and t0parent do very different things. tshift is used to apply circular phase shift to the output (e.g. a shift of 10 samples causes the last 10 samples in the wavelet to be wrapped to the first 10 samples). t0parent only changes the time standard so the output has t0 -= parent.t0.

The returned wavelet is always time shifted by nfft/2.

Parameters
t0parent- time zero of parent seismograms (see above).

Implements mspass::algorithms::deconvolution::ScalarDecon.

158 {
159 try {
160 /* Getting dt from here is unquestionably a flaw in the api, but will
161 * retain for now. Perhaps should a copy of dt in the ScalarDecon
162 * object. */
163 double dt = this->shapingwavelet.sample_interval();
164 return (this->FourierInverse(this->winv, *shapingwavelet.wavelet(), dt,
165 t0parent));
166 } catch (...) {
167 throw;
168 };
169}
mspass::seismic::CoreTimeSeries FourierInverse(const ComplexArray &winv, const ComplexArray &sw, const double dt, const double t0parent)
Return inverse wavelet for Fourier methods.
Definition FFTDeconOperator.cc:115

◆ process()

void mspass::algorithms::deconvolution::LeastSquareDecon::process ( )
virtual

Implements mspass::algorithms::deconvolution::ScalarDecon.

59 {
60
61 const string base_error("LeastSquareDecon::process: ");
62 // apply fft to the input trace data
63 if (data.size() < nfft)
64 for (int i = data.size(); i < nfft; ++i)
65 data.push_back(0.0);
66 ComplexArray d_fft(nfft, &(data[0]));
67 gsl_fft_complex_forward(d_fft.ptr(), 1, nfft, wavetable, workspace);
68
69 // apply fft to wavelet
70 if (wavelet.size() < nfft)
71 for (int i = wavelet.size(); i < nfft; ++i)
72 wavelet.push_back(0.0);
73 ComplexArray b_fft(nfft, &(wavelet[0]));
74 gsl_fft_complex_forward(b_fft.ptr(), 1, nfft, wavetable, workspace);
75
76 // deconvolution: RF=conj(B).*D./(conj(B).*B+damp)
77 b_fft.conj();
78 ComplexArray rf_fft, conj_b_fft(b_fft);
79 b_fft.conj();
80
81 double b_rms = b_fft.rms();
82 ComplexArray denom(conj_b_fft * b_fft);
83 double theta(b_rms * damp);
84 /* This is like normal equation form for damped inverse so theta as computed
85 needs to be squared */
86 theta = theta * theta;
87 for (int k = 0; k < nfft; ++k) {
88 double *ptr;
89 ptr = denom.ptr(k);
90 /* ptr points to the real part - an oddity of this interface */
91 *ptr += theta;
92 }
93 rf_fft = (conj_b_fft * d_fft) / denom;
94 // rf_fft=(conj_b_fft*d_fft)/(conj_b_fft*b_fft+b_rms*damp);
95 /* Compute the frequency domain version of the inverse wavelet now
96 and save it the object for efficiency. */
97 // winv=conj_b_fft/(conj_b_fft*b_fft+b_rms*damp);
98 winv = conj_b_fft / denom;
99
100 // apply shaping wavelet but only to rf estimate - actual output and
101 // inverse_wavelet methods apply it to when needed there for efficiency
102 ShapingWavelet sw(this->get_shaping_wavelet());
103 rf_fft = (*sw.wavelet()) * rf_fft;
104
105 // ifft gets result
106 gsl_fft_complex_inverse(rf_fft.ptr(), 1, nfft, wavetable, workspace);
107 if (sample_shift > 0) {
108 for (int k = sample_shift; k > 0; k--)
109 result.push_back(rf_fft[nfft - k].real());
110 for (int k = 0; k < data.size() - sample_shift; k++)
111 result.push_back(rf_fft[k].real());
112 } else if (sample_shift == 0) {
113 for (int k = 0; k < data.size(); k++)
114 result.push_back(rf_fft[k].real());
115 } else {
116 throw MsPASSError(base_error + "Coding error - trying to use an illegal "
117 "negative time shift parameter",
118 ErrorSeverity::Fatal);
119 }
120}
ShapingWavelet get_shaping_wavelet() const
Definition ScalarDecon.h:65

◆ QCMetrics()

Metadata mspass::algorithms::deconvolution::LeastSquareDecon::QCMetrics ( )
virtual

Return appropriate quality measures.

Each operator commonly has different was to measure the quality of the result. This method should return these in a generic Metadata object.

Implements mspass::algorithms::deconvolution::ScalarDecon.

178 {
179 /* Return only an empty Metadata container. Done as it is
180 easier to maintain the code letting python do this work.
181 This also anticipates new metrics being added which would be
182 easier in python.*/
183 Metadata md;
184 return md;
185}

The documentation for this class was generated from the following files: