The MTPy software package for magnetotelluric data analysis and visualisation

MTPy is an open source Python package to assist with MT data processing, analysis, modelling, visualization and interpretation. It was initiated at the University of Adelaide in 2013 as a means to store and share Python code amongst the MT community (Krieger & Peacock, 2014). Here we provide an overview of the software and describe recent developments to MTPy. These include new functionality and a clean up and standardisation of the source code, as well as the addition of an integrated testing suite, documentation, and examples in order to facilitate the use of MT in the wider geophysics community.


Introduction
The magnetotelluric (MT) method is increasingly being applied to a wide variety of geoscience problems.However, the software available for MT data analysis and interpretation is still very limited in comparison to many of the more mature geophysical methods such as the gravity, magnetic or seismic reflection methods.
MTPy is an open source Python package to assist with MT data processing, analysis, modelling, visualization and interpretation.It was initiated at the University of Adelaide in 2013 as a means to store and share Python code amongst the MT community (Krieger & Peacock, 2014).Here we provide an overview of the software and describe recent developments to MTPy.These include new functionality and a clean up and standardisation of the source code, as well as the addition of an integrated testing suite, documentation, and examples in order to facilitate the use of MT in the wider geophysics community.

Key Functionality
MTPy contains modules to carry out much of the processing and analysis that can be applied to MT data.MTPy works primarily with the industry standard Electronic Data Interchange (EDI) file format however it is compatible with other formats including the Jfile format exported by the Bounded Influence, Remote Reference Processing (BIRRP) code (Chave & Thomson, 2004;Chave, Thomson, & Ander, 1987), and xml.The MTPy structure is based on key steps in working with MT data, namely processing, analysis, modelling, and imaging.These sub-packages are based on modules within the core subpackage (Figure 1, Krieger & Peacock, 2014).
The core sub-package contains functionality to read and write MT data from industry standard formats such as EDI.When data are read in, an MT object is created.The MT object contains site metadata from the header of the EDI file, including the location.It also contains the impedance tensor (Z) and the vertical transfer functions (Tipper).
The processing sub-package is designed to facilitate working with time series data and generating inputs for existing third-party processing codes, for example the BIRRP code (Chave & Thomson, 2004;Chave et al., 1987).
The analysis sub-package includes functions that are commonly used to analyse MT data prior to modelling and inversion.These include: dimensionality analysis, strike angle calculation, phase tensor analysis (T.G. Caldwell, Bibby, & Brown, 2004), and calculation and removal of distortion (H.M. Bibby, Caldwell, & Brown, 2005).In addition, there  are functions to calculate and visualize depth of investigation using the Niblett-Bostick transform (Bostick, 1977;Jones, 1983;Niblett & Sayn-Wittgenstein, 1960).
The imaging sub-package contains functionality to visualise MT data, as well as many of the outputs from the analysis and modelling modules.These include simple plots of resistivity and phase at a single station (e.g. Figure 2), resistivity and phase pseudosections and maps, phase tensor sections and maps (e.g. Figure 3), penetration depth and geoelectric strike plots, and images of resistivity models and the model responses.
The functions in utils underpin these modules, by handling basic underlying functionality such as coordinate transformations, common filehandling operations and calculations that are commonly applied to MT data, such as conversion from impedance tensor (Z) to apparent resistivity and phase.

Recent development
In order to make MTPy a comprehensive toolkit that can be easily installed and used by the wider geophysics community, we are applying software engineering best practices and techniques to improve software quality and usability.New developments include incorporation of a unit-testing suite, continuous build, automatic documentation generation (http://mtpy2.readthedocs.io/en/develop/)and addition of installation guide wiki pages (https://github.com/MTgeophysics/mtpy/wiki).
Recent functionality development to MTPy includes significant expansion of the modules that generate inputs to, and allow visualiation of outputs from, the ModEM 3D inversion code (Egbert & Kelbert, 2012;Kelbert et al., 2014).This includes new functionality to extract vertical slices from 3D models for display on profiles.Both of these support overlay of other datasets in both profile and plan view.These can be used with the seismic module in imaging for plotting 2D seismic reflection data (in profile) and the geology module for plotting shapefiles.We have now also implemented functions to export ModEM 3D models to GOCAD TM sgrid format, and to export depth slices to a column based text format containing x, y, z resistivity.
The analysis and imaging sub-packages have been expanded through the addition of modules that calculate and visualise depth of investigation of MT measurements, for a single site, a profile, or a grid of sites.
We have also added an edi_collection module that works specifically with collections of edi files and enables phase tensors from a collection of stations to be exported to csv or ArcView shapefiles.
Projections and transformations are now handled using the open-source Pyproj library, or if users prefer, the more comprehensive GDAL library.
Finally, we have compiled a set of jupyter notebooks, example scripts, and workshop material within the examples folder in the repository, which demonstrate the key functionality contained in MTPy.

Figure 1 :
Figure 1: MTPy package structure showing the key modules that are under active development.The colours in the workflow diagram represent which parts of MTPy are used at each step.For example, modules in the analysis sub-package are used on the impedance tensor data, while visualisation is carried out on time series data, processed data, and the results of analysis and modelling or inversion.This diagram is modified after Krieger & Peacock (2014).

Figure 2 :
Figure 2: Example of a single station plot generated using the plotresponse module within the imaging sub-package in MTPy.The plot shows Z XY and Z YX resistivity and phase, induction vectors (Tipper; Parkinson, 1962), and phase tensors (T.G. Caldwell et al., 2004) as a function of period.

Figure 3 :
Figure 3: Example of a phase tensor and induction vector map created by the phase_tensor_maps module in the imaging sub-package in MTPy.Phase tensor ellipses are calculated using the method detailed by T. G. Caldwell et al. (2004) and coloured by skew angle in degree.