aspen_pysys.helpers

 1# Copyright 2026 Hariidaran Tamilmaran
 2
 3import math
 4from typing import Any
 5
 6from aspen_pysys.constants import EPSILON, NONE
 7
 8
 9def isclose(a: float, b: float) -> bool:
10    """Check if a number is approximately equal to another.
11
12    Args:
13        a (float): Number
14        b (float): Number
15
16    Returns:
17        bool: If numbers are approximately equal to each other
18    """
19    return math.isclose(a, b, abs_tol=EPSILON)
20
21
22def is_negative(a: float) -> bool:
23    """Check if a number is negative.
24
25    Args:
26        a (float): Number
27
28    Returns:
29        bool: If provided number is negative
30    """
31    return not isclose(a, 0) and a < 0
32
33
34def is_positive(a: float) -> bool:
35    """Check if a number is positive.
36
37    Args:
38        a (float): Number
39
40    Returns:
41        bool: If provided number is positive
42    """
43    return not isclose(a, 0) and a > 0
44
45
46def is_zero(a: float) -> bool:
47    """Check if a number is approximately equal to zero.
48
49    Args:
50        a (float): Number
51
52    Returns:
53        bool: If provided number is approximately equal to zero
54    """
55    return isclose(a, 0)
56
57
58def is_one(a: float) -> bool:
59    """Check if a number is approximately equal to one.
60
61    Args:
62        a (float): Number
63
64    Returns:
65        bool: If provided number is approximately equal to one
66    """
67    return isclose(a, 1)
68
69
70def is_empty(value: Any) -> bool:  # noqa: ANN401
71    """Check if a value obtained from HYSYS is empty, i.e. -32767.
72
73    Args:
74        value (Any): Value obtained from HYSYS
75
76    Returns:
77        bool: If value obtained is empty
78    """
79    return value == NONE
def isclose(a: float, b: float) -> bool:
10def isclose(a: float, b: float) -> bool:
11    """Check if a number is approximately equal to another.
12
13    Args:
14        a (float): Number
15        b (float): Number
16
17    Returns:
18        bool: If numbers are approximately equal to each other
19    """
20    return math.isclose(a, b, abs_tol=EPSILON)

Check if a number is approximately equal to another.

Arguments:
  • a (float): Number
  • b (float): Number
Returns:

bool: If numbers are approximately equal to each other

def is_negative(a: float) -> bool:
23def is_negative(a: float) -> bool:
24    """Check if a number is negative.
25
26    Args:
27        a (float): Number
28
29    Returns:
30        bool: If provided number is negative
31    """
32    return not isclose(a, 0) and a < 0

Check if a number is negative.

Arguments:
  • a (float): Number
Returns:

bool: If provided number is negative

def is_positive(a: float) -> bool:
35def is_positive(a: float) -> bool:
36    """Check if a number is positive.
37
38    Args:
39        a (float): Number
40
41    Returns:
42        bool: If provided number is positive
43    """
44    return not isclose(a, 0) and a > 0

Check if a number is positive.

Arguments:
  • a (float): Number
Returns:

bool: If provided number is positive

def is_zero(a: float) -> bool:
47def is_zero(a: float) -> bool:
48    """Check if a number is approximately equal to zero.
49
50    Args:
51        a (float): Number
52
53    Returns:
54        bool: If provided number is approximately equal to zero
55    """
56    return isclose(a, 0)

Check if a number is approximately equal to zero.

Arguments:
  • a (float): Number
Returns:

bool: If provided number is approximately equal to zero

def is_one(a: float) -> bool:
59def is_one(a: float) -> bool:
60    """Check if a number is approximately equal to one.
61
62    Args:
63        a (float): Number
64
65    Returns:
66        bool: If provided number is approximately equal to one
67    """
68    return isclose(a, 1)

Check if a number is approximately equal to one.

Arguments:
  • a (float): Number
Returns:

bool: If provided number is approximately equal to one

def is_empty(value: Any) -> bool:
71def is_empty(value: Any) -> bool:  # noqa: ANN401
72    """Check if a value obtained from HYSYS is empty, i.e. -32767.
73
74    Args:
75        value (Any): Value obtained from HYSYS
76
77    Returns:
78        bool: If value obtained is empty
79    """
80    return value == NONE

Check if a value obtained from HYSYS is empty, i.e. -32767.

Arguments:
  • value (Any): Value obtained from HYSYS
Returns:

bool: If value obtained is empty