mtpy.modeling.occam1d package

Submodules

mtpy.modeling.occam1d.data module

Created on Mon Oct 30 13:31:30 2023

@author: jpeacock

class mtpy.modeling.occam1d.data.Occam1DData(mt_dataframe, **kwargs)[source]

Bases: object

reads and writes occam 1D data files

Attributes

Description

_data_fn

basename of data file default is Occam1DDataFile

_header_line

header line for description of data columns

_ss

string spacing default is 6*’ ‘

_string_fmt

format of data default is ‘+.6e’

data

array of data

data_fn

full path to data file

freq

frequency array of data

mode

mode to invert for [ ‘TE’ | ‘TM’ | ‘det’ ]

phase_te

array of TE phase

phase_tm

array of TM phase

res_te

array of TE apparent resistivity

res_tm

array of TM apparent resistivity

resp_fn

full path to response file

save_path

path to save files to

Methods

Description

write_data_file

write an Occam1D data file

read_data_file

read an Occam1D data file

read_resp_file

read a .resp file output by Occam1D

Example:
>>> import mtpy.modeling.occam1d as occam1d
>>> #--> make a data file for TE mode
>>> d1 = occam1d.Data()
>>> d1.write_data_file(edi_file=r'/home/MT/mt01.edi', res_err=10, phase_err=2.5,
>>> ...                save_path=r"/home/occam1d/mt01/TE", mode='TE')
property mode
property mode_01
property mode_02
read_data_file(data_fn)[source]

reads a 1D data file

Arguments:

data_fn : full path to data file

Returns:

Occam1D.rpdict : dictionary with keys:

‘freq’ : an array of frequencies with length nf

‘resxy’TE resistivity array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

‘resyx’TM resistivity array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

‘phasexy’TE phase array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

‘phaseyx’TM phase array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

Example:
>>> old = occam1d.Data()
>>> old.data_fn = r"/home/Occam1D/Line1/Inv1_TE/MT01TE.dat"
>>> old.read_data_file()
read_resp_file(resp_fn=None, data_fn=None)[source]

read response file

resp_fn : full path to response file

data_fn : full path to data file

freq : an array of frequencies with length nf

res_teTE resistivity array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

res_tmTM resistivity array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

phase_teTE phase array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

phase_tmTM phase array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

Example:

:: >>> o1d = occam1d.Data() >>> o1d.data_fn = r”/home/occam1d/mt01/TE/Occam1D_DataFile_TE.dat” >>> o1d.read_resp_file(r”/home/occam1d/mt01/TE/TE_7.resp”)

write_data_file(filename, mode='det', remove_outofquadrant=False)[source]

make1Ddatafile will write a data file for Occam1D

Arguments:

rp_tuplenp.ndarray (freq, res, res_err, phase, phase_err)

with res, phase having shape (num_freq, 2, 2).

edi_filestring

full path to edi file to be modeled.

save_pathstring

path to save the file, if None set to dirname of station if edipath = None. Otherwise set to dirname of edipath.

thetarfloat

rotation angle to rotate Z. Clockwise positive and N=0 default = 0

mode[ ‘te’ | ‘tm’ | ‘det’]
mode to model can be (*default*=’both’):
  • ‘te’ for just TE mode (res/phase)

  • ‘tm’ for just TM mode (res/phase)

  • ‘det’ for the determinant of Z (converted to

    res/phase)

add ‘z’ to any of these options to model impedance tensor values instead of res/phase

res_errfloat

errorbar for resistivity values. Can be set to ( default = ‘data’):

  • ‘data’ for errorbars from the data

  • percent number ex. 10 for ten percent

phase_errfloat

errorbar for phase values. Can be set to ( default = ‘data’):

  • ‘data’ for errorbars from the data

  • percent number ex. 10 for ten percent

res_errorfloor: float

error floor for resistivity values in percent

phase_errorfloor: float

error floor for phase in degrees

remove_outofquadrant: True/False; option to remove the resistivity and

phase values for points with phases out of the 1st/3rd quadrant (occam requires 0 < phase < 90 degrees; phases in the 3rd quadrant are shifted to the first by adding 180 degrees)

Example:
>>> import mtpy.modeling.occam1d as occam1d
>>> #--> make a data file
>>> d1 = occam1d.Data()
>>> d1.write_data_file(edi_file=r'/home/MT/mt01.edi', res_err=10,
>>> ...                phase_err=2.5, mode='TE',
>>> ...                save_path=r"/home/occam1d/mt01/TE")

mtpy.modeling.occam1d.model module

Created on Mon Oct 30 13:29:22 2023

@author: jpeacock

class mtpy.modeling.occam1d.model.Occam1DModel(model_fn=None, **kwargs)[source]

Bases: object

read and write the model file fo Occam1D

