Skip to content

Commit

Permalink
use robust fit to get timing slope (#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
kosack committed May 21, 2020
1 parent c527947 commit 8c02fb7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ctapipe/image/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from .hillas import camera_to_shower_coordinates
from ..utils.quantities import all_to_value

from scipy.stats import siegelslopes


__all__ = ["timing_parameters"]

Expand Down Expand Up @@ -54,10 +56,13 @@ def timing_parameters(geom, image, peak_time, hillas_parameters, cleaning_mask=N
longi, _ = camera_to_shower_coordinates(
pix_x, pix_y, x, y, hillas_parameters.psi.to_value(u.rad)
)
(slope, intercept), cov = np.polyfit(
longi, peak_time, deg=1, w=np.sqrt(image), cov=True
)

# use polyfit just to get the covariance matrix and errors
(_s, _i), cov = np.polyfit(longi, peak_time, deg=1, w=np.sqrt(image), cov=True)
slope_err, intercept_err = np.sqrt(np.diag(cov))

# re-fit using a robust-to-outlier algorithm
slope, intercept = siegelslopes(x=longi, y=peak_time)
predicted_time = polyval(longi, (intercept, slope))
deviation = np.sqrt(np.sum((peak_time - predicted_time) ** 2) / peak_time.size)

Expand Down

0 comments on commit 8c02fb7

Please sign in to comment.