-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MapDatasetEventSampler.sample_background() method #2616
Merged
adonath
merged 6 commits into
gammapy:master
from
fabiopintore:MapDatasetEventSampler_bkgsample
Nov 28, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b4855c1
Add sample_background in MapDatasetEventSampler
fabiopintore 35a175a
Add sample_background in MapDatasetEventSampler
fabiopintore 71d32e2
Add sample_background in MapDatasetEventSampler
fabiopintore 5a2a5f9
Implementing Axel comments
fabiopintore 0e416ad
Implementing Axel comments
fabiopintore 04fecb2
Move requires_data decorator
adonath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
from numpy.testing import assert_allclose | ||
import astropy.units as u | ||
from astropy.coordinates import SkyCoord | ||
from gammapy.cube import MapDataset, simulate_dataset | ||
from gammapy.cube import MapDataset, simulate_dataset, MapDatasetEventSampler | ||
from gammapy.cube.tests.test_fit import get_map_dataset | ||
from gammapy.data import GTI | ||
from gammapy.irf import load_cta_irfs | ||
from gammapy.maps import MapAxis, WcsGeom | ||
from gammapy.modeling.models import ( | ||
|
@@ -58,3 +60,46 @@ def test_simulate(): | |
) | ||
assert_allclose(dataset.psf.data[5, 32, 32], 0.04203219) | ||
assert_allclose(dataset.edisp.data.data[10, 10], 0.85944298, rtol=1e-5) | ||
|
||
|
||
def dataset_maker(): | ||
position = SkyCoord(0.0, 0.0, frame="galactic", unit="deg") | ||
energy_axis = MapAxis.from_bounds( | ||
1, 100, nbin=30, unit="TeV", name="energy", interp="log" | ||
) | ||
|
||
spatial_model = GaussianSpatialModel( | ||
lon_0="0 deg", lat_0="0 deg", sigma="0.2 deg", frame="galactic" | ||
) | ||
|
||
spectral_model = PowerLawSpectralModel(amplitude="1e-11 cm-2 s-1 TeV-1") | ||
skymodel = SkyModel(spatial_model=spatial_model, spectral_model=spectral_model) | ||
|
||
geom = WcsGeom.create( | ||
skydir=position, binsz=0.02, width="5 deg", coordsys="GAL", axes=[energy_axis] | ||
) | ||
|
||
t_min = 0 * u.s | ||
t_max = 30000 * u.s | ||
|
||
gti = GTI.create(start=t_min, stop=t_max) | ||
|
||
dataset = get_map_dataset( | ||
sky_model=skymodel, geom=geom, geom_etrue=geom, edisp=True | ||
) | ||
dataset.gti = gti | ||
|
||
return dataset | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test requires a |
||
@requires_data() | ||
def test_MDE_sample_background(): | ||
dataset = dataset_maker() | ||
sampler = MapDatasetEventSampler(random_state=0) | ||
bkg_evt = sampler.sample_background(dataset=dataset) | ||
|
||
assert len(bkg_evt.table["ENERGY"]) == 375084 | ||
assert_allclose(bkg_evt.table["ENERGY"][0], 2.1613281656472028, rtol=1e-5) | ||
assert_allclose(bkg_evt.table["RA"][0], 265.7253792887848, rtol=1e-5) | ||
assert_allclose(bkg_evt.table["DEC"][0], -27.727581635186304, rtol=1e-5) | ||
assert_allclose(bkg_evt.table["MC_ID"][0], 0, rtol=1e-5) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing empty line before
Parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done