All depth measurements are in meters.

Attributes

Description

_model_fn

basename for model file default is Model1D

_ss

string spacing in model file default is 3*’ ‘

_string_fmt

format of model layers default is ‘.0f’

air_layer_height

height of air layer default is 10000

bottom_layer

bottom of the model default is 50000

itdict

dictionary of values from iteration file

iter_fn

full path to iteration file

model_depth

array of model depths

model_fn

full path to model file

model_penalty

array of penalties for each model layer

model_preference_penalty

array of model preference penalties for each layer

model_prefernce

array of preferences for each layer

model_res

array of resistivities for each layer

n_layers

number of layers in the model

num_params

number of parameters to invert for (n_layers+2)

pad_z

padding of model at depth default is 5 blocks

save_path

path to save files

target_depth

depth of target to investigate

z1_layer

depth of first layer default is 10

Methods

Description

write_model_file

write an Occam1D model file, where depth increases on a logarithmic scale

read_model_file

read an Occam1D model file

read_iter_file

read an .iter file output by Occam1D

Example:
>>> #--> make a model file
>>> m1 = occam1d.Model()
>>> m1.write_model_file(save_path=r"/home/occam1d/mt01/TE")
read_iter_file(iter_fn=None, model_fn=None)[source]

read an 1D iteration file

Arguments:

imode : mode to read from

Returns:

Occam1D.itdict : dictionary with keys of the header:

model_resfills this array with the appropriate

values (0) for data, (1) for model

Example:
>>> m1 = occam1d.Model()
>>> m1.model_fn = r"/home/occam1d/mt01/TE/Model1D"
>>> m1.read_iter_file(r"/home/Occam1D/Inv1_TE/M01TE_15.iter")
read_model_file(model_fn=None)[source]

will read in model 1D file

Arguments:

modelfn : full path to model file

Fills attributes:

  • model_depth’ : depth of model in meters

  • model_res : value of resisitivity

  • model_penalty : penalty

  • model_preference : preference

  • model_penalty_preference : preference penalty

Example:
>>> m1 = occam1d.Model()
>>> m1.savepath = r"/home/Occam1D/Line1/Inv1_TE"
>>> m1.read_model_file()
write_model_file(save_path=None, **kwargs)[source]

Makes a 1D model file for Occam1D.

Arguments:

save_path :path to save file to, if just path saved as

savepathmodel.mod, if None defaults to dirpath

n_layers : number of layers

bottom_layer : depth of bottom layer in meters

target_depth : depth to target under investigation

pad_z : padding on bottom of model past target_depth

z1_layer : depth of first layer in meters

air_layer_height : height of air layers in meters

Returns:

Occam1D.modelfn = full path to model file

..Note: This needs to be redone.

Example:
>>> old = occam.Occam1D()
>>> old.make1DModelFile(savepath=r"/home/Occam1D/Line1/Inv1_TE",
>>>                     nlayers=50,bottomlayer=10000,z1layer=50)
>>> Wrote Model file: /home/Occam1D/Line1/Inv1_TE/Model1D

mtpy.modeling.occam1d.plot_l2 module

Created on Mon Oct 30 13:34:53 2023

@author: jpeacock

class mtpy.modeling.occam1d.plot_l2.PlotOccam1DL2(dir_path, model_fn, **kwargs)[source]

Bases: PlotBase

Plot L2 curve of iteration vs rms and roughness.

Arguments::
rms_arrstructured array with keys:
  • ‘iteration’ –> for iteration number (int)

  • ‘rms’ –> for rms (float)

  • ‘roughness’ –> for roughness (float)

Keywords/attributes

Description

ax1

matplotlib.axes instance for rms vs iteration

ax2

matplotlib.axes instance for roughness vs rms

fig

matplotlib.figure instance

fig_dpi

resolution of figure in dots-per-inch

fig_num

number of figure instance

fig_size

size of figure in inches (width, height)

font_size

size of axes tick labels, axes labels is +2

plot_yn

[ ‘y’ | ‘n’] ‘y’ –> to plot on instantiation ‘n’ –> to not plot on instantiation

rms_arr

structure np.array as described above

rms_color

color of rms marker and line

rms_lw

line width of rms line

rms_marker

marker for rms values

rms_marker_size

size of marker for rms values

rms_mean_color

color of mean line

rms_median_color

color of median line

rough_color

color of roughness line and marker

rough_font_size

font size for iteration number inside roughness marker

rough_lw

line width for roughness line

rough_marker

marker for roughness

rough_marker_size

size of marker for roughness

subplot_bottom

subplot spacing from bottom

subplot_left

subplot spacing from left

subplot_right

subplot spacing from right

subplot_top

subplot spacing from top

plot()[source]

Plot L2 curve.

mtpy.modeling.occam1d.plot_response module

