usr_func package

Submodules

usr_func.EIBV module

This function calculates the Expected Information Benefit Value (EIBV) for a given threshold.

usr_func.EIBV.EIBV_approximate(threshold, mu, Sig, H, R) float

Calculates the Expected Information Benefit Value (EIBV) using the univariate normal distribution.

Parameters
  • threshold (float) – Threshold for characterizing the threshold between fresh water and saline water.

  • mu (np.ndarray) – Mean vector.

  • Sig (np.ndarray) – Covariance matrix.

  • H (np.ndarray) – Sampling vector.

  • R (np.ndarray) – Nugget or measurement noise matrix.

Returns

EIBV value.

Return type

float

usr_func.EIBV.EIBV_mvn(threshold, mu, Sig, H, R) float

Calculates the Expected Information Benefit Value (EIBV) using the multivariate normal distribution.

Parameters
  • threshold (float) – Threshold for characterizing the threshold between fresh water and saline water.

  • mu (np.ndarray) – Mean vector.

  • Sig (np.ndarray) – Covariance matrix.

  • H (np.ndarray) – Sampling vector.

  • R (np.ndarray) – Nugget or measurement noise matrix.

Returns

EIBV value.

Return type

float

usr_func.checkfolder module

Check if the folder exists, if not, create it.

usr_func.checkfolder.checkfolder(folder) None
Parameters

folder – str, the folder to be checked.

Returns

None

usr_func.get_resume_state module

This function is used to get the resume state of the system.

usr_func.get_resume_state.get_resume_state() bool
Returns

True if the system is in the resume state, False otherwise.

Return type

bool

Examples

>>> get_resume_state()
False
>>> get_resume_state()
True

usr_func.interpolate_2d module

Interpolate 2D data to a finer grid using griddata.

usr_func.interpolate_2d.interpolate_2d(x, y, nx, ny, value, interpolation_method='linear') tuple
Parameters
  • x (np.ndarray) – x coordinates of the data points.

  • y (np.ndarray) – y coordinates of the data points.

  • nx (int) – Number of points to be refined in the x direction.

  • ny (int) – Number of points to be refined in the y direction.

  • value (np.ndarray) – Values of the data points.

  • interpolation_method (str) – Interpolation method. Default is “linear”.

Returns

x coordinates of the refined grid, y coordinates of the refined grid, and values of the refined grid.

Return type

tuple

Examples

>>> x = np.array([0, 1, 2, 3, 4, 5])
>>> y = np.array([0, 1, 2, 3, 4, 5])
>>> nx = 100
>>> ny = 100
>>> value = np.array([0, 1, 2, 3, 4, 5])
>>> grid_x, grid_y, grid_value = interpolate_2d(x, y, nx, ny, value)
>>> grid_x.shape
(100, 100)
>>> grid_y.shape
(100, 100)
>>> grid_value.shape
(100, 100)

usr_func.interpolate_3d module

Interpolates values for 3d grid by interpolate on 2d layers and combine them together.

usr_func.interpolate_3d.interpolate_3d(x: numpy.ndarray, y: numpy.ndarray, z: numpy.ndarray, value: numpy.ndarray) tuple
Parameters
  • x (np.ndarray) – x coordinates of the data points.

  • y (np.ndarray) – y coordinates of the data points.

  • z (np.ndarray) – z coordinates of the data points.

  • value (np.ndarray) – Values of the data points.

Returns

x coordinates of the refined grid, y coordinates of the refined grid, z coordinates of the refined grid, and values of the refined grid.

Return type

tuple

Examples

>>> x = np.array([0, 1, 2, 3, 4, 5])
>>> y = np.array([0, 1, 2, 3, 4, 5])
>>> z = np.array([0, 0, 0, 0, 0, 0])
>>> value = np.array([0, 1, 2, 3, 4, 5])
>>> grid, values = interpolate_3d(x, y, z, value)
>>> grid.shape
(300, 3)
>>> values.shape
(300,)

usr_func.is_even module

Checks if a given integer even or not.

usr_func.is_even.is_even(value: int) bool
Parameters

