Skip to content

Commit

Permalink
Cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
carhc committed Oct 16, 2024
1 parent 0b584bc commit d98450c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions invisible_cities/reco/icaro_components.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import numpy as np
import pandas as pd
import numpy as np
import pandas as pd

from ..types.symbols import KrFitFunction
from .. evm.ic_containers import FitFunction
from .. core.fit_functions import polynom, expo
from .. types.symbols import KrFitFunction
from .. evm.ic_containers import FitFunction
from .. core.fit_functions import polynom, expo


def lin_seed(x : np.array, y : np.array):
Expand Down Expand Up @@ -80,8 +80,8 @@ def select_fit_variables(fittype : KrFitFunction, dst : pd.DataFrame):
y_data : pd.Series
The dependent variable data prepared for fitting.
'''
if fittype is KrFitFunction.linear : return dst.DT, dst.S2e
elif fittype is KrFitFunction.expo : return dst.DT, dst.S2e
if fittype is KrFitFunction.linear : return dst.DT, dst.S2e
elif fittype is KrFitFunction.expo : return dst.DT, dst.S2e
elif fittype is KrFitFunction.log_lin: return dst.DT, -np.log(dst.S2e)


Expand Down
28 changes: 14 additions & 14 deletions invisible_cities/reco/icaro_components_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from .. core.fit_functions import expo


@given(floats(min_value= 0, max_value= 10),
floats(min_value=10, max_value= 20),
floats(min_value= 1, max_value=100),
floats(min_value= 0, max_value= 10))
@given(floats(min_value = 0, max_value = 10),
floats(min_value = 10, max_value = 20),
floats(min_value = 1, max_value = 100),
floats(min_value = 0, max_value = 10))
def test_lin_function_output_values(x_min, x_max, a, b):
x = np.array([x_min, x_max])
y = a + b * x
Expand All @@ -32,12 +32,12 @@ def test_lin_function_output_values(x_min, x_max, a, b):
floats(min_value = 1e4, max_value = 1e5),
floats(min_value = 1e4, max_value = 1e5))
def test_expo_seed_output_values(zmin, zmax, elt, e0):
x = np.array( [ zmin, zmax ] )
y = e0 * np.exp( - x / elt )
x = np.array([zmin, zmax])
y = e0 * np.exp(-x / elt)
e0_test, elt_test = icarcomp.expo_seed(x, y)

assert np.isclose(e0_test, e0, rtol=0.1)
assert np.isclose(elt_test, elt, rtol=0.1)
assert np.isclose( e0_test, e0, rtol=0.1)
assert np.isclose(elt_test, elt, rtol=0.1)


@pytest.fixture
Expand Down Expand Up @@ -79,15 +79,15 @@ def test_get_function_and_seed_lt_with_data(x_min, x_max, steps, e0, lt):
popt_expo, _ = so.curve_fit(fit_func_expo, x, y, p0=seed_func_expo (x, y))
popt_log_lin, _ = so.curve_fit(fit_func_log_lin, x, y, p0=seed_func_log_lin(x, y))

assert np.isclose(popt_lin[0], popt_expo[0], rtol=1e-1) # The interceipt should be close between lin and expo
assert not np.isclose(popt_lin[1], popt_expo[1], rtol=1e-1) # The "lifetime" should be different between lin and expo
assert np.isclose(popt_lin[0], popt_expo[0], rtol=1e-1) # The interceipt should be close between lin and expo
assert not np.isclose(popt_lin[1], popt_expo[1], rtol=1e-1) # The "lifetime" should be different between lin and expo

assert np.isclose(popt_lin[0], popt_log_lin[0], rtol=1e-10) # The lin and log_lin are the same (the only difference is their
assert np.isclose(popt_lin[1], popt_log_lin[1], rtol=1e-10) # inputs: s2e or -log(s2e)) so both parameters should be the same
assert np.isclose(popt_lin[0], popt_log_lin[0], rtol=1e-10) # The lin and log_lin are the same (the only difference is their
assert np.isclose(popt_lin[1], popt_log_lin[1], rtol=1e-10) # inputs: s2e or -log(s2e)) so both parameters should be the same
# for the purpose of testing this function

@given(floats(min_value=1, max_value=1e5),
floats(min_value=10, max_value=1e5))
@given(floats(min_value = 1, max_value = 1e5),
floats(min_value = 10, max_value = 1e5))
def test_transform_parameters(a, b):
errors = 0.2*np.array([a, b])
fit_output = FitFunction(values=[a, b], errors=errors, cov=np.array([[0.04, 0.02], [0.02, 0.04]]),
Expand Down

0 comments on commit d98450c

Please sign in to comment.