summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-03-31 23:06:57 +0200
committerAki <please@ignore.pl>2023-03-31 23:06:57 +0200
commitea9ffa0faee0ee4a8cff4014c67563b73d023dc1 (patch)
tree16eabeb3be9391a5a14419704a1e3557d1e5ae72
parent75ab8589a266ded5e923f42f15457c84202a8608 (diff)
downloadszilagyi-master.zip
szilagyi-master.tar.gz
szilagyi-master.tar.bz2
SWI calculation now may take wind speed criterion into accountHEAD0.1.0master
-rw-r--r--szilagyi/__init__.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/szilagyi/__init__.py b/szilagyi/__init__.py
index bfde154..70c073e 100644
--- a/szilagyi/__init__.py
+++ b/szilagyi/__init__.py
@@ -13,15 +13,23 @@ There is only one function provided, so the use should be straight-forward. For
-4.88
"""
-from pint.quantity import Quantity
+from pint import quantity as pint_
from ._nomogram import calculate_swi as _calculate_swi
from ._nomogram import MAX_TEMPERATURE_DIFFERENCE, MAX_CONVECTIVE_CLOUD_DEPTH
-def calculate_swi(temperature_difference: Quantity, convective_cloud_depth: Quantity) -> float:
+WIND_SPEED_LIMIT = 40
+
+
+def calculate_swi(
+ temperature_difference: pint_.Quantity,
+ convective_cloud_depth: pint_.Quantity,
+ wind_speed_at_850hpa: pint_.Quantity = None
+) -> float:
"""
- Calculates the Szilagyi Waterspout Index for *temperature_difference* and *convective_cloud_depth*.
+ Calculates the Szilagyi Waterspout Index for *temperature_difference* and *convective_cloud_depth*. Optionally,
+ *wind_speed_at_850hpa* can be provided to filter out cases by this parameter.
Function will raise ValueError if input values are not convertible to their expected units or if they are not in range
of the original nomogram. The maximum values are available as MAX_TEMPERATURE_DIFFERENCE and MAX_CONVECTIVE_CLOUD_DEPTH
@@ -31,6 +39,11 @@ def calculate_swi(temperature_difference: Quantity, convective_cloud_depth: Quan
raise ValueError("temperature_difference must be convertible to Celsius degrees")
if not convective_cloud_depth.is_compatible_with("ft"):
raise ValueError("convective_cloud_depth must be convertible to Feet")
+ if wind_speed_at_850hpa:
+ if not wind_speed_at_850hpa.is_compatible_with("kts"):
+ raise ValueError("wind_speed_at_850hpa must be convertible to Knots")
+ if wind_speed_at_850hpa.m_as("kts") > WIND_SPEED_LIMIT:
+ return -10
temperature_difference = temperature_difference.m_as("delta_degC")
convective_cloud_depth = convective_cloud_depth.m_as("ft")
if temperature_difference < 0 or temperature_difference > MAX_TEMPERATURE_DIFFERENCE: