Exemple #1
0
 def setUp(self):
     self.edi_file = os.path.join(TEST_MTPY_ROOT,
                                  r'data/BBMT/EGC020A_pho.edi')
     self.MT = MT(self.edi_file)
     self.rotation_angle = 30
     self.static_shift_x = 1.2
     self.static_shift_y = 1.5
def test_func():
    """
    test fun
    :return:
    """

    # directory containing edis
    edipath = EDI_DATA_DIR2
    # whether or not to save the figure to file
    save = True

    # full path to file to save to
    savepath = os.path.join(TEMP_OUT_DIR, 'phase_tensor_map_2.png')

    # frequency to plot
    plot_freq = 1.318400e-01

    # gets edi file names as a list
    elst = [
        op.join(edipath, f) for f in os.listdir(edipath) if f.endswith('.edi')
    ]
    mtlist = [MT(ff) for ff in elst]

    # parameters describing ellipses
    ellipse_dict = {
        'ellipse_size': 0.1,
        'ellipse_colorby': 'phimin',
        'ellipse_range': (0, 90, 1),
        'cmap': 'mt_bl2gr2rd'
    }

    # parameters describing the induction vector arrows
    arrow_dict = {
        'arrow_size': 0.02,
        'arrow_lw': 0.01,
        'arrow_head_width': 0.002,
        'arrow_head_length': 0.002,
        'arrow_color_real': 'b',
        'direction': 0,
        'threshold': 0.8
    }

    phase_tensor_map = pptmaps.PlotPhaseTensorMaps(
        # fn_list = elst,
        mt_object_list=mtlist,
        plot_freq=plot_freq,
        #  ftol = .5,
        #  xpad = 0.02,
        plot_tipper='yr',
        arrow_dict=arrow_dict,
        ellipse_dict=ellipse_dict,
    )

    phase_tensor_map.ellipse_size = 0.5
    phase_tensor_map.arrow_size = 10
    phase_tensor_map.redraw_plot()
    if save:
        phase_tensor_map.save_figure(savepath)
        assert (os.path.exists(savepath))
def make_fn_df(df_fn):
    original = Path(
        r"c:\Users\jpeacock\OneDrive - DOI\Geysers\EDI_Files_birrp\Edited\Geographic"
    )
    phase_01 = Path(
        r"c:\Users\jpeacock\OneDrive - DOI\Geysers\CEC\EDI_files_birrp_processed\Geographic\Edited"
    )

    fn_list = []
    for f1 in original.glob("*.edi"):
        m1 = MT(f1)
        for f2 in phase_01.glob("*.edi"):
            m2 = MT(f2)
            if np.isclose(m1.latitude, m2.latitude, 0.0001) and np.isclose(
                    m1.longitude, m2.longitude, 0.0001):
                fn_list.append({"original": f1, "phase_01": f2})
                print(m1.station, m2.station)
                break
    df = pd.DataFrame(fn_list)
    df.to_csv(df_fn, index=False)
Exemple #4
0
def core_edi(datadir):
    """ read edi """
    # Define the path to your edi file

    savepath = datadir
    allfiles = glob.glob(datadir + '\s*.edi')
    for edi_file in allfiles:

        mt_obj = MT(edi_file)
        pt_obj = mt_obj.plot_mt_response(plot_num=1,
                                         plot_tipper='yri',
                                         plot_pt='y')
def remove_static_shift(
    df_fn,
    nf=22,
    save_dir=Path(
        r"c:\Users\jpeacock\OneDrive - DOI\Geysers\CEC\EDI_files_birrp_processed\Geographic\Edited\SS"
    ),
):
    df = pd.read_csv(df_fn)

    for row in df.itertuples():
        m1 = MT(row.original)
        m2 = MT(row.phase_01)

        m1.Z, m1.Tipper = m1.interpolate(m2.frequencies, bounds_error=False)

        sx = np.median(m1.Z.res_xy[:nf] / m2.Z.res_xy[:nf])
        sy = np.median(m1.Z.res_yx[:nf] / m2.Z.res_yx[:nf])

        print(f"station: {m1.station} - {m2.station}: sx={sx}, sy={sy}")

        m2.Z = m2.remove_static_shift(1.0 / sx, 1.0 / sy)
        m2.write_mt_file(save_dir=save_dir)
Exemple #6
0
    def test_get_dimensionality_from_edi_file(self):
        mt_obj = MT(
            os.path.normpath(
                os.path.join(TEST_MTPY_ROOT,
                             "examples/data/edi_files/pb42c.edi")))
        dimensionality_result = np.array([
            1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
            2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3
        ])
        dimensionality = mtg.dimensionality(z_object=mt_obj.Z)

        self.assertTrue(
            np.allclose(dimensionality, dimensionality_result, 1e-8))
