コード例 #1
0
ファイル: analyse.py プロジェクト: myrafproject/myrafproject
        def star_find(self, image, default_later=0):
            """Finds sources on image"""
            self.logger.info("Finding sources on image({})".format(image))
            try:
                image_data = self.data(image)
                if len(image_data.shape) > 2:
                    return aa._find_sources(image_data[default_later])

                return aa._find_sources(image_data)
            except Exception as e:
                self.logger.error(e)
コード例 #2
0
def astroalign_optimized_find_transform(source, target_controlp,
                                        target_invariant_tree,
                                        target_asterisms):
    """
    A faster version of astroalign.find_transform considering that we know the
    target control points, invariants tree and asterisms. For details, see
    astroalign.find_transform

    This allows to compute control points once for reference frame
    """

    source_controlp = astroalign._find_sources(
        source)[:astroalign.MAX_CONTROL_POINTS]

    # Check for low number of reference points
    if len(source_controlp) < 3:
        raise Exception("Reference stars in source image are less than the "
                        "minimum value (3).")
    if len(target_controlp) < 3:
        raise Exception("Reference stars in target image are less than the "
                        "minimum value (3).")

    source_invariants, source_asterisms = astroalign._generate_invariants(
        source_controlp)
    source_invariant_tree = KDTree(source_invariants)
    matches_list = source_invariant_tree.query_ball_tree(target_invariant_tree,
                                                         r=0.1)

    matches = []
    for t1, t2_list in zip(source_asterisms, matches_list):
        for t2 in target_asterisms[t2_list]:
            matches.append(list(zip(t1, t2)))
    matches = np.array(matches)

    inv_model = astroalign._MatchTransform(source_controlp, target_controlp)
    n_invariants = len(matches)
    max_iter = n_invariants
    min_matches = max(
        1, min(10, int(n_invariants * astroalign.MIN_MATCHES_FRACTION)))
    if (len(source_controlp) == 3
            or len(target_controlp) == 3) and len(matches) == 1:
        best_t = inv_model.fit(matches)
        inlier_ind = np.arange(len(matches))  # All of the indices
    else:
        best_t, inlier_ind = astroalign._ransac(matches, inv_model, 1,
                                                max_iter, astroalign.PIXEL_TOL,
                                                min_matches)
    triangle_inliers = matches[inlier_ind]
    d1, d2, d3 = triangle_inliers.shape
    inl_arr = triangle_inliers.reshape(d1 * d2, d3)
    inl_unique = set(tuple(pair) for pair in inl_arr)
    inl_arr_unique = np.array(list(list(apair) for apair in inl_unique))
    so, d = inl_arr_unique.T

    return best_t, (source_controlp[so], target_controlp[d])
コード例 #3
0
    def test_find_sources(self):
        srcs = aa._find_sources(self.image_ref)

        from scipy.spatial import KDTree
        ref_coordtree = KDTree(self.star_ref_pos)

        # Compare here srcs list with self.star_ref_pos
        num_sources = 0
        for asrc in srcs:
            found_source = ref_coordtree.query_ball_point(asrc, 3)
            if found_source:
                num_sources += 1
        fraction_found = float(num_sources) / float(len(srcs))
        self.assertGreater(fraction_found, 0.85)
コード例 #4
0
ファイル: alignment.py プロジェクト: coupole-orsay/castor
def register_stars(images, ref_img=None):
    ''' Register a field of stars in translation, rotation, and scaling.

    Parameters
    ==========
    images : ndarray of shape (N, ny, nx)
        cube containing the images to align.
    ref_img : ndarray of shape (ny, nx) or None (default: None)
        The reference image relatively to which all images should be
        aligned.
        If None, use the first input image.
    Returns
    =======
    registered_images: ndarray of shape (N, ny, nx)
        version of the input, with all images aligned with ref_img.
    '''

    # registered_images = np.full_like(images, np.nan)

    if ref_img is None:
        ref_img = images[0]
        first_im_is_ref = True
    else:
        first_im_is_ref = False

    ref_sources = astroalign._find_sources(ref_img)
    iterable = tqdm(images, desc='Aligning images', total=len(images))
    for i, img in enumerate(iterable):
        if i == 0 and first_im_is_ref:
            continue
        try:
            p, _ = astroalign.find_transform(img, ref_sources)
            mat = p.params[:-1]
        except Exception as e:
            warnings.warn('Image {}: {}'.format(i, e))
            mat = np.array([[1, 0, 0], [0, 1, 0]], dtype=float)
        images[i] = affine_transform(img, mat)

    return images
コード例 #5
0
 def set_reference(self, reference_image):
     print("AstroAlignShift overide detection method")
     self.reference_stars = astroalign._find_sources(
         reference_image)[:astroalign.MAX_CONTROL_POINTS]
     self.reference_invariants, self.reference_asterisms = astroalign._generate_invariants(
         self.reference_stars)