make synthetic data.

This commit is contained in:
rowanc1
2014-05-16 21:49:24 -07:00
parent 5f2bfbfb77
commit 18f0e61780
4 changed files with 34 additions and 28 deletions
+7 -1
View File
@@ -44,7 +44,9 @@ def run(N, plotIt=True):
mtrue[mesh.vectorCCx > 0.6] = 0
prob = LinearProblem(mesh, G)
survey = prob.createSyntheticSurvey(mtrue, std=0.01)
survey = LinearSurvey()
survey.pair(prob)
survey.makeSyntheticData(mtrue, std=0.01)
M = prob.mesh
@@ -68,5 +70,9 @@ def run(N, plotIt=True):
plt.figure(2)
plt.plot(M.vectorCCx, survey.mtrue, 'b-')
plt.plot(M.vectorCCx, mrec, 'r-')
plt.show()
return prob, survey, mesh, mrec
if __name__ == '__main__':
run(100)
-23
View File
@@ -117,29 +117,6 @@ class BaseProblem(object):
"""
raise NotImplementedError('fields is not yet implemented.')
def createSyntheticSurvey(self, m, std=0.05, u=None, **survey_kwargs):
"""
Create synthetic survey given a model, and a standard deviation.
:param numpy.array m: geophysical model
:param numpy.array std: standard deviation
:param numpy.array u: fields for the given model (if pre-calculated)
:param numpy.array survey_kwargs: Keyword arguments for initiating the survey.
:rtype: SurveyObject
:return: survey
Returns the observed data with random Gaussian noise
and Wd which is the same size as data, and can be used to weight the inversion.
"""
survey = self.surveyPair(mtrue=m, **survey_kwargs)
survey.pair(self)
survey.dtrue = survey.dpred(m, u=u)
noise = std*abs(survey.dtrue)*np.random.randn(*survey.dtrue.shape)
survey.dobs = survey.dtrue+noise
survey.std = survey.dobs*0 + std
return survey
class BaseTimeProblem(BaseProblem):
"""Sets up that basic needs of a time domain problem."""
+17
View File
@@ -641,6 +641,23 @@ class BaseSurvey(object):
"Check if the data is synthetic."
return self.mtrue is not None
def makeSyntheticData(self, m, std=0.05, u=None):
"""
Make synthetic data given a model, and a standard deviation.
:param numpy.array m: geophysical model
:param numpy.array std: standard deviation
:param numpy.array u: fields for the given model (if pre-calculated)
"""
if getattr(self, 'dobs', None) is not None:
raise Exception('Survey already has dobs.')
self.mtrue = m
self.dtrue = self.dpred(m, u=u)
noise = std*abs(self.dtrue)*np.random.randn(*self.dtrue.shape)
self.dobs = self.dtrue+noise
self.std = self.dobs*0 + std
#TODO: Move this to the survey class?
# @property
+10 -4
View File
@@ -176,9 +176,9 @@ and sizes of padding. See the example below, that follows this
notation::
h1 = (
(numPad, sizeStart [, increaseFactor]),
(numCore, sizeCode),
(numPad, sizeStart [, increaseFactor])
(cellSize, numPad, [, increaseFactor]),
(cellSize, numCore),
(cellSize, numPad, [, increaseFactor])
)
.. plot::
@@ -186,9 +186,15 @@ notation::
from SimPEG import Mesh, Utils
h1 = [(10, 5, -1.3), (5, 20), (10, 3, 1.3)]
M = Mesh.TensorMesh([h1, h1])
M = Mesh.TensorMesh([h1, h1], x0='CN')
M.plotGrid(showIt=True)
.. note::
You can center your mesh by passing a 'C' for the x0[i] position.
A 'N' will make the entire mesh negative, and a '0' (or a 0) will
make the mesh start at zero.
Hopefully, you now know how to create TensorMesh objects in SimPEG,
and by extension you are also familiar with how to create and use
other types of meshes in this SimPEG framework.