Skip to content

aragog.utilities

utilities

Utilities

FloatOrArray = float | npt.NDArray module-attribute

MultiplyT = TypeVar('MultiplyT', float, npt.NDArray, pd.Series, pd.DataFrame) module-attribute

combine_properties(weight, property1, property2)

Linear weighting of two quantities.

Args: weight: The weight to apply to property1 property1: The value of the first property property2: The value of the second property

Returns: The combined (weighted) property

Source code in aragog/utilities.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def combine_properties(weight: Any, property1: Any, property2: Any) -> Any:
    """Linear weighting of two quantities.

    Args:
        weight: The weight to apply to property1
        property1: The value of the first property
        property2: The value of the second property

    Returns:
        The combined (weighted) property
    """
    out = weight * property1 + (1.0 - weight) * property2

    return out

is_file(value)

Checks if value is a file.

Args: value: Object to be checked

Returns: True if the value is a file, otherwise False

Source code in aragog/utilities.py
50
51
52
53
54
55
56
57
58
59
60
61
62
def is_file(value: Any) -> bool:
    """Checks if value is a file.

    Args:
        value: Object to be checked

    Returns:
        True if the value is a file, otherwise False
    """
    if isinstance(value, (str, Path)):
        return Path(value).is_file()

    return False

is_monotonic_increasing(some_array)

Returns True if an array is monotonically increasing, otherwise returns False.

Source code in aragog/utilities.py
65
66
67
def is_monotonic_increasing(some_array: npt.NDArray) -> bool:
    """Returns True if an array is monotonically increasing, otherwise returns False."""
    return np.all(np.diff(some_array) > 0)

is_number(value)

Checks if value is a number.

Args: value: Object to be checked

Returns: True if the value is a number, otherwise False

Source code in aragog/utilities.py
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def is_number(value: Any) -> bool:
    """Checks if value is a number.

    Args:
        value: Object to be checked

    Returns:
        True if the value is a number, otherwise False
    """
    try:
        float(value)
        return True

    except (TypeError, ValueError):
        return False

profile_decorator(func)

Decorator to profile a function

Source code in aragog/utilities.py
36
37
38
39
40
41
42
43
44
45
46
47
def profile_decorator(func):
    """Decorator to profile a function"""

    @wraps(func)
    def wrapper(*args, **kwargs):
        with Profile() as profile:
            result = func(*args, **kwargs)
        stats = Stats(profile).strip_dirs().sort_stats(SortKey.TIME)
        stats.print_stats()
        return result

    return wrapper

tanh_weight(value, threshold, width)

Computes the tanh weight for viscosity profile and smoothing.

Args: value: Value threshold: Threshold value width: Width of smoothing

Returns: weight

Source code in aragog/utilities.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def tanh_weight(value: FloatOrArray, threshold: float, width: float) -> npt.NDArray:
    """Computes the tanh weight for viscosity profile and smoothing.

    Args:
        value: Value
        threshold: Threshold value
        width: Width of smoothing

    Returns:
        weight
    """
    arg: FloatOrArray = (value - threshold) / width
    weight: npt.NDArray = 0.5 * (1.0 + np.tanh(arg))

    return weight