How to use the photutils.geometry.circular_overlap_grid function in photutils

To help you get started, we’ve selected a few photutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PynPoint / PynPoint / Paper_Scripts / fpf_calculator.py View on Github external
extents[:, 0] = bckg_aps_cntr[:, 0] - radius + 0.5
    extents[:, 1] = bckg_aps_cntr[:, 0] + radius + 1.5
    extents[:, 2] = bckg_aps_cntr[:, 1] - radius + 0.5
    extents[:, 3] = bckg_aps_cntr[:, 1] + radius + 1.5

    ood_filter, extent, phot_extent = aperture_funcs.get_phot_extents(data, bckg_aps_cntr,extents)

    x_min, x_max, y_min, y_max = extent
    x_pmin, x_pmax, y_pmin, y_pmax = phot_extent

    #if no_planet_nghbr==True:
        #print 'Ignore the two apertures near the signal aperture'
    #For each aperture, let's calculate the fraction values given by the intersection between the pixel region of interest
    # and a circle of radius r, then use these fractions to evaluate the final weighted pixel values for each aperture:
    for index in range(len(bckg_aps_cntr)):
        fraction= geometry.circular_overlap_grid(x_pmin[index], x_pmax[index],
                                                  y_pmin[index], y_pmax[index],
                                                  x_max[index] - x_min[index],
                                                  y_max[index]- y_min[index],
                                                  radius, 0, subpix)
        fractions.append(fraction)

        #now, let's return the weighted pixel values but erasing the values ==0. (since the subpixel sampling can result
        # in a fraction =0 and so the pixel value is weighted by 0. and so it is =0. But it is not really 0.)

        #Ignore, if requested, the two apertures near the signal aperture:
        if no_planet_nghbr==True:
            if index != len(bckg_aps_cntr)-1 and index != len(bckg_aps_cntr)-2 and index != 0:
                bckg_values += (filter(lambda a: a !=0.,np.array((data[y_min[index]:y_max[index],x_min[index]:x_max[index]] * fraction)).ravel()))
                bckg_apertures.append(filter(lambda a: a !=0.,np.array((data[y_min[index]:y_max[index],x_min[index]:x_max[index]] * fraction)).ravel()))

            if index==len(bckg_aps_cntr)-1:
github Stargrazer82301 / CAAPR / build / lib / CAAPR / pts / magic / basics / geometry.py View on Github external
"""
        This function ...
        :param x_size:
        :param y_size:
        :return:
        """

        rel_center = self.center

        x_min = - rel_center.x
        x_max = x_size - rel_center.x
        y_min = - rel_center.y
        y_max = y_size - rel_center.y

        fraction = circular_overlap_grid(x_min, x_max, y_min, y_max, x_size, y_size, self.radius, use_exact=0, subpixels=1)

        # Return a new mask
        return Mask(fraction)
github astropy / photutils / photutils / aperture / circle.py View on Github external
elif hasattr(self, 'r_out'):  # annulus
            radius = self.r_out
        else:
            raise ValueError('Cannot determine the aperture radius.')

        masks = []
        for bbox, edges in zip(np.atleast_1d(self.bbox),
                               self._centered_edges):
            ny, nx = bbox.shape
            mask = circular_overlap_grid(edges[0], edges[1], edges[2],
                                         edges[3], nx, ny, radius, use_exact,
                                         subpixels)

            # subtract the inner circle for an annulus
            if hasattr(self, 'r_in'):
                mask -= circular_overlap_grid(edges[0], edges[1], edges[2],
                                              edges[3], nx, ny, self.r_in,
                                              use_exact, subpixels)

            masks.append(ApertureMask(mask, bbox))

        if self.isscalar:
            return masks[0]
        else:
            return masks
github astropy / photutils / photutils / aperture / mask_data.py View on Github external
def _get_fractional_overlap_mask(indiv_absolute_extent, indiv_centered_extent,
                                 overlap, radius, use_exact, subpixels):
    """
    Given a set of coordinates, calculate the masked array for the
    cutout. Returns an empty array if there is no overlap between the
    data and the aperture.
    """

    from ..geometry import circular_overlap_grid

    x_min, x_max, y_min, y_max = indiv_absolute_extent
    x_pmin, x_pmax, y_pmin, y_pmax = indiv_centered_extent

    if overlap:
        return circular_overlap_grid(x_pmin, x_pmax, y_pmin, y_pmax,
                                     x_max - x_min, y_max - y_min,
                                     radius, use_exact, subpixels)
    else:
        # Should this raise a warning or have we already done this once
        # and that is enough?
        return np.array([])
