RectilinearMesh1D
digraph inheritancef15b3b6232 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "ABC" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Helper class that provides a standard way to create an ABC using"]; "Mesh" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Abstract Base Class"]; "myObject" -> "Mesh" [arrowsize=0.5,style="setlinewidth(0.5)"]; "RectilinearMesh1D" [URL="#geobipy.src.classes.mesh.RectilinearMesh1D.RectilinearMesh1D",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Class defining a 1D rectilinear mesh with cell centres and edges."]; "Mesh" -> "RectilinearMesh1D" [arrowsize=0.5,style="setlinewidth(0.5)"]; "myObject" [URL="../core/myObject.html#geobipy.src.classes.core.myObject.myObject",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "ABC" -> "myObject" [arrowsize=0.5,style="setlinewidth(0.5)"]; }@RectilinearMesh1D_Class Module describing a 1D Rectilinear Mesh class
- class geobipy.src.classes.mesh.RectilinearMesh1D.RectilinearMesh1D(centres=None, edges=None, widths=None, log=None, relative_to=None, dimension=0)
Class defining a 1D rectilinear mesh with cell centres and edges.
Contains a simple 1D mesh with cell edges, widths, and centre locations.
RectilinearMesh1D(centres, edges, edgesMin, edgesMax)
- Parameters:
centres (geobipy.DataArray, optional) – The locations of the centre of each cell. Only centres, edges, or widths can be given.
edges (geobipy.DataArray, optional) – The locations of the edges of each cell, including the outermost edges. Only centres, edges, or widths can be given.
widths (geobipy.DataArray, optional) – The widths of the cells.
log ('e' or float, optional) – Entries are given in linear space, but internally cells are logged. Plotting is in log space.
relative_to (float, optional) – If a float is given, updates will be relative to this value.
- Returns:
out – The 1D mesh.
- Return type:
- Raises:
Exception – If both centres and edges are given.
TypeError – centres must be a geobipy.DataArray.
TypeError – edges must be a geobipy.DataArray.
- cellIndex(values, clip=False, trim=False, **kwargs)
Get the index to the cell that each value in values falls in.
- Parameters:
values (array_like) – The values to find the cell indices for
clip (bool) – A negative index which would normally wrap will clip to 0 and self.bins.size instead.
trim (bool) – Do not include out of axis indices. Negates clip, since they wont be included in the output.
- Returns:
out – The cell indices
- Return type:
array_like
- createHdf(parent, name, withPosterior=True, add_axis=None, fillvalue=None, upcast=True)
Create the hdf group metadata in file parent: HDF object to create a group inside myName: Name of the group
- delete_edge(i, values=None)
Delete an edge from the mesh
- Parameters:
i (int) – The edge to remove.
- Returns:
out – Mesh with edge removed.
- Return type:
- classmethod fromHdf(grp, index=None, skip_posterior=False)
Reads in the object froma HDF file
- gradient(values)
Compute the gradient
Parameter gradient \(\nabla_{z}\sigma\) at the ith layer is computed via
(1)\[\nabla_{z}^{i}\sigma = \frac{\sigma_{i+1} - \sigma_{i}}{h_{i} - h_{min}}\]where \(\sigma_{i+1}\) and \(\sigma_{i}\) are the log-parameters on either side of an interface, \(h_{i}\) is the log-thickness of the ith layer, and \(h_{min}\) is the minimum log thickness defined by
(2)\[h_{min} = \frac{z_{max} - z_{min}}{2 k_{max}}\]where \(k_{max}\) is a maximum number of layers, set to be far greater than the expected final solution.
- hdfName()
Reprodicibility procedure
- in_bounds(values)
Return whether values are inside the cell edges
- Parameters:
values (array_like) – Check if these are inside left <= values < right.
- Returns:
out – Are the values inside.
- Return type:
bools
- insert_edge(value, values=None)
Insert a new edge.
- Parameters:
value (numpy.float64) – Location at which to insert a new edge
- Returns:
out – Mesh with inserted edge.
- Return type:
geobipy.RectilinearMesh1D
- map_to_pdf(distribution, pdf, log=False, axis=0)
Creates a Hitmap from the model given the variance of each layer.
For each depth, creates a normal distribution with a mean equal to the interpolated parameter at that depth and variance specified with variance.
- Parameters:
variance (array_like) – The variance of each layer
Hitmap (geobipy.Hitmap) – Hitmap to convert the model to. Must be instantiated before calling so that the model can be interpolated correctly
- mask_cells(distance, values=None)
Mask cells by a distance.
If the edges of the cell are further than distance away, extra cells are inserted such that the cell’s new edges are at distance away from the centre.
- Parameters:
distance (float) – Distance to mask
values (array_like, optional) – If given, values will be remapped to the masked mesh.
- Returns:
out (RectilinearMesh1D) – Masked mesh
indices (ints) – Location of the original centres in the expanded mesh
out_values (array_like, optional) – If values is given, values will be remapped to the masked mesh.
- pad(size)
Copies the properties of a mesh including all priors or proposals, but pads memory to the given size
- Parameters:
size (int) – Create memory upto this size.
- Returns:
out – Padded mesg
- Return type:
- pcolor(values, **kwargs)
Create a pseudocolour plot.
Can take any other matplotlib arguments and keyword arguments e.g. cmap etc.
- Parameters:
values (array_like) – The value of each cell.
alpha (scalar or array_like, optional) – If alpha is scalar, behaves like standard matplotlib alpha and opacity is applied to entire plot If array_like, each pixel is given an individual alpha value.
log ('e' or float, optional) – Take the log of the colour to a base. ‘e’ if log = ‘e’, and a number e.g. log = 10. Values in c that are <= 0 are masked.
equalize (bool, optional) – Equalize the histogram of the colourmap so that all colours have an equal amount.
nbins (int, optional) – Number of bins to use for histogram equalization.
xscale (str, optional) – Scale the x axis? e.g. xscale = ‘linear’ or ‘log’
yscale (str, optional) – Scale the y axis? e.g. yscale = ‘linear’ or ‘log’.
flipX (bool, optional) – Flip the X axis
flipY (bool, optional) – Flip the Y axis
grid (bool, optional) – Plot the grid
noColorbar (bool, optional) – Turn off the colour bar, useful if multiple plotting plotting routines are used on the same figure.
trim (bool, optional) – Set the x and y limits to the first and last non zero values along each axis.
See also
geobipy.plotting.pcolor
For non matplotlib keywords.
matplotlib.pyplot.pcolormesh
For additional keyword arguments you may use.
- perturb(values=None)
Perturb the mesh
Generates a new mesh by perturbing the current mesh based on four probabilities. The probabilities correspond to * Birth, the insertion of a new interface * Death, the deletion of an interface * Change, change one the existing interfaces * No change, do nothing and return the original
The methods.set_priors and setProposals must be used before calling self.perturb.
If an interface is created, or an interface perturbed, any resulting cell width must be greater than the minimum width \(h_{min}\). If the new cell width test fails, the birth or perturbation tries again. If the cycle fails after 10 tries, the entire process begins again such that a death, or no change is possible thus preventing any never-ending cycles.
- Returns:
out – The perturbed mesh
- Return type:
See also
RectilinearMesh1D.set_priors
Must be used before calling self.perturb
RectilinearMesh1D.setProposals
Must be used before calling self.perturb
- piecewise_constant_interpolate(values, other, bound=False, axis=0)
Interpolate values of the cells to another RectilinearMesh in a piecewise constant manner.
- Parameters:
values (geobipy.StatArray) – The values to interpolate. Has size self.nCells
mesh (geobipy.RectilinearMeshND for N = 1, 2, 3.) – A mesh to interpolate to. If 2D, axis must be given to specify which axis to interpolate against.
bound (bool, optional) – Interpolated values above the top of the model are nan.
axis (int, optional) – Axis to interpolate the value to.
- Returns:
out – The interpolated values at the cell centres of the other mesh.
- Return type:
array
- plot(values, **kwargs)
Plots values using the mesh as a line
- Parameters:
reciprocateX (bool, optional) – Take the reciprocal of the x axis
xscale (str, optional) – Scale the x axis? e.g. xscale = ‘linear’ or ‘log’
yscale (str, optional) – Scale the y axis? e.g. yscale = ‘linear’ or ‘log’
flipX (bool, optional) – Flip the X axis
flipY (bool, optional) – Flip the Y axis
noLabels (bool, optional) – Do not plot the labels
- plot_grid(**kwargs)
Plot the grid lines of the mesh.
See also
geobipy.StatArray.pcolor
For additional plotting arguments
- property probability
Evaluate the prior probability for the mesh.
The following equation describes the components of the prior that correspond to the Model1D,
\[p(k | I)p(\boldsymbol{e}| k, I),\]where \(k, I, \boldsymbol{e}\) are the number of cells, prior information, edge location respectively.
The multiplication here can be turned into a summation by taking the log of the components.
- Parameters:
components (bool, optional) – Return all components used in the final probability as well as the final probability
- Returns:
probability (numpy.float64) – The probability
components (array_like, optional) – Return the components of the probability, i.e. the individually evaluated priors as a second return argument if comonents=True on input.
- property range
Get the difference between end edges.
- set_priors(n_cells_prior=None, edges_prior=None, **kwargs)
Setup the priors of the mesh.
By default the following priors are set unless explictly specified.
Prior on the number of cells
Uninformative prior using a uniform distribution.
(3)\[p(k | I) = \begin{cases} \frac{1}{k_{max} - 1} & \quad 1 \leq k \leq k_{max} \newline 0 & \quad otherwise \end{cases}.\]Prior on the cell edges
We use order statistics for the prior on cell edges.
(4)\[p(\boldsymbol{e} | k, I) = \frac{(k -1)!}{\prod_{i=0}^{k-1} \Delta e_{i}},\]where the numerator describes the number of ways that \((k - 1)\) interfaces can be ordered and \(\Delta e_{i} = (e_{max} - e_{min}) - 2 i h_{min}\) describes the interval that is available to place an edge when there are already i edges in the model
- Parameters:
min_edge (float64) – Minimum edge possible
max_edge (float64) – Maximum edge possible
max_cells (int) – Maximum number of cells allowable
min_width (float64, optional) – Minimum width of any layer. If min_width = None, min_width is computed from min_edge, max_edge, and max_cells (recommended).
prng (numpy.random.RandomState(), optional) – Random number generator, if none is given, will use numpy’s global generator.
n_cells_prior (geobipy.Distribution, optional) – Distribution describing the prior on the number of cells. Overrides the default.
edge_prior (geobipy.Distribution, optional) – Distribution describing the prior on the cell edges. Overrides the default.
See also
RectilinearMesh1D.perturb
For a description of the perturbation cycle.
- set_proposals(probabilities, **kwargs)
Setup the proposal distibution.
- Parameters:
probabilities (array_like) – Probability of birth, death, perturb, and no change for the model e.g. probabilities = [0.5, 0.25, 0.15, 0.1]
parameterProposal (geobipy.Distribution) – The proposal distribution for the parameter.
prng (numpy.random.RandomState(), optional) – Random number generator, if none is given, will use numpy’s global generator.
See also
geobipy.Model1D.perturb
For a description of the perturbation cycle.
- property summary
Summary of self
- unperturb()
After a mesh has had its structure perturbed, remap back its previous state. Used for the reversible jump McMC step.