Example #1
0
def generate_2d_shower_model(centroid, width, length, psi):
    """Create a statistical model (2D gaussian) for a shower image in a
    camera. The model's PDF (`model.pdf`) can be passed to
    `make_toymodel_shower_image`.

    Parameters
    ----------
    centroid : (float,float)
        position of the centroid of the shower in camera coordinates
    width : float
        width of shower (minor axis)
    length : float
        length of shower (major axis)
    psi : convertable to `astropy.coordinates.Angle`
        rotation angle about the centroid (0=x-axis)

    Returns
    -------

    a `scipy.stats` object

    """
    aligned_covariance = np.array([[length**2, 0], [0, width**2]])
    # rotate by psi angle: C' = R C R+
    rotation = linalg.rotation_matrix_2d(psi)
    rotated_covariance = rotation.dot(aligned_covariance).dot(rotation.T)
    return multivariate_normal(mean=centroid, cov=rotated_covariance)
Example #2
0
def rotate_camera(angle,pix_x: u.m,pix_y:u.m):
    """rotate the camera coordinates about the center of the camera by
    specified angle. Modifies the CameraGeometry in-place (so
    after this is called, the pix_x and pix_y arrays are
    rotated.
    Note:
    -----
    This is intended only to correct simulated data that are
    rotated by a fixed angle.  For the more general case of
    correction for camera pointing errors (rotations,
    translations, skews, etc), you should use a true coordinate
    transformation defined in `ctapipe.coordinates`.
    Parameters
    ----------
    angle: value convertable to an `astropy.coordinates.Angle`
        rotation angle with unit (e.g. 12 * u.deg), or "12d"
    pix_x: array with x-positions of the camera pixels
    pix_y: array with y-positions of the camera pixels
    """
    if type(pix_x) == astropy.table.column.Column:
        pix_x = pix_x*pix_x.unit
        pix_y = pix_y*pix_y.unit
    rotmat = rotation_matrix_2d(angle)
    rotated = np.dot(rotmat.T, [pix_x.value, pix_y.value])
    pix_x = rotated[0] * pix_x.unit
    pix_y = rotated[1] * pix_x.unit
    
    return pix_x, pix_y
def rotate_camera(angle, pix_x: u.m, pix_y: u.m):
    """rotate the camera coordinates about the center of the camera by
    specified angle. Modifies the CameraGeometry in-place (so
    after this is called, the pix_x and pix_y arrays are
    rotated.
    
    Note: This is intended only to correct simulated data that are
    rotated by a fixed angle.  For the more general case of
    correction for camera pointing errors (rotations,
    translations, skews, etc), you should use a true coordinate
    transformation defined in `ctapipe.coordinates`.

    Parameters
    ----------
    angle: value convertable to an `astropy.coordinates.Angle`
        rotation angle with unit (e.g. 12 * u.deg), or "12d"
    pix_x: array with x-positions of the camera pixels
    pix_y: array with y-positions of the camera pixels
    """
    if type(pix_x) == astropy.table.column.Column:
        pix_x = pix_x * pix_x.unit
        pix_y = pix_y * pix_y.unit
    rotmat = rotation_matrix_2d(angle)
    rotated = np.dot(rotmat.T, [pix_x.value, pix_y.value])
    pix_x = rotated[0] * pix_x.unit
    pix_y = rotated[1] * pix_x.unit

    return pix_x, pix_y
Example #4
0
    def rotate(self, angle):
        """rotate the camera coordinates about the center of the camera by
        specified angle. Modifies the CameraGeometry in-place (so
        after this is called, the pix_x and pix_y arrays are
        rotated.

        Notes
        -----

        This is intended only to correct simulated data that are
        rotated by a fixed angle.  For the more general case of
        correction for camera pointing errors (rotations,
        translations, skews, etc), you should use a true coordinate
        transformation defined in `ctapipe.coordinates`.

        Parameters
        ----------

        angle: value convertable to an `astropy.coordinates.Angle`
            rotation angle with unit (e.g. 12 * u.deg), or "12d"

        """
        rotmat = rotation_matrix_2d(angle)
        rotated = np.dot(rotmat.T, [self.pix_x.value, self.pix_y.value])
        self.pix_x = rotated[0] * self.pix_x.unit
        self.pix_y = rotated[1] * self.pix_x.unit
        self.pix_rotation -= Angle(angle)
        self.cam_rotation -= Angle(angle)
