invert4geom.synthetic#

Attributes#

Functions#

load_synthetic_model([spacing, region, buffer, ...])

Function to perform all necessary steps to create a synthetic model for the examples

contaminate_with_long_wavelength_noise(grid, noise[, ...])

Contaminate a grid with long wavelength noise.

load_bishop_model([coarsen_factor])

Download and return a dataset of the Bishop model which contains basement

gaussian2d(x, y, sigma_x, sigma_y[, x0, y0, angle])

Non-normalized 2D Gaussian function for creating synthetic topography.

synthetic_topography_simple(spacing, region[, ...])

Create a synthetic topography dataset with a few features.

synthetic_topography_regional(spacing, region[, ...])

Create a synthetic topography dataset with a few features which represent the

contaminate(data, stddev[, percent, ...])

Add pseudorandom gaussian noise to an array.

Module Contents#

xesmf = None[source]#
load_synthetic_model(spacing=1000.0, region=(0, 40000, 0, 30000), buffer=0, topography_coarsen_factor=2, topography_percent_noise=None, number_of_constraints=None, density_contrast=None, zref=None, gravity_obs_height=1000, gravity_noise=0.2, resample_for_cv=False, plot_topography=False, plot_topography_diff=True, plot_gravity=True)[source]#

Function to perform all necessary steps to create a synthetic model for the examples in the documentation.

Parameters:
  • spacing (float, optional) – spacing of the grid and gravity, by default 1e3

  • region (tuple[float, float, float, float], optional) – bounding region for the grid, by default (0, 40000, 0, 30000)

  • buffer (float, optional) – buffer to add around the region, by default 0. Buffer region used for creating topography and prisms, while inner region used for extent of gravity and constraints.

  • topography_coarsen_factor (float, optional) – factor to coarsen the topography data by for adding noise, by default 2

  • topography_percent_noise (float | None, optional) – noise decimal percent to add to topography data, by default None

  • number_of_constraints (int | None, optional) – number of random constraints to use, by default None

  • density_contrast (float | None, optional) – density contrast to use, by default None

  • zref (float | None, optional) – reference level to use, by default None

  • gravity_obs_height (float, optional) – gravity observation height to use, by default 1000

  • gravity_noise (float | None, optional) – decimal percentage noise level to add to gravity data, by default 0.2

  • resample_for_cv (bool, optional) – resample gravity data at half spacing to create train and test sets, by default False

  • plot_topography (bool, optional) – plot the topography, by default False

  • plot_topography_diff (bool, optional) – plot the difference between the true and starting topography, by default True

  • plot_gravity (bool, optional) – plot the gravity data, by default True

Returns:

  • true_topography (xarray.DataArray) – the true topography

  • starting_topography (xarray.DataArray) – the starting topography

  • constraint_points (pandas.DataFrame) – the constraint points

  • grav_df (pandas.DataFrame) – the gravity data

Return type:

tuple[xarray.DataArray, xarray.DataArray, pandas.DataFrame, pandas.DataFrame]

contaminate_with_long_wavelength_noise(grid, noise, coarsen_factor=None, spacing=None, noise_as_percent=True, seed=1)[source]#

Contaminate a grid with long wavelength noise.

Parameters:
  • grid (xarray.DataArray) – Grid to contaminate

  • noise (float) – noise to add to the data, can be either absolute or percent of max value of data

  • coarsen_factor (float | None, optional) – Factor to coarsen the data by, by default None

  • spacing (float | None, optional) – Spacing for the long wavelength noise, by default None

  • noise_as_percent (bool, optional) – if True, the value given to noise is treated as a percentage of the max value of the data.

  • seed (int, optional) – seed to use for the random number generator, by default 1

Returns:

Contaminated grid

Return type:

xarray.DataArray

load_bishop_model(coarsen_factor=None)[source]#

Download and return a dataset of the Bishop model which contains basement topography, moho topography, and synthetically generated forward gravity of both topographies. See https://wiki.seg.org/wiki/Bishop_Model for more info on the derivation of this dataset.

Parameters:

coarsen_factor (float, optional) – Factor to coarsen the data by. Data originally at 200m resolution, by default None

Returns:

Dataset with variables “basement_topo”, “moho_topo”, and “gravity”.

Return type:

xarray.Dataset

gaussian2d(x, y, sigma_x, sigma_y, x0=0, y0=0, angle=0.0)[source]#

