コード例 #1
0
ファイル: test_subarray.py プロジェクト: epuesche/ctapipe
def test_subarray_description():

    pos = {}
    tel = {}
    foclen = 16 * u.m
    pix_x = np.arange(1764, dtype=np.float) * u.m
    pix_y = np.arange(1764, dtype=np.float) * u.m

    for ii in range(10):

        tel[ii] = TelescopeDescription.guess(pix_x, pix_y, foclen)
        pos[ii] = (np.random.uniform(200, size=2)-100) * u.m



    sub = SubarrayDescription("test array",
                              tel_positions=pos,
                              tel_descriptions=tel)

    sub.info()

    assert sub.num_tels == 10
    assert sub.tel[0].camera is not None
    assert len(sub.to_table()) == 10

    subsub = sub.select_subarray("newsub", [1,2,3,4])
    assert subsub.num_tels == 4
    assert set(subsub.tels.keys()) == {1,2,3,4}
コード例 #2
0
ファイル: test_subarray.py プロジェクト: smicanov/ctapipe
def test_subarray_description():

    pos = {}
    tel = {}
    foclen = 16 * u.m
    pix_x = np.arange(1764, dtype=np.float) * u.m
    pix_y = np.arange(1764, dtype=np.float) * u.m

    for ii in range(10):
        tel[ii] = TelescopeDescription.guess(pix_x, pix_y, foclen)
        pos[ii] = np.random.uniform(-100, 100, size=2) * u.m

    sub = SubarrayDescription("test array",
                              tel_positions=pos,
                              tel_descriptions=tel)

    sub.info()

    assert sub.num_tels == 10
    assert sub.tel[0].camera is not None
    assert len(sub.to_table()) == 10

    subsub = sub.select_subarray("newsub", [1, 2, 3, 4])
    assert subsub.num_tels == 4
    assert set(subsub.tels.keys()) == {1, 2, 3, 4}
コード例 #3
0
    def init_container(self):
        url = self.url
        max_events = self.max_events
        chec_tel = 0

        data = DataContainer()
        data.meta['origin'] = "targetio"

        # some targetio_event_source specific parameters
        data.meta['input'] = url
        data.meta['max_events'] = max_events
        data.meta['n_rows'] = self.n_rows
        data.meta['n_columns'] = self.n_columns
        data.meta['n_blocks'] = self.n_blocks
        data.meta['n_blockphases'] = N_BLOCKSAMPLES
        data.meta['n_cells'] = self.n_cells
        data.meta['n_modules'] = self.n_modules
        data.meta['tm'] = np.arange(self.n_pix,
                                    dtype=np.uint16) // self.n_tmpix
        data.meta['tmpix'] = np.arange(self.n_pix,
                                       dtype=np.uint16) % self.n_tmpix

        pix_pos = self.pixel_pos * u.m
        foclen = self.optical_foclen * u.m
        teldesc = TelescopeDescription.guess(*pix_pos, foclen)
        data.inst.subarray.tels[chec_tel] = teldesc

        self.data = data
コード例 #4
0
def _fill_instrument_info(data, pyhessio_file, camera_geometry, camera):
    """
    fill the data.inst structure with instrumental information.

    Parameters
    ----------
    data: DataContainer
        data container to fill in

    """
    if not data.inst.telescope_ids:
        data.inst.telescope_ids = list(pyhessio_file.get_telescope_ids())
        data.inst.subarray = SubarrayDescription("MonteCarloArray")

        for tel_id in data.inst.telescope_ids:
            try:

                pix_pos = pyhessio_file.get_pixel_position(tel_id) * u.m
                foclen = pyhessio_file.get_optical_foclen(tel_id) * u.m
                mirror_area = pyhessio_file.get_mirror_area(tel_id) * u.m**2
                num_tiles = pyhessio_file.get_mirror_number(tel_id)
                tel_pos = pyhessio_file.get_telescope_position(tel_id) * u.m

                tel = TelescopeDescription.guess(*pix_pos, foclen)
                tel.optics.mirror_area = mirror_area
                tel.optics.num_mirror_tiles = num_tiles
                data.inst.subarray.tels[tel_id] = tel
                data.inst.subarray.positions[tel_id] = tel_pos

                # deprecated fields that will become part of
                # TelescopeDescription or SubrrayDescription
                data.inst.optical_foclen[tel_id] = foclen
                data.inst.pixel_pos[tel_id] = pix_pos
                data.inst.tel_pos[tel_id] = tel_pos

                nchans = pyhessio_file.get_num_channel(tel_id)
                npix = pyhessio_file.get_num_pixels(tel_id)
                data.inst.num_channels[tel_id] = nchans
                data.inst.num_pixels[tel_id] = npix
                data.inst.mirror_dish_area[tel_id] = mirror_area
                data.inst.mirror_numtiles[tel_id] = num_tiles

                geometry = camera_geometry
                patch_matrix = \
                    utils.geometry.compute_patch_matrix(camera=camera)
                cluster_7_matrix = \
                    utils.geometry.compute_cluster_matrix_7(camera=camera)
                cluster_19_matrix = \
                    utils.geometry.compute_cluster_matrix_19(camera=camera)

                data.inst.geom[tel_id] = geometry
                data.inst.cluster_matrix_7[tel_id] = cluster_7_matrix
                data.inst.cluster_matrix_19[tel_id] = cluster_19_matrix
                data.inst.patch_matrix[tel_id] = patch_matrix

            except HessioGeneralError:
                pass
