Passed
Pull Request — master (#1929)
by
unknown
02:32
created

gammapy/scripts/image_bin.py (1 issue)

1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
from __future__ import absolute_import, division, print_function, unicode_literals
3
import logging
4
import click
0 ignored issues
show
Unable to import 'click'
Loading history...
5
from ..data import EventList
6
from ..maps import Map
7
from ..cube import fill_map_counts
8
9
log = logging.getLogger(__name__)
10
11
12
@click.command("bin")
13
@click.argument("event_file", type=str)
14
@click.argument("reference_file", type=str)
15
@click.argument("out_file", type=str)
16
@click.option("--overwrite", is_flag=True, help="Overwrite existing files?")
17
def cli_image_bin(event_file, reference_file, out_file, overwrite):
18
    """Bin events into an image.
19
20
    You have to give the event, reference and out FITS filename.
21
    """
22
    log.info("Executing cli_image_bin")
23
24
    log.info("Reading {}".format(event_file))
25
    events = EventList.read(event_file)
26
27
    log.info("Reading {}".format(reference_file))
28
    m_ref = Map.read(reference_file)
29
30
    counts_map = Map.from_geom(m_ref.geom)
31
    fill_map_counts(counts_map, events)
32
33
    log.info("Writing {}".format(out_file))
34
    counts_map.write(out_file, overwrite=overwrite)
35