Пример #1
0
    def _test_func(self):
        if not os.path.isdir(edi_path):
            # input file does not exist, skip test after remove the output dir
            os.rmdir(self._output_dir)
            self.skipTest("edi path does not exist: {}".format(edi_path))

        # generate data
        edi_list = glob.glob(edi_path + '/*.edi')
        period_list = EdiCollection(edi_list).select_periods()

        datob = Data(edi_list=edi_list,
                     inv_mode='1',
                     period_list=period_list,
                     epsg=epsg_code,
                     error_type_tipper='abs',
                     error_type_z='egbert',
                     comp_error_type=None,
                     error_floor=10)
        datob.write_data_file(save_path=self._output_dir)

        # create mesh grid model object
        model = Model(
            stations_object=datob.station_locations,
            Data=datob,
            epsg=epsg_code,
            cell_size_east=10000,
            cell_size_north=10000,  # GA_VIC
            pad_north=
            8,  # number of padding cells in each of the north and south directions
            pad_east=8,  # number of east and west padding cells
            pad_z=8,  # number of vertical padding cells
            pad_stretch_v=
            1.5,  # factor to increase by in padding cells (vertical)
            pad_stretch_h=
            1.5,  # factor to increase by in padding cells (horizontal)
            n_air_layers=
            0,  # number of air layers 0, 10, 20, depend on topo elev height
            res_model=
            100,  # halfspace resistivity value for initial reference model
            n_layers=50,  # total number of z layers, including air and pad_z
            z1_layer=50,  # first layer thickness metres, depend
            z_target_depth=500000)
        model.make_mesh(
        )  # the data file will be re-write in this method. No topo elev file used yet
        model.plot_mesh()
        model.plot_mesh_xy()
        model.plot_mesh_xz()

        # write a model file and initialise a resistivity model
        model.write_model_file(save_path=self._output_dir)
Пример #2
0
    def test_func(self):
        if not os.path.isdir(edi_path):
            # input file does not exist, skip test after remove the output dir
            os.rmdir(self._output_dir)
            self.skipTest("edi path does not exist: {}".format(edi_path))

        edi_list = glob.glob(edi_path + '/*.edi')
        period_list = EdiCollection(edi_list).select_periods()
        datob = Data(edi_list=edi_list,
                     inv_mode='1',
                     period_list=period_list,
                     epsg=epsg_code,
                     error_type_tipper=error_type_tipper,
                     error_type_z=error_type_z,
                     comp_error_type=comp_error_type,
                     error_floor=10)
        datob.write_data_file(save_path=self._output_dir)

        # check the output
        if self._expected_output_dir:
            output_data_file = os.path.normpath(os.path.join(self._output_dir, "ModEM_Data.dat"))
            self.assertTrue(os.path.isfile(output_data_file), "output data file does not exist")
            expected_data_file = os.path.normpath(os.path.join(self._expected_output_dir,
                                                               "ModEM_Data.dat"))
            self.assertTrue(
                os.path.isfile(expected_data_file),
                "expected output data file does not exist, nothing to compare"
            )

            print("\ncomparing", output_data_file, "and", expected_data_file)
            with open(output_data_file, 'r') as output:
                with open(expected_data_file, 'r') as expected:
                    diff = difflib.unified_diff(
                        expected.readlines(),
                        output.readlines(),
                        fromfile='expected',
                        tofile='output'
                    )
                    count = 0
                    for line in diff:
                        sys.stdout.write(line)
                        count += 1
                    self.assertTrue(count == 0, "output different!")
        else:
            print("no expected output exist, nothing to compare")
    # can supply a 2 x 2 array for each component or a single value
    error_value_z=np.array([
        [20., 5.],  # error floor value in percent
        [5., 20.]
    ]),  # can supply a 2 x 2 array for each component or a single value
    error_type_tipper='floor_abs',  # type of error to set in tipper, 
    # floor_abs is an absolute value set as a floor
    error_value_tipper=.03,
    model_epsg=28354  # model epsg, currently set to utm zone 54. 
    # See http://spatialreference.org/ to find the epsg code for your projection
)

