def apply(self): """Applies transform.""" if self.mmc.maskrange is None: return i = self.combobox1.currentText() x0 = self.mmc.maskrange[0] x1 = self.mmc.maskrange[1] xcrds = 1 / self.data[i].Z.freq mask = ~np.logical_and(xcrds > x0, xcrds < x1) mt_obj = self.data[i] mt_obj.Z = Z(z_array=mt_obj.Z.z[mask], z_err_array=mt_obj.Z.z_err[mask], freq=mt_obj.Z.freq[mask]) mt_obj.Tipper = Tipper(tipper_array=mt_obj.Tipper.tipper[mask], tipper_err_array=mt_obj.Tipper.tipper_err[mask], freq=mt_obj.Tipper.freq[mask]) if x1 < xcrds.max(): new_freq_list = 1 / xcrds new_Z_obj, new_Tipper_obj = mt_obj.interpolate(new_freq_list) self.data[i].Z = new_Z_obj self.data[i].Tipper = new_Tipper_obj self.change_band()
def __init__(self, impvar): self.impvar = impvar if isinstance(impvar, list): self.z = [] for fn in impvar: self.z.append(Z(fn)) self.savepath = os.path.join(os.path.dirname(self.impvar[0]), 'PTPlots') else: self.z = [Z(impvar)] if isinstance(impvar, str): self.savepath = os.path.join(os.path.dirname(self.impvar), 'PTPlots') else: self.savepath = os.path.join(os.getcwd(), 'PTPlots') # make a list of colors and makers to use for plotting self.mclst = [] for cc in ptplots.colorlst: for mm in ptplots.markerlst: self.mclst.append([cc, mm])
def test_remove_ss(self): # calculate a corrected z array zcor = self.MT.Z.remove_ss(reduce_res_factor_x=self.static_shift_x, reduce_res_factor_y=self.static_shift_y)[1] # make a Z object with the corrected array and calculate resistivity and phase Zcor = Z(z_array=zcor, freq=self.MT.Z.freq) Zcor.compute_resistivity_phase() # check that the resistivity factors are correct self.assertTrue( np.all( np.array((self.MT.Z.resistivity / Zcor.resistivity)[:, 0]) - self.static_shift_x < 1e10)) self.assertTrue( np.all( np.array((self.MT.Z.resistivity / Zcor.resistivity)[:, 1]) - self.static_shift_y < 1e10))
def test_compute_resistivity_phase(self): freq = np.logspace(2, -3, 6) z = np.array([[[-6.395642 - 1.316922e+01j, 45.22294 + 9.921218e+01j], [-42.52678 - 1.013927e+02j, 10.36037 + 1.929462e+01j]], [[-1.028196 - 2.087766e+00j, 8.6883 + 1.588160e+01j], [-7.535859 - 1.517449e+01j, 1.724745 + 3.063922e+00j]], [[-1.255376 - 7.618381e-02j, 6.325392 + 1.997068e+00j], [-6.281115 - 1.554746e+00j, 1.635191 + 4.083652e-01j]], [[-1.285838 - 1.969697e-01j, 5.428554 + 1.687451e+00j], [-5.727512 - 1.275399e+00j, 1.083837 + 4.377386e-01j]], [[-1.065314 - 4.287129e-01j, 2.326234 + 1.113632e+00j], [-2.71029 - 2.188917e+00j, 0.6587484 + 7.972820e-02j]], [[-0.2464714 - 3.519637e-01j, 1.588412 + 5.252950e-01j], [-0.6028374 - 8.850180e-01j, 0.5539547 + 1.885912e-01j]]]) zObj = Z(z_array=z, freq=freq) zObj.compute_resistivity_phase() # resistivity array computed from above z and freq arrays and verified # against outputs from WinGLink res_test = np.array([[[4.286652e-01, 2.377634e+01], [2.417802e+01, 9.592394e-01]], [[1.083191e-01, 6.554236e+00], [5.741087e+00, 2.472473e-01]], [[3.163546e-01, 8.799773e+00], [8.373929e+00, 5.681224e-01]], [[3.384353e+00, 6.463338e+01], [6.886208e+01, 2.732636e+00]], [[2.637378e+01, 1.330308e+02], [2.427406e+02, 8.806122e+00]], [[3.692532e+01, 5.597976e+02], [2.293340e+02, 6.848650e+01]]]) self.assertTrue( np.all(np.abs(zObj.resistivity / res_test - 1.) < 1e-6))
mtObj = MT(edi_file) # use the phase tensor to determine which frequencies are 1D/2D/3D dim = dimensionality( 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) ) # create a True/False array to mask with mask = dim < 3 new_Z_object = Z(z_array=mtObj.Z.z[mask], z_err_array=mtObj.Z.z_err[mask], freq=mtObj.Z.freq[mask]) new_Tipper_object = Tipper(tipper_array=mtObj.Tipper.tipper[mask], tipper_err_array=mtObj.Tipper.tipper_err[mask], freq=mtObj.Tipper.freq[mask]) mtObj.write_mt_file( save_dir=savepath, fn_basename='Synth00_new', file_type='edi', # edi or xml format new_Z_obj=new_Z_object, # provide a z object to update the data new_Tipper_obj= new_Tipper_object, # 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
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')