Created on Mon Oct 30 13:33:37 2023

@author: jpeacock

class mtpy.modeling.occam1d.plot_response.Plot1DResponse(data_te_fn=None, data_tm_fn=None, model_fn=None, resp_te_fn=None, resp_tm_fn=None, iter_te_fn=None, iter_tm_fn=None, **kwargs)[source]

Bases: object

Plot the 1D response and model.

Plots apparent resisitivity and phase

in different subplots with the model on the far right. You can plot both

TE and TM modes together along with different iterations of the model. These will be plotted in different colors or shades of gray depneng on color_scale.

Example:
>>> import mtpy.modeling.occam1d as occam1d
>>> p1 = occam1d.Plot1DResponse(plot_yn='n')
>>> p1.data_te_fn = r"/home/occam1d/mt01/TE/Occam_DataFile_TE.dat"
>>> p1.data_tm_fn = r"/home/occam1d/mt01/TM/Occam_DataFile_TM.dat"
>>> p1.model_fn = r"/home/occam1d/mt01/TE/Model1D"
>>> p1.iter_te_fn = [r"/home/occam1d/mt01/TE/TE_{0}.iter".format(ii)
>>> ...              for ii in range(5,10)]
>>> p1.iter_tm_fn = [r"/home/occam1d/mt01/TM/TM_{0}.iter".format(ii)
>>> ...              for ii in range(5,10)]
>>> p1.resp_te_fn = [r"/home/occam1d/mt01/TE/TE_{0}.resp".format(ii)
>>> ...              for ii in range(5,10)]
>>> p1.resp_tm_fn = [r"/home/occam1d/mt01/TM/TM_{0}.resp".format(ii)
>>> ...              for ii in range(5,10)]
>>> p1.plot()

Attributes

Description

axm

matplotlib.axes instance for model subplot

axp

matplotlib.axes instance for phase subplot

axr

matplotlib.axes instance for app. res subplot

color_mode

[ ‘color’ | ‘bw’ ]

cted

color of TE data markers

ctem

color of TM data markers

ctmd

color of TE model markers

ctmm

color of TM model markers

data_te_fn

full path to data file for TE mode

data_tm_fn

full path to data file for TM mode

depth_limits

(min, max) limits for depth plot in depth_units

depth_scale

[ ‘log’ | ‘linear’ ] default is linear

depth_units

[ ‘m’ | ‘km’ ] *default is ‘km’

e_capsize

capsize of error bars

e_capthick

cap thickness of error bars

fig

matplotlib.figure instance for plot

fig_dpi

resolution in dots-per-inch for figure

fig_num

number of figure instance

fig_size

size of figure in inches [width, height]

font_size

size of axes tick labels, axes labels are +2

grid_alpha

transparency of grid

grid_color

color of grid

iter_te_fn

full path or list of .iter files for TE mode

iter_tm_fn

full path or list of .iter files for TM mode

lw

width of lines for model

model_fn

full path to model file

ms

marker size

mted

marker for TE data

mtem

marker for TM data

mtmd

marker for TE model

mtmm

marker for TM model

phase_limits

(min, max) limits on phase in degrees

phase_major_ticks

spacing for major ticks in phase

phase_minor_ticks

spacing for minor ticks in phase

plot_yn

[ ‘y’ | ‘n’ ] plot on instantiation

res_limits

limits of resistivity in linear scale

resp_te_fn

full path or list of .resp files for TE mode

resp_tm_fn

full path or list of .iter files for TM mode

subplot_bottom

spacing of subplots from bottom of figure

subplot_hspace

height spacing between subplots

subplot_left

spacing of subplots from left of figure

subplot_right

spacing of subplots from right of figure

subplot_top

spacing of subplots from top of figure

subplot_wspace

width spacing between subplots

title_str

title of plot

plot()[source]

Plot data, response and model.

redraw_plot()[source]

Redraw plot if parameters were changed

use this function if you updated some attributes and want to re-plot.

Example:
>>> # change the color and marker of the xy components
>>> import mtpy.modeling.occam2d as occam2d
>>> ocd = occam2d.Occam2DData(r"/home/occam2d/Data.dat")
>>> p1 = ocd.plotAllResponses()
>>> #change line width
>>> p1.lw = 2
>>> p1.redraw_plot().
save_figure(save_fn, file_format='pdf', orientation='portrait', fig_dpi=None, close_plot='y')[source]

Save_plot will save the figure to save_fn.