Exemple #7
0
def test_fun():
    """
    test function
    :return: T/F
    """
    # mtObj = MT(r'C:\Git\mtpy\examples\data\edi_files\pb42c.edi')
    # mtObj = MT(r'E:/Githubz/mtpy/examples/data/edi_files/pb42c.edi')
    edifile = os.path.join(MTPY_ROOT, 'examples/data/edi_files/pb42c.edi')
    mtObj = MT(edifile)

    strike_angle_pb42c = np.array([[np.nan, np.nan], [np.nan, np.nan],
                                   [np.nan, np.nan], [np.nan, np.nan],
                                   [np.nan, np.nan], [np.nan, np.nan],
                                   [np.nan, np.nan], [np.nan, np.nan],
                                   [np.nan, np.nan], [np.nan, np.nan],
                                   [np.nan, np.nan], [np.nan, np.nan],
                                   [np.nan, np.nan], [np.nan, np.nan],
                                   [np.nan, np.nan], [np.nan, np.nan],
                                   [np.nan, np.nan], [np.nan, np.nan],
                                   [38.45662316, 128.45662316],
                                   [28.61883115, 118.61883115],
                                   [14.45341494, 104.45341494],
                                   [8.43320651, 98.43320651],
                                   [4.94952784, 94.94952784],
                                   [2.09090369, 92.09090369],
                                   [1.39146887, 91.39146887],
                                   [0.39905337, 90.39905337],
                                   [-5.49553673, 84.50446327],
                                   [-6.28846049, 83.71153951],
                                   [-7.31641788, 82.68358212],
                                   [-10.45341947, 79.54658053],
                                   [-7.07075086, 82.92924914],
                                   [-7.5429295, 82.4570705],
                                   [-6.06405688, 83.93594312],
                                   [-3.54915951, 86.45084049],
                                   [-3.12596637, 86.87403363],
                                   [-0.47404093, 89.52595907],
                                   [2.74343665, 92.74343665],
                                   [4.78078759, 94.78078759],
                                   [7.71125988, 97.71125988],
                                   [11.0123521, 101.0123521],
                                   [13.81639678, 103.81639678],
                                   [13.60497071, 103.60497071],
                                   [15.87672806, 105.87672806]])

    strike_angle = mtg.strike_angle(z_object=mtObj.Z)

    differ = np.abs(strike_angle[np.isfinite(strike_angle)] -
                    strike_angle_pb42c[np.isfinite(strike_angle_pb42c)]) < 1e-8
    print(differ)
    assert np.all(differ)
Exemple #8
0
def main():
    """ main test """
    datadir = r'C:\Work\Programming\pygmi\data\MT\\'
    edi_file = datadir + r"synth02.edi"

    # Create an MT object
    mt_obj = MT(edi_file)

    print('loading complete')

    app = QtWidgets.QApplication(sys.argv)
    test = Occam1D(None)
    test.indata['MT - EDI'] = {'SYNTH02': mt_obj}
    test.settings()
Exemple #9
0
    def test_defaults(self):
        edi_files = glob.glob(os.path.join(edi_paths[0], '*.edi'))
        mt_objs = [MT(os.path.abspath(file_name)) for file_name in edi_files]
        self.dialog.set_data(mt_objs)
        _rewrite_text(self.dialog.ui.comboBox_topography_file, AUS_TOPO_FILE)
        self.dialog.exec_ = _fake_exec_accept
        if self.dialog.exec_() == QWizard.Accepted:
            print(self.dialog.get_save_file_path())
            pprint.pprint(self.dialog.get_data_kwargs())
            pprint.pprint(self.dialog.get_model_kwargs())

            self.dialog.export_data()

        self.dialog.close()
Exemple #10
0
    def test_get_strike_from_edi_file(self):
        edifile = os.path.normpath(
            os.path.join(TEST_MTPY_ROOT, 'examples/data/edi_files/pb42c.edi'))
        mt_obj = MT(edifile)
        strike_angle_pb42c = np.array([[np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [38.45662316, 128.45662316],
                                       [28.61883115, 118.61883115],
                                       [14.45341494, 104.45341494],
                                       [8.43320651, 98.43320651],
                                       [4.94952784, 94.94952784],
                                       [2.09090369, 92.09090369],
                                       [1.39146887, 91.39146887],
                                       [0.39905337, 90.39905337],
                                       [-5.49553673, 84.50446327],
                                       [-6.28846049, 83.71153951],
                                       [-7.31641788, 82.68358212],
                                       [-10.45341947, 79.54658053],
                                       [-7.07075086, 82.92924914],
                                       [-7.5429295, 82.4570705],
                                       [-6.06405688, 83.93594312],
                                       [-3.54915951, 86.45084049],
                                       [-3.12596637, 86.87403363],
                                       [-0.47404093, 89.52595907],
                                       [2.74343665, 92.74343665],
                                       [4.78078759, 94.78078759],
                                       [7.71125988, 97.71125988],
                                       [11.0123521, 101.0123521],
                                       [13.81639678, 103.81639678],
                                       [13.60497071, 103.60497071],
                                       [15.87672806, 105.87672806]])

        strike_angle = mtg.strike_angle(z_object=mt_obj.Z)

        self.assertTrue(
            np.allclose(strike_angle[np.isfinite(strike_angle)],
                        strike_angle_pb42c[np.isfinite(strike_angle_pb42c)],
                        1e-8))
def test_fun():
    """
    test function
    :return: T/F
    """
    # mtObj = MT(r'C:\Git\mtpy\examples\data\edi_files\pb42c.edi')
    
    mtObj = MT(os.path.join(EDI_DATA_DIR, 'pb42c.edi'))

    dimensionality_result = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
                                      2, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])

    dimensionality = mtg.dimensionality(z_object=mtObj.Z)
    differ = np.abs(dimensionality - dimensionality_result)

    print differ

    assert np.all(np.abs(dimensionality - dimensionality_result) < 1e-8)
