In [1]:
import math
In [2]:
import numpy as np
In [3]:
from pygsf.spatial.rasters.fields import *
In [4]:
fx = np.array([
[1,1,1],
[1,1,1],
[1,1,1]
])
In [5]:
fx
Out[5]:
In [6]:
fy = np.array([
[2,2,2],
[2,2,2],
[2,2,2]
])
In [7]:
magn = magnitude(fx, fy)
In [8]:
magn
Out[8]:
In [9]:
sqrt(1 + 2**2)
Out[9]:
In [10]:
oriens_d = orients_d(fx, fy)
In [11]:
oriens_d
Out[11]:
In [12]:
degrees(math.atan(0.5))
Out[12]:
In [13]:
magn_grad_along_flowlines(fx, fy, 10, 10)
Out[13]:
The previous result is correct.
In [14]:
fx = np.array([
[1,2,3],
[1,2,3],
[1,2,3]
])
In [15]:
fy = np.array([
[0,0,0],
[0,0,0],
[0,0,0]
])
In [16]:
oriens_d = orients_d(fx, fy)
In [17]:
oriens_d
Out[17]:
In [18]:
magnitude(fx, fy)
Out[18]:
In [19]:
np.sqrt(fx**2 + fy**2)
Out[19]:
In [20]:
magn_grad_along_flowlines(
fld_x=fx,
fld_y=fy,
cell_size_x=10,
cell_size_y=10)
Out[20]:
In [21]:
orien_rad = orients_r(fx, fy)
In [22]:
dm_dx, dm_dy = magn_grads(
fld_x=fx,
fld_y=fy,
dir_cell_sizes=[1, 1])
In [23]:
dm_dx
Out[23]:
In [24]:
dm_dy
Out[24]:
In [25]:
velocity_gradient = dm_dx * np.sin(orien_rad) + dm_dy * np.cos(orien_rad)
In [26]:
velocity_gradient
Out[26]:
Results correct.
In [27]:
fx = np.array([
[1,2,3],
[2,3,4],
[3,4,5]
])
In [28]:
fy = -fx
In [29]:
magn = magnitude(fx, fy)
In [30]:
magn
Out[30]:
In [31]:
oriens_d = orients_d(fx, fy)
In [32]:
oriens_d
Out[32]:
In [33]:
magn_grad_along_flowlines(
fld_x=fx,
fld_y=fy,
cell_size_x=1,
cell_size_y=1)
Out[33]:
Cell (0,0) vs. cell (1,1):
sqrt(2) vs. 3 sqrt(2)
dist = sqrt(2)
gradient = (3sqrt(2) - sqrt(2))/sqrt(2) = 2
Result is correct.
In [34]:
magn_grad_along_flowlines(
fld_x=fx,
fld_y=fy,
cell_size_x=10,
cell_size_y=10)
Out[34]:
Result is correct.