volcapy.niklas package

Submodules

volcapy.niklas.banerjee module

Implements the Banerjee formula for the gravitational field froduced by a parallelepiped of uniform density.

volcapy.niklas.banerjee.banerjee(double xh, double xl, double yh, double yl, double zh, double zl, double x_data, double y_data, double z_data)

Returns the gravity field (measured at a data point) produced by a parallelepiped of uniform unit density.

Parameters
xh: float

Location (in meters) of the upper (maximal x) corner of the parallelepiped.

xl: float

Same, but lower corner.

yh: float

Same but along y dimension.

yl: float

Same but along y dimension.

zh: float

Same but along z dimension.

zl: float

Same but along z dimension.

x_data: float

x coordinate (in meters) of the location at which we measure the field.

y_data: float
z_data: float

volcapy.niklas.cell module

Put the definition of a cell in its own file for imports reasons.

class volcapy.niklas.cell.Cell(xl, xh, yl, yh, zl, zh)[source]

Bases: object

Class representing a cell in the inversion grid. A cell is just a cuboid, so all we need are the min and max along each coordinate. Distances should be in meters.

Parameters
xlfloat

Minimum along x-axis (l for low).

xhfloat

Maximum along x-axis (h for high).

ylfloat

Minimum along y-axis (l for low).

yhfloat

Maximum along y-axis (h for high).

zlfloat

Minimum along z-axis (l for low).

zhfloat

Maximum along z-axis (h for high).

volcapy.niklas.coarsener module

Class implementing coarsening functions.

THIS IS STRICTLY 2-DIMENSIONAL, i.e., this only refers to x-y slice.

We might want to have an inversion grid that is coarser than the dsm, i.e., each cell in the inversion grid corresponds to several cells in the dsm grid.

We define the relation fine_grid <-> coarse grid as follows:

We provide two lists: coarsen_x and coarsen_y, they define (for each axis) how many fine cells get aggregated to form a coarse cell.

For example, if coarsen_x = [10, 5, 5, …], then the first cells (along dim-x) of the coarser grid will correspond to the first 10 cells of the fine one, then, the second cells (along dim-x) will correspond to the next 5 cells, and so on.

The practical link between the two is then given by the two lists fine_inds_x and fine_inds_y.

Those are lists of lists. fine_inds_x[i] returns a list of indices, that give the x-indices (in the fine grid) of the fine cells that correspond to cells with x-index i in the coarse grid.

Finally, for the surface cells, we have to determine how many z-levels are below it. We look at the number of z-levels under each sub-cell making up the surface cell and take the minimum one.

class volcapy.niklas.coarsener.Coarsener(coarsen_x, coarsen_y, res_x, res_y, dsm)[source]

Bases: object

Build a grid coarser than the dsm.

Parameters
coarsen_x: [int]

Defines the coarsening along the x-dimension. For example, if coarsen_x = [10, 5, 5, …], then the first cells (along dim-x) of the coarser grid will correspond to the first 10 cells of the dsm, then, the second cells (along dim-x) will correspond to the next 5 cells, and so on.

coarsen_y: [int]
dsm: DSM

Methods

get_coarse_cell(i, j)

Given indices, spits out a coarse cell.

get_coords(i, j)

Get lat/long of the current cell in the coarse grid.

get_fine_cells(i, j)

Get the cells (in the finer grid) corresponding to cell (i, j) in the coarser grid.

get_fine_elevations(i, j)

Get the elevations (in the finer grid) of cells corresponding to cell (i, j) in the coarser grid.

get_fine_indices(i, j)

Get the indices (in the finer grid) of cells correspondin to cell (i, j) in the coarser grid.

get_coarse_cell(i, j)[source]

Given indices, spits out a coarse cell.

get_coords(i, j)[source]

Get lat/long of the current cell in the coarse grid. We use the mean of the coordinates of the cell in the larger grid that correspond to the cell under consideration.

get_fine_cells(i, j)[source]

Get the cells (in the finer grid) corresponding to cell (i, j) in the coarser grid.

Parameters
i,j: int

Index in the coarse grid.

Returns
List[CellDSM]

List of DSM cells that make up the big grid.

get_fine_elevations(i, j)[source]

Get the elevations (in the finer grid) of cells corresponding to cell (i, j) in the coarser grid.

Parameters
i,j: int

Index in the coars grid.

Returns
List[float]

List of elevations in the bigger grid.

get_fine_indices(i, j)[source]

Get the indices (in the finer grid) of cells correspondin to cell (i, j) in the coarser grid.

Parameters
i,j: int

Index in the coarse grid.

Returns
List[(int, int)]

List of indices in the bigger grid.

volcapy.niklas.dsm module

Class implementing dsm functionalities. Also allows to build a dsm object from the raw Niklas data.

A dsm is basically a two dimensional array of cell, where for each cell we get the midpoint along the x-y axis and the elevation.

