Commit f49048b3 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

added new feature to libstfinv and soutifu:

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.
additional time series can be passed to the engine
they are not used to determine the STF but are convolved with the STF
as soon as a new STF is derived


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4161
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 778b35e4
......@@ -30,11 +30,12 @@
*
* REVISIONS and CHANGES
* - 06/05/2011 V1.0 Thomas Forbriger
* - 30/09/2011 V1.1 implemented handling of additional time series pairs
*
* ============================================================================
*/
#define STFINV_STFINV_C_VERSION \
"STFINV_STFINV_C V1.0 "
"STFINV_STFINV_C V1.1"
#define STFINV_STFINV_C_CVSID \
"$Id$"
......@@ -68,9 +69,10 @@ namespace stfinv {
/*======================================================================*/
void initstfinvengine(struct CTriples triples,
struct CWaveform stf,
char* parameters)
void initstfinvenginepairs(struct CTriples triples,
struct CWaveform stf,
struct CPairs pairs,
char* parameters)
{
// remove existing engine if has previously been initialized
freestfinvengine();
......@@ -110,9 +112,40 @@ void initstfinvengine(struct CTriples triples,
aff::SharedHeap<Tvalue>(ctriple.convolvedsynthetics, n));
}
// convert pointer pairs
// notice: it is not required to check consistency here; all header fields
// are transferred to the C++ containers; the C++ engine will check
// consistency during its initialization
stfinv::Tvectorofpairs cxxpairs(pairs.n);
for (int i=0; i<pairs.n; ++i)
{
CWaveformPair cpair=pairs.pairs[i];
cxxpairs[i].sampling=cpair.sampling;
const int& n=cxxpairs[i].sampling.n;
shape=aff::LinearShape(0, n-1, 0);
cxxpairs[i].synthetics
=stfinv::Tseries::Tcoc(shape,
aff::SharedHeap<Tvalue>::Tcoc(cpair.synthetics, n));
cxxpairs[i].convolvedsynthetics
=stfinv::Tseries(shape,
aff::SharedHeap<Tvalue>(cpair.convolvedsynthetics, n));
}
// create engine
stfinv::capi::Pengine=new stfinv::STFEngine(cxxtriples, cxxstf,
cxxpairs,
cxxparameters);
} // void initstfinvenginepairs
/*----------------------------------------------------------------------*/
void initstfinvengine(struct CTriples triples,
struct CWaveform stf,
char* parameters)
{
struct CPairs pairs;
pairs.n=0;
initstfinvenginepairs(triples, stf, pairs, parameters);
} // void initstfinvengine
/*----------------------------------------------------------------------*/
......
......@@ -33,6 +33,7 @@
* - 06/05/2011 V1.0 Thomas Forbriger
* - 28/06/2011 V1.1 requires extern declaration for C++ since binary
* code is compiled by C++ compiler, not C compiler
* - 30/09/2011 V1.2 implemented handling of additional time series pairs
*
* ============================================================================
*/
......@@ -41,7 +42,7 @@
#ifndef STFINV_STFINV__H_VERSION
#define STFINV_STFINV__H_VERSION \
"STFINV_STFINV__H V1.0 "
"STFINV_STFINV__H V1.2"
#define STFINV_STFINV__H_CVSID \
"$Id$"
......@@ -96,6 +97,41 @@ struct CWaveformTriple {
/*----------------------------------------------------------------------*/
/*! \brief A struct to store the time series for a pair of waveforms.
* \ingroup cinterface
*
* This struct provides references to the users workspace, where the time
* series for on receiver are stored.
*/
struct CWaveformPair {
/*! \brief Temporal sampling parameters.
* The header is expected to be the same for both time series.
* In particular the number of samples must be appropriate for the memory
* allocated for both time series arrays.
*/
struct CWaveformHeader sampling;
/*! \brief Time series of synthetic data.
* This field actually is a pointer (C array) to the workspace where the
* users stores the samples of a time series of synthetic data.
* The size of the array is expected to be
* this->header::sampling::n.
*/
Tvalue* synthetics;
/*! \brief Time series of convolved synthetic data.
* This field actually is a pointer (C array) to the workspace where the
* user wishes to receive the samples of the time series of synthetic data
* as a result of convolution with the source time function.
* The size of the array is expected to be
* this->header::sampling::n.
* This will contain the synthetic data (this->synthetics) convolved with
* the obtained source time function as a result of a call to the library
* functions.
*/
Tvalue* convolvedsynthetics;
}; // struct CWaveformPair
/*----------------------------------------------------------------------*/
/*! \brief A struct to store a single waveform.
*
* \ingroup cinterface
......@@ -129,7 +165,7 @@ struct CTriples {
/*! \brief Number of triples (i.e. receivers) in the array.
*/
int n;
/*! \brief Pointer to array of waveform tripples.
/*! \brief Pointer to array of waveform triples.
* This actually is a C array for elements of type struct CWaveformTriple.
* The size ot the array is expected to be identical with the number of
* receivers to be used (i.e. CTriples::n).
......@@ -137,6 +173,30 @@ struct CTriples {
struct CWaveformTriple* triples;
}; // struct CTriples
/*----------------------------------------------------------------------*/
/*! \brief Array of waveform pairs.
* \ingroup cinterface
*
* This is used to pass data for a set of synthetic time series, which should
* be convolved with the new source time function on the fly.
* A collection of time series consists of CPairs::n waveform pairs.
* For each waveform pair this struct holds a reference to a struct
* CWaveformPair which itself provides a reference to the users workspace for
* time series.
*/
struct CPairs {
/*! \brief Number of pairs in the array.
*/
int n;
/*! \brief Pointer to array of waveform pairs.
* This actually is a C array for elements of type struct CWaveformPair.
* The size ot the array is expected to be identical with the number of
* receivers to be used (i.e. CPairs::n).
*/
struct CWaveformPair* pairs;
}; // struct CPairs
/*======================================================================*/
// function interface to libstfinv
......@@ -164,6 +224,46 @@ void initstfinvengine(struct CTriples triples,
struct CWaveform stf,
char* parameters);
/*! \brief Initialize the engine and pass additional time series to be
* convolved on the fly.
*
* The purpose of this function in comparion to initstfinvengine() is
* explained in the comments to parameter \p pairs.
* \ingroup cinterface
*
* \param triples
* This function expects a struct CTriples containing references to the users
* workspace for recorded time series as well as synthetic time series.
* These will be used as input.
* As a third set a reference to a workspace for synthetic time series
* convolved with the source time function is expected.
* The latter will be used as output.
* \param stf
* The struct CWaveform presents a reference to the users work space for the
* source time function time series.
* It will be used to present the result of the processing to the user.
* \param pairs
* The struct CPairs presents a reference to the users work space for
* additional synthetic time series.
* These time series will not be used to determine the optimal source time
* function filter, but will be convolved with the obtained source time
* function on the fly.
* This is in useful in particular with forward modelling code which uses a
* band limited source time function for the initial synthetics already.
* This source time function can be passed through this argument and will
* then be convolved with the optimized source time function, such that the
* result of the convolution is appropriate to obtain synthetics which
* provide a reduced misift with respect to the data.
* \param parameters
* Parameters to select one of the engines as well as to control the engines
* are passed in a character sequence.
* See also \ref main_subsec_parameters
*/
void initstfinvenginewithpairs(struct CTriples triples,
struct CWaveform stf,
struct CPairs pairs,
char* parameters);
/*! \brief Run the engine.
*
* \ingroup cinterface
......
......@@ -30,11 +30,12 @@
*
* REVISIONS and CHANGES
* - 06/05/2011 V1.0 Thomas Forbriger
* - 30/09/2011 V1.1 implemented handling of additional time series pairs
*
* ============================================================================
*/
#define STFINV_STFINVANY_CC_VERSION \
"STFINV_STFINVANY_CC V1.0 "
"STFINV_STFINVANY_CC V1.1"
#define STFINV_STFINVANY_CC_CVSID \
"$Id$"
......@@ -51,20 +52,54 @@ namespace stfinv {
STFEngine::STFEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const std::string& parameters)
{
stfinv::Tvectorofpairs pairs;
pairs.clear();
this->initialize(triples, stf, pairs, parameters);
}
/*----------------------------------------------------------------------*/
//! \brief Constructor.
STFEngine::STFEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const stfinv::Tvectorofpairs& pairs,
const std::string& parameters)
{
this->initialize(triples, stf, pairs, parameters);
}
/*----------------------------------------------------------------------*/
void STFEngine::initialize(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const stfinv::Tvectorofpairs& pairs,
const std::string& parameters)
{
std::string para=parameters;
std::string id=stfinv::tools::clipstring(para, ":");
if (id == std::string(stfinv::STFEngineIdentity::ID))
{
STFINV_assert(pairs.size()==0,
"ERROR: engine does not support additional time series pairs");
Mengine=new stfinv::STFEngineIdentity(triples, stf, para);
}
else if (id == std::string(stfinv::STFEngineFixedWavelet::ID))
{
STFINV_assert(pairs.size()==0,
"ERROR: engine does not support additional time series pairs");
Mengine=new stfinv::STFEngineFixedWavelet(triples, stf, para);
}
else if (id == std::string(stfinv::STFEngineBlindDeconvolution::ID))
{
Mengine=new stfinv::STFEngineBlindDeconvolution(triples, stf, para);
if (pairs.size()>0)
{
Mengine=new stfinv::STFEngineBlindDeconvolution(triples, stf,
pairs, para);
}
else
{
Mengine=new stfinv::STFEngineBlindDeconvolution(triples, stf, para);
}
}
else
{
......
......@@ -30,6 +30,7 @@
*
* REVISIONS and CHANGES
* - 06/05/2011 V1.0 Thomas Forbriger
* - 30/09/2011 V1.1 implemented handling of additional time series pairs
*
* ============================================================================
*/
......@@ -38,7 +39,7 @@
#ifndef STFINV_STFINVANY_H_VERSION
#define STFINV_STFINVANY_H_VERSION \
"STFINV_STFINVANY_H V1.0 "
"STFINV_STFINVANY_H V1.1"
#define STFINV_STFINVANY_H_CVSID \
"$Id$"
......@@ -60,14 +61,14 @@ namespace stfinv {
/*! \brief Constructor.
*
* \param triples
* This function expects a struct CTriples containing references to
* This function expects a vector of triples containing references to
* the users workspace for recorded time series as well as synthetic
* time series. These will be used as input.
* As a third set a reference to a workspace for synthetic time series
* convolved with the source time function is expected.
* The latter will be used as output.
* \param stf
* The struct CWaveform presents a reference to the users work space
* The Waveform presents a reference to the users work space
* for the source time function time series.
* It will be used to present the result of the processing to the user.
* \param parameters
......@@ -78,6 +79,40 @@ namespace stfinv {
STFEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const std::string& parameters);
/*! \brief Constructor.
*
* \param triples
* This function expects a vector of triples containing references to
* the users workspace for recorded time series as well as synthetic
* time series. These will be used as input.
* As a third set a reference to a workspace for synthetic time series
* convolved with the source time function is expected.
* The latter will be used as output.
* \param stf
* The Waveform presents a reference to the users work space
* for the source time function time series.
* It will be used to present the result of the processing to the user.
* \param pairs
* The vector of pairs presents a reference to the users work space for
* additional synthetic time series. These time series will not be
* used to determine the optimal source time function filter, but will
* be convolved with the obtained source time function on the fly.
* This is in useful in particular with forward modelling code which
* uses a band limited source time function for the initial synthetics
* already. This source time function can be passed through this
* argument and will then be convolved with the optimized source time
* function, such that the result of the convolution is appropriate to
* obtain synthetics which provide a reduced misift with respect to
* the data.
* \param parameters
* Parameters to select one of the engines as well as to control the
* engines are passed in a character sequence.
* See also \ref main_subsec_parameters
*/
STFEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const stfinv::Tvectorofpairs& pairs,
const std::string& parameters);
//! \brief Destructor must remove engine.
~STFEngine();
//! \brief Return actual engine.
......@@ -87,6 +122,11 @@ namespace stfinv {
//! \brief List engines currently recognized
static void help(std::ostream& os=std::cout);
private:
//! \brief initialize engine.
void initialize(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const stfinv::Tvectorofpairs& pairs,
const std::string& parameters);
//! \brief Pointer to actual engine.
stfinv::STFBaseEngine* Mengine;
}; // class STFEngine
......
......@@ -30,11 +30,12 @@
*
* REVISIONS and CHANGES
* - 06/05/2011 V1.0 Thomas Forbriger
* - 30/09/2011 V1.1 implemented handling of additional time series pairs
*
* ============================================================================
*/
#define STFINV_STFINVBASE_CC_VERSION \
"STFINV_STFINVBASE_CC V1.0 "
"STFINV_STFINVBASE_CC V1.1"
#define STFINV_STFINVBASE_CC_CVSID \
"$Id$"
......@@ -45,10 +46,30 @@
namespace stfinv {
STFBaseEngine::STFBaseEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const stfinv::Tvectorofpairs& pairs,
const std::string& parameters)
: Mtriples(triples), Mstf(stf), Mpairs(pairs),
Mweights(0,triples.size()-1)
{
this->initialize(parameters);
} // STFBaseEngine::STFBaseEngine(const stfinv::Tvectoroftriples& triples,
/*----------------------------------------------------------------------*/
STFBaseEngine::STFBaseEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const std::string& parameters)
: Mtriples(triples), Mstf(stf), Mweights(0,triples.size()-1)
{
Mpairs.clear();
this->initialize(parameters);
} // STFBaseEngine::STFBaseEngine(const stfinv::Tvectoroftriples& triples,
/*----------------------------------------------------------------------*/
void STFBaseEngine::initialize(const std::string& parameters)
{
this->parseparameters(parameters);
......@@ -80,17 +101,32 @@ namespace stfinv {
// align index ranges; first index will be zero
if (Mstf.series.first()!=0) { Mstf.series.shift(-Mstf.series.first()); }
stfinv::Tvectoroftriples::iterator I=Mtriples.begin();
while (I!=Mtriples.end())
{
if (I->data.first()!=0) { I->data.shift(-(I->data.first())); }
if (I->synthetics.first()!=0)
{ I->synthetics.shift(-(I->synthetics.first())); }
if (I->convolvedsynthetics.first()!=0)
{ I->convolvedsynthetics.shift(-(I->convolvedsynthetics.first())); }
++I;
} // while (I!=Mtriples.end())
} // STFBaseEngine::STFBaseEngine(const stfinv::Tvectoroftriples& triples,
stfinv::Tvectoroftriples::iterator I=Mtriples.begin();
while (I!=Mtriples.end())
{
if (I->data.first()!=0) { I->data.shift(-(I->data.first())); }
if (I->synthetics.first()!=0)
{ I->synthetics.shift(-(I->synthetics.first())); }
if (I->convolvedsynthetics.first()!=0)
{ I->convolvedsynthetics.shift(-(I->convolvedsynthetics.first())); }
++I;
} // while (I!=Mtriples.end())
}
{
stfinv::Tvectorofpairs::iterator I=Mpairs.begin();
while (I!=Mpairs.end())
{
if (I->synthetics.first()!=0)
{ I->synthetics.shift(-(I->synthetics.first())); }
if (I->convolvedsynthetics.first()!=0)
{ I->convolvedsynthetics.shift(-(I->convolvedsynthetics.first())); }
++I;
} // while (I!=Mpairs.end())
}
} // void STFBaseEngine::initialize(const std::string& parameters)
/*----------------------------------------------------------------------*/
......@@ -101,22 +137,42 @@ namespace stfinv {
STFINV_assert(Mstf.sampling.n==Mstf.series.size(),
"inconsistent number of samples");
const double tolerance=1.e-4;
stfinv::Tvectoroftriples::const_iterator I=Mtriples.begin();
while (I!=Mtriples.end())
{
CTripleHeader header=I->header;
STFINV_assert(header.sampling.n==n,
"inconsistent number of samples");
STFINV_assert(header.sampling.n==I->data.size(),
"inconsistent number of samples");
STFINV_assert(header.sampling.n==I->synthetics.size(),
"inconsistent number of samples");
STFINV_assert(header.sampling.n==I->convolvedsynthetics.size(),
"inconsistent number of samples");
STFINV_assert(std::abs(1.-header.sampling.dt/dt)<tolerance,
"inconsistent values of sampling interval");
++I;
} // while (I!=Mtriples.end())
stfinv::Tvectoroftriples::const_iterator I=Mtriples.begin();
while (I!=Mtriples.end())
{
CTripleHeader header=I->header;
STFINV_assert(header.sampling.n==n,
"inconsistent number of samples");
STFINV_assert(header.sampling.n==I->data.size(),
"inconsistent number of samples");
STFINV_assert(header.sampling.n==I->synthetics.size(),
"inconsistent number of samples");
STFINV_assert(header.sampling.n==I->convolvedsynthetics.size(),
"inconsistent number of samples");
STFINV_assert(std::abs(1.-header.sampling.dt/dt)<tolerance,
"inconsistent values of sampling interval");
++I;
} // while (I!=Mtriples.end())
}
{
stfinv::Tvectorofpairs::const_iterator I=Mpairs.begin();
while (I!=Mpairs.end())
{
CWaveformHeader sampling=I->sampling;
STFINV_assert(sampling.n==n,
"inconsistent number of samples");
STFINV_assert(sampling.n==I->synthetics.size(),
"inconsistent number of samples");
STFINV_assert(sampling.n==I->convolvedsynthetics.size(),
"inconsistent number of samples");
STFINV_assert(std::abs(1.-sampling.dt/dt)<tolerance,
"inconsistent values of sampling interval");
++I;
} // while (I!=Mpairs.end())
}
}
/*----------------------------------------------------------------------*/
......@@ -228,12 +284,36 @@ namespace stfinv {
/*----------------------------------------------------------------------*/
Tseries::Tcoc STFBaseEngine::series(const unsigned int& i) const
{
this->checkseriesindex(i);
return(Mpairs[i].synthetics);
}
/*----------------------------------------------------------------------*/
Tseries STFBaseEngine::convolvedseries(const unsigned int& i) const
{
this->checkseriesindex(i);
return(Mpairs[i].convolvedsynthetics);
}
/*----------------------------------------------------------------------*/
void STFBaseEngine::checkreceiverindex(const unsigned int& i) const
{
STFINV_assert(i<Mtriples.size(),
"ERROR: receiver index out of range");
}
/*----------------------------------------------------------------------*/
void STFBaseEngine::checkseriesindex(const unsigned int& i) const
{
STFINV_assert(i<Mpairs.size(),
"ERROR: series index out of range");
}
/*======================================================================*/
double WaveformTriple::offset() const
......
......@@ -30,6 +30,7 @@
*
* REVISIONS and CHANGES
* - 06/05/2011 V1.0 Thomas Forbriger
* - 30/09/2011 V1.1 implemented handling of additional time series pairs
*
* ============================================================================
*/
......@@ -38,7 +39,7 @@
#ifndef STFINV_STFINVBASE_H_VERSION
#define STFINV_STFINVBASE_H_VERSION \
"STFINV_STFINVBASE_H V1.0 "
"STFINV_STFINVBASE_H V1.1"
#define STFINV_STFINVBASE_H_CVSID \
"$Id$"
......@@ -58,6 +59,25 @@ namespace stfinv {
/*----------------------------------------------------------------------*/
/*! \brief A class to store the time series for a pair of time series.
* \ingroup cxxinterface
*/
struct WaveformPair {
/*! \brief Temporal sampling
*/
CWaveformHeader sampling;
/*! \brief Time series of synthetic data.
*/
Tseries::Tcoc synthetics;
/*! \brief Time series of convolved synthetic data.
* This will contain the synthetic data convolved with the obtained source
* time function as a result of a call to the library functions.
*/
Tseries convolvedsynthetics;
}; // class WaveformPair
/*----------------------------------------------------------------------*/
/*! \brief A class to store the time series for a waveform triple.
* \ingroup cxxinterface
*/
......@@ -101,7 +121,14 @@ namespace stfinv {
/*----------------------------------------------------------------------*/
/*! \brief List of triples.
/*! \brief Vector of pairs.
* \ingroup cxxinterface
*/
typedef std::vector<stfinv::WaveformPair> Tvectorofpairs;
/*----------------------------------------------------------------------*/
/*! \brief Vector of triples.
* \ingroup cxxinterface
*/
typedef std::vector<stfinv::WaveformTriple> Tvectoroftriples;
......@@ -171,6 +198,17 @@ namespace stfinv {
STFBaseEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const std::string& parameters);
/*! \brief Constructor.
* This constructor additionally takes a vector of time series pairs.
* In this vector references to synthetic time series data can be
* passed, which are not used in the process of determining the optimal
* source time function but which are convolved with the new source time
* function on the fly.
*/
STFBaseEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const stfinv::Tvectorofpairs& pairs,
const std::string& parameters);
public:
//! \brief abstract base requires virtual destructor