MsPASS C++ API  2.4.4.dev113+gc53d735d5
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
CNRDeconEngine.h
1#ifndef __CNR_DECON_ENGINE_H__
2#define __CNR_DECON_ENGINE_H__
3#include <boost/archive/text_iarchive.hpp>
4#include <boost/archive/text_oarchive.hpp>
5#include <boost/serialization/base_object.hpp>
6#include <boost/serialization/shared_ptr.hpp>
7#include <boost/serialization/version.hpp>
8
9#include "mspass/algorithms/Taper.h"
10#include "mspass/algorithms/deconvolution/FFTDeconOperator.h"
11#include "mspass/algorithms/deconvolution/MTPowerSpectrumEngine.h"
12#include "mspass/algorithms/deconvolution/ShapingWavelet.h"
13#include "mspass/seismic/PowerSpectrum.h"
14#include "mspass/seismic/Seismogram.h"
15#include "mspass/seismic/TimeSeries.h"
16#include "mspass/utility/AntelopePf.h"
17
18namespace mspass::algorithms::deconvolution {
19/* This enum is file scope to intentionally exclude it from python wrappers.
20It is used internally to define the algorithm the processor is to run.
21I (glp) chose that approach over the inheritance approach used in the scalar
22methods as an artistic choice. It is a matter of opinion which approach
23is better. This makes one symbol do multiple things with changes done in
24the parameter setup as opposed to having to select the right symbolic name
25to construct. Anyway, this enum defines algorithms that can be chosen for
26processing.
27*/
28enum class CNR3C_algorithms { generalized_water_level, colored_noise_damping };
36public:
39 /* design note - delete when finished.
40
41 The constructor uses the pf to initialize operator properties.
42 Important in that is the multitaper engine that has a significant
43 initialization cost. the initialize_inverse_operator is a messy
44 way to define load data and then compute the inverse stored
45 internally. Doing it that way, however, allows the same code
46 to be used for both single station and array decon. In single
47 station use every datum has to call initiallize_inverse_operator
48 while with an array decon the operator is define once for an
49 ensemble and applied to all members. THE ASSUMPTION is all the
50 grungy work to assure all that gets done correction is handled
51 in python.
52 */
72 CNRDeconEngine(const CNRDeconEngine &parent);
76 void
78 const mspass::seismic::TimeSeries &noise_data);
87 const mspass::seismic::TimeSeries &wavelet,
88 const mspass::seismic::PowerSpectrum &noise_spectrum);
90 virtual ~CNRDeconEngine() {};
94 const mspass::seismic::PowerSpectrum &psnoise, const double fl,
95 const double fh);
103 const mspass::seismic::PowerSpectrum &psnoise);
105 double get_operator_dt() const { return this->operator_dt; }
140 return this->actual_output(wavelet);
141 }
145 const double t0shift);
150
151private:
152 CNR3C_algorithms algorithm;
153 /* For the colored noise damping algorithm the damper is frequency dependent.
154 The same issue in water level that requires a floor on the water level
155 applies to damping. We use noise_floor to create a lower bound on
156 damper values. Note the damping constant at each frequency is
157 damp*noise except where noise is below noise_floor defined relative to
158 maximum noise value where it is set to n_peak*noise_floor*damp. */
159 double damp;
160 double noise_floor;
161 /* SNR bandbwidth estimates count frequencies with snr above this value */
162 double band_snr_floor;
163 double operator_dt; // Data must match this sample interval
164 int shaping_wavelet_number_poles;
166 /* PF-defined shaping state. Legacy process(d,psnoise,fl,fh) may replace
167 * shapingwavelet for one call, but configured processing restores this. */
169 /* Expected time window size in samples. When signal lengths
170 match this value the slepian tapers are not recomputed. When there
171 is a mismatch it will change. That means this can change dynamically
172 when run on multiple data objects. */
173 int winlength;
176
177 /* This algorithm uses a mix of damping and water level. Above this floor,
178 which acts a bit like a water level, no regularization is done. If
179 snr is less than this value we regularize with damp*noise_amplitude.
180 Note the noise_floor parameter puts a lower bound on the frequency dependent
181 regularization. If noise amplitude (not power) is less than noise_floor
182 the floor is set like a water level as noise_max*noise_level.*/
183 double snr_regularization_floor;
184 /* These are QC metrics computed by process method. Saved to allow them
185 to be use in QCmetrics method. */
186 double regularization_bandwidth_fraction;
187 double peak_snr[3];
188 double signal_bandwidth_fraction[3];
190 /* This is the lag from sample 0 for the time defines as 0 for the
191 wavelet used to compute the inverse. It is needed to resolve time
192 in processing and the actual_output method.*/
193 int winv_t0_lag;
194 /*** Private methods *****/
196 process_with_current_shaping(const mspass::seismic::Seismogram &d,
197 const mspass::seismic::PowerSpectrum &psnoise);
198 void update_shaping_wavelet(const double fl, const double fh);
199 /* These are two algorithms for computing inverse operator in the frequency
200 * domain*/
201 void compute_winv(const mspass::seismic::TimeSeries &wavelet,
202 const mspass::seismic::PowerSpectrum &psnoise);
203 void compute_gwl_inverse(const mspass::seismic::TimeSeries &wavelet,
204 const mspass::seismic::PowerSpectrum &psnoise);
205 void compute_gdamp_inverse(const mspass::seismic::TimeSeries &wavelet,
206 const mspass::seismic::PowerSpectrum &psnoise);
207 friend boost::serialization::access;
208 template <class Archive>
209 void serialize(Archive &ar, const unsigned int version) {
210 // std::cout <<"Entered serialize function"<<std::endl;
211 ar &boost::serialization::base_object<FFTDeconOperator>(*this);
212 // std::cout << "Serializing first group of simple parameters"<<std::endl;
213 ar & algorithm;
214 ar & damp;
215 ar & noise_floor;
216 ar & band_snr_floor;
217 ar & operator_dt;
218 ar & shaping_wavelet_number_poles;
219 // std::cout << "Serializing shapingwavelet"<<std::endl;
220 ar & shapingwavelet;
221 if (version > 0) {
222 ar & configured_shapingwavelet;
223 } else if (Archive::is_loading::value) {
224 configured_shapingwavelet = shapingwavelet;
225 }
226 ar & winlength;
227 // std::cout<<"Serializing power spectrum engine objects"<<std::endl;
228 ar & signal_engine;
229 ar & noise_engine;
230 ar & snr_regularization_floor;
231 // std::cout << "Serializin winv vector"<<std::endl;
232 ar & winv;
233 ar & winv_t0_lag;
234 // std::cout<<"Serializing final block of parameters"<<std::endl;
235 ar & regularization_bandwidth_fraction;
236 /* These fixed length arrays caused probems - seg faults.
237 * Apparently boost doesn't handle that corectly. There may
238 * be a more concise way to do this but this should always work. */
239 // std::cout << "Entering block for 3 component arrays"<<std::endl;
240 for (auto k = 0; k < 3; ++k) {
241 // std::cout << "k="<<k<<std::endl;
242 ar &peak_snr[k];
243 // std::cout << "bandwidth_fraction"<<std::endl;
244 ar &signal_bandwidth_fraction[k];
245 }
246 // std::cout << "Exiting serialize function"<<std::endl;
247 }
248};
249} // namespace mspass::algorithms::deconvolution
251#endif
Colored-noise regularized three-component deconvolution engine.
Definition CNRDeconEngine.h:35
mspass::seismic::PowerSpectrum compute_noise_spectrum(const mspass::seismic::TimeSeries &d2use)
Definition CNRDeconEngine.cc:519
void changeparameter(const mspass::utility::Metadata &md)
Definition CNRDeconEngine.cc:330
CNRDeconEngine & operator=(const CNRDeconEngine &parent)
Definition CNRDeconEngine.cc:424
virtual ~CNRDeconEngine()
Definition CNRDeconEngine.h:90
double get_operator_dt() const
Definition CNRDeconEngine.h:105
CNRDeconEngine()
Definition CNRDeconEngine.cc:155
mspass::seismic::Seismogram process(const mspass::seismic::Seismogram &d, const mspass::seismic::PowerSpectrum &psnoise, const double fl, const double fh)
Definition CNRDeconEngine.cc:908
mspass::seismic::TimeSeries resolution_kernel(const mspass::seismic::TimeSeries &wavelet)
Alias for actual_output using inverse-theory terminology.
Definition CNRDeconEngine.h:139
mspass::seismic::TimeSeries actual_output(const mspass::seismic::TimeSeries &wavelet)
Definition CNRDeconEngine.cc:1207
mspass::seismic::TimeSeries inverse_wavelet(const mspass::seismic::TimeSeries &wavelet, const double t0shift)
Definition CNRDeconEngine.cc:1359
mspass::seismic::TimeSeries output_shaping_wavelet()
Return the output shaping wavelet.
Definition CNRDeconEngine.h:129
void initialize_inverse_operator(const mspass::seismic::TimeSeries &wavelet, const mspass::seismic::TimeSeries &noise_data)
Definition CNRDeconEngine.cc:450
mspass::utility::Metadata QCMetrics()
Definition CNRDeconEngine.cc:1405
mspass::seismic::TimeSeries ideal_output()
Definition CNRDeconEngine.cc:1199
Interfacing object to ease conversion between FORTRAN and C++ complex.
Definition ComplexArray.h:44
Object to hold components needed in all fft based decon algorithms.
Definition FFTDeconOperator.h:22
Multittaper power spectral estimator.
Definition MTPowerSpectrumEngine.h:32
Frequency domain shaping wavelet.
Definition ShapingWavelet.h:22
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
Type-safe metadata container used throughout MsPASS.
Definition Metadata.h:101