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)
예제 #2
0
    "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(" ", "_")
            value = value.replace(r"UTC/GMT", "").replace('"', "")
            attr_dict[key] = value

    for brod_key, mt_key in key_dict.items():
        value = attr_dict[brod_key]
        m.station_metadata.set_attr_from_name(mt_key, value)

    m.write_mt_file(fn.name, save_dir=fn.parent)
예제 #3
0

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
                                       # will write as degrees minutes seconds
                    )
예제 #4
0
    m.hx_metadata.translated_azimuth = (
        m.hx_metadata.measurement_azimuth -
        m.station_metadata.location.declination.value)
    m.hx_metadata.translated_tilt = None
    m.hx_metadata.type = "magnetic"
    m.hx_metadata.units = "nanotesla"

    m.hy_metadata.measurement_azimuth = sdf.hy_azimuth
    m.hy_metadata.measurement_tilt = 0.0
    m.hy_metadata.sensor.manufacturer = "Zonge International"
    m.hy_metadata.sensor.model = "ANT4"
    m.hy_metadata.sensor.type = "magnetic induction coil"
    m.hy_metadata.translated_azimuth = (
        m.hy_metadata.measurement_azimuth -
        m.station_metadata.location.declination.value)
    m.hy_metadata.translated_tilt = None
    m.hy_metadata.type = "magnetic"
    m.hy_metadata.units = "nanotesla"

    m.hz_metadata.measurement_azimuth = 0
    m.hz_metadata.measurement_tilt = 90
    m.hz_metadata.sensor.manufacturer = "Zonge International"
    m.hz_metadata.sensor.model = "ANT4"
    m.hz_metadata.sensor.type = "magnetic induction coil"
    m.hz_metadata.translated_azimuth = 0
    m.hz_metadata.translated_tilt = 90
    m.hz_metadata.type = "magnetic"
    m.hz_metadata.units = "nanotesla"

    m.write_mt_file()
# -*- 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")
예제 #6
0
"""
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)
예제 #7
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')