summaryrefslogtreecommitdiff
path: root/szilagyi/__init__.py
blob: bfde1544b8f93382c16a0104e812cd06e4fde715 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
This is a software implementation of an approximation of the Szilagyi Waterspout Index. The calculated values of the SWI
are continuous. The wind-speed at 850 hPa is ignored as the nomogram dictates it as a simple on/off criterion.

There is only one function provided, so the use should be straight-forward. For example::

	>>> import pint
	>>> import szilagyi
	>>> u = pint.UnitRegistry()
	>>> round(szilagyi.calculate_swi(10.5 * u.delta_degC, 24100 * u.ft), 3)
	0.811
	>>> round(szilagyi.calculate_swi(7 * u.delta_degC, 12500 * u.ft), 3)
	-4.88
"""

from pint.quantity import Quantity

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:
	"""
	Calculates the Szilagyi Waterspout Index for *temperature_difference* and *convective_cloud_depth*.

	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
	constants.
	"""
	if not temperature_difference.is_compatible_with("delta_degC"):
		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")
	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:
		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)