Arguments:

    **save_fn** : string
                  full path to save figure to, can be input as
                  * directory path -> the directory path to save to
                    in which the file will be saved as
                    save_fn/station_name_PhaseTensor.file_format

                  * full path -> file will be save to the given
                    path.  If you use this option then the format
                    will be assumed to be provided by the path

    **file_format** : [ pdf | eps | jpg | png | svg ]
                      file type of saved figure pdf,svg,eps...

    **orientation** : [ landscape | portrait ]
                      orientation in which the file will be saved
                      *default* is portrait

    **fig_dpi** : int
                  The resolution in dots-per-inch the file will be
                  saved.  If None then the dpi will be that at
                  which the figure was made.  I don't think that
                  it can be larger than dpi of the figure.

    **close_plot** : [ y | n ]
                     * 'y' will close the plot after saving.
                     * 'n' will leave plot open

:Example: ::

    >>> # to save plot as jpg
    >>> import mtpy.modeling.occam2d as occam2d
    >>> dfn = r"/home/occam2d/Inv1/data.dat"
    >>> ocd = occam2d.Occam2DData(dfn)
    >>> ps1 = ocd.plotPseudoSection()
    >>> ps1.save_plot(r'/home/MT/figures', file_format='jpg')
update_plot(fig)[source]

Update any parameters that where changed using the built-in draw from canvas.

Use this if you change an of the .fig or axes properties

Example:
>>> # to change the grid lines to only be on the major ticks
>>> import mtpy.modeling.occam2d as occam2d
>>> dfn = r"/home/occam2d/Inv1/data.dat"
>>> ocd = occam2d.Occam2DData(dfn)
>>> ps1 = ocd.plotAllResponses()
>>> [ax.grid(True, which='major') for ax in [ps1.axrte,ps1.axtep]]
>>> ps1.update_plot()

mtpy.modeling.occam1d.run module

Created on Mon Oct 30 13:35:16 2023

@author: jpeacock

class mtpy.modeling.occam1d.run.Occam1DRun(startup_fn=None, occam_path=None, **kwargs)[source]

Bases: object

Run occam 1d from python given the correct files and location of occam1d executable

run_occam1d()[source]

Run occam1d.

mtpy.modeling.occam1d.startup module

Created on Mon Oct 30 13:32:42 2023

@author: jpeacock

class mtpy.modeling.occam1d.startup.Occam1DStartup(data_fn=None, model_fn=None, **kwargs)[source]

Bases: object

read and write input files for Occam1D

Attributes

Description

_ss

string spacing

_startup_fn

basename of startup file default is OccamStartup1D

data_fn

full path to data file

debug_level

debug level default is 1

description

description of inversion for your self default is 1D_Occam_Inv

max_iter

maximum number of iterations default is 20

model_fn

full path to model file

rough_type

roughness type default is 1

save_path

full path to save files to

start_iter

first iteration number default is 0

start_lagrange

starting lagrange number on log scale default is 5

start_misfit

starting misfit value default is 100

start_rho

starting resistivity value (halfspace) in log scale default is 100

start_rough

starting roughness (ignored by Occam1D) default is 1E7

startup_fn

full path to startup file

target_rms

target rms default is 1.0

property data_fn
property model_fn
read_startup_file(startup_fn)[source]

reads in a 1D input file

Arguments:

inputfn : full path to input file

Returns:

Occam1D.indict : dictionary with keys following the header and

‘res’ : an array of resistivity values

Example:
>>> old = occam.Occam1d()
>>> old.savepath = r"/home/Occam1D/Line1/Inv1_TE"
>>> old.read1DInputFile()
write_startup_file(save_path=None, **kwargs)[source]

Make a 1D input file for Occam 1D

Arguments:

savepathfull path to save input file to, if just path then

saved as savepath/input

model_fnfull path to model file, if None then assumed to be in

savepath/model.mod

data_fnfull path to data file, if None then assumed to be

in savepath/TE.dat or TM.dat

rough_type : roughness type. default = 0

max_iter : maximum number of iterations. default = 20

target_rms : target rms value. default = 1.0

start_rhostarting resistivity value on linear scale.

default = 100

description : description of the inversion.

start_lagrangestarting Lagrange multiplier for smoothness.

default = 5

start_rough : starting roughness value. default = 1E7

debuglevelsomething to do with how Fortran debuggs the code

Almost always leave at default = 1

start_iterthe starting iteration number, handy if the

starting model is from a previous run. default = 0

start_misfit : starting misfit value. default = 100

Returns:

Occam1D.inputfn : full path to input file.

Example:
>>> old = occam.Occam1D()
>>> old.make1DdataFile('MT01',edipath=r"/home/Line1",
>>>                    savepath=r"/home/Occam1D/Line1/Inv1_TE",
>>>                    mode='TE')
>>> Wrote Data File: /home/Occam1D/Line1/Inv1_TE/MT01TE.dat
>>>
>>> old.make1DModelFile(savepath=r"/home/Occam1D/Line1/Inv1_TE",
>>>                     nlayers=50,bottomlayer=10000,z1layer=50)
>>> Wrote Model file: /home/Occam1D/Line1/Inv1_TE/Model1D
>>>
>>> old.make1DInputFile(rhostart=10,targetrms=1.5,maxiter=15)
>>> Wrote Input File: /home/Occam1D/Line1/Inv1_TE/Input1D

