invert4geom.synthetic
#
Module Contents#
Functions#
|
Non-normalized 2D Gaussian function for creating synthetic topography. |
|
Create a synthetic topography dataset with a few features. |
|
Create a synthetic topography dataset with a few features which represent the |
|
Add pseudorandom gaussian noise to an array. |
- 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 (NDArray) – Coordinates at which to calculate the Gaussian function
y (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:
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:
xr.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:
xr.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 (NDArray | list[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 Falsepercent_as_max_abs (bool, optional) – If
True
, and percent isTrue
, the stddev used as the standard deviation of the Gaussian noise will be the max absolute value of the data. IfFalse
, and percent isTrue
, the stddev will be calculated on a point-by-point basis, so each data points’ noise will be the same percentage, by default Trueseed (float, optional) – seed to use for the random number generator, by default 0
- Returns:
a tuple of (contaminated data, standard deviations).
- Return type:
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])