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 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)
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)
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))
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)
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()
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()
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)
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))
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
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)
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))
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))
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()
[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(
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)
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
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(" ", "_")
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
get dimensionality/strike angle from an edi file """ import os.path as op import os os.chdir(r'C:\mtpywin\mtpy') # change to path where mtpy is installed import numpy as np from mtpy.core.mt import MT from mtpy.analysis.geometry import dimensionality, strike_angle # directory containing edis edi_path = r'C:\mtpywin\mtpy\examples\data\edi_files_2' # edi file name edi_file = os.path.join(edi_path, 'Synth00.edi') # read edi file into an MT object mtObj = MT(edi_file) # determine strike angle for the 2d parts of impedance tensor strike = strike_angle( z_object=mtObj.Z, skew_threshold= 5, # threshold in skew angle (degrees) to determine if data are 3d eccentricity_threshold= 0.1 # threshold in phase ellipse eccentricity to determine if data are 2d (vs 1d) ) print strike
# -*- 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))
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))
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)
# -*- 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")
""" Created on Mon Nov 30 15:43:54 2020 :author: Jared Peacock :license: MIT """ from pathlib import Path import pandas as pd from mtpy.core.mt import MT epath = Path(r"c:\Users\jpeacock\Documents\milipitas") spath = Path(r"c:\Users\jpeacock\Documents\milipitas\new_edis") loc_fn = Path(r"c:\Users\jpeacock\Documents\milipitas\latlon_NAD83.txt") df = pd.read_csv(loc_fn) for fn in epath.glob("*.edi"): m = MT(fn) m.station = f"{m.station}_{fn.stem}" l = df[df.Station == fn.stem] m.latitude = l.Latitude.values[0] m.longitude = l.Longitude.values[0] m.elevation = l.Elevation.values[0] m.write_mt_file(save_dir=spath) p = m.plot_mt_response(plot_num=2) p.save_plot(spath.joinpath(f"{m.station}.png").as_posix(), fig_dpi=300)
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,
) # edi_path = Path(r"d:\edit2\Rotated_m14_deg") edi_list = list(edi_path.glob("*.edi")) save_dir_edi = Path( r"c:\Users\jpeacock\OneDrive - DOI\Geothermal\Umatilla\EDI_Files_birrp_phase_02\final_edi" ) save_dir_png = Path( r"c:\Users\jpeacock\OneDrive - DOI\Geothermal\Umatilla\EDI_Files_birrp_phase_02\final_png" ) for edi_fn in edi_list: if not edi_fn.is_file(): continue m = MT(fn=edi_fn) m.save_dir = save_dir_edi 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 and J. L. Pepin" m.survey_metadata.citation_dataset.doi = "https://doi.org/10.5066/P9DQJTL9" m.survey_metadata.citation_dataset.year = "2020" m.survey_metadata.comments = None m.survey_metadata.country = "USA"