Exemple #12
0
    def test_get_strike_from_edi_file(self):
        edifile = os.path.normpath(
            os.path.join(TEST_MTPY_ROOT, 'examples/data/edi_files/pb42c.edi'))
        mt_obj = MT(edifile)
        strike_angle_pb42c = np.array([[np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [38.45662316, -51.54337684],
                                       [28.61883115, -61.38116885],
                                       [14.45341494, -75.54658506],
                                       [8.43320651, -81.56679349],
                                       [4.94952784, -85.05047216],
                                       [2.09090369, -87.90909631],
                                       [1.39146887, -88.60853113],
                                       [0.39905337, -89.60094663],
                                       [-5.49553673, 84.50446327],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan], [np.nan, np.nan],
                                       [np.nan, np.nan],
                                       [-6.06405688, 83.93594312],
                                       [-3.54915951, 86.45084049],
                                       [-3.12596637, 86.87403363],
                                       [-0.47404093, 89.52595907],
                                       [2.74343665, -87.25656335],
                                       [4.78078759, -85.21921241],
                                       [7.71125988, -82.28874012],
                                       [11.0123521, -78.9876479],
                                       [13.81639678, -76.18360322],
                                       [13.60497071, -76.39502929],
                                       [np.nan, np.nan]])

        strike_angle = mtg.strike_angle(z_object=mt_obj.Z)

        self.assertTrue(
            np.allclose(strike_angle[np.isfinite(strike_angle)],
                        strike_angle_pb42c[np.isfinite(strike_angle_pb42c)],
                        1e-8))
Exemple #13
0
def test_fun():
    """
    test function
    :return: T/F
    """

    #mtObj = MT(r'C:\Git\mtpy\examples\data\edi_files\pb42c.edi')
    mtObj = MT(os.path.join(EDI_DATA_DIR, 'pb42c.edi'))

    eccentricity_pb42c = (np.array([
        0.01675639, 0.01038589, 0.00527011, 0.00638819, 0.01483804, 0.00385233,
        0.00513294, 0.00403781, 0.02862114, 0.02689821, 0.01425044, 0.05686524,
        0.05742524, 0.02696736, 0.0275285, 0.03647819, 0.04721932, 0.06336521,
        0.12789841, 0.16409303, 0.20630821, 0.34261225, 0.3967886, 0.51629705,
        0.56645987, 0.52558696, 0.46954261, 0.48028767, 0.47490701, 0.44927612,
        0.45185046, 0.44143159, 0.43570377, 0.41537978, 0.40546014, 0.38785478,
        0.37174031, 0.34534557, 0.35510941, 0.32282644, 0.28501461, 0.22463964,
        0.20683855
    ]),
                          np.array([
                              0.17132216, 0.2757994, 0.71263216, 0.50481657,
                              0.21604906, 0.98931454, 0.75816349, 1.06885049,
                              0.23412284, 0.25015825, 0.4117732, 0.06824775,
                              0.13024193, 0.49471091, 0.61126932, 0.5471021,
                              0.6073574, 0.50578334, 0.30809787, 0.44938001,
                              0.35430928, 0.20402482, 0.36750578, 0.30360427,
                              0.27660847, 0.55139247, 0.53103062, 0.48771581,
                              0.19105325, 0.68542871, 0.66189643, 0.1495947,
                              0.11353391, 0.09190586, 0.09006473, 0.1079376,
                              0.13673274, 0.19349474, 0.23780856, 0.35159944,
                              0.55386034, 0.78687532, 0.9654131
                          ]))

    eccentricity = mtg.eccentricity(z_object=mtObj.Z)
    #print eccentricity

    for i in range(2):
        differ = np.abs(eccentricity[i] - eccentricity_pb42c[i]) < 1e-8
        print differ
        assert np.all(differ)  # true if-only every element is true
Exemple #14
0
def test_rotate():
    alpha = 30
    alpharad = np.deg2rad(alpha)
    rotation_matrix = np.matrix([[np.cos(alpharad),
                                  np.sin(alpharad)],
                                 [-np.sin(alpharad),
                                  np.cos(alpharad)]])

    #mt_obj = MT(r'C:\mtpywin\mtpy\data\BBMT\EGC020A_pho.edi') # absolute path is user-dependent
    path2edi = os.path.normpath(
        os.path.join(TEST_MTPY_ROOT, 'data/BBMT/EGC020A_pho.edi'))
    mt_obj = MT(path2edi)

    z_array = mt_obj.Z.z.copy()

    ztest = z_array[0]

    ztest_rot = np.ma.dot(np.ma.dot(rotation_matrix, ztest), rotation_matrix.T)

    mt_obj.Z.rotate(alpha)

    assert np.all(mt_obj.Z.z[0] - ztest_rot < 1e-10)
