Skip to content

Commit

Permalink
Merge pull request #5167 from QRemy/fix_4FGL_to_models
Browse files Browse the repository at this point in the history
Fix SourceCatalogObject4FGL.to_models() for DR4
  • Loading branch information
registerrier committed Mar 19, 2024
2 parents 637ecec + 7e8371f commit 86488ec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions gammapy/catalog/fermi.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,13 @@ def spatial_model(self):
if de["version"] < 28:
path_extended = "$GAMMAPY_DATA/catalogs/fermi/LAT_extended_sources_8years/Templates/"
elif de["version"] < 32:
path_extended = "$GAMMAPY_DATA/catalogs/fermi/LAT_extended_sources_12years/Templates/"
path_extended = (
"$GAMMAPY_DATA/catalogs/fermi/Extended_12years/Templates/"
)
else:
path_extended = "$GAMMAPY_DATA/catalogs/fermi/LAT_extended_sources_14years/Templates/"
path_extended = (
"$GAMMAPY_DATA/catalogs/fermi/Extended_14years/Templates/"
)
path = make_path(path_extended)
with warnings.catch_warnings(): # ignore FITS units warnings
warnings.simplefilter("ignore", FITSFixedWarning)
Expand Down
3 changes: 3 additions & 0 deletions gammapy/catalog/tests/test_fermi.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def test_4FGL_DR4():
model_dnde = model(fp.energy_ref[not_ul])
assert_quantity_allclose(model_dnde, fp_dnde, rtol=0.07)

models = cat.to_models()
assert len(models) == len(cat.table)


@requires_data()
class TestFermi4FGLObject:
Expand Down
5 changes: 4 additions & 1 deletion gammapy/modeling/models/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,10 @@ def __init__(
data_sum = map.data.sum(axis=(1, 2)).reshape((-1, 1, 1))

data = np.divide(
map.data, data_sum, out=np.zeros_like(map.data), where=data_sum != 0
map.data.astype(float),
data_sum,
out=np.zeros_like(map.data, dtype=float),
where=data_sum != 0,
)
data /= map.geom.solid_angle().to_value("sr")
map = map.copy(data=data, unit="sr-1")
Expand Down

0 comments on commit 86488ec

Please sign in to comment.