Skip to content

Commit fbbab0e

Browse files
author
Anastasiia Mikhno
committed
Updated the module to compute the error propagation to use only scipy tools.
1 parent 53e2d18 commit fbbab0e

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/nectarchain/user_scripts/amikhno/analysis_photostat_simple.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
# ctapipe modules
1919
from ctapipe.visualization import CameraDisplay
2020
from iminuit import Minuit
21-
from jacobi import propagate
2221
from matplotlib import pyplot as plt
2322
from matplotlib.backends.backend_pdf import PdfPages
23+
from scipy.optimize._numdiff import approx_derivative
2424

2525
from nectarchain.data.container import GainContainer
2626

@@ -367,6 +367,22 @@ def model(params):
367367
)
368368

369369

370+
def propagate_scipy_compatible(model, params, cov):
371+
"""
372+
Computes output covariance via numerical Jacobian propagation.
373+
"""
374+
params = np.asarray(params)
375+
cov = np.asarray(cov)
376+
377+
y = model(params)
378+
J = approx_derivative(model, params, method="2-point")
379+
380+
# Covariance propagation
381+
ycov = J @ cov @ J.T
382+
383+
return y, ycov
384+
385+
370386
def error_propagation_compute(data, minuit_resulting, plot=True, rebin=True):
371387
"""Compute both parameter uncertainties and per-pixel uncertainties of the model."""
372388

@@ -388,10 +404,10 @@ def error_propagation_compute(data, minuit_resulting, plot=True, rebin=True):
388404
)
389405

390406
# --- Propagate errors through the model
391-
y, ycov = propagate(
407+
y, ycov = propagate_scipy_compatible(
392408
lambda p: model(p), minuit_resulting.values, minuit_resulting.covariance
393-
) # changed
394-
yerr_prop = np.sqrt(np.diag(ycov)) # per-pixel uncertainty
409+
)
410+
yerr_prop = np.sqrt(np.diag(ycov))
395411

396412
# --- Optionally rebin by θ
397413
if rebin:

0 commit comments

Comments
 (0)