Exemple #15
0
    def test_get_eccentricity_from_edi_file(self):
        mt_obj = MT(
            os.path.normpath(
                os.path.join(TEST_MTPY_ROOT,
                             "examples/data/edi_files/pb42c.edi")))
        eccentricity_pb42c = (np.array([
            0.01675639, 0.01038589, 0.00527011, 0.00638819, 0.01483804,
            0.00385233, 0.00513294, 0.00403781, 0.02862114, 0.02689821,
            0.01425044, 0.05686524, 0.05742524, 0.02696736, 0.0275285,
            0.03647819, 0.04721932, 0.06336521, 0.12789841, 0.16409303,
            0.20630821, 0.34261225, 0.3967886, 0.51629705, 0.56645987,
            0.52558696, 0.46954261, 0.48028767, 0.47490701, 0.44927612,
            0.45185046, 0.44143159, 0.43570377, 0.41537978, 0.40546014,
            0.38785478, 0.37174031, 0.34534557, 0.35510941, 0.32282644,
            0.28501461, 0.22463964, 0.20683855
        ]),
                              np.array([
                                  0.01648335, 0.01850986, 0.02356282,
                                  0.02351531, 0.0245181, 0.0295284, 0.03050838,
                                  0.03262934, 0.04868243, 0.04905988,
                                  0.04742146, 0.04365671, 0.06595206,
                                  0.09502736, 0.11485881, 0.1330897,
                                  0.16488362, 0.18365985, 0.2233313,
                                  0.32718984, 0.35370171, 0.38087385,
                                  0.55555244, 0.59755086, 0.60360704,
                                  0.82315127, 0.75538697, 0.73747297,
                                  0.46115785, 0.85300128, 0.95439195,
                                  0.4485694, 0.42871072, 0.43533434,
                                  0.43440266, 0.4950619, 0.56743593,
                                  0.64693597, 0.74768197, 0.90040195,
                                  1.01527094, 1.15623132, 1.34441602
                              ]))

        eccentricity = mtg.eccentricity(z_object=mt_obj.Z)
        for i in range(2):
            self.assertTrue(
                np.allclose(eccentricity[i], eccentricity_pb42c[i], 1e-8))
Exemple #16
0
    def test_get_eccentricity_from_edi_file(self):
        mt_obj = MT(
            os.path.normpath(
                os.path.join(TEST_MTPY_ROOT,
                             "examples/data/edi_files/pb42c.edi")))
        eccentricity_pb42c = (np.array([
            0.01675639, 0.01038589, 0.00527011, 0.00638819, 0.01483804,
            0.00385233, 0.00513294, 0.00403781, 0.02862114, 0.02689821,
            0.01425044, 0.05686524, 0.05742524, 0.02696736, 0.0275285,
            0.03647819, 0.04721932, 0.06336521, 0.12789841, 0.16409303,
            0.20630821, 0.34261225, 0.3967886, 0.51629705, 0.56645987,
            0.52558696, 0.46954261, 0.48028767, 0.47490701, 0.44927612,
            0.45185046, 0.44143159, 0.43570377, 0.41537978, 0.40546014,
            0.38785478, 0.37174031, 0.34534557, 0.35510941, 0.32282644,
            0.28501461, 0.22463964, 0.20683855
        ]),
                              np.array([
                                  0.17132216, 0.2757994, 0.71263216,
                                  0.50481657, 0.21604906, 0.98931454,
                                  0.75816349, 1.06885049, 0.23412284,
                                  0.25015825, 0.4117732, 0.06824775,
                                  0.13024193, 0.49471091, 0.61126932,
                                  0.5471021, 0.6073574, 0.50578334, 0.30809787,
                                  0.44938001, 0.35430928, 0.20402482,
                                  0.36750578, 0.30360427, 0.27660847,
                                  0.55139247, 0.53103062, 0.48771581,
                                  0.19105325, 0.68542871, 0.66189643,
                                  0.1495947, 0.11353391, 0.09190586,
                                  0.09006473, 0.1079376, 0.13673274,
                                  0.19349474, 0.23780856, 0.35159944,
                                  0.55386034, 0.78687532, 0.9654131
                              ]))

        eccentricity = mtg.eccentricity(z_object=mt_obj.Z)
        for i in range(2):
            self.assertTrue(
                np.allclose(eccentricity[i], eccentricity_pb42c[i], 1e-8))
Exemple #17
0
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 31 13:19:35 2017

