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

Public Member Functions

 WaterLevelDecon (const WaterLevelDecon &parent)
 
 WaterLevelDecon (const mspass::utility::Metadata &md)
 
 WaterLevelDecon (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 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

◆ WaterLevelDecon() [1/3]

mspass::algorithms::deconvolution::WaterLevelDecon::WaterLevelDecon ( )
inline
15 : FFTDeconOperator(), ScalarDecon() {
16 this->wlv = 0.1;
17 this->regularization_fraction = 0.0;
18 };

◆ WaterLevelDecon() [2/3]

mspass::algorithms::deconvolution::WaterLevelDecon::WaterLevelDecon ( const WaterLevelDecon parent)
11 : FFTDeconOperator(parent), ScalarDecon(parent) {
12 wlv = parent.wlv;
13}

◆ WaterLevelDecon() [3/3]

mspass::algorithms::deconvolution::WaterLevelDecon::WaterLevelDecon ( const mspass::utility::Metadata md)
31 : FFTDeconOperator(md) {
32 try {
33 this->read_metadata(md);
34 } catch (...) {
35 throw;
36 }
37}

Member Function Documentation

◆ actual_output()

CoreTimeSeries mspass::algorithms::deconvolution::WaterLevelDecon::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.

130 {
131 try {
132 ComplexArray W(nfft, &(wavelet[0]));
133 gsl_fft_complex_forward(W.ptr(), 1, nfft, wavetable, workspace);
134 ComplexArray ao_fft;
135 ao_fft = winv * W;
136 /* We always apply the shaping wavelet - this perhaps should be optional
137 but probably better done with a none option for the shaping wavelet */
138 ao_fft = (*shapingwavelet.wavelet()) * ao_fft;
139 gsl_fft_complex_inverse(ao_fft.ptr(), 1, nfft, wavetable, workspace);
140 vector<double> ao;
141 ao.reserve(nfft);
142 for (unsigned int k = 0; k < ao_fft.size(); ++k)
143 ao.push_back(ao_fft[k].real());
144 /* We always shift this wavelet to the center of the data vector.
145 We handle the time through the CoreTimeSeries object. */
146 int i0 = nfft / 2;
147 ao = circular_shift(ao, i0);
148 ao = normalize<double>(ao);
149 CoreTimeSeries result(nfft);
150 /* Getting dt from here is unquestionably a flaw in the api, but will
151 retain for now. Perhaps should a copy of dt in the ScalarDecon object. */
152 double dt = this->shapingwavelet.sample_interval();
153 result.set_t0(-dt * ((double)i0));
154 result.set_dt(dt);
155 result.set_live();
156 result.set_tref(TimeReferenceType::Relative);
157 result.set_npts(nfft);
158 for (int k = 0; k < nfft; ++k)
159 result.s[k] = ao[k];
160 ;
161 return result;
162 } catch (...) {
163 throw;
164 };
165}
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::WaterLevelDecon::changeparameter ( const mspass::utility::Metadata md)
virtual

Reimplemented from mspass::algorithms::deconvolution::ScalarDecon.

39 {
40 try {
41 this->read_metadata(md);
42 } catch (...) {
43 throw;
44 };
45}

◆ inverse_wavelet() [1/2]

CoreTimeSeries mspass::algorithms::deconvolution::WaterLevelDecon::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.

179 {
180 try {
181 return this->inverse_wavelet(0.0);
182 } catch (...) {
183 throw;
184 };
185}
mspass::seismic::CoreTimeSeries inverse_wavelet()
Return default FIR represesentation of the inverse filter.
Definition WaterLevelDecon.cc:179

◆ inverse_wavelet() [2/2]

CoreTimeSeries mspass::algorithms::deconvolution::WaterLevelDecon::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.

Output wavelet is always circular shifted with 0 lag at center.

Parameters
t0parent- time zero of parent seismograms (see above).
Exceptions
SeisppErroris thrown if the tshift value is more than half the length of the data (nfft*dt). Reason is justified above.

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

167 {
168 try {
169 /* Getting dt from here is unquestionably a flaw in the api, but will
170 * retain for now. Perhaps should a copy of dt in the ScalarDecon
171 * object. */
172 double dt = this->shapingwavelet.sample_interval();
174 this->winv, *shapingwavelet.wavelet(), dt, t0parent));
175 } catch (...) {
176 throw;
177 };
178}
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::WaterLevelDecon::process ( )
virtual

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

