GPLIB++
C1DRecObjective.h
Go to the documentation of this file.
1 #ifndef C1DRECOBJECTIVE_H
2 #define C1DRECOBJECTIVE_H
3 #include "PlottableObjective.h"
4 #include "RecCalc.h"
5 #include "SeismicDataComp.h"
6 #include <boost/shared_ptr.hpp>
7 #include <numeric>
8 #include <algorithm>
9 namespace gplib
10  {
11  //! Calculate the misfit between observed receiver function for a given 1D model by calculating a synthetic receiver function from that model
12  /*! The constructor takes a few essential parameters that are expected not to change during the
13  * program (in most cases inversion), e.g. the data to fit. See also #C1DRecObjective for the necessary
14  * constructor parameters.
15  *
16  * There are two ways to calculate the Misfit for a given model, either calling GeneralObjective#CalcPerformance,
17  * or, for parallel programs, calling the three function PreParallel, SafeParallel and PostParallel in that order.
18  * In both cases you have to give the parameter #member, which is a ::ttranscribed of size 2n, where
19  * n is the number of layers of the model. The first n entries are the layer thicknesses in km and the last n entries
20  * are the S-wave velocities in km/s. Densities and P-Wave velocities are calculated from S-Velocities by hard-coded relationships.
21  */
23  {
24  private:
25  //! The object holding the calculated synthetic data
26  SeismicDataComp RecSynthData;
27  //! The slowness used in the calculation
28  double slowness;
29  //! The object holding the 1D model for forward calculation
30  ResPkModel Model;
31  //! The object used to calculate the synthetics
32  RecCalc RecCalculator;
33  //! The relative errorfloor
34  double errorlevel;
35  //! The absolute errorfloor is calculated from the relative errorfloor
36  double errorvalue;
37  //! Poisson's ratio vp/vs, this might become part of the model
38  double poisson;
39  //! We might not want to use the whole receiver function for misfit calculation, the startpoint is calculated from the starttime in SetTimeWindow
40  int startpoint;
41  //! We might not want to use the whole receiver function for misfit calculation, the endpoint is calculated from the endtime in SetTimeWindow
42  int endpoint;
43  //! The measured data is stored in a shared pointer.
44  /*! For parallel implementations we often work with several instances of this
45  * class that all work with the same ObservedData. To save memory we use a shared_pointer
46  * and to avoid collisions SeismicDataComp is const */
47  boost::shared_ptr<const SeismicDataComp> ObservedData;
48  protected:
50  {
51  return *ObservedData;
52  }
53  public:
54  //! return a pointer to a copy of the current object
55  virtual C1DRecObjective *clone() const
56  {
57  return new C1DRecObjective(*this);
58  }
59  //! Set the time window used for misfit calculations, start and end are in seconds
60  void SetTimeWindow(const double start, const double end);
61  //! Set the errorlevel for fit, this is relative to the maximum amplitude, not for each individual data point
62  void SetErrorLevel(const double level)
63  {
64  errorlevel = level;
65  const double recmaxamp = *std::max_element(ObservedData->GetData().begin(),
66  ObservedData->GetData().end());
67  // we specify the error relative to the maximum amplitude
68  //this is usually the initial correlation peak
69  // here we calculate its value
70  errorvalue = errorlevel * recmaxamp;
71  }
72  //! Set poisson's ratio, at the moment the same for all layers, used for calculating P-velocity
73  void SetPoisson(const double ratio)
74  {
75  poisson = ratio;
76  }
77  //! Write the synthetic data to a sac file with name filename, makes only sense after calculating the misfit
78  virtual void WriteData(const std::string &filename)
79  {
80  RecSynthData.WriteAsSac(filename);
81  }
82  //! Write the current model to ascii file for calculations
83  void WriteModel(const std::string &filename)
84  {
85  Model.WriteModel(filename);
86  }
87  //! Write the current model to ascii file for plotting
88  void WritePlot(const std::string &filename)
89  {
90  Model.WritePlot(filename);
91  }
92  //! We have to write runfiles before parallel execution
93  virtual void PreParallel(const ttranscribed &member);
94  //! We also clean up files serially
95  virtual double PostParallel(const ttranscribed &member);
96  //! Calculate the misfit between the data calculated from model vector member and measured data given in the constructor.
97  virtual void SafeParallel(const ttranscribed &member);
98  C1DRecObjective(const C1DRecObjective &Old);
100  //! The constructor needs a few essential parameters
101  /*! @param TheRecData Shared pointer to the measured receiver function
102  * @param myshift the time shift used for calculating the measured receiver function
103  * @param mysigma sigma used for calculating the measured receiver function
104  * @param myc water level used for calculating the measured receiver function
105  * @param myslowness slowness used for calculating the measured receiver function
106  * @param method The method used to calculate the observed data. Can be specdiv or iterdecon
107  * @param normalized Is the measured data normalized to an initial correlation peak of 1
108  * @param InWave Is the incoming plane wave a p-wave or a s-wave
109  */
110  C1DRecObjective(boost::shared_ptr<const SeismicDataComp> TheRecData, int myshift,
111  double mysigma, double myc, double myslowness, RecCalc::trfmethod method =
112  RecCalc::specdiv, bool normalized = true, ResPkModel::WaveType InWave =
114 
115  virtual ~C1DRecObjective();
116  friend class AbsVelRecObjective;
117  };
118  }
119 #endif // C1DRECOBJECTIVE_H
trfmethod
There are several ways to calculate receiver functions.
Definition: RecCalc.h:18
This class is used to calculate receiver functions from seismic data.
Definition: RecCalc.h:14
ublas::vector< double > ttranscribed
Definition: gentypes.h:21
virtual double PostParallel(const ttranscribed &member)
We also clean up files serially.
void WritePlot(const std::string &filename)
Write out an ascii file for plotting with xmgrace etc.
This only adds a few plotting functions to GeneralObjective to define a common interface.
void WritePlot(const std::string &filename)
Write the current model to ascii file for plotting.
C1DRecObjective(const C1DRecObjective &Old)
virtual C1DRecObjective * clone() const
return a pointer to a copy of the current object
void SetErrorLevel(const double level)
Set the errorlevel for fit, this is relative to the maximum amplitude, not for each individual data p...
virtual void WriteData(const std::string &filename)
Write the synthetic data to a sac file with name filename, makes only sense after calculating the mis...
const SeismicDataComp & GetObservedData()
virtual void SafeParallel(const ttranscribed &member)
Calculate the misfit between the data calculated from model vector member and measured data given in ...
void WriteModel(const std::string &filename)
Write the current model to ascii file for calculations.
This objective function calculates the weighted misfit for a receiver function and the corresponding ...
void SetPoisson(const double ratio)
Set poisson's ratio, at the moment the same for all layers, used for calculating P-velocity.
virtual void PreParallel(const ttranscribed &member)
We have to write runfiles before parallel execution.
virtual void WriteModel(const std::string filename)
Write the model in its native format to a file.
Definition: ResPkModel.cpp:55
Calculate the misfit between observed receiver function for a given 1D model by calculating a synthet...
C1DRecObjective & operator=(const C1DRecObjective &source)
void SetTimeWindow(const double start, const double end)
Set the time window used for misfit calculations, start and end are in seconds.
This class stores and writes model for the respktn 1D seismic code that we use for receiver function ...
Definition: ResPkModel.h:18
int WriteAsSac(const std::string &filename) const
Write the data in sac binary format.