@author: u64125
"""

from mtpy.core.mt import MT
import mtpy.analysis.geometry as mtg
import numpy as np

mtObj = MT(r'C:\Git\mtpy\examples\data\edi_files\pb42c.edi')

dimensionality_result = np.array([
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
    2, 2, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
])

dimensionality = mtg.dimensionality(z_object=mtObj.Z)

assert np.all(np.abs(dimensionality - dimensionality < 1e-8))
Exemple #18
0
    def test_pt(self):
        self.mtobj = MT(
            os.path.normpath(
                os.path.join(TEST_MTPY_ROOT,
                             "examples/data/edi_files/pb42c.edi")))
        self.pt_expected = np.array([[[1.30644963e+00, -2.67740187e-02],
                                      [-1.33702443e-02, 1.28968939e+00]],
                                     [[1.21678059e+00, -1.07765729e-02],
                                      [-8.20007589e-03, 1.23374034e+00]],
                                     [[1.17164177e+00, 1.09018782e-03],
                                      [-6.68510048e-03, 1.18271654e+00]],
                                     [[1.22540541e+00, 4.38999476e-03],
                                      [-4.20009647e-03, 1.24116127e+00]],
                                     [[1.22262143e+00, -1.27947436e-02],
                                      [-4.73195876e-03, 1.25493677e+00]],
                                     [[1.21501297e+00, -8.79427102e-03],
                                      [1.03830156e-02, 1.22427493e+00]],
                                     [[1.22785045e+00, 1.39792917e-02],
                                      [-7.08673035e-03, 1.23846962e+00]],
                                     [[1.26661703e+00, -1.11292454e-02],
                                      [1.82801360e-03, 1.26240177e+00]],
                                     [[1.18539706e+00, 6.39442474e-03],
                                      [-1.01453767e-02, 1.25514910e+00]],
                                     [[1.28549981e+00, -1.00606766e-01],
                                      [3.97760695e-02, 1.32053655e+00]],
                                     [[1.22555721e+00, -6.29531701e-02],
                                      [3.36638894e-02, 1.24514491e+00]],
                                     [[1.15217304e+00, 2.47597860e-02],
                                      [-4.69132792e-02, 1.28928907e+00]],
                                     [[1.07175797e+00, -3.58092355e-03],
                                      [-3.12450311e-02, 1.19733081e+00]],
                                     [[1.00918431e+00, -1.48723334e-02],
                                      [-1.04135860e-03, 1.06274597e+00]],
                                     [[9.15517149e-01, -7.13677311e-03],
                                      [4.49100302e-03, 9.67281170e-01]],
                                     [[7.82696110e-01, 1.70157289e-02],
                                      [1.87039067e-02, 8.29411722e-01]],
                                     [[7.05442477e-01, 3.78377052e-02],
                                      [2.11076586e-02, 7.39844699e-01]],
                                     [[6.35185233e-01, 4.73463102e-02],
                                      [3.31681155e-02, 6.45232848e-01]],
                                     [[5.55546920e-01, 6.54610202e-02],
                                      [6.89078895e-02, 5.23858436e-01]],
                                     [[5.33096567e-01, 7.08103577e-02],
                                      [6.49382268e-02, 4.46884668e-01]],
                                     [[5.27354094e-01, 8.09968253e-02],
                                      [1.96849609e-02, 3.71188472e-01]],
                                     [[5.11384716e-01, 8.77380469e-02],
                                      [1.36652476e-02, 2.64391007e-01]],
                                     [[5.07676485e-01, 8.88590722e-02],
                                      [-2.89224644e-03, 2.26830209e-01]],
                                     [[5.32226186e-01, 7.99515723e-02],
                                      [-8.08381040e-03, 1.72606458e-01]],
                                     [[5.88599443e-01, 7.82062018e-02],
                                      [-8.45485953e-03, 1.64746123e-01]],
                                     [[6.08649155e-01, 8.25165235e-02],
                                      [-2.18321304e-02, 1.89799568e-01]],
                                     [[6.72877101e-01, 7.17000488e-02],
                                      [-8.23242896e-02, 2.38847621e-01]],
                                     [[7.83704974e-01, 9.35718439e-02],
                                      [-1.08804893e-01, 2.69048188e-01]],
                                     [[8.10341816e-01, 9.92141045e-02],
                                      [-1.26495824e-01, 2.81539705e-01]],
                                     [[9.44396211e-01, 9.79869018e-02],
                                      [-1.86664281e-01, 3.53878350e-01]],
                                     [[1.20372744e+00, 1.43106117e-01],
                                      [-1.82486049e-01, 4.45265471e-01]],
                                     [[1.16782854e+00, 1.13799885e-01],
                                      [-1.75825646e-01, 4.46497807e-01]],
                                     [[1.34754960e+00, 7.86821351e-02],
                                      [-1.52050649e-01, 5.27637774e-01]],
                                     [[1.54766037e+00, 1.07732214e-01],
                                      [-1.24203091e-01, 6.35758473e-01]],
                                     [[1.57964820e+00, 7.39413746e-02],
                                      [-1.02148722e-01, 6.66546887e-01]],
                                     [[1.62101014e+00, 9.00546725e-02],
                                      [-5.05253680e-02, 7.14423033e-01]],
                                     [[1.68957924e+00, 3.97165705e-02],
                                      [4.57251401e-02, 7.76737215e-01]],
                                     [[1.66003469e+00, 3.22243697e-02],
                                      [9.00225059e-02, 8.14143062e-01]],
                                     [[1.62779118e+00, 3.26316490e-03],
                                      [1.68213765e-01, 7.85939990e-01]],
                                     [[1.51783857e+00, -1.45050231e-02],
                                      [2.23460898e-01, 7.96441583e-01]],
                                     [[1.41377974e+00, -3.64217144e-02],
                                      [2.56732302e-01, 8.12803360e-01]],
                                     [[1.32448223e+00, -9.04193565e-02],
                                      [2.46858147e-01, 8.54516882e-01]],
                                     [[1.22981959e+00, -1.86648528e-01],
                                      [3.20105326e-01, 8.15014902e-01]]])

        assert (np.all(
            np.abs((self.pt_expected - self.mtobj.pt.pt) /
                   self.pt_expected) < 1e-6))

        alpha_expected = np.array([
            -33.66972565, -65.89384737, -76.59867325, 89.65473659,
            -75.76307747, 85.13326608, 73.50684783, -32.810132, -88.46092736,
            -59.97035554, -61.88664666, -85.4110878, -82.24967714,
            -81.72640079, -88.53701804, 71.29889577, 60.1345369, 48.55666153,
            38.3651419, 28.79048968, 16.40517236, 11.16030354, 8.50965433,
            5.65066256, 4.67255493, 4.12192474, -0.70110747, -0.84768598,
            -1.47667976, -4.27011302, -1.48608617, -2.45732916, -2.55670157,
            -0.51738522, -0.88470366, 1.24832387, 2.67364329, 4.11167901,
            5.75654718, 8.07694833, 10.06615916, 9.20560479, 8.91737594
        ])

        beta_expected = np.array([
            -0.14790673, -0.03012061, 0.09460956, 0.09976904, -0.09322928,
            -0.22522043, 0.24468941, -0.14677427, 0.19414636, -1.54172397,
            -1.11970814, 0.84076362, 0.3492499, -0.19123344, -0.17692124,
            -0.02999968, 0.33160131, 0.31720792, -0.09148111, 0.17165854,
            1.95175741, 2.72709705, 3.56012648, 3.55975888, 3.28108606,
            3.72287137, 4.79442926, 5.44077452, 5.8397381, 6.18330647,
            5.58466467, 5.08560032, 3.50735531, 3.03177428, 2.24126272,
            1.7223648, -0.06979335, -0.66910857, -1.95471268, -2.93540374,
            -3.75023764, -4.39936596, -6.95935213
        ])

        azimuth_expected = alpha_expected - beta_expected

        assert (np.all(
            np.abs((alpha_expected - self.mtobj.pt.alpha) /
                   alpha_expected) < 1e-6))
        assert (np.all(
            np.abs((beta_expected - self.mtobj.pt.beta) /
                   beta_expected) < 1e-6))
        assert (np.all(
            np.abs((azimuth_expected - self.mtobj.pt.azimuth) /
                   azimuth_expected) < 1e-6))
        [np.array(train_df['data1'][i][0:]) for i in range(len(train_df))])
    data_mean1 = np.mean(train_data1)
    data_dev1 = np.std(train_data1)
    train_data1_N = (train_data1 - data_mean1) / data_dev1

if True:
    model = load_model(save_model_name, custom_objects={'rmse_m': un.rmse_m})
    slst0 = [s0[:-4] for s0 in slst]
    ocm = occam1d.Model()
    ocm.read_model_file(os.path.join(train_fold, 'Model1D'))
    plot_depth = ocm.model_depth[1:].copy()
    plot_depth[plot_depth == 0] = 1
    res_all = pd.DataFrame(columns=[])
    res_all['depth(m)'] = ocm.model_depth[1:]
    for idx, fn in enumerate(slst):
        mt_obj = MT(os.path.join(current_path, edi_folder + fn))
        freq = mt_obj.Z.freq
        res_det0 = mt_obj.Z.res_det
        phase_det0 = un.phase_shift_1(mt_obj.Z.phase_det)
        f1d0 = interp1d(freq,
                        res_det0,
                        kind='linear',
                        fill_value='extrapolate')
        res_det0 = f1d0(freq0)
        f1d1 = interp1d(freq,
                        phase_det0,
                        kind='linear',
                        fill_value='extrapolate')
        phase_det0 = f1d1(freq0)
        res_det = un.savgol_smooth_Jon_3(res_det0).reshape(-1, input_size, 1)
        phase_det = un.savgol_smooth_Jon_3(phase_det0).reshape(
Exemple #20
0
 def setUp(self):
     _BaseTest.setUp(self)
     mt_objs = [MT(edi_file) for edi_file in self.edi_files]
     self.edi_collection = EdiCollection(mt_objs=mt_objs)
Exemple #21
0
    def test_edi_files(self):
        """
        test fun
        :return:
        """
        # directory containing edis
        edipath = EDI_DATA_DIR
        # whether or not to save the figure to file
        save = True

        # full path to file to save to
        savepath = os.path.join(self._temp_dir, 'phase_tensor_map.png')

        # frequency to plot
        plot_freq = 1e-2

        # gets edi file names as a list
        elst = [
            op.join(edipath, f) for f in os.listdir(edipath)
            if f.endswith('.edi')
        ]
        mtlist = [MT(ff) for ff in elst]

        # parameters describing ellipses
        ellipse_dict = {
            'ellipse_size': .01,
            'ellipse_colorby': 'phimax',
            'ellipse_range': (0, 90, 1),
            'cmap': 'mt_bl2gr2rd'
        }

        # parameters describing the induction vector arrows
        arrow_dict = {
            'arrow_size': 0.02,
            'arrow_lw': 0.01,
            'arrow_head_width': 0.002,
            'arrow_head_length': 0.002,
            'arrow_color_real': 'b',
            'direction': 0,
            'threshold': 0.8
        }

        phase_tensor_map = pptmaps.PlotPhaseTensorMaps(
            mt_object_list=mtlist,
            plot_freq=plot_freq,
            # ftol = .5,
            # xpad = 0.02,
            # plot_tipper = 'yr',
            # ellipse_size=ellipse_dict['ellipse_size'],
            # ellipse_dict=ellipse_dict, # old line ( 22/02/2018 )
            ellipse_size=.01,
            ellipse_colorby='phimax',
            ellipse_range=(0, 90, 1),
            ellipse_cmap='mt_bl2gr2rd',
        )
        # need to set properties and redraw
        phase_tensor_map.ellipse_size = 0.01
        phase_tensor_map.redraw_plot()

        if save:
            phase_tensor_map.save_figure(savepath, close_plot='n')
            assert (os.path.exists(savepath))
Exemple #22
0
import mtpy.modeling.occam1d as occam1d
from tqdm import tqdm_notebook
from mtpy.core.mt import MT
from sklearn.model_selection import train_test_split
from keras.callbacks import EarlyStopping, ModelCheckpoint, ReduceLROnPlateau
from keras.models import load_model
from keras.layers.merge import concatenate
from keras.engine.training import Model
from keras.layers import Input, Dense, Reshape
from keras import optimizers
from itools import forWeb_cnn_1D as un

current_path = os.getcwd()
fold_train = 'train_unet'  #folder for saving datasets
edi_file = 'edi_data/plc002.edi'  #sample 'edi' file
mt_obj = MT(os.path.join(current_path, edi_file))
occam1d_path = os.path.join(
    current_path, 'itools/Occam1DCSEM/Source/OCCAM1DCSEM'
)  # path to Occam1D open source, need edit if different folder path
#-----------------------------------------------------------------------------------------------------------------------

n_layers = 49  #input layers
input_size = 128  #number of frequency

epochs = 150  #maximum iteration
batch_size = 32  #batch size

version = 1  #version number

#-----------------------------------------------------------------------------------------------------------------------
t_start = time.time()
Exemple #23
0
survey_csv_fn = (
    r"c:\Users\jpeacock\OneDrive - DOI\Geothermal\GabbsValley\gv_survey_summary.csv"
)
# edi_fn = r"c:\Users\jpeacock\OneDrive - DOI\EDI_FILES\gv160.edi"

# test_fn = Path(r"c:\Users\jpeacock\Documents\GitHub\sandbox_scripts\test.edi")
# if test_fn.exists():
#     test_fn.unlink()
edi_path = Path(r"c:\Users\jpeacock\OneDrive - DOI\EDI_FILES")
edi_list = [edi_path.joinpath(f"gv{ii:03}.edi") for ii in range(100, 170)]

for edi_fn in edi_list:
    if not edi_fn.is_file():
        continue

    m = MT(fn=edi_fn)

    survey_df = pd.read_csv(survey_csv_fn)
    sdf = [
        entry for entry in survey_df.loc[survey_df.station ==
                                         m.station].itertuples()
    ][0]

    # survey
    m.survey_metadata.acquired_by.author = "Jared R. Peacock"
    m.survey_metadata.acquired_by.comments = "U.S. Geological Survey"
    m.survey_metadata.citation_dataset.authors = (
        "J. R. Peacock, D. L. Siler, B. Dean, L. Zielinski")
    m.survey_metadata.citation_dataset.doi = "https://doi.org/10.5066/P9GZ9Z56"
    m.survey_metadata.citation_dataset.year = "2020"
    m.survey_metadata.comments = None
Exemple #24
0
from mtpy.imaging.plot_mt_response import PlotMTResponse

# ======================================================================================================================
# How to Run this script:
# python examples/scripts/plot_two_edi_files.py /c/Githubz/mtpy/data/edifiles/15125A.edi
# OR provide edi files
# python examples/scripts/plot_two_edi_files.py /c/Githubz/mtpy/data/edifiles/15125A.edi /c/Githubz/mtpy/data/edifiles/15129A.edi
# ======================================================================================================================
if __name__ == "__main__":

    if len(sys.argv) < 2:
        print("USAGE: python %s edifile1 [edifile2]" % sys.argv[0])
        sys.exit(1)
    elif len(sys.argv) == 2:  # one edi file provided
        edifile = sys.argv[1]  # /c/Githubz/mtpy/data/edifiles/15125A.edi
        mt_obj = MT(edifile)

        rp1 = PlotMTResponse(
            z_object=mt_obj.Z,  # this is mandatory
            # t_object=mt_obj.Tipper,
            # pt_obj=mt_obj.pt,
            station=mt_obj.station,
            #plot_tipper='yr',  # plots the real part of the tipper
            plot_num=3)  # plot_num =1 xy + yx; 2 all; 3 xy yx det

        # rp1.xy_color = (.5,.5,.9)
        # rp1.xy_marker = '*'
        # rp1.redraw_plot()
    elif (len(sys.argv) == 3):  # overlay 2 edi files provided
        edifile = sys.argv[1]  #
        mt_obj = MT(edifile)
Exemple #25
0
chars = 280

key_dict = {
    "latitude": "location.latitude",
    "longitude": "location.longitude",
    "elevation": "location.elevation",
    "declination": "location.declination.value",
    "declination.epoch": "location.declination.epoch",
    "start": "time_period.start",
    "end": "time_period.end",
}
# "runlist": "run_list"}

for fn in fn_list:
    m = MT(fn)

    find = m.station_metadata.comments.find("SITE LATITUDE")
    lines = m.station_metadata.comments[find:find + chars].split("\n")
    attr_dict = {}
    for line in lines:
        if line.count("=") == 0:
            continue
        if line.count("=") > 1:
            key, value = line.split(" ")
            attr, units, value = value.split("=")
            attr_dict[key.lower()] = value
            attr_dict[f"{key.lower()}.{attr}"] = units
        else:
            key, value = line.split("=")
            key = key.replace("SITE", "").lower().strip().replace(" ", "_")
# -*- coding: utf-8 -*-
"""
This script will rotate principle axis back to geographic coordinates.

