コード例 #1
0
ファイル: test_ModEM_model.py プロジェクト: zy911k24/mtpy
    def test_write_gocad_sgrid_file(self):

        if not os.path.exists(self._sgrid_fn):
            self._sgrid_fn = None

        output_fn = os.path.basename(self._sgrid_fn)

        # read data file to get centre position
        dObj = Data()
        dObj.read_data_file(data_fn=self._data_fn)

        # get centre coordinates
        centre = np.array([0., 0., 0.])
        centre[0] = dObj.center_point['east']
        centre[1] = dObj.center_point['north']

        # create a model object using the data object and read in gocad sgrid file
        mObj = Model(data_obj=dObj)
        mObj.read_model_file(model_fn=self._model_fn)
        mObj.save_path = self._output_dir
        mObj.write_gocad_sgrid_file(origin=centre,
                                    fn=os.path.join(self._output_dir,
                                                    output_fn[:-3]))

        output_data_file = os.path.normpath(
            os.path.join(self._output_dir, output_fn))

        self.assertTrue(os.path.isfile(output_data_file),
                        "output data file not found")

        expected_data_file = os.path.normpath(self._sgrid_fn)

        self.assertTrue(
            os.path.isfile(expected_data_file),
            "Ref output data file does not exist, nothing to compare with")

        is_identical, msg = diff_files(output_data_file, expected_data_file)
        print(msg)
        self.assertTrue(
            is_identical,
            "The output file is not the same with the baseline file.")
コード例 #2
0
ファイル: ModEM_to_gocad.py プロジェクト: zy911k24/mtpy
@author: Alison Kirkby

create modem input files

"""

import os.path as op
import os
os.chdir(r'C:/mtpywin/mtpy'
         )  # change to the directory where your mtpy is installed to
# ensure you are using the correct mtpy

from mtpy.modeling.modem import Model
import numpy as np

# path to save to
wd = r'C:\mtpywin\mtpy\examples\model_files\ModEM_2'

# provide centre position of model in real world coordinates (eastings/northings)
centre = np.array([0., 0., 0.])

# modem .rho file
iterfn = 'Modular_MPI_NLCG_004.rho'

moo = Model(model_fn=op.join(wd, iterfn))
moo.read_model_file()
moo.write_gocad_sgrid_file(
    origin=centre,
    fn=r'C:\test\ModEM\ModEM_output.sg'  # filename to save to, optional
    # saves in model directory if not provided
)