# Unlike when writing topography from a file, don't modify the
#  elevation of the Data object as we need the station elevations
#  to create surface model.
do.write_data_file()

# create model file
mo = Model(
    station_locations=do.station_locations,
    cell_size_east=8000,
    cell_size_north=8000,
    pad_north=
    7,  # number of padding cells in each of the north and south directions
    pad_east=7,  # number of east and west padding cells
    pad_z=6,  # number of vertical padding cells
    pad_stretch_v=1.6,  # factor to increase by in padding cells (vertical)
    pad_stretch_h=1.4,  # factor to increase by in padding cells (horizontal)
    pad_num=
    3,  # number of constant-width cells to add to outside of model before padding cells start 
    # this number is currently multiplied by 1.5 internally
Пример #4
0
    def test_fun(self):

        edipath = EDI_DATA_DIR  # path where edi files are located

        # period list (will not include periods outside of the range of the edi file)
        start_period = -2
        stop_period = 3
        n_periods = 17
        period_list = np.logspace(start_period, stop_period, n_periods)

        # list of edi files, search for all files ending with '.edi'
        edi_list = [
            os.path.join(edipath, ff) for ff in os.listdir(edipath)
            if (ff.endswith('.edi'))
        ]

        do = Data(
            edi_list=edi_list,
            inv_mode='1',
            save_path=self._output_dir,
            period_list=period_list,
            error_type_z='floor_egbert',
            error_value_z=5,
            error_type_tipper='floor_abs',
            error_value_tipper=.03,
            model_epsg=28354  # model epsg, currently set to utm zone 54
        )
        do.write_data_file()
        do.data_array['elev'] = 0.
        do.write_data_file(fill=False)

        # create model file
        mo = Model(
            station_locations=do.station_locations,
            cell_size_east=500,
            cell_size_north=500,
            pad_north=
            7,  # number of padding cells in each of the north and south directions
            pad_east=7,  # number of east and west padding cells
            pad_z=6,  # number of vertical padding cells
            pad_stretch_v=
            1.6,  # factor to increase by in padding cells (vertical)
            pad_stretch_h=
            1.4,  # factor to increase by in padding cells (horizontal)
            n_air_layers=10,  # number of air layers
            res_model=100,  # halfspace resistivity value for reference model
            n_layers=90,  # total number of z layers, including air
            z1_layer=10,  # first layer thickness
            pad_method='stretch',
            z_target_depth=120000)

        mo.make_mesh()
        mo.write_model_file(save_path=self._output_dir)

        # add topography to res model
        mo.add_topography_to_model2(AUS_TOPO_FILE)
        # mo.add_topography_to_model2(r'E:/Data/MT_Datasets/concurry_topo/AussieContinent_etopo1.asc')
        mo.write_model_file(save_path=self._output_dir)

        do.project_stations_on_topography(mo)

        co = Covariance()
        co.write_covariance_file(model_fn=mo.model_fn)

        for afile in ("ModEM_Data.dat", "covariance.cov",
                      "ModEM_Model_File.rho"):
            output_data_file = os.path.normpath(
                os.path.join(self._output_dir, afile))

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

            expected_data_file = os.path.normpath(
                os.path.join(self._expected_output_dir, afile))

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

            # print ("Comparing", output_data_file, "and", expected_data_file)

            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.")
Пример #5
0
               inv_mode = '1',
               save_path=workdir,
               period_list=period_list,
               period_buffer = 2, # factor to stretch interpolation by. For example: if period_buffer=2
                                 # then interpolated data points will only be included if they are
                                 # within a factor of 2 of a true data point
               error_type_z='floor_egbert', # error type (egbert is % of sqrt(zxy*zyx))
                                            # floor means apply it as an error floor
               error_value_z=5, # error floor (or value) in percent
               error_type_tipper = 'floor_abs', # type of error to set in tipper, 
                                                # floor_abs is an absolute value set as a floor
               error_value_tipper =.03,
               model_epsg=28354 # model epsg, currently set to utm zone 54. 
                                # See http://spatialreference.org/ to find the epsg code for your projection
               )