コード例 #5
0
ファイル: test_telescope.py プロジェクト: epuesche/ctapipe
def test_telescope_description():

    # setup a dummy telescope that look like an MST with FlashCam
    foclen = 16*u.m
    pix_x = np.arange(1764, dtype=np.float) * u.m
    pix_y = np.arange(1764, dtype=np.float) * u.m

    tel = TelescopeDescription.guess(pix_x, pix_y, foclen)

    assert tel.camera.cam_id == 'FlashCam'
    assert tel.optics.tel_type == 'MST'
    assert str(tel) == 'MST:FlashCam'
コード例 #6
0
def test_telescope_description():

    # setup a dummy telescope that look like an MST with FlashCam
    foclen = 16 * u.m
    pix_x = np.arange(1764, dtype=np.float) * u.m
    pix_y = np.arange(1764, dtype=np.float) * u.m

    tel = TelescopeDescription.guess(pix_x, pix_y, foclen)

    assert tel.camera.cam_id == 'FlashCam'
    assert tel.optics.tel_type == 'MST'
    assert str(tel) == 'MST:FlashCam'
コード例 #7
0
    def prepare_subarray_info(telescope_descriptions, header):
        """
        Constructs a SubarrayDescription object from the
        ``telescope_descriptions`` given by ``SimTelFile``

        Parameters
        ----------
        telescope_descriptions: dict
            telescope descriptions as given by ``SimTelFile.telescope_descriptions``
        header: dict
            header as returned by ``SimTelFile.header``

        Returns
        -------
        SubarrayDescription :
            instrumental information
        """

        tel_descriptions = {}  # tel_id : TelescopeDescription
        tel_positions = {}  # tel_id : TelescopeDescription

        for tel_id, telescope_description in telescope_descriptions.items():
            cam_settings = telescope_description['camera_settings']
            tel_description = TelescopeDescription.guess(
                cam_settings['pixel_x'] * u.m,
                cam_settings['pixel_y'] * u.m,
                equivalent_focal_length=cam_settings['focal_length'] * u.m
            )
            tel_description.optics.mirror_area = (
                cam_settings['mirror_area'] * u.m ** 2
            )
            tel_description.optics.num_mirror_tiles = (
                cam_settings['n_mirrors']
            )
            tel_descriptions[tel_id] = tel_description

            tel_idx = np.where(header['tel_id'] == tel_id)[0][0]
            tel_positions[tel_id] = header['tel_pos'][tel_idx] * u.m

        return SubarrayDescription(
            "MonteCarloArray",
            tel_positions=tel_positions,
            tel_descriptions=tel_descriptions,
        )
コード例 #8
0
    def _init_container(self):
        """
        Prepare the ctapipe event container, and fill it with the information
        that does not change with event, including the instrument information.
        """
        chec_tel = 0

        data = TargetIODataContainer()
        data.meta['origin'] = "targetio"

        data.meta['input'] = self.input_url
        data.meta['max_events'] = self.max_events

        # Instrument information
        pix_pos = self._pixel_pos * u.m
        foclen = self._optical_foclen * u.m
        teldesc = TelescopeDescription.guess(*pix_pos, foclen)
        data.inst.subarray.tels[chec_tel] = teldesc

        self._data = data
