summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-09-03 00:41:49 +0200
committerAki <please@ignore.pl>2022-09-03 00:41:49 +0200
commit222bc58e3b51a70e95e15fe4681d50809f54c50a (patch)
tree14a6bc7409708a3efbf17b868b42fcf36339d855
parent6a5f689cf6acfc0ad99134a8e65854f8a8aa1774 (diff)
downloadszilagyi-222bc58e3b51a70e95e15fe4681d50809f54c50a.zip
szilagyi-222bc58e3b51a70e95e15fe4681d50809f54c50a.tar.gz
szilagyi-222bc58e3b51a70e95e15fe4681d50809f54c50a.tar.bz2
Moved all calculation logic to nomogram
-rw-r--r--szilagyi/nomogram.py9
-rw-r--r--szilagyi/plots.py10
2 files changed, 6 insertions, 13 deletions
diff --git a/szilagyi/nomogram.py b/szilagyi/nomogram.py
index 299d930..55276ae 100644
--- a/szilagyi/nomogram.py
+++ b/szilagyi/nomogram.py
@@ -1,7 +1,7 @@
import math
from collections import deque
-from ._dataset import Vector
+from . import _dataset
def look_downwards(data, x, start):
@@ -61,10 +61,9 @@ def find_boundary_curves(swis, x, y):
return segments
-def calculate_swi(segments, x, y):
- vec = Vector(x, y)
- low = segments[0]
- high = segments[1]
+def calculate_swi(x, y):
+ low, high = find_boundary_curves(_dataset.INDICES, x, y)
+ vec = _dataset.Vector(x, y)
dist_to_low = min(abs(vec - p) for p in (low[1][low[2]], low[1][low[2]]))
dist_to_high = min(abs(vec - p) for p in (high[1][high[2]], high[1][high[2]]))
return dist_to_low / (dist_to_low + dist_to_high) * (high[0] - low[0]) + low[0]
diff --git a/szilagyi/plots.py b/szilagyi/plots.py
index 072a32d..b38b99e 100644
--- a/szilagyi/plots.py
+++ b/szilagyi/plots.py
@@ -15,12 +15,6 @@ def grid(start, end, steps):
if __name__ == "__main__":
- swis = _dataset.INDICES
-
- def _swi(x, y): # dt, depth
- segments = find_boundary_curves(swis, x, y)
- return calculate_swi(segments, x, y)
-
C = []
X = list(grid(0, 40, 1000))
Y = list(grid(0, 50000, 1000))
@@ -30,12 +24,12 @@ if __name__ == "__main__":
for x_scaled in range(0, 1000):
x = x_scaled / 25
try:
- swi = _swi(x, y)
+ swi = calculate_swi(x, y)
except (IndexError, RuntimeError):
swi = -10
row.append(swi)
C.append(row)
plot.pcolormesh(X, Y, C, cmap='viridis', vmin=-10, vmax=10, rasterized=True)
- for _, data in swis:
+ for _, data in _dataset.INDICES:
plot.plot([x[0] for x in data], [x[1] for x in data])
plot.show()