Commit af5502db authored by Calmel Blaise's avatar Calmel Blaise
Browse files

Load common functions

parent b7c95165
No related merge requests found
Showing with 90 additions and 0 deletions
+90 -0
import numpy as np
import scipy.stats as sp
# from decimal import Decimal
from sigfig import round as sigfig_round
def units_conversion(units_id="SI"):
"""Computes the units conversion from SI units used internally to the
desired display units.
Parameters
----------
units_id: str
String variable identifying units (English, SI) SI is the default.
Returns
-------
units: dict
dictionary of unit conversion and labels
"""
if units_id == "SI":
units = {
"L": 1,
"Q": 1,
"A": 1,
"V": 1,
"label_L": "m",
"label_Q": "m3/s",
"label_A": "m2",
"label_V": "m/s",
"ID": "SI",
}
else:
units = {
"L": 1.0 / 0.3048,
"Q": (1.0 / 0.3048) ** 3,
"A": (1.0 / 0.3048) ** 2,
"V": 1.0 / 0.3048,
"label_L": "ft",
"label_Q": "ft3/s",
"label_A": "ft2",
"label_V": "ft/s",
"ID": "English",
}
return units
def convert_temperature(temp_in, units_in, units_out) -> float:
"""Converts temperature from F to C or C to F.
Parameters
==========
temp_in: np.array
temperature in units_in
units_in: str
C for Celcius or F for Fahrenheit
units_out: str
C for Celcius or F for Fahrenheit
Returns
=======
temp_out: np.array
temperature in units_out
"""
temp_out = None
if units_in == "F":
if units_out == "C":
temp_out = (temp_in - 32) * (5.0 / 9.0)
else:
temp_out = temp_in
elif units_in == "C":
if units_out == "C":
temp_out = temp_in
else:
temp_out = (temp_in * (9.0 / 5.0)) + 32
return temp_out
def scientific_notation(n, sig: int = 3):
if np.isnan(n):
n = 0
elif np.isinf(n):
return n
return sigfig_round(n, sig)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment