Commit df243d58 authored by niklas.thiel's avatar niklas.thiel
Browse files

Merge branch 'develop' into pup

Conflicts:
	doc/latex/6_Parameter_Definition.tex
	src/IFOS2D.c
	src/calc_misfit.c
	src/exchange_par.c
	src/globvar.h
parents 914e765c 973a56a6
c this is <filters.inc>
c ----------------------------------------------------------------------------
c ($Id$)
c
c Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
c
......
......@@ -3,7 +3,6 @@
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 05/01/2003
*
......@@ -34,8 +33,6 @@
*/
#define TF_POLESNZEROES_CC_VERSION \
"TF_POLESNZEROES_CC V1.0 "
#define TF_POLESNZEROES_CC_CVSID \
"$Id$"
#include <fourier/polesnzeroes.h>
......
......@@ -3,7 +3,6 @@
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 05/01/2003
*
......@@ -38,8 +37,6 @@
#define TF_POLESNZEROES_H_VERSION \
"TF_POLESNZEROES_H V1.0 "
#define TF_POLESNZEROES_H_CVSID \
"$Id$"
#include<cmath>
#include<complex>
......
c this is <polesnzeros.inc>
cS
c ----------------------------------------------------------------------------
c ($Id$)
c
c Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
c
......
this is <README>
============================================================================
SEIFE --- seismic waveform filters
----------------------------------
$Id$
============================================================================
For compilation instructions see README.1st in the root directory of the tar-ball or
http://gpitrsvn.gpi.uni-karlsruhe.de:8000/TFSoftware/wiki/docs/installation
For compilation instructions see README.1st in the root directory.
libseife is a collection of Fortran 77 functions and subroutines for time
series analysis and digital filters. It is a full-grown signal processing
......@@ -37,5 +34,15 @@ Dependencies
external dependencies: -
internal dependencies: -
Arrays in C version
-------------------
The proper definition of arrays and parameters to be passed to the C-API of
libseife becomes obvious in function seife_first, which is defined in cseife.c
A call
seife_first(x, n);
will address elements x[0] to x[n-1] in C-array x.
----- END OF README -----
......@@ -70,7 +70,7 @@ documentation.
User documentation
------------------
The theory behind the Fourier domain least squares engine is outlined by
The theory behind the Fourier domain least squares procedure is outlined by
Lisa Groos (2013, Appendix F, page 146). She also describes a way to find an
approrpiate water level by application of the L-curve criterion (Groos, 2013,
Appendix G, page 148).
......@@ -87,6 +87,9 @@ tests/onlinehelp Provides access to these texts. Just issue
to get access.
A toy example and a step-by-step introduction are provided in subdirectory
src/ts/wf/testcases in README.soutifu
A short descrpition of the library and the accompanying program soutifu is
provided on the OpenTOAST web-page:
http://www.opentoast.de/Data_analysis_code_soutifu_and_libstfinv.php
......
......@@ -40,7 +40,7 @@
"STFINV_DEBUG_H V1.0"
/*! \brief produce debug output
* \ingroup misc_h
* \ingroup group_debug
*
* \param C output will be generated if C == true
* \param N name of function
......@@ -54,8 +54,15 @@
std::cerr.flush(); \
}
/*! \brief report value in a sequence of output operators
* \ingroup group_debug
*
* \param P parameter to dump
*/
#define STFINV_value( P ) #P << "=" << P
/*! \brief report value of expression
* \ingroup misc_h
* \ingroup group_debug
*
* \param P parameter to dump
*/
......
......@@ -104,7 +104,7 @@ processing are described in the \ref page_help.
/*! \brief Engines implemented in libstfinv
\defgroup engines Engines
\defgroup group_engines Engines
\todo
A detailed description for implementers is still missing
......@@ -116,7 +116,7 @@ processing are described in the \ref page_help.
/*! \brief Tools and utilities used by the libstfinv engines
\defgroup tools Internal tools and utilities
\defgroup group_tools Internal tools and utilities
\todo
A detailed description for implementers is still missing
......@@ -136,4 +136,18 @@ processing are described in the \ref page_help.
\date 04.10.2015
*/
/*======================================================================*/
/*! \brief Debug tools
\defgroup group_debug Debugging module
\todo
Selection of debug statements in most parts of the code is done by bits in
the value of the debug variable. E.g∵ The value 16 (bit 4) selects debugging
of the taper function. This is not yet properly documented.
\date 04.10.2015
*/
// ----- END OF doxygen.txt -----
......@@ -94,9 +94,9 @@
Programs using this library will require the following libraries in
addition:
- libfourierxx (available from TFSoftware)
- libfourierxx (available from Seitosh)
- libfftw3
- libaff (available from TFSoftware)
- libaff (available from Seitosh)
C programs will further be required to link against
......
......@@ -29,11 +29,12 @@
*
* REVISIONS and CHANGES
* - 06/05/2011 V1.0 Thomas Forbriger
* - 18/01/2016 V1.1 rename function to secomtospace
*
* ============================================================================
*/
#define STFINV_PARAMETERHANDLER_CC_VERSION \
"STFINV_PARAMETERHANDLER_CC V1.0"
"STFINV_PARAMETERHANDLER_CC V1.1"
#include <algorithm>
#include <stfinv/parameterhandler.h>
......@@ -50,7 +51,7 @@ std::string stfinv::tools::clipstring(std::string& s, const std::string& delim)
s.erase();
}
return(result);
} // std::string stfinv::tools::clipstring^
} // std::string stfinv::tools::clipstring()
/*----------------------------------------------------------------------*/
......@@ -71,11 +72,12 @@ stfinv::tools::Tparamap stfinv::tools::makeparamap(const std::string& p,
/*----------------------------------------------------------------------*/
std::string stfinv::tools::commatospace(std::string s)
std::string stfinv::tools::secomtospace(std::string s)
{
std::replace(s.begin(), s.end(), ',', ' ');
std::replace(s.begin(), s.end(), ';', ' ');
return(s);
} // std::string stfinv::tools::commatospace(const std::string& s)
} // std::string stfinv::tools::secomtospace(const std::string& s)
/*----------------------------------------------------------------------*/
......
......@@ -29,6 +29,7 @@
*
* REVISIONS and CHANGES
* - 06/05/2011 V1.0 Thomas Forbriger
* - 18/01/2016 V1.1 rename function to secomtospace
*
* ============================================================================
*/
......@@ -37,7 +38,7 @@
#ifndef STFINV_PARAMETERHANDLER_H_VERSION
#define STFINV_PARAMETERHANDLER_H_VERSION \
"STFINV_PARAMETERHANDLER_H V1.0"
"STFINV_PARAMETERHANDLER_H V1.1"
#include <string>
#include <map>
......@@ -45,12 +46,12 @@
namespace stfinv {
/*! \brief Namespace for internal tools
* \ingroup tools
* \ingroup group_tools
*/
namespace tools {
/*! strip substring
* \ingroup tools
* \ingroup group_tools
*
* Strips off first substring up to given delimiter.
* The string is passed as a reference and will be modified (i.e. the
......@@ -65,14 +66,14 @@ namespace stfinv {
/*----------------------------------------------------------------------*/
/*! \brief A map to store parameters.
* \ingroup tools
* \ingroup group_tools
*/
typedef std::map<std::string,std::string> Tparamap;
/*----------------------------------------------------------------------*/
/*! \brief Create a parameter map from a parameter string
* \ingroup tools
* \ingroup group_tools
*
* \param p parameter string
* \param delimiter delimiter which separates two parameters
......@@ -85,18 +86,19 @@ namespace stfinv {
/*----------------------------------------------------------------------*/
/*! replace comma by whitespace
* \ingroup tools
/*! replace commas and semicolons by whitespace
* \ingroup group_tools
*
* \param s input string
* \return input string with all commas replaced by whitespace
* \return input string with all commas replaced by whitespace and
* all semicolons replaced by whitespace
*/
std::string commatospace(std::string s);
std::string secomtospace(std::string s);
/*----------------------------------------------------------------------*/
/*! \brief remove leading and trailing whitespace
* \ingroup tools
* \ingroup group_tools
*
* \param s any string
* \return value a input string with any leading and trailing whitespace
......
......@@ -47,7 +47,7 @@
namespace stfinv {
/*! \brief Fourier domain least squares engine
* \ingroup engines
* \ingroup group_engines
*
* \par Concept behind this engine
* If
......
......@@ -30,7 +30,7 @@
namespace stfinv {
/*! \brief Engine to find a finite, causal source time-history in time domain
* \ingroup engines
* \ingroup group_engines
*
* \par Concept behin this engine
*
......
......@@ -44,7 +44,7 @@
namespace stfinv {
/*! \brief Engine to provide a fixed wavelet
* \ingroup engines
* \ingroup group_engines
*/
class STFEngineFixedWavelet: public stfinv::STFFourierDomainEngine {
public:
......
......@@ -32,13 +32,20 @@
* - 30/09/2011 V1.1 implemented handling of additional time series pairs
* - 04/10/2011 V1.2 correction in debug message
* - 14/10/2015 V1.3 new end-user usage functions
* - 28/06/2016 V1.4 introduce taper parameter to taper correction filter
* response in the time domain
* - 22/07/2016 V1.5 thof:
* - provide separate FFT processor addressing just the
* source time function correction filter
* - implement taper function
*
* ============================================================================
*/
#define STFINV_STFINVFOURIER_CC_VERSION \
"STFINV_STFINVFOURIER_CC V1.3"
"STFINV_STFINVFOURIER_CC V1.5"
#include <sstream>
#include <cmath>
#include <stfinv/stfinvfourier.h>
#include <stfinv/stfinvfourier_summary_usage.h>
#include <stfinv/stfinvfourier_description_usage.h>
......@@ -165,13 +172,21 @@ namespace stfinv {
* next integer multiple of the divisor larger than fpad*nsamples.
*
* \par Workspace
* Two FFT engines will be created:
* Two FFT engines will be created.
* They are only used one-way, since input data is not altered during
* processing input time series only have to be transformed once to Fourier
* domain.
* Results of processing have to be transformed to time domain.
* -# One engine (\c STFFourierDomainEngine::Mfftengineinput) being shared
* by recorded data and synthetic data, because both have to be transformed
* to Fourier domain at once.
* Transformation to Fourier domain takes place in
* STFFourierDomainEngine::fftinput.
* -# One engine (\c STFFourierDomainEngine::Mfftengineoutput) being shared
* by the stf and the convolved synthetics, because both have to be
* transformed to the time domain at once.
* Transformation to time domain takes place in
* STFFourierDomainEngine::fftoutput.
*/
void STFFourierDomainEngine::initialize()
{
......@@ -226,6 +241,8 @@ namespace stfinv {
Mfftengineoutput=fourier::fft::DRFFTWAFFArrayEngine(
1+this->nreceivers()+this->npairs(),
nsamples);
Mfftenginestf=fourier::fft::DRFFTWAFFArrayEngine(this->stfseries(),
this->stfspec());
// set time shift for STF if requested
// -----------------------------------
......@@ -234,28 +251,70 @@ namespace stfinv {
is >> Mtshift;
}
Mapplyshift=this->parameterisset("tshift");
// taper definition
// ----------------
{
std::istringstream is(stfinv::tools::secomtospace(
this->parameter("irtap","0.,1.,2.,3.")));
is >> Mtt1 >> Mtt2 >> Mtt3 >> Mtt4;
}
Mapplystftaper=this->parameterisset("irtap");
STFINV_assert((Mtt1<=Mtt2) && (Mtt2<=Mtt3) && (Mtt3<=Mtt4),
"ERROR: taper definition times not in increasing order");
STFINV_debug(Mdebug&1, "STFFourierDomainEngine::initialize()",
"this->nsamples()=" << this->nsamples() << " " <<
"padfactor=" << padfactor << " " <<
"divisor=" << divisor << " " <<
"nsamples=" << nsamples << " " <<
"Mapplyshift=" << Mapplyshift << " " <<
"Mtshift=" << Mtshift << " ");
STFINV_value(this->nsamples()) << "\n " <<
STFINV_value(padfactor) << "\n " <<
STFINV_value(divisor) << "\n " <<
STFINV_value(nsamples) << "\n " <<
STFINV_value(Mapplyshift) << "\n " <<
STFINV_value(Mtshift) << "\n " <<
STFINV_value(Mapplystftaper) << "\n " <<
STFINV_value(Mtt1) << "\n " <<
STFINV_value(Mtt2) << "\n " <<
STFINV_value(Mtt3) << "\n " <<
STFINV_value(Mtt4));
} // void STFFourierDomainEngine::initialize()
/*----------------------------------------------------------------------*/
/*!
* Provide data passed (through the API) by the caller of the library to an
* engine operating in the Fourier domain.
* All input is available as time series data in first place.
* -# Copy time series data to STFFourierDomainEngine::Mfftengineinput
* -# Transform time series data to Fourier domain
* -# Clear output coefficients
*
* This function should be called by the very first statement of the
* exec-function of the derived class (e.g. STFEngineFDLeastSquares::exec).
*/
void STFFourierDomainEngine::fftinput()
{
this->getinput();
Mfftengineinput.r2c();
Mfftengineoutput.series()=0.;
} // void STFFourierDomainEngine::fftinput()
/*----------------------------------------------------------------------*/
/*!
* Provide results of Fourier domain operation to the caller of the library.
* -# Apply time domain taper to correction filter, if requested
* -# Apply convolution with correction filter response to all synthetic
* input data
* -# Apply time shift to impulse response of correction filter, if
* requested
* -# Transform Fourier series to time domain
* -# Copy time series data to buffer array accessible through API
*
* This function should be called by the very last statement of the
* exec-function of the derived class (e.g. STFEngineFDLeastSquares::exec).
*/
void STFFourierDomainEngine::fftoutput()
{
if (this->Mapplystftaper) { this->taperstf(); }
this->convolve();
if (Mapplyshift) { this->stfshift(); }
Mfftengineoutput.c2r();
......@@ -296,6 +355,13 @@ namespace stfinv {
/*----------------------------------------------------------------------*/
STFFourierDomainEngine::TAseries STFFourierDomainEngine::stfseries() const
{
return(Mfftengineoutput.series(this->nreceivers()));
} // STFFourierDomainEngine::Tspectrum STFFourierDomainEngine::stfseries() const
/*----------------------------------------------------------------------*/
STFFourierDomainEngine::TAspectrum
STFFourierDomainEngine::recordingcoeff(const unsigned int& i) const
{
......@@ -353,6 +419,8 @@ namespace stfinv {
void STFFourierDomainEngine::getinput()
{
// clear workspace through reference
// (remark: return value sarray is a reference to an array addressing all
// samples of all time series contained in Mfftengineinput)
TAseries sarray=Mfftengineinput.series();
sarray=0.;
......@@ -379,6 +447,11 @@ namespace stfinv {
/*----------------------------------------------------------------------*/
/*!
* Read out time series data from Mfftengineoutput.
* The time series containers in Mfftengineoutput are expected to be larger
* than those used for the API of the library (because of padding).
*/
void STFFourierDomainEngine::putoutput()
{
// scaling factor for source correction filter
......@@ -415,6 +488,18 @@ namespace stfinv {
/*----------------------------------------------------------------------*/
/*! \brief Convolve all synthetics with the source time function correction
* filter.
*
* The filter response is available in terms of the Fourier coefficients of
* the correction filter as are returned by
* STFFourierDomainEngine::stfspec().
* Convolution takes place in the Fourier domain simply by a multiplication
* of Fourier coefficients.
* Since all Fourier coefficients are expected to be scaled appropriately to
* represent samples for the Fourier integral transform, no scaling has to
* be applied here.
*/
void STFFourierDomainEngine::convolve()
{
TAspectrum synthetic=this->syntheticspec();
......@@ -483,6 +568,96 @@ namespace stfinv {
} // for (unsigned int j=0; j<this->nfreq(); ++j)
} // void STFFourierDomainEngine::stfshift()
/*----------------------------------------------------------------------*/
/*!
* Apply a time domain taper to the impulse response of the source time
* function correction filter.
*/
void STFFourierDomainEngine::taperstf()
{
STFINV_debug(Mdebug&16, "STFFourierDomainEngine::taperstf()",
STFINV_value(Mapplystftaper));
if (this->Mapplystftaper)
{
// transform correction filter to time domain
Mfftenginestf.c2r();
Tfftengine::TAseries thestfseries=this->stfseries();
thestfseries *= Mfftenginestf.scale_series(this->dt());
// apply taper
/*
* Concept of application to periodic time series allowing for negative
* values of taper times:
*
* All samples between t2 and t3 remain unaltered. It is reasonable to
* process the taper starting at t3 passing t4 to t1 and then ending at
* t2. Behind this is the concept that time series are implicitely
* periodic in discrete Fourier transform.
*/
// samples in series
int nsamples=thestfseries.size(0);
// duration of time series
double T=this->dt()*nsamples;
// make sure taper definition is not longer than time series.
STFINV_assert((this->Mtt4-this->Mtt1)<T,
"Taper width is larger than length of time series");
// set taper time values under conpect of periodic series
double tt3=this->Mtt3;
double tt4=this->Mtt4;
double tt1=this->Mtt1+T;
double tt2=this->Mtt2+T;
// sample to start at
int l3=int(std::floor(tt3/this->dt()));
int l2=int(std::ceil(tt2/this->dt()));
STFINV_debug(Mdebug&16, "STFFourierDomainEngine::taperstf()",
STFINV_value(T) << "\n " <<
STFINV_value(this->dt()) << "\n " <<
STFINV_value(nsamples) << "\n " <<
STFINV_value(tt3) << "\n " <<
STFINV_value(tt4) << "\n " <<
STFINV_value(tt1) << "\n " <<
STFINV_value(tt2) << "\n " <<
STFINV_value(l3) << "\n " <<
STFINV_value(l2));
for (int l=l3; l<=l2; ++l)
{
// time of sample
double t=l*this->dt();
// index to series
int rl = l%nsamples;
if (rl < 0) { rl += nsamples; }
STFINV_assert(((rl >= thestfseries.f(0)) &&
(rl <= thestfseries.l(0))),
"Index out of range. Internal programming error! "
"Report as bug!")
// taper factor
double factor=1.;
if ( (t>=tt3) && (t<=tt4) && (tt4>tt3) )
{
factor=0.5+0.5*cos(M_PI*(t-tt3)/(tt4-tt3));
}
else if ( (t>tt4) && (t<tt1) )
{
factor=0.;
}
else if ( (t>=tt1) && (t<=tt2) && (tt2>tt1) )
{
factor=0.5-0.5*cos(M_PI*(t-tt1)/(tt2-tt1));
}
// apply to series
thestfseries(rl) = thestfseries(rl)*factor;
STFINV_debug(Mdebug&16, "STFFourierDomainEngine::taperstf()",
STFINV_value(t) << " " <<
STFINV_value(l) << " " <<
STFINV_value(rl) << " " <<
STFINV_value(factor));
}
// transform correction filter to Fourier domain
Mfftenginestf.r2c();
this->stfspec() *= Mfftenginestf.scale_spectrum(this->dt());
} // if (this->Mapplystftaper)
} // void STFFourierDomainEngine::taperstf()
} // namespace stfinv
/* ----- END OF stfinvfourier.cc ----- */
......@@ -30,6 +30,9 @@
* - 08/05/2011 V1.0 Thomas Forbriger
* - 30/09/2011 V1.1 implemented handling of additional time series pairs
* - 14/10/2015 V1.2 new end-user usage functions
* - 28/06/2016 V1.3 provide time domain tapering of filter response
* - 22/07/2016 V1.4 provide separate FFT processor addressing just the
* source time function correction filter
*
* ============================================================================
*/
......@@ -38,7 +41,7 @@
#ifndef STFINV_STFINVFOURIER_H_VERSION
#define STFINV_STFINVFOURIER_H_VERSION \
"STFINV_STFINVFOURIER_H V1.2"
"STFINV_STFINVFOURIER_H V1.4"
#include <stfinv/stfinvbase.h>
#include <aff/array.h>
......@@ -51,12 +54,19 @@ namespace stfinv {
* This is just a base class.
* The constructor is protected and should only be called from a derived
* class.
* The intention of this class is to provide all processing steps common to
* all engines operating in the Fourier domain in one single base class.
* The individual engines of different Fourier domain approaches then need
* not reimplement these steps.
* They essentially need only provide a specific exec-function (e.g.
* STFEngineFDLeastSquares::exec).
*
* This class maintains a workspace for Fourier transforms.
* It provides the FFT from input signals to the workspace through a member
* functions as well as the convolution of the synthetic data with a given
* source wavelet Fourier transform and a subsequent FFT to time domain for
* the convolved synthetics as well as the source correction filter separately.
* the convolved synthetics as well as the source correction filter
* separately.
*
* \par What STFFourierDomainEngine does for you
* All derived classes call STFFourierDomainEngine::fftinput prior to
......@@ -69,13 +79,27 @@ namespace stfinv {
* \par