Created on Wed Jan 26 11:07:21 2022

@author: jpeacock
"""
# =============================================================================
# Imports
# =============================================================================
from pathlib import Path
from mtpy.core.mt import MT

# =============================================================================

edi_path = Path(r"c:\Users\jpeacock\OneDrive - DOI\mt\principle_axis")

for edi_filename in edi_path.glob("*.edi"):
    m = MT(edi_filename)
    m.Z.rotate(m.Z.rotation_angle)
    m.Tipper.rotate(m.Tipper.rotation_angle)

    p = m.plot_mt_response(plot_num=2)
    p.save_plot(edi_path.joinpath(f"{m.station}_geographic.png").as_posix(),
                fig_dpi=300)

    m.write_mt_file(fn_basename=f"{m.station}_geographic.edi")
Exemple #27
0
import os
os.chdir(r'C:/mtpywin/mtpy') # change to path where mtpy is installed


from mtpy.core.mt import MT
from mtpy.utils.calculator import get_period_list


# directory format for windows users
edi_path = r'C:\mtpywin\mtpy\examples\data\edi_files_2' 
savepath = r'C:\tmp'


edi_file = os.path.join(edi_path,'Synth00.edi')

mtObj = MT(edi_file)

#new_freq_list = mtObj.Z.freq # takes every second frequency
new_freq_list = 1./get_period_list(1e-4,1e3,5) # 5 periods per decade from 0.0001 to 100000 s

# create new Z and Tipper objects containing interpolated data
new_Z_obj, new_Tipper_obj = mtObj.interpolate(new_freq_list)

# write a new edi file using the new data
mtObj.write_mt_file(save_dir=savepath, 
                    fn_basename='Synth00_new', 
                    file_type='edi', # edi or xml format
                    new_Z_obj=new_Z_obj, # provide a z object to update the data
                    new_Tipper_obj=new_Tipper_obj, # provide a tipper object to update the data
                    longitude_format='LONG', # write longitudes as 'LON' or 'LONG'
                    latlon_format='dd' # write as decimal degrees (any other input
Exemple #28
0
import matplotlib.pyplot as plt

# directory containing edis
edipath = r'C:\Git\mtpy\examples\data\edi_files_2'
# whether or not to save the figure to file
save = True

# full path to file to save to
savepath = r'C:\Git\mtpy\examples\plots\edi_plots\phase_tensor_map_2.png'

# frequency to plot
plot_freq = 1.318400e-01

# gets edi file names as a list
elst = [op.join(edipath, f) for f in os.listdir(edipath) if f.endswith('.edi')]
mtlist = [MT(ff) for ff in elst]

# parameters describing ellipses
ellipse_dict = {
    'ellipse_size': 0.1,
    'ellipse_colorby': 'phimin',
    'ellipse_range': (0, 90, 1),
    'cmap': 'mt_bl2gr2rd'
}

# parameters describing the induction vector arrows
arrow_dict = {
    'arrow_size': 0.02,
    'arrow_lw': 0.01,
    'arrow_head_width': 0.002,
    'arrow_head_length': 0.002,
Exemple #29
0
def analysis_edi(datadir):
    """ analysis """
    # Define the path to your edi file
    edi_file = datadir + r"edifiles2\15125A.edi"
    savepath = datadir
    edi_path = datadir + 'edifiles2'

    # Create an MT object
    mt_obj = MT(edi_file)

    # look at the skew values as a histogram
    plt.hist(mt_obj.pt.beta, bins=50)
    plt.xlabel('Skew angle (degree)')
    plt.ylabel('Number of values')

    plt.show()

    # Have a look at the dimensionality
    dim = dimensionality(z_object=mt_obj.Z,
                         skew_threshold=5,
                         eccentricity_threshold=0.1)

    print(dim)

    # calculate strike
    strike = strike_angle(z_object=mt_obj.Z,
                          skew_threshold=5,
                          eccentricity_threshold=0.1)

    # display the median strike angle for this station
    # two values because of 90 degree ambiguity in strike
    strikemedian = np.nanmedian(strike, axis=0)

    print(strikemedian)

    # Use dimensionality to mask a file

    mask = dim < 3
    # Apply masking. The new arrays z_array, z_err_array, and freq will
    # exclude values where mask is False (i.e. the 3D parts)
    new_Z_obj = Z(z_array=mt_obj.Z.z[mask],
                  z_err_array=mt_obj.Z.z_err[mask],
                  freq=mt_obj.Z.freq[mask])

    new_Tipper_obj = Tipper(tipper_array=mt_obj.Tipper.tipper[mask],
                            tipper_err_array=mt_obj.Tipper.tipper_err[mask],
                            freq=mt_obj.Tipper.freq[mask])

    # Write a new edi file
    mt_obj.write_mt_file(save_dir=savepath,
                         fn_basename='Synth00_mask3d',
                         file_type='edi',
                         new_Z_obj=new_Z_obj,
                         new_Tipper_obj=new_Tipper_obj,
                         longitude_format='LONG',
                         latlon_format='dd')

    # Plot strike
    # Get full path to all files with the extension '.edi' in edi_path
    edi_list = [
        os.path.join(edi_path, ff) for ff in os.listdir(edi_path)
        if ff.endswith('.edi')
    ]

    # make a plot (try also plot_type = 1 to plot by decade)
    strikeplot = PlotStrike(fn_list=edi_list, plot_type=2, plot_tipper='y')
    # save to file
    # strikeplot.save_plot(savepath,
    #                      file_format='.png',
    #                      fig_dpi=400)

    strike = strikemedian[0]  # 0 index chosen based on geological information
    mt_obj.Z.rotate(strike)
    mt_obj.Tipper.rotate(strike)

    # check the rotation angle
    print(mt_obj.Z.rotation_angle)
    # Write a new edi file (as before)
    mt_obj.write_mt_file(save_dir=savepath,
                         fn_basename='Synth00_rotate%1i' % strike,
                         file_type='edi',
                         longitude_format='LONG',
                         latlon_format='dd')