MsPASS C++ API  2.4.1.dev4+g92330b7a
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
8#include "mspass/algorithms/Taper.h"
9#include "mspass/algorithms/deconvolution/FFTDeconOperator.h"
10#include "mspass/algorithms/deconvolution/MTPowerSpectrumEngine.h"
11#include "mspass/algorithms/deconvolution/ShapingWavelet.h"
12#include "mspass/seismic/PowerSpectrum.h"
13#include "mspass/seismic/Seismogram.h"
14#include "mspass/seismic/TimeSeries.h"
15#include "mspass/utility/AntelopePf.h"
16
17namespace mspass::algorithms::deconvolution {
18/* This enum is file scope to intentionally exclude it from python wrappers.
19It is used internally to define the algorithm the processor is to run.
20I (glp) chose that approach over the inheritance approach used in the scalar
21methods as an artistic choice. It is a matter of opinion which approach
22is better. This makes one symbol do multiple things with changes done in
23the parameter setup as opposed to having to select the right symbolic name
24to construct. Anyway, this enum defines algorithms that can be chosen for
25processing.
26*/
27enum class CNR3C_algorithms { generalized_water_level, colored_noise_damping };
35public:
38 /* design note - delete when finished.
39
40 The constructor uses the pf to initialize operator properties.
41 Important in that is the multitaper engine that has a significant
42 initialization cost. the initialize_inverse_operator is a messy
43 way to define load data and then compute the inverse stored
44 internally. Doing it that way, however, allows the same code
45 to be used for both single station and array decon. In single
46 station use every datum has to call initiallize_inverse_operator
47 while with an array decon the operator is define once for an
48 ensemble and applied to all members. THE ASSUMPTION is all the
49 grungy work to assure all that gets done correction is handled
50 in python.
51 */
71 CNRDeconEngine(const CNRDeconEngine &parent);
75 void
77 const mspass::seismic::TimeSeries &noise_data);
80 const mspass::seismic::TimeSeries &wavelet,
81 const mspass::seismic::PowerSpectrum &noise_spectrum);
83 virtual ~CNRDeconEngine() {};
87 const mspass::seismic::PowerSpectrum &psnoise, const double fl,
88 const double fh);
90 double get_operator_dt() const { return this->operator_dt; }
123 return this->actual_output(wavelet);
124 }
128 const double t0shift);
133
134private:
135 CNR3C_algorithms algorithm;
136 /* For the colored noise damping algorithm the damper is frequency dependent.
137 The same issue in water level that requires a floor on the water level
138 applies to damping. We use noise_floor to create a lower bound on
139 damper values. Note the damping constant at each frequency is
140 damp*noise except where noise is below noise_floor defined relative to
141 maximum noise value where it is set to n_peak*noise_floor*damp. */
142 double damp;
143 double noise_floor;
144 /* SNR bandbwidth estimates count frequencies with snr above this value */
145 double band_snr_floor;
146 double operator_dt; // Data must match this sample interval
147 int shaping_wavelet_number_poles;
149 /* Expected time window size in samples. When signal lengths
150 match this value the slepian tapers are not recomputed. When there
151 is a mismatch it will change. That means this can change dynamically
152 when run on multiple data objects. */
153 int winlength;
156
157 /* This algorithm uses a mix of damping and water level. Above this floor,
158 which acts a bit like a water level, no regularization is done. If
159 snr is less than this value we regularize with damp*noise_amplitude.
160 Note the noise_floor parameter puts a lower bound on the frequency dependent
161 regularization. If noise amplitude (not power) is less than noise_floor
162 the floor is set like a water level as noise_max*noise_level.*/
163 double snr_regularization_floor;
164 /* These are QC metrics computed by process method. Saved to allow them
165 to be use in QCmetrics method. */
166 double regularization_bandwidth_fraction;
167 double peak_snr[3];
168 double signal_bandwidth_fraction[3];
170 /* This is the lag from sample 0 for the time defines as 0 for the
171 wavelet used to compute the inverse. It is needed to resolve time
172 in the actual_output method.*/
173 int winv_t0_lag;
174 /*** Private methods *****/
175 void update_shaping_wavelet(const double fl, const double fh);
176 /* These are two algorithms for computing inverse operator in the frequency
177 * domain*/
178 void compute_winv(const mspass::seismic::TimeSeries &wavelet,
179 const mspass::seismic::PowerSpectrum &psnoise);
180 void compute_gwl_inverse(const mspass::seismic::TimeSeries &wavelet,
181 const mspass::seismic::PowerSpectrum &psnoise);
182 void compute_gdamp_inverse(const mspass::seismic::TimeSeries &wavelet,
183 const mspass::seismic::PowerSpectrum &psnoise);
184 friend boost::serialization::access;
185 template <class Archive>
186 void serialize(Archive &ar, const unsigned int version) {
187 // std::cout <<"Entered serialize function"<<std::endl;
188 ar &boost::serialization::base_object<FFTDeconOperator>(*this);
189 // std::cout << "Serializing first group of simple parameters"<<std::endl;
190 ar & algorithm;
191 ar & damp;
192 ar & noise_floor;
193 ar & band_snr_floor;
194 ar & operator_dt;
195 ar & shaping_wavelet_number_poles;
196 // std::cout << "Serializing shapingwavelet"<<std::endl;
197 ar & shapingwavelet;
198 ar & winlength;
199 // std::cout<<"Serializing power spectrum engine objects"<<std::endl;
200 ar & signal_engine;
201 ar & noise_engine;
202 ar & snr_regularization_floor;
203 // std::cout << "Serializin winv vector"<<std::endl;
204 ar & winv;
205 ar & winv_t0_lag;
206 // std::cout<<"Serializing final block of parameters"<<std::endl;
207 ar & regularization_bandwidth_fraction;
208 /* These fixed length arrays caused probems - seg faults.
209 * Apparently boost doesn't handle that corectly. There may
210 * be a more concise way to do this but this should always work. */
211 // std::cout << "Entering block for 3 component arrays"<<std::endl;
212 for (auto k = 0; k < 3; ++k) {
213 // std::cout << "k="<<k<<std::endl;
214 ar &peak_snr[k];
215 // std::cout << "bandwidth_fraction"<<std::endl;
216 ar &signal_bandwidth_fraction[k];
217 }
218 // std::cout << "Exiting serialize function"<<std::endl;
219 }
220};
221} // namespace mspass::algorithms::deconvolution
222#endif
Colored-noise regularized three-component deconvolution engine.
Definition CNRDeconEngine.h:34
mspass::seismic::PowerSpectrum compute_noise_spectrum(const mspass::seismic::TimeSeries &d2use)
Definition CNRDeconEngine.cc:317
void changeparameter(const mspass::utility::Metadata &md)
Definition CNRDeconEngine.cc:164
CNRDeconEngine & operator=(const CNRDeconEngine &parent)
Definition CNRDeconEngine.cc:248
virtual ~CNRDeconEngine()
Definition CNRDeconEngine.h:83
double get_operator_dt() const
Definition CNRDeconEngine.h:90
CNRDeconEngine()
Definition CNRDeconEngine.cc:15
mspass::seismic::Seismogram process(const mspass::seismic::Seismogram &d, const mspass::seismic::PowerSpectrum &psnoise, const double fl, const double fh)
Definition CNRDeconEngine.cc:583
mspass::seismic::TimeSeries resolution_kernel(const mspass::seismic::TimeSeries &wavelet)
Alias for actual_output using inverse-theory terminology.
Definition CNRDeconEngine.h:122
mspass::seismic::TimeSeries actual_output(const mspass::seismic::TimeSeries &wavelet)
Definition CNRDeconEngine.cc:708
mspass::seismic::TimeSeries inverse_wavelet(const mspass::seismic::TimeSeries &wavelet, const double t0shift)
Definition CNRDeconEngine.cc:816
mspass::seismic::TimeSeries output_shaping_wavelet()
Return the output shaping wavelet.
Definition CNRDeconEngine.h:112
void initialize_inverse_operator(const mspass::seismic::TimeSeries &wavelet, const mspass::seismic::TimeSeries &noise_data)
Definition CNRDeconEngine.cc:271
mspass::utility::Metadata QCMetrics()
Definition CNRDeconEngine.cc:838
mspass::seismic::TimeSeries ideal_output()
Definition CNRDeconEngine.cc:700
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
Type-safe metadata container used throughout MsPASS.
Definition Metadata.h:101