Example #5
0
def generate_2d_shower_model(centroid, width, length, psi):
    """Create a statistical model (2D gaussian) for a shower image in a
    camera. The model's PDF (`model.pdf`) can be passed to
    `make_toymodel_shower_image`.

    Parameters
    ----------
    centroid : (float,float)
        position of the centroid of the shower in camera coordinates
    width : float
        width of shower (minor axis)
    length : float
        length of shower (major axis)
    psi : convertable to `astropy.coordinates.Angle`
        rotation angle about the centroid (0=x-axis)

    Returns
    -------

    a `scipy.stats` object

    """
    aligned_covariance = np.array([[length**2, 0], [0, width**2]])
    # rotate by psi angle: C' = R C R+
    rotation = linalg.rotation_matrix_2d(psi)
    rotated_covariance = rotation.dot(aligned_covariance).dot(rotation.T)
    return multivariate_normal(mean=centroid, cov=rotated_covariance)
Example #6
0
    def rotate(self, angle):
        """rotate the camera coordinates about the center of the camera by
        specified angle. Modifies the CameraGeometry in-place (so
        after this is called, the pix_x and pix_y arrays are
        rotated.

        Notes
        -----

        This is intended only to correct simulated data that are
        rotated by a fixed angle.  For the more general case of
        correction for camera pointing errors (rotations,
        translations, skews, etc), you should use a true coordinate
        transformation defined in `ctapipe.coordinates`.

        Parameters
        ----------

        angle: value convertable to an `astropy.coordinates.Angle`
            rotation angle with unit (e.g. 12 * u.deg), or "12d"

        """
        rotmat = rotation_matrix_2d(angle)
        rotated = np.dot(rotmat.T, [self.pix_x.value, self.pix_y.value])
        self.pix_x = rotated[0] * self.pix_x.unit
        self.pix_y = rotated[1] * self.pix_x.unit
        self.pix_rotation -= Angle(angle)
        self.cam_rotation -= Angle(angle)
Example #7
0
    def pdf(self, x, y):
        """2d probability for photon electrons in the camera plane"""
        aligned_covariance = np.array(
            [[self.length.to_value(u.m) ** 2, 0], [0, self.width.to_value(u.m) ** 2]]
        )
        # rotate by psi angle: C' = R C R+
        rotation = linalg.rotation_matrix_2d(self.psi)
        rotated_covariance = rotation @ aligned_covariance @ rotation.T

        return multivariate_normal(
            mean=[self.x.to_value(u.m), self.y.to_value(u.m)], cov=rotated_covariance
        ).pdf(np.column_stack([x.to_value(u.m), y.to_value(u.m)]))
Example #8
0
    def pdf(self, x, y):
        '''2d probability for photon electrons in the camera plane'''
        mu = u.Quantity([self.x, self.y]).to_value(u.m)

        rotation = linalg.rotation_matrix_2d(-Angle(self.psi))
        pos = np.column_stack([x.to_value(u.m), y.to_value(u.m)])
        long, trans = rotation @ (pos - mu).T

        trans_pdf = norm(loc=0, scale=self.width).pdf(trans)

        a, loc, scale = self._moments_to_parameters()

        return trans_pdf * skewnorm(a=a, loc=loc, scale=scale).pdf(long)
Example #9
0
    def pdf(self, x, y):
        '''2d probability for photon electrons in the camera plane'''
        mu = u.Quantity([self.x, self.y]).to_value(u.m)

        rotation = linalg.rotation_matrix_2d(-Angle(self.psi))
        pos = np.column_stack([x.to_value(u.m), y.to_value(u.m)])
        long, trans = rotation @ (pos - mu).T

        trans_pdf = norm(loc=0, scale=self.width.to_value(u.m)).pdf(trans)

        a, loc, scale = self._moments_to_parameters()

        return trans_pdf * skewnorm(a=a, loc=loc, scale=scale).pdf(long)
Example #10
0
    def pdf(self, x, y):
        '''2d probability for photon electrons in the camera plane'''
        aligned_covariance = np.array([
            [self.length.to_value(u.m)**2, 0],
            [0, self.width.to_value(u.m)**2]
        ])
        # rotate by psi angle: C' = R C R+
        rotation = linalg.rotation_matrix_2d(self.psi)
        rotated_covariance = rotation @ aligned_covariance @ rotation.T

        return multivariate_normal(
            mean=[self.x.to_value(u.m), self.y.to_value(u.m)],
            cov=rotated_covariance,
        ).pdf(np.column_stack([x.to_value(u.m), y.to_value(u.m)]))
Example #11
0
def rotate(pix_x,pix_y,angle):
    """rotate the camera coordinates about the center of the camera by
    specified angle.
    
    Parameters
    ----------
    pix_x: x-position of pixel with unit
    pix_y: y-position of pixel with unit
    angle: value convertable to an `astropy.coordinates.Angle`
        rotation angle with unit (e.g. 12 * u.deg), or "12d"
        
    Returns
    -------
    roated x- and y-positions
    """
    rotmat = rotation_matrix_2d(angle)
    rotated = np.dot(rotmat.T, [pix_x.value,pix_y.value])
    pix_x = rotated[0] * pix_x.unit
    pix_y = rotated[1] * pix_x.unit
    
    return pix_x,pix_y