mtpy.modeling.occam1d.tools module

Module contents

Created on Mon Oct 30 13:56:36 2023

@author: jpeacock

class mtpy.modeling.occam1d.Occam1DData(mt_dataframe, **kwargs)[source]

Bases: object

reads and writes occam 1D data files

Attributes

Description

_data_fn

basename of data file default is Occam1DDataFile

_header_line

header line for description of data columns

_ss

string spacing default is 6*’ ‘

_string_fmt

format of data default is ‘+.6e’

data

array of data

data_fn

full path to data file

freq

frequency array of data

mode

mode to invert for [ ‘TE’ | ‘TM’ | ‘det’ ]

phase_te

array of TE phase

phase_tm

array of TM phase

res_te

array of TE apparent resistivity

res_tm

array of TM apparent resistivity

resp_fn

full path to response file

save_path

path to save files to

Methods

Description

write_data_file

write an Occam1D data file

read_data_file

read an Occam1D data file

read_resp_file

read a .resp file output by Occam1D

Example:
>>> import mtpy.modeling.occam1d as occam1d
>>> #--> make a data file for TE mode
>>> d1 = occam1d.Data()
>>> d1.write_data_file(edi_file=r'/home/MT/mt01.edi', res_err=10, phase_err=2.5,
>>> ...                save_path=r"/home/occam1d/mt01/TE", mode='TE')
property mode
property mode_01
property mode_02
read_data_file(data_fn)[source]

reads a 1D data file

Arguments:

data_fn : full path to data file

Returns:

Occam1D.rpdict : dictionary with keys:

‘freq’ : an array of frequencies with length nf

‘resxy’TE resistivity array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

‘resyx’TM resistivity array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

‘phasexy’TE phase array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

‘phaseyx’TM phase array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

Example:
>>> old = occam1d.Data()
>>> old.data_fn = r"/home/Occam1D/Line1/Inv1_TE/MT01TE.dat"
>>> old.read_data_file()
read_resp_file(resp_fn=None, data_fn=None)[source]

read response file

resp_fn : full path to response file

data_fn : full path to data file

freq : an array of frequencies with length nf

res_teTE resistivity array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

res_tmTM resistivity array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

phase_teTE phase array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

phase_tmTM phase array with shape (nf,4) for (0) data,
  1. dataerr, (2) model, (3) modelerr

Example:

:: >>> o1d = occam1d.Data() >>> o1d.data_fn = r”/home/occam1d/mt01/TE/Occam1D_DataFile_TE.dat” >>> o1d.read_resp_file(r”/home/occam1d/mt01/TE/TE_7.resp”)

write_data_file(filename, mode='det', remove_outofquadrant=False)[source]

make1Ddatafile will write a data file for Occam1D

Arguments:

rp_tuplenp.ndarray (freq, res, res_err, phase, phase_err)

with res, phase having shape (num_freq, 2, 2).

edi_filestring

full path to edi file to be modeled.

save_pathstring

path to save the file, if None set to dirname of station if edipath = None. Otherwise set to dirname of edipath.

thetarfloat

rotation angle to rotate Z. Clockwise positive and N=0 default = 0

mode[ ‘te’ | ‘tm’ | ‘det’]
mode to model can be (*default*=’both’):
  • ‘te’ for just TE mode (res/phase)

  • ‘tm’ for just TM mode (res/phase)

  • ‘det’ for the determinant of Z (converted to

    res/phase)

add ‘z’ to any of these options to model impedance tensor values instead of res/phase

res_errfloat

errorbar for resistivity values. Can be set to ( default = ‘data’):

  • ‘data’ for errorbars from the data

  • percent number ex. 10 for ten percent

phase_errfloat

errorbar for phase values. Can be set to ( default = ‘data’):

  • ‘data’ for errorbars from the data

  • percent number ex. 10 for ten percent

res_errorfloor: float

error floor for resistivity values in percent

phase_errorfloor: float

error floor for phase in degrees

remove_outofquadrant: True/False; option to remove the resistivity and

phase values for points with phases out of the 1st/3rd quadrant (occam requires 0 < phase < 90 degrees; phases in the 3rd quadrant are shifted to the first by adding 180 degrees)

Example:
>>> import mtpy.modeling.occam1d as occam1d
>>> #--> make a data file
>>> d1 = occam1d.Data()
>>> d1.write_data_file(edi_file=r'/home/MT/mt01.edi', res_err=10,
>>> ...                phase_err=2.5, mode='TE',
>>> ...                save_path=r"/home/occam1d/mt01/TE")
class mtpy.modeling.occam1d.Occam1DModel(model_fn=None, **kwargs)[source]

