Commit eb3e37f0 authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by jlaura
Browse files

control point type propagation on to_isis (#320)

* added cnet matcher

* removed old mosaic matcher

* removed old mosaic matcher

Updated db to use mixin and adds tests

try except srid config table look up and PROJ_LIB set in Demo nb (#301)

added param

geopandas -> gpd

removed less than useful error message

* fixing some stuff

* distance check for phase matcher

* potential bug in subpixel

* python loops are dumb

* left print line in matcher

* removed unused init lines

* removed try except
parent 74d20faa
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -1470,14 +1470,13 @@ WHERE points.active = True AND measures.active=TRUE AND measures.jigreject=FALSE
              The sql query to execute in the database.

        """

        df = pd.read_sql(sql, engine)
        df.rename(columns={'imageid':'image_index','id':'point_id',
                           'sample':'x', 'line':'y'}, inplace=True)
        df.rename(columns={'imageid':'image_index','id':'point_id', 'pointtype' : 'type',
            'sample':'x', 'line':'y', 'serial': 'serialnumber'}, inplace=True)
        if flistpath is None:
            flistpath = os.path.splitext(path)[0] + '.lis'

        cnet.to_isis(path, df, self.serials())
        cnet.to_isis(df, path)
        cnet.write_filelist(self.files, path=flistpath)

    @staticmethod
+6 −2
Original line number Diff line number Diff line
@@ -168,7 +168,7 @@ def themis_ground_to_ctx_matcher(cnet):
                    match_results.append(ex)
                    continue

                if ret is not None:
                if ret is not None and None not in ret:
                    x,y,metrics = ret
                else:
                    match_results.append("Failed to Converge")
@@ -180,9 +180,13 @@ def themis_ground_to_ctx_matcher(cnet):
            # get best offsets, if possible we need better metric for what a
            # good match looks like
            match_results = np.asarray([res for res in match_results if isinstance(res, list)])
            if match_results.shape[0] == 0:
                # no matches
                continue
            match_results = match_results[np.argwhere(match_results[:,3] == match_results[:,3].min())][0][0]

            if match_results[3] > 2:
                # best match diverged too much
                continue

            measure = measures.loc[match_results[0]]
@@ -228,7 +232,7 @@ def themis_ground_to_ctx_matcher(cnet):


    # These should be defined somewhere in Autocnet/plio, if so it should be imported
    columns = ['point_id', 'PointType', 'chooserName', 'datetime', 'editLock', 'ignore',
    columns = ['point_id', 'type', 'chooserName', 'datetime', 'editLock', 'ignore',
           'jigsawRejected', 'referenceIndex', 'AprioriSource',
           'aprioriSurfPointSourceFile', 'RadiusSource',
           'aprioriRadiusSourceFile', 'latitudeConstrained',
+17 −9
Original line number Diff line number Diff line
@@ -193,7 +193,7 @@ def subpixel_template(sx, sy, dx, dy, s_img, d_img, search_size=251, template_si
    dy += (y_offset + dyr)
    return dx, dy, strength

def iterative_phase(sx, sy, dx, dy, s_img, d_img, size=251, reduction=11, convergence_threshold=1.0, **kwargs):
def iterative_phase(sx, sy, dx, dy, s_img, d_img, size=251, reduction=11, convergence_threshold=1.0, max_dist=50, **kwargs):
    """
    Iteratively apply a subpixel phase matcher to source (s_img) amd destination (d_img)
    images. The size parameter is used to set the initial search space. The algorithm
@@ -237,13 +237,18 @@ def iterative_phase(sx, sy, dx, dy, s_img, d_img, size=251, reduction=11, conver
    --------
    subpixel_phase : the function that applies a single iteration of the phase matcher
    """

    # get initial destination location
    dsample = dx
    dline = dy
    while True:
        s_template, _, _ = clip_roi(s_img, sx, sy,
                                   size_x=size, size_y=size)
        d_search, dxr, dyr = clip_roi(d_img, dx, dy,
                                 size_x=size, size_y=size)

        if (s_template is None) or (d_search is None):
            return None, None, None

        if s_template.shape != d_search.shape:
            s_size = s_template.shape
            d_size = d_search.shape
@@ -252,9 +257,9 @@ def iterative_phase(sx, sy, dx, dy, s_img, d_img, size=251, reduction=11, conver
            # the current maximum image size and reduce from there on potential
            # future iterations.
            size = updated_size
        s_template, _, _ = clip_roi(s_img, sx, sy,
            s_template, _, _ = clip_roi(s_template, sx, sy,
                                 size_x=updated_size, size_y=updated_size)
        d_search, dxr, dyr = clip_roi(d_img, dx, dy,
            d_search, dxr, dyr = clip_roi(d_search, dx, dy,
                                size_x=updated_size, size_y=updated_size)
            if (s_template is None) or (d_search is None):
                return None, None, None
@@ -270,9 +275,12 @@ def iterative_phase(sx, sy, dx, dy, s_img, d_img, size=251, reduction=11, conver

        # Break if the solution has converged
        size -= reduction
    if abs(shift_x) <= convergence_threshold and abs(shift_y) <= convergence_threshold:
        return dx, dy, metrics
    elif size <1:
        dist = np.linalg.norm([dsample-dx, dline-dy])
        if size <1:
            return None, None, None
    else:
        return iterative_phase(sx, sy,  dx, dy, s_img, d_img, size, **kwargs)
        if abs(shift_x) <= convergence_threshold and\
           abs(shift_y) <= convergence_threshold and\
           abs(dist) <= max_dist:
            break
    return dx, dy, metrics