diff --git a/SimPEG/Examples/Linear.py b/SimPEG/Examples/Linear.py index 931af126..3fa02c11 100644 --- a/SimPEG/Examples/Linear.py +++ b/SimPEG/Examples/Linear.py @@ -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) diff --git a/SimPEG/Problem.py b/SimPEG/Problem.py index 803f77c0..671dc60e 100644 --- a/SimPEG/Problem.py +++ b/SimPEG/Problem.py @@ -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.""" diff --git a/SimPEG/Survey.py b/SimPEG/Survey.py index bc297fcb..206c8be3 100644 --- a/SimPEG/Survey.py +++ b/SimPEG/Survey.py @@ -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 diff --git a/docs/api_Mesh.rst b/docs/api_Mesh.rst index c947a3fe..c698cf67 100644 --- a/docs/api_Mesh.rst +++ b/docs/api_Mesh.rst @@ -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.