MsPASS C++ API  2.4.1.dev4+g92330b7a
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
TimeDomainGIDDecon.h
1#ifndef __TIME_DOMAIN_GID_DECON__
2#define __TIME_DOMAIN_GID_DECON__
3#include "mspass/algorithms/TimeWindow.h"
4#include "mspass/algorithms/deconvolution/ComplexArray.h"
5#include "mspass/algorithms/deconvolution/CNRDeconEngine.h"
6#include "mspass/algorithms/deconvolution/FFTDeconOperator.h"
7#include "mspass/algorithms/deconvolution/ScalarDecon.h"
8#include "mspass/algorithms/deconvolution/ThreeCSpike.h"
9#include "mspass/seismic/CoreTimeSeries.h"
10#include "mspass/seismic/PowerSpectrum.h"
11#include "mspass/seismic/Seismogram.h"
12#include "mspass/seismic/TimeSeries.h"
13#include "mspass/utility/AntelopePf.h"
14#include "mspass/utility/Metadata.h"
15#include "mspass/utility/dmatrix.h"
16#include <list>
17#include <memory>
18#include <ostream>
19#include <string>
20#include <vector>
21namespace mspass::algorithms::deconvolution {
46public:
54 TimeDomainGIDDecon(const TimeDomainGIDDecon &parent) = delete;
82 int loadnoise(const mspass::seismic::TimeSeries &noise);
86 int loadnoise(const mspass::seismic::PowerSpectrum &noise_spectrum);
92 double deconvolution_window_start() const { return this->fftwin.start; };
94 double deconvolution_window_end() const { return this->fftwin.end; };
96 double noise_window_start() const { return this->nwin.start; };
98 double noise_window_end() const { return this->nwin.end; };
100 std::string configuration_pf_text() const { return this->config_pf_text; };
103 return this->leaf_parameters_changed;
104 };
107 return this->changed_leaf_metadata;
108 };
111 return this->external_wavelet_loaded;
112 };
114 bool external_noise_is_loaded() const { return this->external_noise_loaded; };
117 return this->external_noise_spectrum_loaded;
118 };
121 if (!this->external_wavelet_loaded)
123 return this->external_wavelet;
124 };
127 if (!this->external_noise_loaded)
129 return this->external_noise;
130 };
133 if (!this->external_noise_spectrum_loaded)
135 return this->external_noise_spectrum;
136 };
146 void process();
154 std::vector<double> lag_weight_vector() const;
165
166private:
167 /* These are data at different stages of process. d_all is the
168 largest signal window that is assumed to have been initialized by the
169 load method for this object. d_decon is the
170 result of applying the preprocessor (signal processing) deconvolution to
171 all three components. d_decon is computed from d, which is a windowed
172 version of the input data received by the load method. It has a
173 time duration less than or at least equal to that of d_all.
174 r is the residual, which is accumulated during the iterative method.
175 The time duration of r is the same as d. It is initialized by
176 convolving the inverse filter with d_all.
177 n is the noise data. It should normally be at least as long a d_all*/
178 mspass::seismic::CoreSeismogram d_all, d_decon, r, n;
179 /* We save the set of data lengths for clarity and a minor bit efficiency.
180 ndwin is the number of samples in d_all and r.
181 nnwin is the number of samples in n. */
182 int ndwin, nnwin;
183 /* Save the TimeWindow objects that define the extent of d_all, d_decon,
184 and n. Some things need at least some of these downstream */
185 mspass::algorithms::TimeWindow dwin, nwin, fftwin;
186 std::string config_pf_text;
187 double target_dt;
190 int noise_component;
194 std::list<ThreeCSpike> spikes;
201 std::vector<double> lag_weights;
202 /* This vector contains the function time shifted and added to lag_weights
203 vector after each iteration. */
204 std::vector<double> wtf;
205 int nwtf; // size of wtf - cached because wtf is inside the deepest loop
206
207 /* This is a pointer to the BasicDeconOperator class used for preprocessing
208 Classic use of inheritance to simplify the api. */
209 std::unique_ptr<ScalarDecon> preprocessor;
210 std::unique_ptr<CNRDeconEngine> cnrprocessor;
211 mspass::seismic::TimeSeries current_wavelet;
212 mspass::seismic::TimeSeries external_wavelet;
213 mspass::seismic::TimeSeries external_noise;
214 mspass::seismic::PowerSpectrum external_noise_spectrum;
215 std::vector<std::vector<double>> ns_noise_components;
216 bool external_wavelet_loaded, external_noise_loaded,
217 external_noise_spectrum_loaded, external_wavelet_allowed;
218 bool processed;
219 bool residual_noise_from_external;
220 bool leaf_parameters_changed;
221 mspass::utility::Metadata changed_leaf_metadata;
222
223 /* This parameter is set in the constructor. It would normally be half the
224 length of the fir representation of the inverse wavelet.*/
225 int wavelet_pad;
233 std::vector<double> actual_o_fir;
234 int actual_o_0; // offset from sample zero for zero lag position
235 IterDeconType decon_type;
236 /* This is called by the constructor to create the wtf penalty function */
237 void construct_weight_penalty_function(const mspass::utility::Metadata &md);
238 void invalidate_processing_state();
244 void update_residual_matrix(ThreeCSpike spk);
251 void update_lag_weights(int col, const double candidate_amplitude);
257 double compute_resid_linf_floor(
261 bool has_not_converged();
262 /* These are convergence attributes. lw_inf indicates Linf norm of
263 lag_weight array, lw_l2 is L2 metric of lag_weight, resid_inf is Linf
264 norm of residual vector, and resid_l2 is L2 of resid matrix. prev
265 modifier means the size of that quantity in the previous iteration. initial
266 means initial value at the top of the loop.*/
267 double lw_linf_initial, lw_linf_prev;
268 double lw_l2_initial, lw_l2_prev;
269 double resid_linf_initial, resid_linf_prev;
270 double resid_l2_initial, resid_l2_prev;
271 /* These are convergence parameters for the different tests */
272 int iter_count, iter_max; // actual iteration count and ceiling to break loop
273 /*lw metrics are scaled with range of 0 to 1. l2 gets scaled by number of
274 points and so can use a similar absolute scale. */
275 double lw_linf_floor, lw_l2_floor;
276 /* We use a probability level to define the floor Linf of the residual
277 matrix. For L2 we use the conventional fractional improvement metric. */
278 double resid_linf_prob, resid_linf_floor;
279 double resid_l2_tol;
280 double ns_peak_sigma_threshold, ns_peak_probability_threshold;
281 double ns_residual_noise_ratio_floor, ns_peak_threshold;
282 double ns_last_peak_significance, ns_noise_l2, ns_noise_amplitude_rms;
283 int ns_max_spikes, ns_refit_interval;
284 double ns_ridge_beta, ns_fractional_improvement_final;
285 bool ns_use_empirical_noise_threshold, ns_converged;
286 std::string ns_stop_reason;
287 bool gid_converged;
288 std::string gid_stop_reason;
289 std::string lag_weight_penalty_function;
290 double lag_weight_penalty_scale_factor;
291 int lag_weight_function_width;
292 std::vector<double> adaptive_penalty_memory;
293 std::vector<double> adaptive_penalty_retention;
294 double adaptive_penalty_last_confidence;
295 double adaptive_penalty_last_immediate_strength;
296 double adaptive_penalty_last_specificity;
297 double adaptive_penalty_last_decay_factor;
298 double adaptive_penalty_noise_amplitude;
299 double adaptive_penalty_memory_linf;
300 double adaptive_penalty_memory_l2;
301 double group_sparse_lambda, group_sparse_lambda_scale;
302 double group_sparse_lambda_used, group_sparse_tolerance;
303 double group_sparse_active_threshold, group_sparse_active_threshold_scale;
304 double group_sparse_active_threshold_quantile;
305 double group_sparse_active_threshold_quantile_value;
306 double group_sparse_active_threshold_used;
307 double group_sparse_objective_initial, group_sparse_objective_final;
308 double group_sparse_fractional_improvement_final;
309 double group_sparse_debiased_objective_final;
310 double group_sparse_debiased_fractional_improvement_final;
311 int group_sparse_max_iterations, group_sparse_iterations;
312 int group_sparse_active_groups;
313 bool group_sparse_converged;
314
315};
316} // namespace mspass::algorithms::deconvolution
317#endif
Defines a time window.
Definition TimeWindow.h:12
double start
Definition TimeWindow.h:17
double end
Definition TimeWindow.h:21
Base class decon operator for single station 3C decon (receiver functions).
Definition ScalarDecon.h:30
std::vector< double > wavelet
Source-wavelet estimate used by concrete scalar methods.
Definition ScalarDecon.h:142
Sparse three-component spike used by iterative deconvolution.
Definition ThreeCSpike.h:16
Three-component generalized iterative deconvolution in time.
Definition TimeDomainGIDDecon.h:45
mspass::utility::Metadata QCMetrics()
Definition TimeDomainGIDDecon.cc:1370
void clear_external_noise()
Definition TimeDomainGIDDecon.cc:543
mspass::seismic::TimeSeries loaded_external_noise() const
Definition TimeDomainGIDDecon.h:126
mspass::seismic::CoreTimeSeries actual_output()
Definition TimeDomainGIDDecon.cc:308
bool external_wavelet_is_loaded() const
Definition TimeDomainGIDDecon.h:110
int loadnoise(const mspass::seismic::CoreSeismogram &d, mspass::algorithms::TimeWindow nwin)
Definition TimeDomainGIDDecon.cc:419
double noise_window_end() const
Definition TimeDomainGIDDecon.h:98
int load(const mspass::seismic::CoreSeismogram &d, mspass::algorithms::TimeWindow dwin)
Definition TimeDomainGIDDecon.cc:394
mspass::seismic::CoreSeismogram getresult()
Definition TimeDomainGIDDecon.cc:1356
bool external_noise_is_loaded() const
Definition TimeDomainGIDDecon.h:114
double noise_window_start() const
Definition TimeDomainGIDDecon.h:96
std::string configuration_pf_text() const
Definition TimeDomainGIDDecon.h:100
bool external_noise_spectrum_is_loaded() const
Definition TimeDomainGIDDecon.h:116
mspass::seismic::CoreTimeSeries inverse_wavelet()
Definition TimeDomainGIDDecon.cc:318
TimeDomainGIDDecon & operator=(const TimeDomainGIDDecon &parent)=delete
double deconvolution_window_start() const
Definition TimeDomainGIDDecon.h:92
mspass::seismic::PowerSpectrum loaded_external_noise_spectrum() const
Definition TimeDomainGIDDecon.h:132
mspass::utility::Metadata changed_leaf_parameters() const
Definition TimeDomainGIDDecon.h:106
mspass::seismic::CoreTimeSeries ideal_output()
Definition TimeDomainGIDDecon.cc:304
~TimeDomainGIDDecon()
Definition TimeDomainGIDDecon.cc:241
void process()
Definition TimeDomainGIDDecon.cc:739
bool leaf_parameters_have_changed() const
Definition TimeDomainGIDDecon.h:102
mspass::seismic::CoreSeismogram sparse_output()
Definition TimeDomainGIDDecon.cc:1314
TimeDomainGIDDecon(const TimeDomainGIDDecon &parent)=delete
mspass::seismic::TimeSeries loaded_external_wavelet() const
Definition TimeDomainGIDDecon.h:120
int loadwavelet(const mspass::seismic::TimeSeries &wavelet)
Definition TimeDomainGIDDecon.cc:450
void changeparameter(const mspass::utility::Metadata &md)
Definition TimeDomainGIDDecon.cc:291
double deconvolution_window_end() const
Definition TimeDomainGIDDecon.h:94
std::vector< double > lag_weight_vector() const
Definition TimeDomainGIDDecon.cc:1349
void clear_external_wavelet()
Definition TimeDomainGIDDecon.cc:538
Vector (three-component) seismogram data object.
Definition CoreSeismogram.h:39
Scalar time series data object.
Definition CoreTimeSeries.h:17
Definition PowerSpectrum.h:11
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