Non-normalized 2D Gaussian function for creating synthetic topography.

Parameters:
  • x (numpy.ndarray) – Coordinates at which to calculate the Gaussian function

  • y (numpy.ndarray) – Coordinates at which to calculate the Gaussian function

  • sigma_x (float) – Standard deviation in the x and y directions

  • sigma_y (float) – Standard deviation in the x and y directions

  • x0 (float, optional) – Coordinates of the center of the distribution, by default 0

  • y0 (float, optional) – Coordinates of the center of the distribution, by default 0

  • angle (float, optional) – Rotation angle of the gaussian measure from the x axis (north) growing positive to the east (positive y axis), by default 0.0

Returns:

Gaussian function evaluated at x, y

Return type:

numpy.ndarray

Notes

This function was adapted from the Fatiando-Legacy function gaussian2d: https://legacy.fatiando.org/api/utils.html?highlight=gaussian#fatiando.utils.gaussian2d

synthetic_topography_simple(spacing, region, registration='g', scale=1, yoffset=0)[source]#

Create a synthetic topography dataset with a few features.

Parameters:
  • spacing (float) – grid spacing in meters

  • region (tuple[float, float, float, float]) – bounding edges of the grid in meters in format (xmin, xmax, ymin, ymax)

  • registration (str, optional) – grid registration type, either “g” for gridline or “p” for pixel, by default “g”

  • scale (float, optional) – value to scale the topography by, by default 1

  • yoffset (float, optional) – value to offset the topography by, by default 0

Returns:

synthetic topography dataset

Return type:

xarray.Dataset

synthetic_topography_regional(spacing, region, registration='g', scale=1, yoffset=0)[source]#

Create a synthetic topography dataset with a few features which represent the surface responsible for the regional component of gravity.

Parameters:
  • spacing (float) – grid spacing in meters

  • region (tuple[float, float, float, float]) – bounding edges of the grid in meters in format (xmin, xmax, ymin, ymax)

  • registration (str, optional) – grid registration type, either “g” for gridline or “p” for pixel, by default “g”

  • scale (float, optional) – value to scale the topography by, by default 1

  • yoffset (float, optional) – value to offset the topography by, by default 0

Returns:

synthetic topography dataset

Return type:

xarray.Dataset

contaminate(data, stddev, percent=False, percent_as_max_abs=True, seed=0)[source]#

Add pseudorandom gaussian noise to an array. Noise added is normally distributed with zero mean and a standard deviation from stddev.

Parameters:
  • data (numpy.ndarray | list[numpy.ndarray]) – data to contaminate, can be a single array, or a list of arrays.

  • stddev (float | list[float]) – standard deviation of the Gaussian noise that will be added to data. Length must be the same as data if data is a list.

  • percent (bool, optional) – If True, will consider stddev as a decimal percentage of the data and the standard deviation of the Gaussian noise will be calculated with this, by default False

  • percent_as_max_abs (bool, optional) – If True, and percent is True, the stddev used as the standard deviation of the Gaussian noise will be the max absolute value of the data. If False, and percent is True, the stddev will be calculated on a point-by-point basis, so each data points’ noise will be the same percentage, by default True

  • seed (float, optional) – seed to use for the random number generator, by default 0

Returns:

  • contam (numpy.ndarray | list[numpy.ndarray]) – contaminated data. If data is a list, will return a list of arrays.

  • stddev (float | list[float]) – standard deviation of the Gaussian noise added to the data. If stddev is a list, will return a list of floats.

Return type:

tuple[numpy.typing.NDArray | list[numpy.typing.NDArray], float | list[float]]

Notes

This function was adapted from the Fatiando-Legacy function gaussian2d: https://legacy.fatiando.org/api/utils.html?highlight=gaussian#fatiando.utils.contaminate

Examples

>>> import numpy as np
>>> data = np.ones(5)
>>> noisy, std = contaminate(data, 0.05, seed=0, percent=True)
>>> print(std)
0.05
>>> print(noisy)
array([1.00425372, 0.99136197, 1.02998834, 1.00321222, 0.97118374])
>>> data = [np.zeros(5), np.ones(3)]
>>> noisy = contaminate(data, [0.1, 0.2], seed=0)
>>> print(noisy[0])
array([ 0.00850745, -0.01727606,  0.05997669,  0.00642444, -0.05763251])
>>> print(noisy[1])
array([0.89814061, 1.0866216 , 1.01523779])