github Stargrazer82301 / CAAPR / CAAPR / pts / magic / basics / geometry.py View on Github external
"""
        This function ...
        :param x_size:
        :param y_size:
        :return:
        """

        rel_center = self.center

        x_min = - rel_center.x
        x_max = x_size - rel_center.x
        y_min = - rel_center.y
        y_max = y_size - rel_center.y

        fraction = circular_overlap_grid(x_min, x_max, y_min, y_max, x_size, y_size, self.radius, use_exact=0, subpixels=1)

        # Return a new mask
        return Mask(fraction)
github astropy / photutils / photutils / aperture / aperture_funcs.py View on Github external
if method == 'center':
        use_exact = 0
        subpixels = 1
    elif method == 'subpixel':
        use_exact = 0
    else:
        use_exact = 1
        subpixels = 1

    from ..geometry import circular_overlap_grid

    for i in range(len(flux)):

        if not np.isnan(flux[i]):

            fraction = circular_overlap_grid(x_pmin[i], x_pmax[i],
                                             y_pmin[i], y_pmax[i],
                                             x_max[i] - x_min[i],
                                             y_max[i] - y_min[i],
                                             radius, use_exact, subpixels)

            if r_in is not None:
                fraction -= circular_overlap_grid(x_pmin[i], x_pmax[i],
                                                  y_pmin[i], y_pmax[i],
                                                  x_max[i] - x_min[i],
                                                  y_max[i] - y_min[i],
                                                  r_in, use_exact, subpixels)

            flux[i] = np.sum(data[y_min[i]:y_max[i],
                                  x_min[i]:x_max[i]] * fraction)

            if error is not None:
github astropy / photutils / photutils / aperture / aperture_funcs.py View on Github external
subpixels = 1

    from ..geometry import circular_overlap_grid

    for i in range(len(flux)):

        if not np.isnan(flux[i]):

            fraction = circular_overlap_grid(x_pmin[i], x_pmax[i],
                                             y_pmin[i], y_pmax[i],
                                             x_max[i] - x_min[i],
                                             y_max[i] - y_min[i],
                                             radius, use_exact, subpixels)

            if r_in is not None:
                fraction -= circular_overlap_grid(x_pmin[i], x_pmax[i],
                                                  y_pmin[i], y_pmax[i],
                                                  x_max[i] - x_min[i],
                                                  y_max[i] - y_min[i],
                                                  r_in, use_exact, subpixels)

            flux[i] = np.sum(data[y_min[i]:y_max[i],
                                  x_min[i]:x_max[i]] * fraction)

            if error is not None:

                fluxvar[i] = find_fluxvar(data, fraction, error, flux[i],
                                          x_min[i], x_max[i], y_min[i],
                                          y_max[i], pixelwise_error)

    if error is None:
        return (flux, )
github Stargrazer82301 / CAAPR / CAAPR / CAAPR_AstroMagic / PTS / pts / magic / basics / geometry.py View on Github external
"""
        This function ...
        :param x_size:
        :param y_size:
        :return:
        """

        rel_center = self.center

        x_min = - rel_center.x
        x_max = x_size - rel_center.x
        y_min = - rel_center.y
        y_max = y_size - rel_center.y

        fraction = circular_overlap_grid(x_min, x_max, y_min, y_max, x_size, y_size, self.radius, use_exact=0, subpixels=1)

        # Return a new mask
        return Mask(fraction)
github astropy / photutils / photutils / aperture / aperture_funcs.py View on Github external
from ..geometry import circular_overlap_grid

    for i in range(len(positions)):

        if ood_filter[i] is not True:

            fractions[y_min[i]: y_max[i], x_min[i]: x_max[i], i] = \
                circular_overlap_grid(x_pmin[i], x_pmax[i],
                                      y_pmin[i], y_pmax[i],
                                      x_max[i] - x_min[i],
                                      y_max[i] - y_min[i],
                                      radius, use_exact, subpixels)

            if r_in is not None:
                fractions[y_min[i]: y_max[i], x_min[i]: x_max[i], i] -= \
                    circular_overlap_grid(x_pmin[i], x_pmax[i],
                                          y_pmin[i], y_pmax[i],
                                          x_max[i] - x_min[i],
                                          y_max[i] - y_min[i],
                                          r_in, use_exact, subpixels)

    return np.squeeze(fractions)