Bases: object

read and write the model file fo Occam1D

All depth measurements are in meters.

Attributes

Description

_model_fn

basename for model file default is Model1D

_ss

string spacing in model file default is 3*’ ‘

_string_fmt

format of model layers default is ‘.0f’

air_layer_height

height of air layer default is 10000

bottom_layer

bottom of the model default is 50000

itdict

dictionary of values from iteration file

iter_fn

full path to iteration file

model_depth

array of model depths

model_fn

full path to model file

model_penalty

array of penalties for each model layer

model_preference_penalty

array of model preference penalties for each layer

model_prefernce

array of preferences for each layer

model_res

array of resistivities for each layer

n_layers

number of layers in the model

num_params

number of parameters to invert for (n_layers+2)

pad_z

padding of model at depth default is 5 blocks

save_path

path to save files

target_depth

depth of target to investigate

z1_layer

depth of first layer default is 10

Methods

Description

write_model_file

write an Occam1D model file, where depth increases on a logarithmic scale

read_model_file

read an Occam1D model file

read_iter_file

read an .iter file output by Occam1D

Example:
>>> #--> make a model file
>>> m1 = occam1d.Model()
>>> m1.write_model_file(save_path=r"/home/occam1d/mt01/TE")
read_iter_file(iter_fn=None, model_fn=None)[source]

read an 1D iteration file

Arguments:

imode : mode to read from

Returns:

Occam1D.itdict : dictionary with keys of the header:

model_resfills this array with the appropriate

values (0) for data, (1) for model

Example:
>>> m1 = occam1d.Model()
>>> m1.model_fn = r"/home/occam1d/mt01/TE/Model1D"
>>> m1.read_iter_file(r"/home/Occam1D/Inv1_TE/M01TE_15.iter")
read_model_file(model_fn=None)[source]

will read in model 1D file

Arguments:

modelfn : full path to model file

Fills attributes:

  • model_depth’ : depth of model in meters

  • model_res : value of resisitivity

  • model_penalty : penalty

  • model_preference : preference

  • model_penalty_preference : preference penalty

Example:
>>> m1 = occam1d.Model()
>>> m1.savepath = r"/home/Occam1D/Line1/Inv1_TE"
>>> m1.read_model_file()
write_model_file(save_path=None, **kwargs)[source]

Makes a 1D model file for Occam1D.

Arguments:

save_path :path to save file to, if just path saved as

savepathmodel.mod, if None defaults to dirpath

n_layers : number of layers

bottom_layer : depth of bottom layer in meters

target_depth : depth to target under investigation

pad_z : padding on bottom of model past target_depth

z1_layer : depth of first layer in meters

air_layer_height : height of air layers in meters

Returns:

Occam1D.modelfn = full path to model file

..Note: This needs to be redone.

Example:
>>> old = occam.Occam1D()
>>> old.make1DModelFile(savepath=r"/home/Occam1D/Line1/Inv1_TE",
>>>                     nlayers=50,bottomlayer=10000,z1layer=50)
>>> Wrote Model file: /home/Occam1D/Line1/Inv1_TE/Model1D
class mtpy.modeling.occam1d.Occam1DRun(startup_fn=None, occam_path=None, **kwargs)[source]

Bases: object

Run occam 1d from python given the correct files and location of occam1d executable

run_occam1d()[source]

Run occam1d.

class mtpy.modeling.occam1d.Occam1DStartup(data_fn=None, model_fn=None, **kwargs)[source]

Bases: object

read and write input files for Occam1D

Attributes

Description

_ss

string spacing

_startup_fn

basename of startup file default is OccamStartup1D

data_fn

full path to data file

debug_level

debug level default is 1

description

description of inversion for your self default is 1D_Occam_Inv

max_iter

maximum number of iterations default is 20

model_fn

full path to model file

rough_type

roughness type default is 1

save_path

full path to save files to

start_iter

first iteration number default is 0

start_lagrange

starting lagrange number on log scale default is 5

start_misfit

starting misfit value default is 100

start_rho

starting resistivity value (halfspace) in log scale default is 100

start_rough

starting roughness (ignored by Occam1D) default is 1E7

startup_fn

full path to startup file

target_rms

target rms default is 1.0

property data_fn
property model_fn
read_startup_file(startup_fn)[source]

reads in a 1D input file

Arguments:

inputfn : full path to input file

Returns:

Occam1D.indict : dictionary with keys following the header and

‘res’ : an array of resistivity values

Example:
>>> old = occam.Occam1d()
>>> old.savepath = r"/home/Occam1D/Line1/Inv1_TE"
>>> old.read1DInputFile()
write_startup_file(save_path=None, **kwargs)[source]

