MsPASS C++ API  2.4.4.dev114+gf4c3cfaca
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
FFTDeconOperator.h
1#ifndef __FFT_DECON_OPERATOR_H__
2#define __FFT_DECON_OPERATOR_H__
3#include "mspass/algorithms/TimeWindow.h"
4#include "mspass/algorithms/deconvolution/ComplexArray.h"
5#include "mspass/algorithms/deconvolution/GSLFFTResources.h"
6#include "mspass/seismic/CoreTimeSeries.h"
7#include "mspass/seismic/PowerSpectrum.h"
8#include "mspass/utility/Metadata.h"
9#include <boost/archive/text_iarchive.hpp>
10#include <boost/archive/text_oarchive.hpp>
11#include <gsl/gsl_errno.h>
12#include <gsl/gsl_fft_complex.h>
13#include <string>
14namespace mspass::algorithms::deconvolution {
23public:
64 void change_size(const int nfft_new);
66 void change_shift(const int shift) { sample_shift = shift; };
68 int get_size() { return nfft; };
70 int get_shift() { return sample_shift; };
72 int operator_size() { return static_cast<int>(nfft); };
74 int operator_shift() { return sample_shift; };
80 double df(const double dt) {
81 double period;
82 period = static_cast<double>(nfft) * dt;
83 return 1.0 / period;
84 };
93 const ComplexArray &sw,
94 const double dt,
95 const double t0parent);
96
97protected:
99 int nfft;
103 gsl_fft_complex_wavetable *wavetable;
105 gsl_fft_complex_workspace *workspace;
108
109private:
110 friend boost::serialization::access;
111 template <class Archive>
112 void save(Archive &ar, const unsigned int version) const {
113 // std::cout << "Entered FFTDecon serialization save function"<<std::endl;
114 ar & nfft;
115 ar & sample_shift;
116 ar & winv;
117 // std::cout << "Exiting save function" << std::endl;
118 }
119 template <class Archive> void load(Archive &ar, const unsigned int version) {
120 int loaded_nfft;
121 int loaded_sample_shift;
122 ComplexArray loaded_winv;
123 ar & loaded_nfft;
124 ar & loaded_sample_shift;
125 ar & loaded_winv;
126 const std::string caller("FFTDeconOperator serialization load");
127 if (loaded_nfft <= 0)
129 caller + ": archived fft length must be positive",
130 mspass::utility::ErrorSeverity::Invalid);
131 if (loaded_sample_shift < 0 || loaded_sample_shift > loaded_nfft)
133 caller + ": archived sample shift is outside the fft buffer",
134 mspass::utility::ErrorSeverity::Invalid);
135 /* An operator may be serialized before its inverse is initialized. */
136 if (loaded_winv.size() != 0 && loaded_winv.size() != loaded_nfft)
138 caller + ": archived inverse size does not match fft length",
139 mspass::utility::ErrorSeverity::Invalid);
140 auto resources = detail::AllocateGSLFFTResources(loaded_nfft, caller);
141
142 /* Everything above may throw. Swaps, frees, scalar stores, and releases
143 * below form the no-throw commit into either a default or initialized
144 * target. */
145 winv.swap(loaded_winv);
146 if (wavetable != nullptr)
147 gsl_fft_complex_wavetable_free(wavetable);
148 if (workspace != nullptr)
149 gsl_fft_complex_workspace_free(workspace);
150 nfft = loaded_nfft;
151 sample_shift = loaded_sample_shift;
152 wavetable = resources.wavetable.release();
153 workspace = resources.workspace.release();
154 }
155 BOOST_SERIALIZATION_SPLIT_MEMBER()
156};
157
158/* This helper is best referenced here */
159
172std::vector<double> circular_shift(const std::vector<double> &d, const int i0);
178int ComputeFFTLength(const mspass::algorithms::TimeWindow w, const double dt);
180void ValidateWindowDuration(const mspass::algorithms::TimeWindow w,
181 const std::string &window_name,
182 const std::string &caller);
190int ComputeFFTLength(const mspass::utility::Metadata &md);
198int ComputeDeconSampleShift(const mspass::utility::Metadata &md);
205void ValidatePowerSpectrumCoversDC(
206 const mspass::seismic::PowerSpectrum &spectrum,
207 const std::string &caller);
218std::vector<double> ExtractLagWindow(ComplexArray &fft_buffer,
219 const int output_length,
220 const int sample_shift);
226extern "C" {
227unsigned int nextPowerOf2(unsigned int n);
228}
229} // namespace mspass::algorithms::deconvolution
230#endif
Defines a time window.
Definition TimeWindow.h:12
Interfacing object to ease conversion between FORTRAN and C++ complex.
Definition ComplexArray.h:44
int size() const
Definition ComplexArray.cc:275
void swap(ComplexArray &other) noexcept
Definition ComplexArray.h:88
Object to hold components needed in all fft based decon algorithms.
Definition FFTDeconOperator.h:22
void changeparameter(const mspass::utility::Metadata &md)
Reconfigure the FFT operator from Metadata.
Definition FFTDeconOperator.cc:123
gsl_fft_complex_workspace * workspace
GSL scratch workspace allocated for nfft.
Definition FFTDeconOperator.h:105
FFTDeconOperator()
Construct an empty FFT operator shell.
Definition FFTDeconOperator.cc:16
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:190
gsl_fft_complex_wavetable * wavetable
GSL factorization table allocated for nfft.
Definition FFTDeconOperator.h:103
void change_shift(const int shift)
Set the sample offset used to unwrap deconvolution lag windows.
Definition FFTDeconOperator.h:66
int operator_size()
Return the current FFT work-buffer length.
Definition FFTDeconOperator.h:72
~FFTDeconOperator()
Release allocated GSL FFT work objects.
Definition FFTDeconOperator.cc:84
ComplexArray winv
Frequency-domain inverse wavelet coefficients for derived operators.
Definition FFTDeconOperator.h:107
int operator_shift()
Return the current deconvolution lag-window sample shift.
Definition FFTDeconOperator.h:74
int sample_shift
Sample offset used to place zero lag in deconvolution outputs.
Definition FFTDeconOperator.h:101
int nfft
Current FFT work-buffer length in samples.
Definition FFTDeconOperator.h:99
int get_size()
Return the current FFT work-buffer length.
Definition FFTDeconOperator.h:68
int get_shift()
Return the current deconvolution lag-window sample shift.
Definition FFTDeconOperator.h:70
double df(const double dt)
Return frequency spacing for the current FFT length.
Definition FFTDeconOperator.h:80
FFTDeconOperator & operator=(const FFTDeconOperator &parent)
Assign FFT size and lag shift from another operator.
Definition FFTDeconOperator.cc:90
void change_size(const int nfft_new)
Change the FFT work-buffer length.
Definition FFTDeconOperator.cc:170
Scalar time series data object.
Definition CoreTimeSeries.h:17
Definition PowerSpectrum.h:11
Type-safe metadata container used throughout MsPASS.
Definition Metadata.h:101
Base class for error object thrown by MsPASS library routines.
Definition MsPASSError.h:38