4 #include <boost/bind.hpp>
5 #include <boost/cast.hpp>
18 C1DRecObjective::C1DRecObjective(boost::shared_ptr<const SeismicDataComp> TheRecData,
19 int myshift,
double mysigma,
double myc,
double myslowness,
21 RecCalculator(myshift, mysigma, myc, true, method), ObservedData(TheRecData)
24 slowness = myslowness;
30 endpoint = ObservedData->GetData().size();
33 const double recmaxamp = *max_element(ObservedData->GetData().begin(),
34 ObservedData->GetData().end());
35 const bool isone = fcmp(recmaxamp, 1.0, 1e-4) == 0;
36 if (isone && !normalized)
38 "Input data has maximum amplitude of 1, but no normalization used");
39 if (!isone && normalized)
41 "Input data does not have an amplitude of 1, but normalization is used");
50 PlottableObjective(Old), RecSynthData(Old.RecSynthData), slowness(Old.slowness), Model(
51 Old.Model), RecCalculator(Old.RecCalculator), errorlevel(Old.errorlevel), errorvalue(
52 Old.errorvalue), poisson(Old.poisson), startpoint(Old.startpoint), endpoint(
53 Old.endpoint), ObservedData(Old.ObservedData)
62 startpoint = max(boost::numeric_cast<size_t>(0),
63 boost::numeric_cast<size_t>(
64 (start - ObservedData->GetB()) / ObservedData->GetDt()));
67 boost::numeric_cast<size_t>(
68 (end - ObservedData->GetB()) / ObservedData->GetDt()),
69 ObservedData->GetData().size());
71 if (endpoint < startpoint)
73 "Start index " + stringify(startpoint) +
" and end index "
74 + stringify(endpoint) +
" do not make sense !");
82 RecSynthData = source.RecSynthData;
83 slowness = source.slowness;
85 RecCalculator = source.RecCalculator;
86 poisson = source.poisson;
87 errorlevel = source.errorlevel;
88 errorvalue = source.errorvalue;
89 startpoint = source.startpoint;
90 endpoint = source.endpoint;
91 ObservedData = source.ObservedData;
97 const unsigned int nfulllayers = member.size() / 2;
100 ttranscribed thickness(nfulllayers), velocity(nfulllayers);
101 copy(member.begin(), member.begin() + nfulllayers, thickness.begin());
102 copy(member.begin() + nfulllayers, member.begin() + 2 * nfulllayers,
105 const unsigned int ncolllayers = velocity.size();
106 Model.
Init(ncolllayers);
107 copy(thickness.begin(), thickness.end(), Model.
SetThickness().begin());
108 copy(velocity.begin(), velocity.end(), Model.
SetSVelocity().begin());
109 transform(velocity.begin(), velocity.end(), Model.
SetDensity().begin(),
111 transform(velocity.begin(), velocity.end(),
112 Model.
SetPVelocity().begin(), boost::bind(multiplies<double>(), _1, poisson));
113 Model.
SetDt(ObservedData->GetDt());
114 Model.
SetNpts(ObservedData->GetData().size());
121 SetMisfit().resize(endpoint - startpoint);
123 double returnvalue = 0.0;
125 for (
int i = startpoint; i < endpoint; ++i)
131 returnvalue +=
CalcMisfit(ObservedData->GetData().at(i),
132 RecSynthData.
GetData().at(i), errorvalue, 0.0, i - startpoint);
trfmethod
There are several ways to calculate receiver functions.
ublas::vector< double > ttranscribed
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
void SynthSafeParallel(const std::string &filename, ResPkModel &Model, SeismicDataComp &Receiver, const bool cleanfiles=false)
All operations that are safe to execute in parallel.
virtual double PostParallel(const ttranscribed &member)
We also clean up files serially.
trealdata & SetDensity()
Read-write access to the vector of densities in g/cm^3 in each layer.
Calculate density from a given S-velocity, the formula is taken from Owen et al. JGR 89...
This only adds a few plotting functions to GeneralObjective to define a common interface.
C1DRecObjective(const C1DRecObjective &Old)
void SetNormalize(const bool what)
Change whether the output receiver function is normalized to a maximum amplitude of 1...
void SynthPostParallel(const std::string &filename, ResPkModel &Model, SeismicDataComp &Receiver, const bool cleanfiles=false)
Operations of the synthetic receiver function calculation that are not safe in parallel and hafe to b...
void CopyHeader(const SeismicDataComp &source)
Copy the information in the header from another object.
int GetFitExponent()
Get the Fit exponent.
void SetErrorLevel(const double level)
Set the errorlevel for fit, this is relative to the maximum amplitude, not for each individual data p...
trealdata & SetThickness()
Read-write access to the vector of thicknesses in km in each layer.
double CalcMisfit(const double measured, const double predicted, const double measerror, const double errorlevel, const int index)
void SetNpts(const unsigned int s)
Set the number of points for synthetic seismogram calculation.
virtual ~C1DRecObjective()
trealdata & SetPVelocity()
Read-write access to the vector of P-velocities in km/s in each layer.
void SynthPreParallel(const std::string &filename, ResPkModel &Model, SeismicDataComp &Receiver, const bool cleanfiles=false)
The three Synth*Parallel methods provide alternative acces to the steps in CalcRecSynth for safe para...
const std::string & GetParallelID()
Derived classes need to read the ParallelId for their forward calculations.
double GetRMS()
Get the current RMS.
void Init(const int nlayers)
Init provides a convenient way to allocate memory in all structures for a given number of layers...
trealdata & SetSVelocity()
Read-write access to the vector of S-velocities in km/s in each layer.
tdata & SetSynthData()
Only derived classes can write access the Synthetic data.
virtual void SafeParallel(const ttranscribed &member)
Calculate the misfit between the data calculated from model vector member and measured data given in ...
tmisfit & SetMisfit()
Only derived classes can write access the Misfit.
void SetInputWave(WaveType w)
virtual void PreParallel(const ttranscribed &member)
We have to write runfiles before parallel execution.
PlottableObjective & operator=(const PlottableObjective &source)
Calculate the misfit between observed receiver function for a given 1D model by calculating a synthet...
C1DRecObjective & operator=(const C1DRecObjective &source)
void CollapseModel(ttranscribed &Thickness, ttranscribed &ParmValue)
Remove layers with identical parameters from the model and collapse them into a single layer each...
void SetTimeWindow(const double start, const double end)
Set the time window used for misfit calculations, start and end are in seconds.
void SetRMS(const double x)
void SetDt(const double s)
Set the time between two samples in s, this is for synthetic forward calculations.
The basic exception class for all errors that arise in gplib.
void SetSlowness(const double s)
Set the slowness in s/km for the synthetic forward calculation.