Make a 1D input file for Occam 1D

Arguments:

savepathfull path to save input file to, if just path then

saved as savepath/input

model_fnfull path to model file, if None then assumed to be in

savepath/model.mod

data_fnfull path to data file, if None then assumed to be

in savepath/TE.dat or TM.dat

rough_type : roughness type. default = 0

max_iter : maximum number of iterations. default = 20

target_rms : target rms value. default = 1.0

start_rhostarting resistivity value on linear scale.

default = 100

description : description of the inversion.

start_lagrangestarting Lagrange multiplier for smoothness.

default = 5

start_rough : starting roughness value. default = 1E7

debuglevelsomething to do with how Fortran debuggs the code

Almost always leave at default = 1

start_iterthe starting iteration number, handy if the

starting model is from a previous run. default = 0

start_misfit : starting misfit value. default = 100

Returns:

Occam1D.inputfn : full path to input file.

Example:
>>> old = occam.Occam1D()
>>> old.make1DdataFile('MT01',edipath=r"/home/Line1",
>>>                    savepath=r"/home/Occam1D/Line1/Inv1_TE",
>>>                    mode='TE')
>>> Wrote Data File: /home/Occam1D/Line1/Inv1_TE/MT01TE.dat
>>>
>>> old.make1DModelFile(savepath=r"/home/Occam1D/Line1/Inv1_TE",
>>>                     nlayers=50,bottomlayer=10000,z1layer=50)
>>> Wrote Model file: /home/Occam1D/Line1/Inv1_TE/Model1D
>>>
>>> old.make1DInputFile(rhostart=10,targetrms=1.5,maxiter=15)
>>> Wrote Input File: /home/Occam1D/Line1/Inv1_TE/Input1D
class mtpy.modeling.occam1d.Plot1DResponse(data_te_fn=None, data_tm_fn=None, model_fn=None, resp_te_fn=None, resp_tm_fn=None, iter_te_fn=None, iter_tm_fn=None, **kwargs)[source]

Bases: object

Plot the 1D response and model.

Plots apparent resisitivity and phase

in different subplots with the model on the far right. You can plot both

TE and TM modes together along with different iterations of the model. These will be plotted in different colors or shades of gray depneng on color_scale.

Example:
>>> import mtpy.modeling.occam1d as occam1d
>>> p1 = occam1d.Plot1DResponse(plot_yn='n')
>>> p1.data_te_fn = r"/home/occam1d/mt01/TE/Occam_DataFile_TE.dat"
>>> p1.data_tm_fn = r"/home/occam1d/mt01/TM/Occam_DataFile_TM.dat"
>>> p1.model_fn = r"/home/occam1d/mt01/TE/Model1D"
>>> p1.iter_te_fn = [r"/home/occam1d/mt01/TE/TE_{0}.iter".format(ii)
>>> ...              for ii in range(5,10)]
>>> p1.iter_tm_fn = [r"/home/occam1d/mt01/TM/TM_{0}.iter".format(ii)
>>> ...              for ii in range(5,10)]
>>> p1.resp_te_fn = [r"/home/occam1d/mt01/TE/TE_{0}.resp".format(ii)
>>> ...              for ii in range(5,10)]
>>> p1.resp_tm_fn = [r"/home/occam1d/mt01/TM/TM_{0}.resp".format(ii)
>>> ...              for ii in range(5,10)]
>>> p1.plot()

Attributes

Description

axm

matplotlib.axes instance for model subplot

axp

matplotlib.axes instance for phase subplot

axr

matplotlib.axes instance for app. res subplot

color_mode

[ ‘color’ | ‘bw’ ]

cted

color of TE data markers

ctem

color of TM data markers

ctmd

color of TE model markers

ctmm

color of TM model markers

data_te_fn

full path to data file for TE mode

data_tm_fn

full path to data file for TM mode

depth_limits

(min, max) limits for depth plot in depth_units

depth_scale

[ ‘log’ | ‘linear’ ] default is linear

depth_units

[ ‘m’ | ‘km’ ] *default is ‘km’

e_capsize

capsize of error bars

e_capthick

cap thickness of error bars

fig

matplotlib.figure instance for plot

fig_dpi

resolution in dots-per-inch for figure

fig_num

number of figure instance

fig_size

size of figure in inches [width, height]

font_size

size of axes tick labels, axes labels are +2

grid_alpha

transparency of grid

grid_color

color of grid

iter_te_fn

full path or list of .iter files for TE mode

iter_tm_fn

full path or list of .iter files for TM mode

lw

width of lines for model

model_fn

full path to model file

ms

marker size

mted

marker for TE data

mtem

marker for TM data

mtmd

marker for TE model

