Skip to content

Commit

Permalink
Merge pull request #151 from eneights/main
Browse files Browse the repository at this point in the history
Fix documentation link and only print one log-likelihood warning
  • Loading branch information
ckarwin authored Mar 4, 2024
2 parents a109ad8 + fc983a8 commit f8a8518
Show file tree
Hide file tree
Showing 5 changed files with 1,766 additions and 25,265 deletions.
10 changes: 9 additions & 1 deletion cosipy/threeml/COSILike.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import logging
logger = logging.getLogger(__name__)

import inspect

class COSILike(PluginPrototype):
"""
COSI 3ML plugin.
Expand Down Expand Up @@ -127,6 +129,10 @@ def set_model(self, model):
model : astromodels.core.model.Model
Any model supported by astromodels
"""

# Temporary fix to only print log-likelihood warning once max per fit
if inspect.stack()[1][3] == '_assign_model_to_data':
self._printed_warning = False

# Get point sources and extended sources from model:
point_sources = model.point_sources
Expand Down Expand Up @@ -294,7 +300,9 @@ def get_log_like(self):
expectation = self._signal + self._bkg.contents

expectation += 1e-12 # to avoid -infinite log-likelihood (occurs when expected counts = 0 but data != 0)
logger.warning("Adding 1e-12 to each bin of the expectation to avoid log-likelihood = -inf.")
if not self._printed_warning:
logger.warning("Adding 1e-12 to each bin of the expectation to avoid log-likelihood = -inf.")
self._printed_warning = True
# This 1e-12 should be defined as a parameter in the near future (HY)

# Convert data into an arrary:
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ List of tutorials and contents, as a link to the corresponding Python notebook i
- Meaning of the TS map and how to compute confidence contours
- Computing a TS map, getting the best location and estimating the error

5. Fitting the spectrum of a GRB `(ipynb) <https://github.com/cositools/cosipy/tree/main/docs/tutorials/spectral_fits/continuum_fit/grb/SpectralFit.ipynb>`_
5. Fitting the spectrum of a GRB `(ipynb) <https://github.com/cositools/cosipy/blob/main/docs/tutorials/spectral_fits/continuum_fit/grb/SpectralFit_GRB.ipynb>`_

- Introduction to 3ML and astromodels
- Likelihood analysis.
Expand Down Expand Up @@ -69,7 +69,7 @@ List of tutorials and contents, as a link to the corresponding Python notebook i
Spacecraft orientation and location <Point_source_resonse.ipynb>
Detector response and signal expectation <DetectorResponse.ipynb>
TS Map: localizing a GRB <ts_map/Parallel_TS_map_computation_DC2.ipynb>
Fitting the spectrum of a GRB <spectral_fits/continuum_fit/grb/SpectralFit.ipynb>
Fitting the spectrum of a GRB <spectral_fits/continuum_fit/grb/SpectralFit_GRB.ipynb>
Fitting the spectrum of the Crab <spectral_fits/continuum_fit/crab/SpectralFit_Crab.ipynb>
Extended source model fitting <spectral_fits/extended_source_fit/diffuse_511_spectral_fit.ipynb>
Image deconvolution <image_deconvolution/511keV/ScAttBinning/511keV-DC2-ScAtt-ImageDeconvolution.ipynb>
Expand Down
Loading

0 comments on commit f8a8518

Please sign in to comment.