mtpy.modeling.occam2d package
Submodules
mtpy.modeling.occam2d.data module
Created on Tue Mar 7 19:01:14 2023
@author: jpeacock
- class mtpy.modeling.occam2d.data.Occam2DData(dataframe=None, center_point=None, **kwargs)[source]
Bases:
objectReads and writes data files and more.
Inherets Profile, so the intended use is to use Data to project stations onto a profile, then write the data file.
Model Modes
Description
1 or log_all
Log resistivity of TE and TM plus Tipper
2 or log_te_tip
Log resistivity of TE plus Tipper
3 or log_tm_tip
Log resistivity of TM plus Tipper
4 or log_te_tm
Log resistivity of TE and TM
5 or log_te
Log resistivity of TE
6 or log_tm
Log resistivity of TM
7 or all
TE, TM and Tipper
8 or te_tip
TE plus Tipper
9 or tm_tip
TM plus Tipper
10 or te_tm
TE and TM mode
11 or te
TE mode
12 or tm
TM mode
13 or tip
Only Tipper
- Example Write Data File:
>>> from mtpy.modeling.occam2d import Data >>> occam_data_object = Data() >>> occam_data_object.read_data_file(r"path/to/data/file.dat") >>> occam_data_object.model_mode = 2 >>> occam_data_object.write_data_file(r"path/to/new/data/file_te.dat")
- property data_filename
Data filename.
- property dataframe
Dataframe function.
- property frequencies
Frequencies function.
- mask_from_datafile(mask_datafn)[source]
Reads a separate data file and applies mask from this data file.
mask_datafn needs to have exactly the same frequencies, and station names must match exactly.
- property n_data
N data.
- property n_frequencies
N frequencies.
- property n_stations
N stations.
- property offsets
Offsets function.
- read_data_file(data_fn=None)[source]
- Read in an existing data file and populate appropriate attributes
data
data_list
freq
station_list
station_locations
- Arguments::
- data_fnstring
full path to data file default is None and set to save_path/fn_basename
- Example:
>>> import mtpy.modeling.occam2d as occam2d >>> ocd = occam2d.Data() >>> ocd.read_data_file(r"/home/Occam2D/Line1/Inv1/Data.dat")
- read_response_file(response_fn=None, data_fn=None)[source]
- Read in an existing response file and populate the dataframe with
responses instead of data. Note, the data file also needs to be defined
- Arguments::
- response_fnstring
full path to data file default is None and set to save_path/fn_basename
- Example:
>>> import mtpy.modeling.occam2d as occam2d >>> ocr = occam2d.Data() >>> ocr.read_response_file(r"/home/Occam2D/Line1/Inv1/Data.dat")
- property stations
Stations function.
- write_data_file(data_fn=None)[source]
Write a data file.
- Arguments::
- data_fnstring
full path to data file. default is save_path/fn_basename
If there data is None, then _fill_data is called to create a profile, rotate data and get all the necessary data. This way you can use write_data_file directly without going through the steps of projecting the stations, etc.
- Example:
:: >>> edipath = r”/home/mt/edi_files” >>> slst = [‘mt{0:03}’.format(ss) for ss in range(1, 20)] >>> ocd = occam2d.Data(edi_path=edipath, station_list=slst) >>> ocd.save_path = r”/home/occam/line1/inv1” >>> ocd.write_data_file()
mtpy.modeling.occam2d.mesh module
Created on Tue Mar 7 18:02:57 2023
@author: jpeacock
- class mtpy.modeling.occam2d.mesh.Mesh(station_locations=None, **kwargs)[source]
Bases:
objectdeals only with the finite element mesh. Builds a finite element mesh based on given parameters defined below. The mesh reads in the station locations, finds the center and makes the relative location of the furthest left hand station 0. The mesh increases in depth logarithmically as required by the physics of MT. Also, the model extends horizontally and vertically with padding cells in order to fullfill the assumption of the forward operator that at the edges the structure is 1D. Stations are place on the horizontal nodes as required by Wannamaker’s forward operator.
Mesh has the ability to create a mesh that incorporates topography given a elevation profile. It adds more cells to the mesh with thickness z1_layer. It then sets the values of the triangular elements according to the elevation value at that location. If the elevation covers less than 50% of the triangular cell, then the cell value is set to that of air
Note
Mesh is inhereted by Regularization, so the mesh can also be be built from there, same as the example below.
Arguments:
Key Words/Attributes
Description
air_key
letter associated with the value of air default is 0
air_value
value given to an air cell, default is 1E13
cell_width
width of cells with in station area in meters default is 100
elevation_profile
elevation profile along the profile line. given as np.ndarray(nx, 2), where the elements are x_location, elevation. If elevation profile is given add_elevation is called automatically. default is None
mesh_fn
full path to mesh file.
mesh_values
letter values of each triangular mesh element if the cell is free value is ?
n_layers
number of vertical layers in mesh default is 90
num_x_pad_cells
number of horizontal padding cells outside the the station area that will increase in size by x_pad_multiplier. default is 7
num_x_pad_small_cells
number of horizonal padding cells just outside the station area with width cell_width. This is to extend the station area if needed. default is 2
num_z_pad_cells
number of vertical padding cells below z_target_depth down to z_bottom. default is 5
rel_station_locations
relative station locations within the mesh. The locations are relative to the center of the station area. default is None, filled later
save_path
full path to save mesh file to. default is current working directory.
station_locations
location of stations in meters, can be on a relative grid or in UTM.
x_grid
location of horizontal grid nodes in meters
x_nodes
relative spacing between grid nodes
x_pad_multiplier
horizontal padding cells will increase by this multiple out to the edge of the grid. default is 1.5
z1_layer
thickness of the first layer in the model. Should be at least 1/4 of the first skin depth default is 10
z_bottom
bottom depth of the model (m). Needs to be large enough to be 1D at the edge. default is 200000.0
z_grid
location of vertical nodes in meters
z_nodes
relative distance between vertical nodes in meters
z_target_depth
depth to deepest target of interest. Below this depth cells will be padded to z_bottom
Methods
Description
add_elevation
adds elevation to the mesh given elevation profile.
build_mesh
builds the mesh given the attributes of Mesh. If elevation_profile is not None, add_elevation is called inside build_mesh
plot_mesh
plots the built mesh with station location.
read_mesh_file
reads in an existing mesh file and populates the appropriate attributes.
write_mesh_file
writes a mesh file to save_path
- Example:
>>> import mtpy.modeling.occam2d as occcam2d >>> edipath = r"/home/mt/edi_files" >>> slist = ['mt{0:03}'.format(ss) for ss in range(20)] >>> ocd = occam2d.Data(edi_path=edipath, station_list=slist) >>> ocd.save_path = r"/home/occam/Line1/Inv1" >>> ocd.write_data_file() >>> ocm = occam2d.Mesh(ocd.station_locations) >>> # add in elevation >>> ocm.elevation_profile = ocd.elevation_profile >>> # change number of layers >>> ocm.n_layers = 110 >>> # change cell width in station area >>> ocm.cell_width = 200 >>> ocm.build_mesh() >>> ocm.plot_mesh() >>> ocm.save_path = ocd.save_path >>> ocm.write_mesh_file()
- add_elevation(elevation_profile=None)[source]
the elevation model needs to be in relative coordinates and be a numpy.ndarray(2, num_elevation_points) where the first column is the horizontal location and the second column is the elevation at that location.
If you have a elevation model use Profile to project the elevation information onto the profile line
To build the elevation I’m going to add the elevation to the top of the model which will add cells to the mesh. there might be a better way to do this, but this is the first attempt. So I’m going to assume that the first layer of the mesh without elevation is the minimum elevation and blocks will be added to max elevation at an increment according to z1_layer
Note
the elevation model should be symmetrical ie, starting at the first station and ending on the last station, so for now any elevation outside the station area will be ignored and set to the elevation of the station at the extremities. This is not ideal but works for now.
Arguments:
- elevation_profilenp.ndarray(2, num_elev_points)
1st row is for profile location
2nd row is for elevation values
Computes:
- mesh_valuesmesh values, setting anything above topography
to the key for air, which for Occam is ‘0’
- build_mesh()[source]
Build the finite element mesh given the parameters defined by the attributes of Mesh. Computes relative station locations by finding the center of the station area and setting the middle to 0. Mesh blocks are built by calculating the distance between stations and putting evenly spaced blocks between the stations being close to cell_width. This places a horizontal node at the station location. If the spacing between stations is smaller than cell_width, a horizontal node is placed between the stations to be sure the model has room to change between the station.
If elevation_profile is given, add_elevation is called to add topography into the mesh.
- Populates attributes:
mesh_values
rel_station_locations
x_grid
x_nodes
z_grid
z_nodes
- Example:
:: >>> import mtpy.modeling.occam2d as occcam2d >>> edipath = r”/home/mt/edi_files” >>> slist = [‘mt{0:03}’.format(ss) for ss in range(20)] >>> ocd = occam2d.Data(edi_path=edipath, station_list=slist) >>> ocd.save_path = r”/home/occam/Line1/Inv1” >>> ocd.write_data_file() >>> ocm = occam2d.Mesh(ocd.station_locations) >>> # add in elevation >>> ocm.elevation_profile = ocd.elevation_profile >>> # change number of layers >>> ocm.n_layers = 110 >>> # change cell width in station area >>> ocm.cell_width = 200 >>> ocm.build_mesh()
- plot_mesh(**kwargs)[source]
Plot built mesh with station locations.
Key Words
Description
depth_scale
[ ‘km’ | ‘m’ ] scale of mesh plot. default is ‘km’
fig_dpi
dots-per-inch resolution of the figure default is 300
fig_num
number of the figure instance default is ‘Mesh’
fig_size
size of figure in inches (width, height) default is [5, 5]
fs
size of font of axis tick labels, axis labels are fs+2. default is 6
ls
[ ‘-’ | ‘.’ | ‘:’ ] line style of mesh lines default is ‘-’
marker
marker of stations default is r”$lacktriangledown$”
ms
size of marker in points. default is 5
plot_triangles
[ ‘y’ | ‘n’ ] to plot mesh triangles. default is ‘n’
- read_mesh_file(mesh_fn)[source]
reads an occam2d 2D mesh file
Arguments:
- mesh_fnstring
full path to mesh file
Populates:
x_grid : array of horizontal locations of nodes (m)
- x_nodes: array of horizontal node relative distances
(column locations (m))
z_grid : array of vertical node locations (m)
- z_nodesarray of vertical nodes
(row locations(m))
mesh_values : np.array of free parameters
To do:
incorporate fixed values
- Example:
>>> import mtpy.modeling.occam2d as occam2d >>> mg = occam2d.Mesh() >>> mg.mesh_fn = r"/home/mt/occam/line1/Occam2Dmesh" >>> mg.read_mesh_file()
- write_mesh_file(save_path=None, basename='Occam2DMesh')[source]
Write a finite element mesh file.
Calls build_mesh if it already has not been called.
Arguments:
- save_pathstring
directory path or full path to save file
- basenamestring
basename of mesh file. default is ‘Occam2DMesh’
Returns:
- mesh_fnstring
full path to mesh file
- example:
>>> import mtpy.modeling.occam2d as occam2d >>> edi_path = r"/home/mt/edi_files" >>> profile = occam2d.Profile(edi_path) >>> profile.plot_profile() >>> mesh = occam2d.Mesh(profile.station_locations) >>> mesh.build_mesh() >>> mesh.write_mesh_file(save_path=r"/home/occam2d/Inv1")
mtpy.modeling.occam2d.model module
Created on Tue Mar 7 19:11:57 2023
@author: jpeacock
- class mtpy.modeling.occam2d.model.Occam2DModel(iter_fn=None, model_fn=None, mesh_fn=None, **kwargs)[source]
Bases:
StartupRead .iter file output by Occam2d. Builds the resistivity model from mesh and regularization files found from the .iter file. The resistivity model is an array(x_nodes, z_nodes) set on a regular grid, and the values of the model response are filled in according to the regularization grid. This allows for faster plotting.
Inherets Startup because they are basically the same object.
Argument:
- iter_fnstring
full path to .iter file to read. default is None.
- model_fnstring
full path to regularization file. default is None and found directly from the .iter file. Only input if the regularization is different from the file that is in the .iter file.
- mesh_fnstring
full path to mesh file. default is None Found directly from the model_fn file. Only input if the mesh is different from the file that is in the model file.
Key Words/Attributes
Description
data_fn
full path to data file
iter_fn
full path to .iter file
mesh_fn
full path to mesh file
mesh_x
np.ndarray(x_nodes, z_nodes) mesh grid for plotting
mesh_z
np.ndarray(x_nodes, z_nodes) mesh grid for plotting
model_values
model values from startup file
plot_x
nodes of mesh in horizontal direction
plot_z
nodes of mesh in vertical direction
res_model
np.ndarray(x_nodes, z_nodes) resistivity model values in linear scale
Methods
Description
build_model
get the resistivity model from the .iter file in a regular grid according to the mesh file with resistivity values according to the model file
read_iter_file
read .iter file and fill appropriate attributes
write_iter_file
write an .iter file incase you want to set it as the starting model or a priori model
- Example:
:: >>> model = occam2D.Model(r”/home/occam/line1/inv1/test_01.iter”) >>> model.build_model()
- read_iter_file(iter_fn=None)[source]
Read an iteration file.
Arguments:
- iter_fnstring
full path to iteration file if iterpath=None. If iterpath is input then iterfn is just the name of the file without the full path.
Returns:
- Example:
>>> import mtpy.modeling.occam2d as occam2d >>> itfn = r"/home/Occam2D/Line1/Inv1/Test_15.iter" >>> ocm = occam2d.Model(itfn) >>> ocm.read_iter_file()
mtpy.modeling.occam2d.regularization module
Created on Tue Mar 7 18:13:52 2023
@author: jpeacock
- class mtpy.modeling.occam2d.regularization.Regularization(station_locations=None, **kwargs)[source]
Bases:
MeshCreates a regularization grid based on Mesh.
Note that Mesh is inherited
- by Regularization, therefore the intended use is to build a mesh with
the Regularization class.
The regularization grid is what Occam calculates the inverse model on. Setup is tricky and can be painful, as you can see it is not quite fully functional yet, as it cannot incorporate topography yet. It seems like you’d like to have the regularization setup so that your target depth is covered well, in that the regularization blocks to this depth are sufficiently small to resolve resistivity structure at that depth. Finally, you want the regularization to go to a half space at the bottom, basically one giant block.
- Arguments::
- station_locationsnp.ndarray(n_stations)
array of station locations along a profile line in meters.
Key Words/Attributes
Description
air_key
letter associated with the value of air default is 0
air_value
value given to an air cell, default is 1E13
binding_offset
offset from the right side of the furthest left hand model block in meters. The regularization grid is setup such that this should be 0.
cell_width
width of cells with in station area in meters default is 100
description
description of the model for the model file. default is ‘simple inversion’
elevation_profile
elevation profile along the profile line. given as np.ndarray(nx, 2), where the elements are x_location, elevation. If elevation profile is given add_elevation is called automatically. default is None
mesh_fn
full path to mesh file.
mesh_values
letter values of each triangular mesh element if the cell is free value is ?
model_columns
model_name
model_rows
min_block_width
[ float ] minimum model block width in meters, default is 2*cell_width
n_layers
number of vertical layers in mesh default is 90
num_free_param
[ int ] number of free parameters in the model. this is a tricky number to estimate apparently.
num_layers
[ int ] number of regularization layers.
num_x_pad_cells
number of horizontal padding cells outside the the station area that will increase in size by x_pad_multiplier. default is 7
num_x_pad_small_cells
number of horizonal padding cells just outside the station area with width cell_width. This is to extend the station area if needed. default is 2
num_z_pad_cells
number of vertical padding cells below z_target_depth down to z_bottom. default is 5
prejudice_fn
full path to prejudice file default is ‘none’
reg_basename
basename of regularization file (model file) default is ‘Occam2DModel’
reg_fn
full path to regularization file (model file) default is save_path/reg_basename
rel_station_locations
relative station locations within the mesh. The locations are relative to the center of the station area. default is None, filled later
save_path
full path to save mesh and model file to. default is current working directory.
statics_fn
full path to static shift file Static shifts in occam may not work. default is ‘none’
station_locations
location of stations in meters, can be on a relative grid or in UTM.
trigger
[ float ] multiplier to merge model blocks at depth. A higher number increases the number of model blocks at depth. default is .65
x_grid
location of horizontal grid nodes in meters
x_nodes
relative spacing between grid nodes
x_pad_multiplier
horizontal padding cells will increase by this multiple out to the edge of the grid. default is 1.5
z1_layer
thickness of the first layer in the model. Should be at least 1/4 of the first skin depth default is 10
z_bottom
bottom depth of the model (m). Needs to be large enough to be 1D at the edge. default is 200000.0
z_grid
location of vertical nodes in meters
z_nodes
relative distance between vertical nodes in meters
z_target_depth
depth to deepest target of interest. Below this depth cells will be padded to z_bottom
Note
regularization does not work with topography yet. Having problems calculating the number of free parameters.
- Example:
>>> edipath = r"/home/mt/edi_files" >>> profile = occam2d.Profile(edi_path=edi_path) >>> profile.generate_profile() >>> reg = occam2d.Regularization(profile.station_locations) >>> reg.build_mesh() >>> reg.build_regularization() >>> reg.save_path = r"/home/occam2d/Line1/Inv1" >>> reg.write_regularization_file()
- build_regularization()[source]
Builds larger boxes around existing mesh blocks for the regularization.
As the model deepens the regularization boxes get larger.
The regularization boxes are merged mesh cells as prescribed by the Occam method.
- get_block_cell_centres()[source]
Get cell centres of blocks, and indices in model_values array for each mesh block.
- Return type:
None.
- get_num_free_params()[source]
Estimate the number of free parameters in model mesh.
I’m assuming that if there are any fixed parameters in the block, then that model block is assumed to be fixed. Not sure if this is right cause there is no documentation.
DOES NOT WORK YET
- read_regularization_file(reg_fn)[source]
Read in a regularization file and populate attributes: * binding_offset * mesh_fn * model_columns * model_rows * prejudice_fn * statics_fn
- write_regularization_file(reg_fn=None, reg_basename=None, statics_fn='none', prejudice_fn='none', save_path=None)[source]
Write a regularization file for input into occam.
Calls build_regularization if build_regularization has not already been called.
if reg_fn is None, then file is written to save_path/reg_basename
- Arguments::
- reg_fnstring
full path to regularization file. default is None and file will be written to save_path/reg_basename
- reg_basenamestring
basename of regularization file
- statics_fnstring
full path to static shift file .. note:: static shift does not always work in
occam2d.exe
- prejudice_fnstring
full path to prejudice file
- save_pathstring
path to save regularization file. default is current working directory
mtpy.modeling.occam2d.startup module
Created on Tue Mar 7 18:24:58 2023
@author: jpeacock
- class mtpy.modeling.occam2d.startup.Startup(**kwargs)[source]
Bases:
objectReads and writes the startup file for Occam2D.
Note
Be sure to look at the Occam 2D documentation for description of all parameters
Key Words/Attributes
Description
data_fn
full path to data file
date_time
date and time the startup file was written
debug_level
[ 0 | 1 | 2 ] see occam documentation default is 1
description
brief description of inversion run default is ‘startup created by mtpy’
diagonal_penalties
penalties on diagonal terms default is 0
format
Occam file format default is ‘OCCAMITER_FLEX’
iteration
current iteration number default is 0
iterations_to_run
maximum number of iterations to run default is 20
lagrange_value
starting lagrange value default is 5
misfit_reached
[ 0 | 1 ] 0 if misfit has been reached, 1 if it has. default is 0
misfit_value
current misfit value. default is 1000
model_fn
full path to model file
model_limits
limits on model resistivity values default is None
model_value_steps
limits on the step size of model values default is None
model_values
np.ndarray(num_free_params) of model values
param_count
number of free parameters in model
resistivity_start
starting resistivity value. If model_values is not given, then all values with in model_values array will be set to resistivity_start
roughness_type
[ 0 | 1 | 2 ] type of roughness default is 1
roughness_value
current roughness value. default is 1E10
save_path
directory path to save startup file to default is current working directory
startup_basename
basename of startup file name. default is Occam2DStartup
startup_fn
full path to startup file. default is save_path/startup_basename
stepsize_count
max number of iterations per step default is 8
target_misfit
target misfit value. default is 1.
- Example:
>>> startup = occam2d.Startup() >>> startup.data_fn = ocd.data_fn >>> startup.model_fn = profile.reg_fn >>> startup.param_count = profile.num_free_params >>> startup.save_path = r"/home/occam2d/Line1/Inv1"
- write_startup_file(startup_fn=None, save_path=None, startup_basename=None)[source]
Write a startup file based on the parameters of startup class.
Default file name is save_path/startup_basename
- Arguments::
- startup_fnstring
full path to startup file. default is None
- save_pathstring
directory to save startup file. default is None
- startup_basenamestring
basename of starup file. default is None
Module contents
- class mtpy.modeling.occam2d.Mesh(station_locations=None, **kwargs)[source]
Bases:
objectdeals only with the finite element mesh. Builds a finite element mesh based on given parameters defined below. The mesh reads in the station locations, finds the center and makes the relative location of the furthest left hand station 0. The mesh increases in depth logarithmically as required by the physics of MT. Also, the model extends horizontally and vertically with padding cells in order to fullfill the assumption of the forward operator that at the edges the structure is 1D. Stations are place on the horizontal nodes as required by Wannamaker’s forward operator.
Mesh has the ability to create a mesh that incorporates topography given a elevation profile. It adds more cells to the mesh with thickness z1_layer. It then sets the values of the triangular elements according to the elevation value at that location. If the elevation covers less than 50% of the triangular cell, then the cell value is set to that of air
Note
Mesh is inhereted by Regularization, so the mesh can also be be built from there, same as the example below.
Arguments:
Key Words/Attributes
Description
air_key
letter associated with the value of air default is 0
air_value
value given to an air cell, default is 1E13
cell_width
width of cells with in station area in meters default is 100
elevation_profile
elevation profile along the profile line. given as np.ndarray(nx, 2), where the elements are x_location, elevation. If elevation profile is given add_elevation is called automatically. default is None
mesh_fn
full path to mesh file.
mesh_values
letter values of each triangular mesh element if the cell is free value is ?
n_layers
number of vertical layers in mesh default is 90
num_x_pad_cells
number of horizontal padding cells outside the the station area that will increase in size by x_pad_multiplier. default is 7
num_x_pad_small_cells
number of horizonal padding cells just outside the station area with width cell_width. This is to extend the station area if needed. default is 2
num_z_pad_cells
number of vertical padding cells below z_target_depth down to z_bottom. default is 5
rel_station_locations
relative station locations within the mesh. The locations are relative to the center of the station area. default is None, filled later
save_path
full path to save mesh file to. default is current working directory.
station_locations
location of stations in meters, can be on a relative grid or in UTM.
x_grid
location of horizontal grid nodes in meters
x_nodes
relative spacing between grid nodes
x_pad_multiplier
horizontal padding cells will increase by this multiple out to the edge of the grid. default is 1.5
z1_layer
thickness of the first layer in the model. Should be at least 1/4 of the first skin depth default is 10
z_bottom
bottom depth of the model (m). Needs to be large enough to be 1D at the edge. default is 200000.0
z_grid
location of vertical nodes in meters
z_nodes
relative distance between vertical nodes in meters
z_target_depth
depth to deepest target of interest. Below this depth cells will be padded to z_bottom
Methods
Description
add_elevation
adds elevation to the mesh given elevation profile.
build_mesh
builds the mesh given the attributes of Mesh. If elevation_profile is not None, add_elevation is called inside build_mesh
plot_mesh
plots the built mesh with station location.
read_mesh_file
reads in an existing mesh file and populates the appropriate attributes.
write_mesh_file
writes a mesh file to save_path
- Example:
>>> import mtpy.modeling.occam2d as occcam2d >>> edipath = r"/home/mt/edi_files" >>> slist = ['mt{0:03}'.format(ss) for ss in range(20)] >>> ocd = occam2d.Data(edi_path=edipath, station_list=slist) >>> ocd.save_path = r"/home/occam/Line1/Inv1" >>> ocd.write_data_file() >>> ocm = occam2d.Mesh(ocd.station_locations) >>> # add in elevation >>> ocm.elevation_profile = ocd.elevation_profile >>> # change number of layers >>> ocm.n_layers = 110 >>> # change cell width in station area >>> ocm.cell_width = 200 >>> ocm.build_mesh() >>> ocm.plot_mesh() >>> ocm.save_path = ocd.save_path >>> ocm.write_mesh_file()
- add_elevation(elevation_profile=None)[source]
the elevation model needs to be in relative coordinates and be a numpy.ndarray(2, num_elevation_points) where the first column is the horizontal location and the second column is the elevation at that location.
If you have a elevation model use Profile to project the elevation information onto the profile line
To build the elevation I’m going to add the elevation to the top of the model which will add cells to the mesh. there might be a better way to do this, but this is the first attempt. So I’m going to assume that the first layer of the mesh without elevation is the minimum elevation and blocks will be added to max elevation at an increment according to z1_layer
Note
the elevation model should be symmetrical ie, starting at the first station and ending on the last station, so for now any elevation outside the station area will be ignored and set to the elevation of the station at the extremities. This is not ideal but works for now.
Arguments:
- elevation_profilenp.ndarray(2, num_elev_points)
1st row is for profile location
2nd row is for elevation values
Computes:
- mesh_valuesmesh values, setting anything above topography
to the key for air, which for Occam is ‘0’
- build_mesh()[source]
Build the finite element mesh given the parameters defined by the attributes of Mesh. Computes relative station locations by finding the center of the station area and setting the middle to 0. Mesh blocks are built by calculating the distance between stations and putting evenly spaced blocks between the stations being close to cell_width. This places a horizontal node at the station location. If the spacing between stations is smaller than cell_width, a horizontal node is placed between the stations to be sure the model has room to change between the station.
If elevation_profile is given, add_elevation is called to add topography into the mesh.
- Populates attributes:
mesh_values
rel_station_locations
x_grid
x_nodes
z_grid
z_nodes
- Example:
:: >>> import mtpy.modeling.occam2d as occcam2d >>> edipath = r”/home/mt/edi_files” >>> slist = [‘mt{0:03}’.format(ss) for ss in range(20)] >>> ocd = occam2d.Data(edi_path=edipath, station_list=slist) >>> ocd.save_path = r”/home/occam/Line1/Inv1” >>> ocd.write_data_file() >>> ocm = occam2d.Mesh(ocd.station_locations) >>> # add in elevation >>> ocm.elevation_profile = ocd.elevation_profile >>> # change number of layers >>> ocm.n_layers = 110 >>> # change cell width in station area >>> ocm.cell_width = 200 >>> ocm.build_mesh()
- plot_mesh(**kwargs)[source]
Plot built mesh with station locations.
Key Words
Description
depth_scale
[ ‘km’ | ‘m’ ] scale of mesh plot. default is ‘km’
fig_dpi
dots-per-inch resolution of the figure default is 300
fig_num
number of the figure instance default is ‘Mesh’
fig_size
size of figure in inches (width, height) default is [5, 5]
fs
size of font of axis tick labels, axis labels are fs+2. default is 6
ls
[ ‘-’ | ‘.’ | ‘:’ ] line style of mesh lines default is ‘-’
marker
marker of stations default is r”$lacktriangledown$”
ms
size of marker in points. default is 5
plot_triangles
[ ‘y’ | ‘n’ ] to plot mesh triangles. default is ‘n’
- read_mesh_file(mesh_fn)[source]
reads an occam2d 2D mesh file
Arguments:
- mesh_fnstring
full path to mesh file
Populates:
x_grid : array of horizontal locations of nodes (m)
- x_nodes: array of horizontal node relative distances
(column locations (m))
z_grid : array of vertical node locations (m)
- z_nodesarray of vertical nodes
(row locations(m))
mesh_values : np.array of free parameters
To do:
incorporate fixed values
- Example:
>>> import mtpy.modeling.occam2d as occam2d >>> mg = occam2d.Mesh() >>> mg.mesh_fn = r"/home/mt/occam/line1/Occam2Dmesh" >>> mg.read_mesh_file()
- write_mesh_file(save_path=None, basename='Occam2DMesh')[source]
Write a finite element mesh file.
Calls build_mesh if it already has not been called.
Arguments:
- save_pathstring
directory path or full path to save file
- basenamestring
basename of mesh file. default is ‘Occam2DMesh’
Returns:
- mesh_fnstring
full path to mesh file
- example:
>>> import mtpy.modeling.occam2d as occam2d >>> edi_path = r"/home/mt/edi_files" >>> profile = occam2d.Profile(edi_path) >>> profile.plot_profile() >>> mesh = occam2d.Mesh(profile.station_locations) >>> mesh.build_mesh() >>> mesh.write_mesh_file(save_path=r"/home/occam2d/Inv1")
- class mtpy.modeling.occam2d.Occam2DData(dataframe=None, center_point=None, **kwargs)[source]
Bases:
objectReads and writes data files and more.
Inherets Profile, so the intended use is to use Data to project stations onto a profile, then write the data file.
Model Modes
Description
1 or log_all
Log resistivity of TE and TM plus Tipper
2 or log_te_tip
Log resistivity of TE plus Tipper
3 or log_tm_tip
Log resistivity of TM plus Tipper
4 or log_te_tm
Log resistivity of TE and TM
5 or log_te
Log resistivity of TE
6 or log_tm
Log resistivity of TM
7 or all
TE, TM and Tipper
8 or te_tip
TE plus Tipper
9 or tm_tip
TM plus Tipper
10 or te_tm
TE and TM mode
11 or te
TE mode
12 or tm
TM mode
13 or tip
Only Tipper
- Example Write Data File:
>>> from mtpy.modeling.occam2d import Data >>> occam_data_object = Data() >>> occam_data_object.read_data_file(r"path/to/data/file.dat") >>> occam_data_object.model_mode = 2 >>> occam_data_object.write_data_file(r"path/to/new/data/file_te.dat")
- property data_filename
Data filename.
- property dataframe
Dataframe function.
- property frequencies
Frequencies function.
- mask_from_datafile(mask_datafn)[source]
Reads a separate data file and applies mask from this data file.
mask_datafn needs to have exactly the same frequencies, and station names must match exactly.
- property n_data
N data.
- property n_frequencies
N frequencies.
- property n_stations
N stations.
- property offsets
Offsets function.
- read_data_file(data_fn=None)[source]
- Read in an existing data file and populate appropriate attributes
data
data_list
freq
station_list
station_locations
- Arguments::
- data_fnstring
full path to data file default is None and set to save_path/fn_basename
- Example:
>>> import mtpy.modeling.occam2d as occam2d >>> ocd = occam2d.Data() >>> ocd.read_data_file(r"/home/Occam2D/Line1/Inv1/Data.dat")
- read_response_file(response_fn=None, data_fn=None)[source]
- Read in an existing response file and populate the dataframe with
responses instead of data. Note, the data file also needs to be defined
- Arguments::
- response_fnstring
full path to data file default is None and set to save_path/fn_basename
- Example:
>>> import mtpy.modeling.occam2d as occam2d >>> ocr = occam2d.Data() >>> ocr.read_response_file(r"/home/Occam2D/Line1/Inv1/Data.dat")
- property stations
Stations function.
- write_data_file(data_fn=None)[source]
Write a data file.
- Arguments::
- data_fnstring
full path to data file. default is save_path/fn_basename
If there data is None, then _fill_data is called to create a profile, rotate data and get all the necessary data. This way you can use write_data_file directly without going through the steps of projecting the stations, etc.
- Example:
:: >>> edipath = r”/home/mt/edi_files” >>> slst = [‘mt{0:03}’.format(ss) for ss in range(1, 20)] >>> ocd = occam2d.Data(edi_path=edipath, station_list=slst) >>> ocd.save_path = r”/home/occam/line1/inv1” >>> ocd.write_data_file()
- class mtpy.modeling.occam2d.Occam2DModel(iter_fn=None, model_fn=None, mesh_fn=None, **kwargs)[source]
Bases:
StartupRead .iter file output by Occam2d. Builds the resistivity model from mesh and regularization files found from the .iter file. The resistivity model is an array(x_nodes, z_nodes) set on a regular grid, and the values of the model response are filled in according to the regularization grid. This allows for faster plotting.
Inherets Startup because they are basically the same object.
Argument:
- iter_fnstring
full path to .iter file to read. default is None.
- model_fnstring
full path to regularization file. default is None and found directly from the .iter file. Only input if the regularization is different from the file that is in the .iter file.
- mesh_fnstring
full path to mesh file. default is None Found directly from the model_fn file. Only input if the mesh is different from the file that is in the model file.
Key Words/Attributes
Description
data_fn
full path to data file
iter_fn
full path to .iter file
mesh_fn
full path to mesh file
mesh_x
np.ndarray(x_nodes, z_nodes) mesh grid for plotting
mesh_z
np.ndarray(x_nodes, z_nodes) mesh grid for plotting
model_values
model values from startup file
plot_x
nodes of mesh in horizontal direction
plot_z
nodes of mesh in vertical direction
res_model
np.ndarray(x_nodes, z_nodes) resistivity model values in linear scale
Methods
Description
build_model
get the resistivity model from the .iter file in a regular grid according to the mesh file with resistivity values according to the model file
read_iter_file
read .iter file and fill appropriate attributes
write_iter_file
write an .iter file incase you want to set it as the starting model or a priori model
- Example:
:: >>> model = occam2D.Model(r”/home/occam/line1/inv1/test_01.iter”) >>> model.build_model()
- read_iter_file(iter_fn=None)[source]
Read an iteration file.
Arguments:
- iter_fnstring
full path to iteration file if iterpath=None. If iterpath is input then iterfn is just the name of the file without the full path.
Returns:
- Example:
>>> import mtpy.modeling.occam2d as occam2d >>> itfn = r"/home/Occam2D/Line1/Inv1/Test_15.iter" >>> ocm = occam2d.Model(itfn) >>> ocm.read_iter_file()
- class mtpy.modeling.occam2d.Regularization(station_locations=None, **kwargs)[source]
Bases:
MeshCreates a regularization grid based on Mesh.
Note that Mesh is inherited
- by Regularization, therefore the intended use is to build a mesh with
the Regularization class.
The regularization grid is what Occam calculates the inverse model on. Setup is tricky and can be painful, as you can see it is not quite fully functional yet, as it cannot incorporate topography yet. It seems like you’d like to have the regularization setup so that your target depth is covered well, in that the regularization blocks to this depth are sufficiently small to resolve resistivity structure at that depth. Finally, you want the regularization to go to a half space at the bottom, basically one giant block.
- Arguments::
- station_locationsnp.ndarray(n_stations)
array of station locations along a profile line in meters.
Key Words/Attributes
Description
air_key
letter associated with the value of air default is 0
air_value
value given to an air cell, default is 1E13
binding_offset
offset from the right side of the furthest left hand model block in meters. The regularization grid is setup such that this should be 0.
cell_width
width of cells with in station area in meters default is 100
description
description of the model for the model file. default is ‘simple inversion’
elevation_profile
elevation profile along the profile line. given as np.ndarray(nx, 2), where the elements are x_location, elevation. If elevation profile is given add_elevation is called automatically. default is None
mesh_fn
full path to mesh file.
mesh_values
letter values of each triangular mesh element if the cell is free value is ?
model_columns
model_name
model_rows
min_block_width
[ float ] minimum model block width in meters, default is 2*cell_width
n_layers
number of vertical layers in mesh default is 90
num_free_param
[ int ] number of free parameters in the model. this is a tricky number to estimate apparently.
num_layers
[ int ] number of regularization layers.
num_x_pad_cells
number of horizontal padding cells outside the the station area that will increase in size by x_pad_multiplier. default is 7
num_x_pad_small_cells
number of horizonal padding cells just outside the station area with width cell_width. This is to extend the station area if needed. default is 2
num_z_pad_cells
number of vertical padding cells below z_target_depth down to z_bottom. default is 5
prejudice_fn
full path to prejudice file default is ‘none’
reg_basename
basename of regularization file (model file) default is ‘Occam2DModel’
reg_fn
full path to regularization file (model file) default is save_path/reg_basename
rel_station_locations
relative station locations within the mesh. The locations are relative to the center of the station area. default is None, filled later
save_path
full path to save mesh and model file to. default is current working directory.
statics_fn
full path to static shift file Static shifts in occam may not work. default is ‘none’
station_locations
location of stations in meters, can be on a relative grid or in UTM.
trigger
[ float ] multiplier to merge model blocks at depth. A higher number increases the number of model blocks at depth. default is .65
x_grid
location of horizontal grid nodes in meters
x_nodes
relative spacing between grid nodes
x_pad_multiplier
horizontal padding cells will increase by this multiple out to the edge of the grid. default is 1.5
z1_layer
thickness of the first layer in the model. Should be at least 1/4 of the first skin depth default is 10
z_bottom
bottom depth of the model (m). Needs to be large enough to be 1D at the edge. default is 200000.0
z_grid
location of vertical nodes in meters
z_nodes
relative distance between vertical nodes in meters
z_target_depth
depth to deepest target of interest. Below this depth cells will be padded to z_bottom
Note
regularization does not work with topography yet. Having problems calculating the number of free parameters.
- Example:
>>> edipath = r"/home/mt/edi_files" >>> profile = occam2d.Profile(edi_path=edi_path) >>> profile.generate_profile() >>> reg = occam2d.Regularization(profile.station_locations) >>> reg.build_mesh() >>> reg.build_regularization() >>> reg.save_path = r"/home/occam2d/Line1/Inv1" >>> reg.write_regularization_file()
- build_regularization()[source]
Builds larger boxes around existing mesh blocks for the regularization.
As the model deepens the regularization boxes get larger.
The regularization boxes are merged mesh cells as prescribed by the Occam method.
- get_block_cell_centres()[source]
Get cell centres of blocks, and indices in model_values array for each mesh block.
- Return type:
None.
- get_num_free_params()[source]
Estimate the number of free parameters in model mesh.
I’m assuming that if there are any fixed parameters in the block, then that model block is assumed to be fixed. Not sure if this is right cause there is no documentation.
DOES NOT WORK YET
- read_regularization_file(reg_fn)[source]
Read in a regularization file and populate attributes: * binding_offset * mesh_fn * model_columns * model_rows * prejudice_fn * statics_fn
- write_regularization_file(reg_fn=None, reg_basename=None, statics_fn='none', prejudice_fn='none', save_path=None)[source]
Write a regularization file for input into occam.
Calls build_regularization if build_regularization has not already been called.
if reg_fn is None, then file is written to save_path/reg_basename
- Arguments::
- reg_fnstring
full path to regularization file. default is None and file will be written to save_path/reg_basename
- reg_basenamestring
basename of regularization file
- statics_fnstring
full path to static shift file .. note:: static shift does not always work in
occam2d.exe
- prejudice_fnstring
full path to prejudice file
- save_pathstring
path to save regularization file. default is current working directory
- class mtpy.modeling.occam2d.Startup(**kwargs)[source]
Bases:
objectReads and writes the startup file for Occam2D.
Note
Be sure to look at the Occam 2D documentation for description of all parameters
Key Words/Attributes
Description
data_fn
full path to data file
date_time
date and time the startup file was written
debug_level
[ 0 | 1 | 2 ] see occam documentation default is 1
description
brief description of inversion run default is ‘startup created by mtpy’
diagonal_penalties
penalties on diagonal terms default is 0
format
Occam file format default is ‘OCCAMITER_FLEX’
iteration
current iteration number default is 0
iterations_to_run
maximum number of iterations to run default is 20
lagrange_value
starting lagrange value default is 5
misfit_reached
[ 0 | 1 ] 0 if misfit has been reached, 1 if it has. default is 0
misfit_value
current misfit value. default is 1000
model_fn
full path to model file
model_limits
limits on model resistivity values default is None
model_value_steps
limits on the step size of model values default is None
model_values
np.ndarray(num_free_params) of model values
param_count
number of free parameters in model
resistivity_start
starting resistivity value. If model_values is not given, then all values with in model_values array will be set to resistivity_start
roughness_type
[ 0 | 1 | 2 ] type of roughness default is 1
roughness_value
current roughness value. default is 1E10
save_path
directory path to save startup file to default is current working directory
startup_basename
basename of startup file name. default is Occam2DStartup
startup_fn
full path to startup file. default is save_path/startup_basename
stepsize_count
max number of iterations per step default is 8
target_misfit
target misfit value. default is 1.
- Example:
>>> startup = occam2d.Startup() >>> startup.data_fn = ocd.data_fn >>> startup.model_fn = profile.reg_fn >>> startup.param_count = profile.num_free_params >>> startup.save_path = r"/home/occam2d/Line1/Inv1"
- write_startup_file(startup_fn=None, save_path=None, startup_basename=None)[source]
Write a startup file based on the parameters of startup class.
Default file name is save_path/startup_basename
- Arguments::
- startup_fnstring
full path to startup file. default is None
- save_pathstring
directory to save startup file. default is None
- startup_basenamestring
basename of starup file. default is None