mtmm

marker for TM model

phase_limits

(min, max) limits on phase in degrees

phase_major_ticks

spacing for major ticks in phase

phase_minor_ticks

spacing for minor ticks in phase

plot_yn

[ ‘y’ | ‘n’ ] plot on instantiation

res_limits

limits of resistivity in linear scale

resp_te_fn

full path or list of .resp files for TE mode

resp_tm_fn

full path or list of .iter files for TM mode

subplot_bottom

spacing of subplots from bottom of figure

subplot_hspace

height spacing between subplots

subplot_left

spacing of subplots from left of figure

subplot_right

spacing of subplots from right of figure

subplot_top

spacing of subplots from top of figure

subplot_wspace

width spacing between subplots

title_str

title of plot

plot()[source]

Plot data, response and model.

redraw_plot()[source]

Redraw plot if parameters were changed

use this function if you updated some attributes and want to re-plot.

Example:
>>> # change the color and marker of the xy components
>>> import mtpy.modeling.occam2d as occam2d
>>> ocd = occam2d.Occam2DData(r"/home/occam2d/Data.dat")
>>> p1 = ocd.plotAllResponses()
>>> #change line width
>>> p1.lw = 2
>>> p1.redraw_plot().
save_figure(save_fn, file_format='pdf', orientation='portrait', fig_dpi=None, close_plot='y')[source]

Save_plot will save the figure to save_fn.

Arguments:

    **save_fn** : string
                  full path to save figure to, can be input as
                  * directory path -> the directory path to save to
                    in which the file will be saved as
                    save_fn/station_name_PhaseTensor.file_format

                  * full path -> file will be save to the given
                    path.  If you use this option then the format
                    will be assumed to be provided by the path

    **file_format** : [ pdf | eps | jpg | png | svg ]
                      file type of saved figure pdf,svg,eps...

    **orientation** : [ landscape | portrait ]
                      orientation in which the file will be saved
                      *default* is portrait

    **fig_dpi** : int
                  The resolution in dots-per-inch the file will be
                  saved.  If None then the dpi will be that at
                  which the figure was made.  I don't think that
                  it can be larger than dpi of the figure.

    **close_plot** : [ y | n ]
                     * 'y' will close the plot after saving.
                     * 'n' will leave plot open

:Example: ::

    >>> # to save plot as jpg
    >>> import mtpy.modeling.occam2d as occam2d
    >>> dfn = r"/home/occam2d/Inv1/data.dat"
    >>> ocd = occam2d.Occam2DData(dfn)
    >>> ps1 = ocd.plotPseudoSection()
    >>> ps1.save_plot(r'/home/MT/figures', file_format='jpg')
update_plot(fig)[source]

Update any parameters that where changed using the built-in draw from canvas.

Use this if you change an of the .fig or axes properties

Example:
>>> # to change the grid lines to only be on the major ticks
>>> import mtpy.modeling.occam2d as occam2d
>>> dfn = r"/home/occam2d/Inv1/data.dat"
>>> ocd = occam2d.Occam2DData(dfn)
>>> ps1 = ocd.plotAllResponses()
>>> [ax.grid(True, which='major') for ax in [ps1.axrte,ps1.axtep]]
>>> ps1.update_plot()
class mtpy.modeling.occam1d.PlotOccam1DL2(dir_path, model_fn, **kwargs)[source]

Bases: PlotBase

Plot L2 curve of iteration vs rms and roughness.

Arguments::
rms_arrstructured array with keys:
  • ‘iteration’ –> for iteration number (int)

  • ‘rms’ –> for rms (float)

  • ‘roughness’ –> for roughness (float)

Keywords/attributes

Description

ax1

matplotlib.axes instance for rms vs iteration

ax2

matplotlib.axes instance for roughness vs rms

fig

matplotlib.figure instance

fig_dpi

resolution of figure in dots-per-inch

fig_num

number of figure instance

fig_size

size of figure in inches (width, height)

font_size

size of axes tick labels, axes labels is +2

plot_yn

[ ‘y’ | ‘n’] ‘y’ –> to plot on instantiation ‘n’ –> to not plot on instantiation

rms_arr

structure np.array as described above

rms_color

color of rms marker and line

rms_lw

line width of rms line

rms_marker

marker for rms values

rms_marker_size

size of marker for rms values

rms_mean_color

color of mean line

rms_median_color

color of median line

rough_color

color of roughness line and marker

rough_font_size

font size for iteration number inside roughness marker

rough_lw

line width for roughness line

rough_marker

marker for roughness

rough_marker_size

size of marker for roughness

subplot_bottom

subplot spacing from bottom

subplot_left

subplot spacing from left

subplot_right

subplot spacing from right

subplot_top

subplot spacing from top

plot()[source]

Plot L2 curve.