コード例 #9
0
    def _init_container(self):
        """
        Prepare the ctapipe event container, and fill it with the information
        that does not change with event, including the instrument information.
        """
        chec_tel = 0

        data = TargetIODataContainer()
        data.meta['origin'] = "targetio"

        data.meta['input'] = self.input_url
        data.meta['max_events'] = self.max_events

        # Instrument information
        pix_pos = self._pixel_pos * u.m
        foclen = self._optical_foclen * u.m
        teldesc = TelescopeDescription.guess(*pix_pos, foclen)
        data.inst.subarray.tels[chec_tel] = teldesc

        self._data = data
コード例 #10
0
    def prepare_subarray_info(telescope_descriptions, header):
        """
        Constructs a SubarrayDescription object from the
        ``telescope_descriptions`` given by ``SimTelFile``

        Parameters
        ----------
        telescope_descriptions: dict
            telescope descriptions as given by ``SimTelFile.telescope_descriptions``
        header: dict
            header as returned by ``SimTelFile.header``

        Returns
        -------
        SubarrayDescription :
            instrumental information
        """

        tel_descriptions = {}  # tel_id : TelescopeDescription
        tel_positions = {}  # tel_id : TelescopeDescription

        for tel_id, telescope_description in telescope_descriptions.items():
            cam_settings = telescope_description['camera_settings']
            tel_description = TelescopeDescription.guess(
                cam_settings['pixel_x'] * u.m,
                cam_settings['pixel_y'] * u.m,
                equivalent_focal_length=cam_settings['focal_length'] * u.m)
            tel_description.optics.mirror_area = (cam_settings['mirror_area'] *
                                                  u.m**2)
            tel_description.optics.num_mirror_tiles = (
                cam_settings['mirror_area'])
            tel_descriptions[tel_id] = tel_description

            tel_idx = np.where(header['tel_id'] == tel_id)[0][0]
            tel_positions[tel_id] = header['tel_pos'][tel_idx] * u.m

        return SubarrayDescription(
            "MonteCarloArray",
            tel_positions=tel_positions,
            tel_descriptions=tel_descriptions,
        )
def set_tel_info(event, f_tel):
    for i in range(len(f_tel["tel_id"])):
        tel_id = f_tel["tel_id"][i]
        event.inst.mirror_dish_area[
            tel_id] = f_tel["mirror_dish_area"][i] * u.m**2
        event.inst.num_pixels[tel_id] = f_tel["num_pixels"][i]
        event.inst.num_channels[tel_id] = f_tel["num_channels"][i]
        event.inst.optical_foclen[tel_id] = f_tel["optical_foclen"][i] * u.m
        event.inst.mirror_numtiles[tel_id] = f_tel["mirror_numtiles"][i]
        event.inst.tel_pos[tel_id] = f_tel["tel_pos"][i]
        if f_tel["geom"][i] == 0:
            event.inst.pixel_pos[tel_id] = f_tel["pixel_pos1"][i] * u.m
        else:
            event.inst.pixel_pos[tel_id] = f_tel["pixel_pos2"][i] * u.m
        tel = TelescopeDescription.guess(*event.inst.pixel_pos[tel_id],
                                         event.inst.optical_foclen[tel_id])
        tel.optics.mirror_area = event.inst.mirror_dish_area[tel_id]
        tel.optics.num_mirror_tiles = event.inst.mirror_numtiles[tel_id]
        event.inst.subarray.tels[tel_id] = tel
        event.inst.subarray.positions[tel_id] = f_tel["tel_pos"][i] * u.m
    return event
コード例 #12
0
    def _build_subarray_info(self, file):
        """
        constructs a SubarrayDescription object from the info in an
        EventIO/HESSSIO file

        Parameters
        ----------
        file: HessioFile
            The open pyhessio file

        Returns
        -------
        SubarrayDescription :
            instrumental information
        """
        telescope_ids = list(file.get_telescope_ids())
        subarray = SubarrayDescription("MonteCarloArray")

        for tel_id in telescope_ids:
            try:

                pix_pos = file.get_pixel_position(tel_id) * u.m
                foclen = file.get_optical_foclen(tel_id) * u.m
                mirror_area = file.get_mirror_area(tel_id) * u.m**2
                num_tiles = file.get_mirror_number(tel_id)
                tel_pos = file.get_telescope_position(tel_id) * u.m

                tel = TelescopeDescription.guess(
                    *pix_pos, equivalent_focal_length=foclen)
                tel.optics.mirror_area = mirror_area
                tel.optics.num_mirror_tiles = num_tiles
                subarray.tels[tel_id] = tel
                subarray.positions[tel_id] = tel_pos

            except self.pyhessio.HessioGeneralError:
                pass

        return subarray