Exemplo n.º 1
0
def test_fill_map_counts_uint_column(events):
    # Check that unsigned int column works.
    # Regression test for https://github.com/gammapy/gammapy/issues/1620
    axis = MapAxis.from_edges([0, 3, 6], name="event_id")
    m = Map.create(npix=(2, 1), binsz=10, axes=[axis])
    fill_map_counts(m, events)
    assert m.data.sum() == 1
    assert_allclose(m.data[0, 0, 0], 1)
Exemplo n.º 2
0
def test_fill_map_counts_hpx(events):
    # 2D map
    m = Map.from_geom(HpxGeom(1))
    fill_map_counts(m, events)
    assert m.data[4] == 2

    # 3D with energy axis
    axis = MapAxis.from_edges([9, 11, 13], name="energy", unit="TeV")
    m = Map.from_geom(HpxGeom(1, axes=[axis]))
    fill_map_counts(m, events)
    assert m.data[0, 4] == 1
    assert m.data[1, 4] == 1
Exemplo n.º 3
0
def test_fill_map_counts_wcs(events):
    # 2D map
    m = Map.create(npix=(2, 1), binsz=10)
    fill_map_counts(m, events)
    assert_allclose(m.data, [[1, 0]])

    # 3D with energy axis
    axis = MapAxis.from_edges([9, 11, 13], name="energy", unit="TeV")
    m = Map.create(npix=(2, 1), binsz=10, axes=[axis])
    fill_map_counts(m, events)
    assert m.data.sum() == 1
    assert_allclose(m.data[0, 0, 0], 1)
Exemplo n.º 4
0
def cli_image_bin(event_file, reference_file, out_file, overwrite):
    """Bin events into an image.

    You have to give the event, reference and out FITS filename.
    """
    log.info("Executing cli_image_bin")

    log.info("Reading {}".format(event_file))
    events = EventList.read(event_file)

    log.info("Reading {}".format(reference_file))
    m_ref = Map.read(reference_file)

    counts_map = Map.from_geom(m_ref.geom)
    fill_map_counts(counts_map, events)

    log.info("Writing {}".format(out_file))
    counts_map.write(out_file, overwrite=overwrite)
Exemplo n.º 5
0
geom = WcsGeom.create(binsz=0.02 * u.deg, skydir=pos_target, width="5 deg")

#  Let's create an ON-map and an OFF-map:

# In[ ]:

on_map = Map.from_geom(geom)
off_map = Map.from_geom(geom)

events_vela_on = events_vela.select_parameter("PHASE", on_phase_range)
events_vela_off = events_vela.select_parameter("PHASE", off_phase_range)

# In[ ]:

fill_map_counts(on_map, events_vela_on)
fill_map_counts(off_map, events_vela_off)

# Defining alpha as the ratio of the ON and OFF phase zones
alpha = (on_phase_range[1] - on_phase_range[0]) / (off_phase_range[1] -
                                                   off_phase_range[0])

# Create and fill excess map
# The pulsed events are the difference between the ON-phase count and alpha times the OFF-phase count
excess_map = on_map - off_map * alpha

# Plot excess map
excess_map.smooth(kernel="gauss", width=0.2 * u.deg).plot(add_cbar=True)

# ## Phase-resolved spectrum
Exemplo n.º 6
0
def test_fill_map_counts_keyerror(events):
    axis = MapAxis([0, 1, 2], name="nokey")
    m = WcsNDMap.create(binsz=0.1, npix=10, axes=[axis])
    with pytest.raises(KeyError):
        fill_map_counts(m, events)