Computes the derivatives in X and Y from a regular grid using finite differences
pip install numpy
pip install matplotlib
import numpy as np
import matplotlib.pyplot as plt
- compute_derivative_x Compute the derivative in the X-direction using finite differences
Arguments:
data
: 2D array of shape (n, m) containing the data.
delta_x
: The known spacing between data points in the x-direction.
derivative_type
: String specifying the type of derivative calculation. Can be 'left', 'right', or 'center'.Returns:
derivative
2D array of shape (n, m) containing the numerical derivative in the x-direction.
- compute_derivative_y Compute the derivative in the Y-direction using finite differences
Arguments:
data
: 2D array of shape (n, m) containing the data.
delta_y
: The known spacing between data points in the y-direction.
derivative_type
: String specifying the type of derivative calculation. Can be 'left', 'right', or 'center'.Returns:
derivative
2D array of shape (n, m) containing the numerical derivative in the y-direction
- quick_plotContourMap Plots a contour map with the result of the derivative by finite difference
n = 150
m = 100
data = np.random.random((n, m))
delta_x = 0.35
delta_y = 0.25
x_derivative = compute_derivative_x(data, delta_x, 'center')
quick_plotContourMap(x_derivative)
n = 20
m = 18
data = np.random.random((n, m))
delta_x = 0.15
delta_y = 0.12
y_derivative = compute_derivative_y(data, delta_y, 'right')
quick_plotContourMap(y_derivative)