summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--szilagyi/__init__.py9
-rw-r--r--szilagyi/_nomogram.py4
-rw-r--r--szilagyi/plots.py17
3 files changed, 16 insertions, 14 deletions
diff --git a/szilagyi/__init__.py b/szilagyi/__init__.py
index 426abe4..6281a95 100644
--- a/szilagyi/__init__.py
+++ b/szilagyi/__init__.py
@@ -13,6 +13,7 @@ There is only one function provided, so the use should be straight-forward. For
"""
from ._nomogram import calculate_swi as _calculate_swi
+from ._nomogram import MAX_TEMPERATURE_DIFFERENCE, MAX_CONVECTIVE_CLOUD_DEPTH
def calculate_swi(temperature_difference, convective_cloud_depth):
@@ -22,8 +23,8 @@ def calculate_swi(temperature_difference, convective_cloud_depth):
May raise :exc:`ValueError` if the values are not in range of the original nomogram.
"""
- if temperature_difference < 0 or temperature_difference > 40:
- raise ValueError("temperature_difference must be within <0, 40> range")
- if convective_cloud_depth < 0 or convective_cloud_depth > 50000:
- raise ValueError("convective_cloud_depth must be within <0, 50000> range")
+ if temperature_difference < 0 or temperature_difference > MAX_TEMPERATURE_DIFFERENCE:
+ raise ValueError(f"temperature_difference must be within <0, {MAX_TEMPERATURE_DIFFERENCE}> range")
+ if convective_cloud_depth < 0 or convective_cloud_depth > MAX_CONVECTIVE_CLOUD_DEPTH:
+ raise ValueError(f"convective_cloud_depth must be within <0, {MAX_CONVECTIVE_CLOUD_DEPTH}> range")
return _calculate_swi(temperature_difference, convective_cloud_depth)
diff --git a/szilagyi/_nomogram.py b/szilagyi/_nomogram.py
index 4dcd141..024bfd0 100644
--- a/szilagyi/_nomogram.py
+++ b/szilagyi/_nomogram.py
@@ -4,6 +4,10 @@ from collections import deque
from . import _dataset
+MAX_TEMPERATURE_DIFFERENCE = 40
+MAX_CONVECTIVE_CLOUD_DEPTH = 50000
+
+
class NomogramEdgeCase(Exception):
def __init__(self, value):
self.value = value
diff --git a/szilagyi/plots.py b/szilagyi/plots.py
index b21a07b..924eeee 100644
--- a/szilagyi/plots.py
+++ b/szilagyi/plots.py
@@ -3,11 +3,8 @@ import math
import matplotlib.pyplot as plot
from . import _dataset
-from ._nomogram import calculate_swi
-
-
-MAX_X = 40
-MAX_Y = 50000
+from ._nomogram import calculate_swi as _calculate_swi
+from ._nomogram import MAX_TEMPERATURE_DIFFERENCE, MAX_CONVECTIVE_CLOUD_DEPTH
def _grid(start, end, steps):
@@ -26,12 +23,12 @@ def _scaled_range(steps, maximum):
def colorful(width=1000, height=1000):
C = []
- X = list(_grid(0, MAX_X, width))
- Y = list(_grid(0, MAX_Y, height))
- for y in _scaled_range(height, MAX_Y):
+ X = list(_grid(0, MAX_TEMPERATURE_DIFFERENCE, width))
+ Y = list(_grid(0, MAX_CONVECTIVE_CLOUD_DEPTH, height))
+ for y in _scaled_range(height, MAX_CONVECTIVE_CLOUD_DEPTH):
row = []
- for x in _scaled_range(width, MAX_X):
- row.append(calculate_swi(x, y))
+ for x in _scaled_range(width, MAX_TEMPERATURE_DIFFERENCE):
+ row.append(_calculate_swi(x, y))
C.append(row)
plot.pcolormesh(X, Y, C, cmap='viridis', vmin=-10, vmax=10, rasterized=True)
for _, data in _dataset.INDICES: