当前位置: 首页>>代码示例>>Python>>正文


Python CameraGeometry.mask方法代码示例

本文整理汇总了Python中ctapipe.instrument.CameraGeometry.mask方法的典型用法代码示例。如果您正苦于以下问题:Python CameraGeometry.mask方法的具体用法?Python CameraGeometry.mask怎么用?Python CameraGeometry.mask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ctapipe.instrument.CameraGeometry的用法示例。


在下文中一共展示了CameraGeometry.mask方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convert_geometry_hex1d_to_rect2d

# 需要导入模块: from ctapipe.instrument import CameraGeometry [as 别名]
# 或者: from ctapipe.instrument.CameraGeometry import mask [as 别名]
def convert_geometry_hex1d_to_rect2d(geom, signal, key=None, add_rot=0):
    """converts the geometry object of a camera with a hexagonal grid into
    a square grid by slanting and stretching the 1D arrays of pixel x
    and y positions and signal intensities are converted to 2D
    arrays. If the signal array contains a time-dimension it is
    conserved.

    Parameters
    ----------
    geom : CameraGeometry object
        geometry object of hexagonal cameras
    signal : ndarray
        1D (no timing) or 2D (with timing) array of the pmt signals
    key : (default: None)
        arbitrary key to store the transformed geometry in a buffer
    add_rot : int/float (default: 0)
        parameter to apply an additional rotation of `add_rot` times 60°

    Returns
    -------
    new_geom : CameraGeometry object
        geometry object of the slanted picture now with a rectangular
        grid and a 2D grid for the pixel positions. contains now a 2D
        masking array signifying which of the pixels came from the
        original geometry and which are simply fillers from the
        rectangular grid
    rot_img : ndarray 2D (no timing) or 3D (with timing)
        the rectangular signal image
    """

    if key in rot_buffer:

        # if the conversion with this key was done before and stored,
        # just read it in
        (geom, new_geom, hex_to_rect_map) = rot_buffer[key]
    else:

        # otherwise, we have to do the conversion first now,
        # skew all the coordinates of the original geometry

        # extra_rot is the angle to get back to aligned hexagons with flat
        # tops. Note that the pixel rotation angle brings the camera so that
        # hexagons have a point at the top, so need to go 30deg back to
        # make them flat
        extra_rot = geom.pix_rotation - 30 * u.deg

        # total rotation angle:
        rot_angle = (add_rot * 60 * u.deg) - extra_rot

        logger.debug("geom={}".format(geom))
        logger.debug("rot={}, extra={}".format(rot_angle, extra_rot))

        rot_x, rot_y = unskew_hex_pixel_grid(geom.pix_x, geom.pix_y,
                                             cam_angle=rot_angle)

        # with all the coordinate points, we can define the bin edges
        # of a 2D histogram
        x_edges, y_edges, x_scale = get_orthogonal_grid_edges(rot_x, rot_y)

        # this histogram will introduce bins that do not correspond to
        # any pixel from the original geometry. so we create a mask to
        # remember the true camera pixels by simply throwing all pixel
        # positions into numpy.histogramdd: proper pixels contain the
        # value 1, false pixels the value 0.
        square_mask = np.histogramdd([rot_y, rot_x],
                                     bins=(y_edges, x_edges))[0].astype(bool)

        # to be consistent with the pixel intensity, instead of saving
        # only the rotated positions of the true pixels (rot_x and
        # rot_y), create 2D arrays of all x and y positions (also the
        # false ones).
        grid_x, grid_y = np.meshgrid((x_edges[:-1] + x_edges[1:]) / 2.,
                                     (y_edges[:-1] + y_edges[1:]) / 2.)

        ids = []
        # instead of blindly enumerating all pixels, let's instead
        # store a list of all valid -- i.e. picked by the mask -- 2D
        # indices
        for i, row in enumerate(square_mask):
            for j, val in enumerate(row):
                if val is True:
                    ids.append((i, j))

        # the area of the pixels (note that this is still a deformed
        # image)
        pix_area = np.ones_like(grid_x) \
            * (x_edges[1] - x_edges[0]) * (y_edges[1] - y_edges[0])

        # creating a new geometry object with the attributes we just determined
        new_geom = CameraGeometry(
            cam_id=geom.cam_id + "_rect",
            pix_id=ids,  # this is a list of all the valid coordinate pairs now
            pix_x=grid_x * u.m,
            pix_y=grid_y * u.m,
            pix_area=pix_area * u.m ** 2,
            neighbors=geom.neighbors,
            pix_type='rectangular', apply_derotation=False)

        # storing the pixel mask for later use
        new_geom.mask = square_mask
#.........这里部分代码省略.........
开发者ID:epuesche,项目名称:ctapipe,代码行数:103,代码来源:geometry_converter.py

示例2: convert_geometry_1d_to_2d

# 需要导入模块: from ctapipe.instrument import CameraGeometry [as 别名]
# 或者: from ctapipe.instrument.CameraGeometry import mask [as 别名]
def convert_geometry_1d_to_2d(geom, signal, key=None, add_rot=0):
    """converts the geometry object of a camera with a hexagonal grid into
    a square grid by slanting and stretching the 1D arrays of pixel x
    and y positions and signal intensities are converted to 2D
    arrays. If the signal array contains a time-dimension it is
    conserved.

    Parameters
    ----------
    geom : CameraGeometry object
        geometry object of hexagonal cameras
    signal : ndarray
        1D (no timing) or 2D (with timing) array of the pmt signals
    key : (default: None)
        arbitrary key to store the transformed geometry in a buffer
    add_rot : int/float (default: 0)
        parameter to apply an additional rotation of @add_rot times 60°

    Returns
    -------
    new_geom : CameraGeometry object
        geometry object of the slanted picture now with a rectangular
        grid and a 2D grid for the pixel positions contains now a 2D
        masking array signifying which of the pixels came from the
        original geometry and which are simply fillers from the
        rectangular grid square_img : ndarray 2D (no timing) or 3D
        (with timing) array of the pmt signals

    """

    if key in rot_buffer:

        # if the conversion with this key was done and stored before,
        # just read it in
        (rot_x, rot_y, x_edges, y_edges, new_geom,
         rot_angle, pix_rotation, x_scale) = rot_buffer[key]
    else:

        # otherwise, we have to do the conversion now first, skew all
        # the coordinates of the original geometry

        # extra_rot is the angle to get back to aligned hexagons with flat
        # tops. Note that the pixel rotation angle brings the camera so that
        # hexagons have a point at the top, so need to go 30deg back to
        # make them flat
        extra_rot = geom.pix_rotation - 30 * u.deg

        # total rotation angle:
        rot_angle = (add_rot * 60 * u.deg) - extra_rot
        # if geom.cam_id.startswith("NectarCam")\
        #         or geom.cam_id.startswith("LSTCam"):
        #     rot_angle += geom.cam_rotation + 90 * u.deg

        logger.debug("geom={}".format(geom))
        logger.debug("rot={}, extra={}".format(rot_angle, extra_rot))

        rot_x, rot_y = unskew_hex_pixel_grid(geom.pix_x, geom.pix_y,
                                             cam_angle=rot_angle)

        # with all the coordinate points, we can define the bin edges
        # of a 2D histogram
        x_edges, y_edges, x_scale = get_orthogonal_grid_edges(rot_x, rot_y)

        # this histogram will introduce bins that do not correspond to
        # any pixel from the original geometry. so we create a mask to
        # remember the true camera pixels by simply throwing all pixel
        # positions into numpy.histogramdd: proper pixels contain the
        # value 1, false pixels the value 0.
        square_mask = np.histogramdd([rot_y, rot_x],
                                     bins=(y_edges, x_edges))[0].astype(bool)

        # to be consistent with the pixel intensity, instead of saving
        # only the rotated positions of the true pixels (rot_x and
        # rot_y), create 2D arrays of all x and y positions (also the
        # false ones).
        grid_x, grid_y = np.meshgrid((x_edges[:-1] + x_edges[1:]) / 2.,
                                     (y_edges[:-1] + y_edges[1:]) / 2.)

        ids = []
        # instead of blindly enumerating all pixels, let's instead
        # store a list of all valid -- i.e. picked by the mask -- 2D
        # indices
        for i, row in enumerate(square_mask):
            for j, val in enumerate(row):
                if val is True:
                    ids.append((i, j))

        # the area of the pixels (note that this is still a deformed
        # image)
        pix_area = np.ones_like(grid_x) \
            * (x_edges[1] - x_edges[0]) * (y_edges[1] - y_edges[0])

        # creating a new geometry object with the attributes we just determined
        new_geom = CameraGeometry(
            cam_id=geom.cam_id + "_rect",
            pix_id=ids,  # this is a list of all the valid coordinate pairs now
            pix_x=grid_x * u.m,
            pix_y=grid_y * u.m,
            pix_area=pix_area * u.m ** 2,
            neighbors=geom.neighbors,
#.........这里部分代码省略.........
开发者ID:epuesche,项目名称:ctapipe,代码行数:103,代码来源:geometry_converter.py


注:本文中的ctapipe.instrument.CameraGeometry.mask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。