56 {
57
58 // apply fft to the input trace data
59 // data and wavelet sizes need to be zero padded if the are short
60 if (data.size() < nfft)
61 for (int i = data.size(); i < nfft; ++i)
62 data.push_back(0.0);
63 ComplexArray d_fft(nfft, &(data[0]));
64 gsl_fft_complex_forward(d_fft.ptr(), 1, nfft, wavetable, workspace);
65
66 // apply fft to wavelet
67 if (wavelet.size() < nfft)
68 for (int i = wavelet.size(); i < nfft; ++i)
69 wavelet.push_back(0.0);
70 ComplexArray b_fft(nfft, &(wavelet[0]));
71 gsl_fft_complex_forward(b_fft.ptr(), 1, nfft, wavetable, workspace);
72
73 double b_rms = b_fft.rms();
74 if (b_rms == 0.0)
75 throw MsPASSError(
76 "WaterLevelDecon::process(): wavelet data vector is all zeros");
77
78 // water level - count the number of points below water level
79 int nunderwater(0);
80 for (int i = 0; i < nfft; i++) {
81 /* We have to avoid hard zeros because the formula below will
82 * yield an NaN when that happens from 0/0 */
83 double bamp;
84 bamp = abs(b_fft[i]);
85 /*WARNING: this is dependent on implementation detail of ComplexArray
86 that defines the data as a FortranComplex64 - real,imag pairs. */
87 if (bamp < b_rms * wlv) {
88 /* Use 64 bit epsilon as the floor for defining a pure zero */
89 if (bamp / b_rms < DBL_EPSILON) {
90 *b_fft.ptr(i) = b_rms * wlv;
91 *(b_fft.ptr(i) + 1) = b_rms * wlv;
92 } else {
93 // real part
94 *b_fft.ptr(i) = (*b_fft.ptr(i) / abs(b_fft[i])) * b_rms * wlv;
95 // imag part
96 *(b_fft.ptr(i) + 1) =
97 (*(b_fft.ptr(i) + 1) / abs(b_fft[i])) * b_rms * wlv;
98 }
99 ++nunderwater;
100 }
101 }
102 regularization_fraction = ((double)nunderwater) / ((double)nfft);
103 ComplexArray rf_fft;
104 rf_fft = d_fft / b_fft;
105 /* Make numerator for inverse from zero lag spike */
106 double *d0 = new double[nfft];
107 for (int k = 0; k < nfft; ++k)
108 d0[k] = 0.0;
109 d0[0] = 1.0;
110 ComplexArray delta0(nfft, d0);
111 delete[] d0;
112 gsl_fft_complex_forward(delta0.ptr(), 1, nfft, wavetable, workspace);
113 winv = delta0 / b_fft;
114
115 // apply shaping wavelet to rf estimate
116 rf_fft = (*shapingwavelet.wavelet()) * rf_fft;
117
118 // ifft gets result
119 gsl_fft_complex_inverse(rf_fft.ptr(), 1, nfft, wavetable, workspace);
120 if (sample_shift > 0) {
121 for (int k = sample_shift; k > 0; k--)
122 result.push_back(rf_fft[nfft - k].real());
123 for (unsigned int k = 0; k < data.size() - sample_shift; k++)
124 result.push_back(rf_fft[k].real());
125 } else {
126 for (unsigned int k = 0; k < data.size(); k++)
127 result.push_back(rf_fft[k].real());
128 }
129}

◆ QCMetrics()

Metadata mspass::algorithms::deconvolution::WaterLevelDecon::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.

186 {
187 /* Return only an empty Metadata container. Done as it is
188 easier to maintain the code letting python do this work.
189 This also anticipates new metrics being added which would be
190 easier in python.*/
191 Metadata md;
192 return md;
193}

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