value (int) – The integer to check.

Returns

True if the integer is even, False otherwise.

Return type

bool

Examples

>>> is_even(2)
True
>>> is_even(3)
False

usr_func.is_list_empty module

Checks if a given list is empty or not.

usr_func.is_list_empty.is_list_empty(glist: list) bool
Parameters

glist – can be nested list such as [], [[]], [[[]]] etc.

Returns

True if it is empty, such as [], [[]], [[[]]], etc.

Examples

>>> is_list_empty([])
True
>>> is_list_empty([[]])
True
>>> is_list_empty([[[]]])
True
>>> is_list_empty([1, 2, 3])
False
>>> is_list_empty([1, 2, []])
False

usr_func.normalize module

Normalize a numpy array to a range of [amin, amax]

usr_func.normalize.normalize(x, amin=0, amax=1) numpy.ndarray
Parameters
  • x – numpy array to be normalized

  • amin – minimum value of the normalized array

  • amax – maximum value of the normalized array

Returns

Normalized numpy array

Examples

>>> x = np.arange(10)
>>> print(x)
[0 1 2 3 4 5 6 7 8 9]
>>> print(normalize(x))
[0.         0.11111111 0.22222222 0.33333333 0.44444444 0.55555556
    0.66666667 0.77777778 0.88888889 1.        ]
>>> x = np.arange(10)
>>> print(x)
[0 1 2 3 4 5 6 7 8 9]
>>> print(normalize(x, amin=1, amax=2))
[1.         1.11111111 1.22222222 1.33333333 1.44444444 1.55555556
    1.66666667 1.77777778 1.88888889 2.        ]

usr_func.refill_nan_values module

This function refills the NaN values in a 2D array using the nearest neighbor

usr_func.refill_nan_values.refill_nan_values(data: numpy.ndarray) numpy.ndarray
Parameters

data (np.ndarray) – 2D array with NaN values

Returns

2D array with NaN values refilled

Return type

np.ndarray

Raises

TypeError – If data is not a numpy array

Examples

>>> import numpy as np
>>> from refill_nan_values import refill_nan_values
>>> data = np.array([[1, 2, 3], [4, np.nan, 6], [7, 8, 9]])
>>> refill_nan_values(data)
array([[1., 2., 3.],
        [4., 5., 6.],
        [7., 8., 9.]])

usr_func.set_resume_state module

This function is used to set the resume state of the simulation.

usr_func.set_resume_state.set_resume_state(state: bool = False) None
Parameters

state (bool) – True if the simulation is to be resumed, False otherwise.

Returns

None

Examples

>>> set_resume_state(True)
$ cat resume_flag.txt
10.0
$ cat counter.txt  # it comes from the previous run, so the number may vary.
34.0
>>> set_resume_state(False)
$ cat resume_flag.txt
0.0
$ cat counter.txt
0.0

usr_func.sort_polygon_vertices module

The function is used to sort the polygon counter-clockwisely.

usr_func.sort_polygon_vertices.sort_polygon_vertices(polygon: numpy.ndarray) numpy.ndarray
Args: vertices of the polygon is not organised in order.

polygon: np.array([[x1, y1, z1],

Returns

sorted polygon with the direction of counter-clockwise.

Examples

>>> polygon = np.array([[0, 0, 0],
...                     [0, 1, 0],
...                     [1, 1, 0],
...                     [1, 0, 0]])
>>> sort_polygon_vertices(polygon)
array([[0, 0, 0],
        [1, 0, 0],
        [1, 1, 0],
        [0, 1, 0]])

usr_func.vectorize module

Vectorize the input array according to column first ordering.

usr_func.vectorize.vectorize(array: numpy.ndarray) numpy.ndarray
Parameters

array – (n, m) dimension array.

Returns

(n*m, 1) dimension vector.

Return type

vector

Examples

>>> array = np.array([[1, 2, 3],
...                   [4, 5, 6]])
>>> vectorize(array)
array([[1],
       [4],
       [2],
       [5],
       [3],
       [6]])

Module contents