Skip to content

Commit

Permalink
Add sf error
Browse files Browse the repository at this point in the history
Signed-off-by: cgalelli <[email protected]>
  • Loading branch information
cgalelli committed Apr 9, 2024
1 parent e3a60ed commit a8403c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gammapy/stats/tests/test_variability.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_structure_function():
* u.s
)

sf, distances = structure_function(flux, flux_err, time)
sf, sf_error, distances = structure_function(flux, flux_err, time)

assert_allclose(
sf,
Expand Down
11 changes: 9 additions & 2 deletions gammapy/stats/variability.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def structure_function(flux, flux_err, time, tdelta_precision=5):
shape = distances.shape + flux.shape[1:]
factor = np.zeros(shape)
norm = np.zeros(shape)
error = np.zeros(shape)

for i, distance in enumerate(distances):
indexes = np.array(np.where(dist_matrix == distance))
Expand All @@ -273,10 +274,16 @@ def structure_function(flux, flux_err, time, tdelta_precision=5):
w = (flux[index[1], ...] / flux_err[index[1], ...]) * (
flux[index[0], ...] / flux_err[index[0], ...]
)

f = np.nan_to_num(f)
w = np.nan_to_num(w)
factor[i] = factor[i] + f * w
norm[i] = norm[i] + w
sf = factor / norm

return sf, distances
err = (w**2) * (25 * f - 2 * flux[index[1], ...] * flux[index[0], ...])
err = np.nan_to_num(err)

error[i] = error[i] + np.abs(err)
sf = factor / norm
sf_error = np.sqrt(error / norm)
return sf, sf_error, distances

0 comments on commit a8403c8

Please sign in to comment.