Since we only have midpoints, and since the cells might have different sizes, we also need a list of resolutions.

class volcapy.niklas.dsm.CellDSM(x, y, z, res_x, res_y)[source]

Bases: object

Cell for DSM. The difference is that the dsm gives us midpoints, whereas cells in the inversion grid are defined by their corners. We thus use the resolution of each cell to return the corners.

Attributes
xh
xl
yh
yl
zh
zl
property xh
property xl
property yh
property yl
property zh
property zl
class volcapy.niklas.dsm.DSM(longs, lats, elevations, res_x, res_y)[source]

Bases: object

DSM functionalities

Methods

from_matfile(path)

Construct from matlab data.

classmethod from_matfile(path)[source]

Construct from matlab data.

Parameters
path: string

Path to .mat file. Data inside should have the same format as provided by Niklas.

volcapy.niklas.find_permutation module

volcapy.niklas.forward module

Compute forward operator for a whole inversion grid.

volcapy.niklas.forward.compute_cell_response_at_point(cell, point)[source]

Compute the repsonse of an individual inversion cell on a measurement point.

Parameters
cell: Cell

Inversion cell whose response we want to compute.

point: (float, float, float)

Coordinates (x, y, z) of the point at which we measure the response.

volcapy.niklas.forward.compute_top_cell_response_at_point(cell, point, z_base=0)[source]

Same as the above, but for a cell which contains subdivisions (i.e. a topmost cell). Note that for such cells, we extend the parallelograms down to zbase.

Parameters
cell: Cell

Inversion cell whose response we want to compute.

point: (float, float, float)

Coordinates (x, y, z) of the point at which we measure the response.

z_base: float

Altitude (in meters) of the lowest level we consider.

volcapy.niklas.forward.forward(inversion_grid, data_points, z_base)[source]

Compute forward operator associated to a given geometry/discretization defined by an inversion grid. The forward give the response at locations defined by the datapoints vector.

Parameters
inversion_grid: InversionGrid
data_points: List[(float, float, float)]

List containing the coordinates, in order (x, y, z) of the data points at which we measure the response / gravitational field.

z_base: float

Altitude (in meters) of the lowest level we consider. I.e., we will build inversion cells down to that level.

volcapy.niklas.inversion_grid module

Class implementing inversion grid.

The inversion grid has two importan properties

  • It has a coarser resolution than the dsm, meaning that a single cell in the

inversion grid corresponds to several cells in the dsm grid. * It is irregular, i.e. it doesn’t span an entire parallelepiped.

This is due to the fact that we don’t include cells outside the volcano (in the air).

class volcapy.niklas.inversion_grid.InversionGrid(coarsen_x, coarsen_y, res_x, res_y, zlevels, dsm)[source]

Bases: collections.abc.Sequence

Methods

fill_grid()

Create the cells in the grid, taking into account the fact that the grid is irregulat, i.e., the number a z-floors can change, since we do not include cells that are ‘in the air’ wrt the dsm.

fine_cells_from_topmost_ind(ind)

Given the index of a topmost cell, give the fine cells that correspond to it.

ind_in_regular_grid(cell)

Gives the a cell would have if it was in a regular 3D grid enclosing the irregular grid.

topmost_ind_to_2d_ind(ind)

Given the index of a topmost cell in the list of cells, give the x and y index (in the 2D grid) which correspond to that cell.

fill_grid()[source]

Create the cells in the grid, taking into account the fact that the grid is irregulat, i.e., the number a z-floors can change, since we do not include cells that are ‘in the air’ wrt the dsm.

fine_cells_from_topmost_ind(ind)[source]

Given the index of a topmost cell, give the fine cells that correspond to it.

ind_in_regular_grid(cell)[source]

Gives the a cell would have if it was in a regular 3D grid enclosing the irregular grid.

The goal of this function is to be able to map inversion results to a regular 3D array, since most visualization softwares use that format.

Parameters
cell: Cell
Returns
(i, j, k)

Index of the cell in a regular grid that encloses the irregular one. The grid is chosen such that it just encloses the regular one. The grid doesn’t care about individual cell resolutions. This is not much of a drawback since the only cells that dont have a standard resolution are on the borders fo the grid and will thus be clearly identifiable in a plot.

topmost_ind_to_2d_ind(ind)[source]

Given the index of a topmost cell in the list of cells, give the x and y index (in the 2D grid) which correspond to that cell.

The goal of this method is to be able to find dsm cells that belong to a given topmost cell.

Note that storing this as an attribute of each topmost cell would be memory costly, so we chose to compute it dynamically.

Parameters
ind: int

Index, in the ‘cells’ list of the topmost cell we are interested ind.

Returns
(int, int)

x-y index (in the 2D version of the inversion grid) of the given cell. One can then use the get_fine_cells method of the coarsener to find the corresponding dsm cells.

Module contents