Commit 271a6c39 authored by Laura, Jason R.'s avatar Laura, Jason R. Committed by Bauck, Kirsten (Contractor) Hailey
Browse files

Fixes regression in point placement

parent 15a21fd1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -33,6 +33,11 @@ heading to indicate that only the bug fixes and security fixes are in the bug fi
release.
-->
## [Unreleased]
### Added
- Debug logging to `place_points_in_overlap` and `distribute_points_in_geom` to make debugging issues easier.

### Fixed
- Error in `find_interesting_feature` that was mis-using the ROI API. This bug was introduced in 1.2.0 when the ROI API updated.

## [1.2.0]
### Added
+15 −4
Original line number Diff line number Diff line
@@ -460,6 +460,7 @@ def distribute_points_in_geom(geom, method="classic",
                              ewpts_func=lambda x: ceil(round(x,1)*5),
                              Session=None,
                              ratio_size=0.1,
                              min_area=0.004,
                              **kwargs):
    """
    Given a geometry, attempt a basic classification of the shape.
@@ -487,10 +488,15 @@ def distribute_points_in_geom(geom, method="classic",

    ewpts_func : obj
                 Function taking a Number and returning an int
    
    ratio_size : float
                 A number that represent the minimum size the
                 ratio is set at to be considered a sliver.

    min_area : float
               The minimum area, as measured in the project SRID,
               below which points will not be placed and above which
               points will be placed.
    Returns
    -------
    valid : np.ndarray
@@ -523,6 +529,9 @@ def distribute_points_in_geom(geom, method="classic",
            longid = i
    ratio = short/long
    
    logging.debug(f'Area: {geom.area}')
    logging.debug(f'Ratio: {ratio}')

    ns = False
    ew = False
    valid = []
@@ -536,13 +545,14 @@ def distribute_points_in_geom(geom, method="classic",
        ew = True

    # Decision Tree
    if ratio < ratio_size and geom.area < 0.01:
        # Class: Slivers - ignore.
    if ratio < ratio_size and geom.area < min_area:
        logging.debug('Ratio check failed.')
        return np.array([])
    elif geom.area <= 0.004 and ratio >= 0.25:
        # Single point at the centroid
    elif geom.area <= min_area and ratio >= ratio_size:
        logging.debug('Placing a single point.')
        valid = single_centroid(geom)
    elif ns==True:
        logging.debug('Placing N/S oriented points.')
        # Class, north/south poly, multi-point
        nspts = nspts_func(long)
        ewpts = ewpts_func(short)
@@ -551,6 +561,7 @@ def distribute_points_in_geom(geom, method="classic",
        else:
            valid = point_distribution_func(geom, nspts, ewpts, Session=Session, **kwargs)
    elif ew == True:
        logging.debug('Placing E/W oriented points.')
        # Since this is an LS, we should place these diagonally from the 'lower left' to the 'upper right'
        nspts = ewpts_func(short)
        ewpts = nspts_func(long)
+2 −6
Original line number Diff line number Diff line
@@ -112,12 +112,8 @@ def generate_ground_points(Session,
            log.warning(f'Line or sample are outside of the base.')
            continue
        
        image = roi.Roi(ground_mosaic, sample, line, size_x=size[0], size_y=size[1])
        try:
            image.clip()
        except:
            continue
        image_roi = image.clipped_array
        image = roi.Roi(ground_mosaic, sample, line)
        image_roi = image.clip(size_x=size[0], size_y=size[1])

        interesting = extract_most_interesting(bytescale(image_roi),  extractor_parameters={}, extractor_method='vlfeat')
        # interesting = extract_most_interesting(bytescale(image_roi),  extractor_parameters={'nfeatures':500}, extractor_method='orb')
+3 −3
Original line number Diff line number Diff line
@@ -186,9 +186,9 @@ def find_intresting_point(nodes, lon, lat, size=71):
        line = try_line

        # Extract ORB features in a sub-image around the desired point
        image_roi = roi.Roi(node.geodata, sample, line, size_x=size, size_y=size)
        image_roi = roi.Roi(node.geodata, sample, line)
        try:
            roi_array = image_roi.clipped_array # Units are pixels for the array
            roi_array = image_roi.clip(size_x=size, size_y=size) # Units are pixels for the array
        except:
            log.info(f'Failed to find interesting features in image.')
            continue
@@ -199,7 +199,7 @@ def find_intresting_point(nodes, lon, lat, size=71):
            continue

        # Extract the most interesting feature in the search window
        interesting = extract_most_interesting(image_roi.clipped_array)
        interesting = extract_most_interesting(roi_array)
        
        if interesting is not None:
            # We have found an interesting feature and have identified the reference point.
+8 −13
Original line number Diff line number Diff line
@@ -117,12 +117,8 @@ def find_interesting_point(nodes, lon, lat, size=71, **kwargs):
        line = try_line

        # Extract ORB features in a sub-image around the desired point
        image_roi = roi.Roi(node.geodata, sample, line, size_x=size, size_y=size)
        try:
            roi_array = image_roi.clipped_array # Units are pixels for the array
        except:
            log.info(f'Failed to find interesting features in image.')
            continue
        image_roi = roi.Roi(node.geodata, sample, line)
        roi_array = image_roi.clip(size_x=size, size_y=size) # Units are pixels for the array

        # Check if the image is valid and could be used as the reference
        if not is_valid_lroc_image(roi_array):
@@ -130,7 +126,7 @@ def find_interesting_point(nodes, lon, lat, size=71, **kwargs):
            continue

        # Extract the most interesting feature in the search window
        interesting = extract_most_interesting(image_roi.clipped_array)
        interesting = extract_most_interesting(roi_array)
        
        if interesting is not None:
            # We have found an interesting feature and have identified the reference point.
@@ -224,6 +220,7 @@ def place_points_in_overlap(overlap,
    # Determine the point distribution in the overlap geom
    geom = overlap.geom
    candidate_points = compgeom.distribute_points_in_geom(geom, ratio_size=ratio_size, **distribute_points_kwargs, **kwargs)
    logging.debug(f'Found {len(candidate_points)} in overlap {overlap.id}.')
    if not candidate_points.any():
        warnings.warn(f'Failed to distribute points in overlap {overlap.id}')
        return []
@@ -282,6 +279,7 @@ def place_points_in_overlap(overlap,
        else:
            if len(point.measures) >= 2:
                points_to_commit.append(point)
    log.debug(f'Committing: {points_to_commit}')
    if points_to_commit:
        with ncg.session_scope() if ncg else nullcontext(session) as session:
            session.add_all(points_to_commit)
@@ -359,12 +357,9 @@ def place_points_in_image(image,
            continue

        # Extract ORB features in a sub-image around the desired point
        image_roi = roi.Roi(node.geodata, sample, line, size_x=size, size_y=size)
        image_roi.clip()
        try:
            interesting = extract_most_interesting(image.clipped_array)
        except:
            continue
        image_roi = roi.Roi(node.geodata, sample, line)
        roi_array = image_roi.clip(size_x=size, size_y=size)
        interesting = extract_most_interesting(roi_array)

        # kps are in the image space with upper left origin and the roi
        # could be the requested size or smaller if near an image boundary.
Loading