@@ 377-407 (lines=31) @@ | ||
374 | ||
375 | return {"counts": np.array(counts, dtype=int).sum()} |
|
376 | ||
377 | def estimate_norm_ul(self, datasets): |
|
378 | """Estimate upper limit for a flux point. |
|
379 | ||
380 | Parameters |
|
381 | ---------- |
|
382 | datasets : `~gammapy.modeling.Datasets` |
|
383 | the list of dataset object |
|
384 | ||
385 | Returns |
|
386 | ------- |
|
387 | result : dict |
|
388 | Dict with upper limit for the flux point norm. |
|
389 | """ |
|
390 | norm = self.model.norm |
|
391 | ||
392 | # TODO: the minuit backend has convergence problems when the fit statistic is not |
|
393 | # of parabolic shape, which is the case, when there are zero counts in the |
|
394 | # energy bin. For this case we change to the scipy backend. |
|
395 | counts = self.estimate_counts(datasets)["counts"] |
|
396 | ||
397 | if np.all(counts == 0): |
|
398 | result = self.fit.confidence( |
|
399 | parameter=norm, |
|
400 | sigma=self.sigma_ul, |
|
401 | backend="scipy", |
|
402 | reoptimize=self.reoptimize, |
|
403 | ) |
|
404 | else: |
|
405 | result = self.fit.confidence(parameter=norm, sigma=self.sigma_ul) |
|
406 | ||
407 | return {"norm_ul": result["errp"] + norm.value} |
|
408 | ||
409 | def estimate_norm_ts(self, datasets): |
|
410 | """Estimate ts and sqrt(ts) for the flux point. |
@@ 1047-1075 (lines=29) @@ | ||
1044 | ||
1045 | return {"counts": np.array(counts, dtype=int)} |
|
1046 | ||
1047 | def estimate_norm_ul(self): |
|
1048 | """Estimate upper limit for a flux point. |
|
1049 | ||
1050 | Returns |
|
1051 | ------- |
|
1052 | result : dict |
|
1053 | Dict with upper limit for the flux point norm. |
|
1054 | """ |
|
1055 | if not self._contribute_to_stat: |
|
1056 | return {"norm_ul": np.nan} |
|
1057 | ||
1058 | norm = self.model.norm |
|
1059 | ||
1060 | # TODO: the minuit backend has convergence problems when the fit statistic is not |
|
1061 | # of parabolic shape, which is the case, when there are zero counts in the |
|
1062 | # energy bin. For this case we change to the scipy backend. |
|
1063 | counts = self.estimate_counts()["counts"] |
|
1064 | ||
1065 | if np.all(counts == 0): |
|
1066 | result = self.fit.confidence( |
|
1067 | parameter=norm, |
|
1068 | sigma=self.sigma_ul, |
|
1069 | backend="scipy", |
|
1070 | reoptimize=self.reoptimize, |
|
1071 | ) |
|
1072 | else: |
|
1073 | result = self.fit.confidence(parameter=norm, sigma=self.sigma_ul) |
|
1074 | ||
1075 | return {"norm_ul": result["errp"] + norm.value} |
|
1076 | ||
1077 | def estimate_norm_ts(self): |
|
1078 | """Estimate ts and sqrt(ts) for the flux point. |