This workbook contains some examples for reading, analysing and plotting processed MT data. It covers most of the steps available in MTPy. For more details on specific input parameters and other functionality, we recommend looking at the mtpy documentation, which can be found at: https://mtpy2.readthedocs.io/en/develop/master_doc.html.
This workbook is structured according to some of the key modules in MTPy: Core, Analysis, Imaging, and Modeling.
To start with, you will need to make sure MTPy is installed and is working correctly. Please see the installation guide (https://github.com/MTgeophysics/mtpy/wiki/MTPy-installation-guide-on-Windows-PC) for details.
Before you begin these examples, we suggest you make a temporary folder (e.g. C:/tmp) to save all example outputs.
This workbook exists as a Jupyter notebook and a pdf. If you are running the Jupyter notebook, you can run each of the cells, modifying the inputs to suit your requirements. Most of these examples have been written to be self contained.
In Jupyter, you can add the following line to the top of any cell and it will write the contents of that cell to a python script: %%writefile example.py
You can also select multiple cells and copy them to a new Jupyter notebook.
Many of the examples below make use of the matplotlib colour maps. Please see https://matplotlib.org/examples/color/colormaps_reference.html for colour map options.
These first few examples cover some of the basic functions and tools that can be used to look at data contained in an edi file, plot it, and make changes (e.g. sample onto different frequencies).
In [1]:
# import required modules
from mtpy.core.mt import MT
# Define the path to your edi file
edi_file = "C:/mtpywin/mtpy/examples/data/edi_files_2/Synth00.edi"
# Create an MT object
mt_obj = MT(edi_file)
The mt_obj contains all the data from the edi file, e.g. impedance, tipper, frequency as well as station information (lat/long). To look at any of these parameters you can type, for example:
In [2]:
# To see the latitude and longitude
print mt_obj.lat, mt_obj.lon
In [3]:
# To see the easting, northing, and elevation
print mt_obj.east, mt_obj.north, mt_obj.elev
There are many other parameters you can look at in the mt_obj. Just type mt_obj.[TAB] to see what is available. In the MT object are the Z and Tipper objects (mt_obj.Z; mt_obj.Tipper). These contain all information related to, respectively, the impedance tensor and the tipper.
In [4]:
# for example, to see the frequency values represented in the impedance tensor:
print mt_obj.Z.freq
In [5]:
# or to see the impedance tensor (first 4 elements)
print mt_obj.Z.z[:4]
In [6]:
# or the resistivity or phase (first 4 values)
print mt_obj.Z.resistivity[:4]
print mt_obj.Z.phase[:4]
As with the MT object, you can explore the object by typing mt_obj.Z.[TAB] to see the available attributes.
In this example we plot MT data from an edi file.
In [7]:
# import required modules
from mtpy.core.mt import MT
import os
# Define the path to your edi file and save path
edi_file = "C:/mtpywin/mtpy/examples/data/edi_files_2/Synth00.edi"
savepath = r"C:/tmp"
# Create an MT object
mt_obj = MT(edi_file)
# To plot the edi file we read in in Part 1 & save to file:
pt_obj = mt_obj.plot_mt_response(plot_num=1, # 1 = yx and xy; 2 = all 4 components
# 3 = off diagonal + determinant
plot_tipper = 'yri',
plot_pt = 'y' # plot phase tensor 'y' or 'n'
)
#pt_obj.save_plot(os.path.join(savepath,"Synth00.png"), fig_dpi=400)
This example demonstrates how to resample the data onto new frequency values and write to a new edi file. In the example below, you can either choose every second frequency or resample onto five periods per decade. To do this we need to make a new Z object, and save it to a file.
In [8]:
# import required modules
from mtpy.core.mt import MT
import os
# Define the path to your edi file and save path
edi_file = r"C:/mtpywin/mtpy/examples/data/edi_files_2/Synth00.edi"
savepath = r"C:/tmp"
# Create an MT object
mt_obj = MT(edi_file)
# First, define a frequency array:
# Every second frequency:
new_freq_list = mt_obj.Z.freq[::2]
# OR 5 periods per decade from 10^-4 to 10^3 seconds
from mtpy.utils.calculator import get_period_list
new_freq_list = 1./get_period_list(1e-4,1e3,5)
# Create new Z and Tipper objects containing interpolated data
new_Z_obj, new_Tipper_obj = mt_obj.interpolate(new_freq_list)
# Write a new edi file using the new data
mt_obj.write_mt_file(
save_dir=savepath,
fn_basename='Synth00_5ppd',
file_type='edi',
new_Z_obj=new_Z_obj, # provide a z object to update the data
new_Tipper_obj=new_Tipper_obj, # provide a tipper object
longitude_format='LONG', # write longitudes as 'LONG' not ‘LON’
latlon_format='dd'# write as decimal degrees (any other input
# will write as degrees:minutes:seconds
)
Out[8]: