import numpy as np def calc_upper(c: int, m: float, b: float, period: float) -> float: return np.floor(c / period) * period * m + b def calc_lower(c: int, m: float, b: float, period: float) -> float: return np.ceil(c / period) * period * m + b def calc_mean(c:int , m_u: float, b_u: float, m_l: float, b_l: float, period: float) -> float: return (calc_upper(c, m_u, b_u, period) + calc_lower(c, m_l, b_l, period)) / 2 def calc_rect(c:int , m_u: float, b_u: float, m_l: float, b_l: float, step_period: float, rect_period: float) -> float: if ((c - 1) % rect_period) < 4: return calc_upper(c, m_u, b_u, step_period) else: return calc_lower(c, m_l, b_l, step_period) def lin_interpol(x0:float, x1:float, y0:float, y1:float) -> (float, float): m = (y1 - y0) / (x1 - x0) b = y1 - m * x1 return m, b def calculate_deltas(sweep:list[float]): deltas = [] lv = sweep[0] for meas in list(sweep)[1:]: deltas.append((meas / lv)) lv = meas return deltas def compute_absolute_percentage_errors(measurements: list[float], guesses: list[float]): return [np.abs((guess - meas) / meas) * 100 for guess, meas in zip(guesses, measurements)]