do.write_data_file()
do.data_array['elev'] = 0.
do.write_data_file(fill=False)

# create model file
mo = Model(stations_object=do.stations_obj,
                cell_size_east=8000,
                cell_size_north=8000,
                pad_north=7, # number of padding cells in each of the north and south directions
                pad_east=7,# number of east and west padding cells
                pad_z=6, # number of vertical padding cells
                pad_stretch_v=1.6, # factor to increase by in padding cells (vertical)
                pad_stretch_h=1.4, # factor to increase by in padding cells (horizontal)
                n_air_layers = 10, #number of air layers
                res_model=100, # halfspace resistivity value for reference model
                n_layers=100, # total number of z layers, including air
Пример #6
0
:author: Jared Peacock

:license: MIT

"""

from mtpy.modeling.modem import Data

dfn = r"c:\Users\jpeacock\OneDrive - DOI\Geothermal\GreatBasin\modem_inv\inv_02\gb_modem_data_z03_t02_edits.dat"

new_fns = [
    r"c:\Users\jpeacock\OneDrive - DOI\Geothermal\GreatBasin\modem_inv\inv_02\edi_files\AVG055.edi",
    r"c:\Users\jpeacock\OneDrive - DOI\Geothermal\GreatBasin\modem_inv\inv_02\edi_files\AVG056.edi",
    r"c:\Users\jpeacock\OneDrive - DOI\Geothermal\GreatBasin\modem_inv\inv_02\edi_files\SP05.edi",
    r"c:\Users\jpeacock\OneDrive - DOI\Geothermal\GreatBasin\modem_inv\inv_02\edi_files\USArray.CAM02.2010.edi",
    r"c:\Users\jpeacock\OneDrive - DOI\Geothermal\GreatBasin\modem_inv\inv_02\edi_files\USArray.CAM06.2010.edi",
]

d = Data()
d.read_data_file(dfn)
d.error_type_z = "eigen_floor"
d.error_value_z = 0.03
d.error_type_tipper = "abs_floor"
d.error_value_tipper = 0.02
d.model_epsg = 32611
d.data_array, d.mt_dict = d.add_station(fn=new_fns)

d.write_data_file(fn_basename="gb_modem_data_z03_t02_add.dat",
                  compute_error=False,
                  fill=False)
Пример #7
0
    def test_fun_rotate(self):
        # set the dir to the output from the previously correct run
        self._expected_output_dir = os.path.join(SAMPLE_DIR, 'ModEM_rotate40')

        edipath = EDI_DATA_DIR2

        # example to specify a number of periods per decade
        start_period = 0.002
        stop_period = 2000
        periods_per_decade = 4
        period_list = get_period_list(start_period,
                                      stop_period,
                                      periods_per_decade,
                                      include_outside_range=True)

        # list of edi files, search for all files ending with '.edi'
        edi_list = [
            os.path.join(edipath, ff) for ff in os.listdir(edipath)
            if (ff.endswith('.edi'))
        ]

        do = Data(
            edi_list=edi_list,
            inv_mode='1',
            save_path=self._output_dir,
            period_list=period_list,
            period_buffer=
            2,  # factor to stretch interpolation by. For example: if period_buffer=2
            # then interpolated data points will only be included if they are
            # within a factor of 2 of a true data point
            error_type_z=
            'floor_egbert',  # error type (egbert is % of sqrt(zxy*zyx))
            # floor means apply it as an error floor
            error_value_z=5,  # error floor (or value) in percent
            error_type_tipper='floor_abs',  # type of error to set in tipper, 
            # floor_abs is an absolute value set as a floor
            error_value_tipper=.03,
            rotation_angle=40,
            model_epsg=28354  # model epsg, currently set to utm zone 54. 
            # See http://spatialreference.org/ to find the epsg code for your projection
        )
        do.write_data_file()
        do.data_array['elev'] = 0.
        do.write_data_file(fill=False)

        # mesh rotation angle is the opposite direction to the rotation of the stations
        if do.rotation_angle == 0:
            mesh_rotation_angle = 0
        else:
            mesh_rotation_angle = -do.rotation_angle

        # create model file
        mo = Model(
            stations_object=do.station_locations,
            cell_size_east=8000,
            cell_size_north=8000,
            pad_north=
            7,  # number of padding cells in each of the north and south directions
            pad_east=7,  # number of east and west padding cells
            pad_z=6,  # number of vertical padding cells
            pad_stretch_v=
            1.6,  # factor to increase by in padding cells (vertical)
            pad_stretch_h=
            1.4,  # factor to increase by in padding cells (horizontal)
            n_air_layers=10,  #number of air layers
            res_model=100,  # halfspace resistivity value for reference model
            n_layers=100,  # total number of z layers, including air
            z1_layer=10,  # first layer thickness
            pad_method='stretch',  # method for calculating padding
            z_mesh_method='new',
            z_target_depth=
            120000,  # depth to bottom of core model (padding after this depth)
            mesh_rotation_angle=mesh_rotation_angle)

        mo.make_mesh()
        mo.write_model_file(save_path=self._output_dir)

        # add topography to res model
        mo.add_topography_to_model2(AUS_TOPO_FILE)
        mo.write_model_file(save_path=self._output_dir)

        co = Covariance()
        co.smoothing_east = 0.4
        co.smoothing_north = 0.4
        co.smoothing_z = 0.4
        co.write_covariance_file(model_fn=mo.model_fn)

        for afile in ("ModEM_Data.dat", "covariance.cov",
                      "ModEM_Model_File.rho"):
            output_data_file = os.path.normpath(
                os.path.join(self._output_dir, afile))

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

            expected_data_file = os.path.normpath(
                os.path.join(self._expected_output_dir, afile))

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

            # print ("Comparing", output_data_file, "and", expected_data_file)

            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.")
Пример #8
0
east_mc = east_mc.dataframe.query("ID not in @frg_avg_sites")

# add average files
avg_path = Path(
    r"c:\Users\jpeacock\OneDrive - DOI\Geothermal\GreatBasin\modem_inv\canv_01\new_edis"
)
fn_list = [avg_path.joinpath(f"AVG{ii}.edi") for ii in range(215, 225)]

# add all the eastern files
fn_list += east_mc.fn.to_list()

new_df = mc.dataframe.query("ID in @new_stations")
fn_list += new_df.fn.to_list()

d = Data()
d.read_data_file(dfn)
d.error_value_z = 3.0
d.error_type_tipper = "abs_floor"
d.error_value_tipper = 0.02

d.data_array, d.mt_dict = d.add_station(fn_list)

d.write_data_file(
    fn_basename="gb_modem_data_z03_t02.dat",
    save_path=
    r"c:\Users\jpeacock\OneDrive - DOI\Geothermal\GreatBasin\modem_inv\gb_01",
    compute_error=False,
    fill=False,
)
Пример #9
0
    # eo = mtedi.Edi(edi_list[0])  # this may miss some periods?
    # period_list = 1. / eo.Z.freq # period_list = np.logspace(-3,3)

    print("edi_list = {}".format(edi_list))
    period_list = EdiCollection(edi_list).select_periods()

    datob = Data(edi_list=edi_list,
                 inv_mode='1',
                 period_list=period_list,
                 epsg=epsg_code,
                 error_type='floor',
                 error_floor=10)
    # period_buffer=0.000001)

    datob.write_data_file(save_path=outputdir)

    # create mesh grid model object
    # model = Model(Data=datob,
    model = Model(
        station_object=datob.station_locations,
        epsg=epsg_code,  # epsg
        # cell_size_east=500, cell_size_north=500,  # concurry
        cell_size_east=10000,
        cell_size_north=10000,  #GA_VIC
        # cell_size_east=1000, cell_size_north=1000, # Concurry
        cell_number_ew=120,
        cell_number_ns=100,  # option to specify cell numbers
        pad_north=
        8,  # number of padding cells in each of the north and south directions
        pad_east=8,  # number of east and west padding cells
Пример #10
0
def build_modem_inputfiles(edi_path, output_path):
    """
    For a given se to edi files in edi_path, build the ModEM input files into output_path
    :param edi_path: # path where edi files are located r'C:\mtpywin\mtpy\examples\data\edi_files_2'
    :param output_path: # path to save to  r'C:\test\ModEM'
    :return:
    """

    # not nece os.chdir(r'C:\mtpywin\mtpy')  # change this path to the path where mtpy is installed

    ## period list (won't include periods outside of the range of the edi file) ###
    ## comment/uncomment your desired method ######################################
    ###############################################################################

    ## example to specify start, stop and total number of periods
    # start_period = 0.001
    # stop_period = 1000
    # n_periods = 25
    # period_list = np.logspace(np.log10(start_period),
    #                          np.log10(stop_period),
    #                          n_periods)

    # example to specify a number of periods per decade
    start_period = 0.002
    stop_period = 2000
    periods_per_decade = 4
    period_list = get_period_list(start_period,
                                  stop_period,
                                  periods_per_decade,
                                  include_outside_range=True)

    ## an example to use the periods from a particular edi file
    # edifile_periods = op.join(edipath,'Synth00.edi')
    # eobj = Edi(edifile_periods)
    # period_list = 1./eobj.freq

    ###############################################################################
    workdir = output_path
    edipath = edi_path
    # list of edi files, search for all files ending with '.edi'
    edi_list = [
        op.join(edipath, ff) for ff in os.listdir(edipath)
        if (ff.endswith('.edi'))
    ]

    # make the save path if it doesn't exist
    if not op.exists(workdir):
        os.mkdir(workdir)

    do = Data(
        edi_list=edi_list,
        inv_mode='1',
        save_path=workdir,
        period_list=period_list,
        period_buffer=
        2,  # factor to stretch interpolation by. For example: if period_buffer=2
        # then interpolated data points will only be included if they are
        # within a factor of 2 of a true data point
        error_type_z=np.array([
            ['floor_percent', 'floor_egbert'],
            # error type, options are 'egbert', 'percent', 'mean_od', 'eigen', 'median', 'off_diagonals'
            ['floor_egbert', 'percent']
        ]),  # add floor to apply it as an error floor
        # can supply a 2 x 2 array for each component or a single value
        error_value_z=np.array([
            [20., 5.],  # error floor value in percent
            [5., 20.]
        ]),  # can supply a 2 x 2 array for each component or a single value
        error_type_tipper='floor_abs',  # type of error to set in tipper,
        # floor_abs is an absolute value set as a floor
        error_value_tipper=.03,
        model_epsg=28354  # model epsg, currently set to utm zone 54.
        # See http://spatialreference.org/ to find the epsg code for your projection
    )
    do.write_data_file()

    # set elevations to zero as we need to ensure the stations are on the topography
    do.data_array['elev'] = 0.
    do.write_data_file(fill=False)

    # create model file
    mo = Model(
        station_locations=do.station_locations,
        cell_size_east=8000,
        cell_size_north=8000,
        pad_north=
        7,  # number of padding cells in each of the north and south directions
        pad_east=7,  # number of east and west padding cells
        pad_z=6,  # number of vertical padding cells
        pad_stretch_v=1.6,  # factor to increase by in padding cells (vertical)
        pad_stretch_h=1.4,  # factor to increase by in padding cells (horizontal)
        pad_num=
        3,  # number of constant-width cells to add to outside of model before padding cells start
        # this number is currently multiplied by 1.5 internally
        n_air_layers=
        10,  # number of air layers, set to 0 to incorporate bathymetry only
        res_model=100,  # halfspace resistivity value for reference model
        n_layers=100,  # total number of z layers, including air
        z1_layer=10,  # first layer thickness
        pad_method='stretch',  # method for calculating padding
        z_mesh_method='new',
        z_target_depth=
        120000  # depth to bottom of core model (padding after this depth)
    )

    mo.make_mesh()
    mo.write_model_file(save_path=workdir)

    # add topography to res model
    # if the number of air layers is zero - bathymetry only will be added.
    # if the number of air layers is nonzero - topography will be added, discretised into that number of cells
    # mo.add_topography_to_model2(r'C:\mtpywin\mtpy\examples\data\AussieContinent_etopo1.asc')
    mo.add_topography_to_model2(
        r'C:\Githubz\mtpy\examples\data\AussieContinent_etopo1.asc')
    mo.write_model_file(save_path=workdir)

    # update data elevations
    do.project_stations_on_topography(mo)

    # show the mesh
    mo.plot_sealevel_resistivity()

    co = Covariance()
    co.smoothing_east = 0.4
    co.smoothing_north = 0.4
    co.smoothing_z = 0.4
    co.write_covariance_file(model_fn=mo.model_fn)
Пример #11
0
data_fn = r'C:\mtpywin\mtpy\examples\model_files\ModEM\ModEM_Data.dat'
dObj = Data()
dObj.read_data_file(data_fn=data_fn)

### option 2 ####
stationxyfile = r'C:\mtpywin\mtpy\examples\model_files\gocad\stationxy.txt'
xy = np.loadtxt(stationxyfile, usecols=(1, 2))
station_names = np.loadtxt(stationxyfile, usecols=(0, ), dtype='S10')
period_list = np.logspace(1, 4, 19)  # change to your period list

# create data file
dObj = Data(epsg=epsg)
dObj._initialise_empty_data_array(xy,
                                  period_list,
                                  location_type='LL',
                                  station_names=station_names)
dObj.write_data_file(fill=False, save_path=workdir)

# Create model file
mObj = Model(Data=dObj, save_path=workdir)
mObj.read_gocad_sgrid_file(gocad_sgrid_file)
mObj.model_fn_basename = op.join(workdir, 'ModEM_Model_forward.ws')
mObj.write_model_file()

# create covariance file
cov = Covariance(save_path=workdir,
                 smoothing_east=0.3,
                 smoothing_north=0.3,
                 smoothing_z=0.3)
cov.write_covariance_file(model_fn=mObj.model_fn)
Пример #12
0
    def run(self):
        # monkey patch plt.show() so the plot is not displayed in worker thread
        true_plt_show = plt.show
        plt.show = _fake_plt_show
        self._figures = []
        try:
            if not os.path.exists(self.output_dir):
                os.mkdir(self.output_dir)

            # get period_list list
            self.status_updated.emit("Selecting Periods...")
            period_list = EdiCollection(self._edi_list).select_periods(**self._select_period_kwargs)
            # save period plot for reference
            figure = plt.gcf()
            figure.savefig(os.path.join(self.output_dir, self._period_image_name))
            if self.show:
                self.figure_updated.emit('Period Distribution', figure)

            # data object
            self.status_updated.emit("Creating ModEM Data Object...")
            self._data_kwargs['period_list'] = period_list
            data = Data(edi_list=self._edi_list, **self._data_kwargs)
            # write data file
            self.status_updated.emit("Writing Initial ModEM Data File...")
            data.write_data_file()

            # create model
            self.status_updated.emit("Creating Mesh Model...")
            model = Model(data_object=data, **self._mesh_kwagrs)
            model.make_mesh()
            # plot mesh
            model.plot_mesh(fig_num=plt.gcf().number + 1)
            figure = plt.gcf()
            figure.savefig(os.path.join(self.output_dir, self._mesh_image_name))
            if self.show:
                self.figure_updated.emit("Mesh", figure)
                # model.plot_mesh_xy()
                # self.figure_updated.emit("Mesh XY", plt.gcf())
                # model.plot_mesh_xz()
                # self.figure_updated.emit("Mesh XZ", plt.gcf())
            model.write_model_file()

            # add topography
            self.status_updated.emit("Adding Topography...")
            model.add_topography_to_mesh(**self._topo_args)
            if self.show:
                model.plot_topograph()  # this is too slow so only plot and save image when asked
                figure = plt.gcf()
                figure.savefig(os.path.join(self.output_dir, self._topo_image_name))
                self.figure_updated.emit("Topography", figure)
            self.status_updated.emit("Updating Mesh Model...")
            model.write_model_file()

            # covariance
            self.status_updated.emit("Creating Covariance File...")
            self._covariance_kwargs['mask_arr'] = model.covariance_mask
            cov = Covariance(**self._covariance_kwargs)
            self.status_updated.emit("Writing Covariance File...")
            cov.write_covariance_file(model_fn=model.model_fn, sea_water=self._topo_args['sea_resistivity'],
                                      air=self._topo_args['air_resistivity'])

            self.status_updated.emit("Creating README File...")
            self.write_readme(os.path.join(self.output_dir, self._readme_name))
            # done
            self.status_updated.emit("Finishing...")

        except Exception as e:
            frm = inspect.trace()[-1]
            mod = inspect.getmodule(frm[0])
            self.export_error.emit("{}: {}".format(mod.__name__, e.message))

        # restore plt.show()
        plt.show = true_plt_show
Пример #13
0
    def test_fun_edi_elevation(self):

        edipath = EDI_DATA_DIR  # path where edi files are located
        # set the dir to the output from the previously correct run
        self._expected_output_dir = os.path.join(SAMPLE_DIR, 'ModEM')

        # period list (will not include periods outside of the range of the edi file)
        start_period = -2
        stop_period = 3
        n_periods = 17
        period_list = np.logspace(start_period, stop_period, n_periods)

        # list of edi files, search for all files ending with '.edi'
        edi_list = [
            os.path.join(edipath, ff) for ff in os.listdir(edipath)
            if (ff.endswith('.edi'))
        ]

        do = Data(
            edi_list=edi_list,
            inv_mode='1',
            save_path=self._output_dir,
            period_list=period_list,
            error_type_z='floor_egbert',
            error_value_z=5,
            error_type_tipper='floor_abs',
            error_value_tipper=.03,
            model_epsg=28354  # model epsg, currently set to utm zone 54
        )

        do.write_data_file()

        # create model file
        mo = Model(
            station_locations=do.station_locations,
            cell_size_east=500,
            cell_size_north=500,
            pad_north=
            7,  # number of padding cells in each of the north and south directions
            pad_east=7,  # number of east and west padding cells
            pad_z=6,  # number of vertical padding cells
            pad_stretch_v=
            1.6,  # factor to increase by in padding cells (vertical)
            pad_stretch_h=
            1.4,  # factor to increase by in padding cells (horizontal)
            n_air_layers=10,  # number of air layers
            res_model=100,  # halfspace resistivity value for reference model
            n_layers=90,  # total number of z layers, including air
            z1_layer=10,  # first layer thickness
            pad_method='stretch',
            z_target_depth=120000)

        mo.make_mesh()
        mo.write_model_file(save_path=self._output_dir)

        # Add topography from EDI data
        mo.add_topography_from_data(do)
        mo.write_model_file(save_path=self._output_dir)

        # BM: note this function makes a call to `write_data_file` and this is the datafile being
        #  compared!
        do.project_stations_on_topography(mo)

        co = Covariance()
        co.write_covariance_file(model_fn=mo.model_fn)

        # BM: if this test is failing check that the correct filenames are being selected
        #   for comparison
        for test_output, expected_output in (
            ("ModEM_Data_topo.dat", "ModEM_Data_EDI_elev.dat"),
            ("covariance.cov", "covariance_EDI_elev.cov"),
            ("ModEM_Model_File.rho", "ModEM_Model_File_EDI_elev.rho")):
            output_data_file = os.path.normpath(
                os.path.join(self._output_dir, test_output))

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

            expected_data_file = os.path.normpath(
                os.path.join(self._expected_output_dir, expected_output))

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

            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 '{}'."
                .format(output_data_file, expected_data_file))