Commit 8945f4a0 authored by Bauck, Kirsten (Contractor) Hailey's avatar Bauck, Kirsten (Contractor) Hailey
Browse files

refactor overlaps and add sensor classes

parent 76526f6f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@ release.
- Functionality to add measure to a point
- Functionality to convert from sample, line (x,y) pixel coordinates to Body-Centered, Body-Fixed (BCBF) coordinates in meters.
- Functionality to test for valid input images.
- Refactored place_points_in_overlap to make it easier to understand and work with
- Created `sensor.py` that creates a class for either a 'csm' camera sensor or an 'isis' camera sensor. This removes confusing and wordy code. Now just need to create a sensor object based on the input 'csm' or 'isis'. Code inside classes will figure out the rest.
- Fuctionality to convert between oc2xyz and xyz2oc in `spatial.py`

### Fixed
- string injection via format with sqlalchemy text() object.
+3 −4
Original line number Diff line number Diff line
@@ -584,7 +584,7 @@ class Points(Base, BaseMixin):
                                        choosername=choosername))
        return point 

    def add_measures_to_point(self, candidates, choosername='autocnet'):
    def add_measures_to_point(self, candidates, sensor, choosername='autocnet', **kwargs):
        """
        Attempt to add 1+ measures to a point from a list of candidate nodes. The
        function steps over each node and attempts to use the node's sensor model
@@ -603,10 +603,9 @@ class Points(Base, BaseMixin):
            if not os.path.exists(node['image_path']):
                log.info(f'Unable to find input image {node["image_path"]}')
                continue
            
            try:
                # ToDo: We want ot abstract away this to be a generic sensor model. No more 'isis' vs. 'csm' in the code
                sample, line = isis.ground_to_image(node["image_path"], self.geom.x, self.geom.y)
                # TODO: Take this projection out of the CSM model and work it into the point
                sample, line = sensor.calculate_sample_line(node, self.geom.x, self.geom.y, **kwargs)
            except:
                log.info(f"{node['image_path']} failed ground_to_image. Likely due to being processed incorrectly or is just a bad image that failed campt.")

+3 −1
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import pytest

import shapely
from autocnet.io.db.model import Points
from autocnet.spatial import sensor

def test_points_exists(tables):
    assert Points.__tablename__ in tables
@@ -72,6 +73,7 @@ def test_create_point_with_reference_measure(session):
def test_add_measures_to_point(session):
    point = Points()
    point.adjusted = shapely.Point(0,0,0)
    test_sensor = sensor.create_sensor('isis')
    
    node = MagicMock()
    node.isis_serial = 'serial'
@@ -81,7 +83,7 @@ def test_add_measures_to_point(session):

    with patch('autocnet.spatial.isis.ground_to_image') as mocked_call:
        mocked_call.return_value = (0.5, 0.5)
        point.add_measures_to_point(reference_nodes)
        point.add_measures_to_point(reference_nodes, test_sensor)

    assert len(point.measures) == 4
    assert point.measures[0].line == 0.5
+72 −0
Original line number Diff line number Diff line
import numpy as np

def is_valid_lroc_polar_image(roi_array, 
                   include_var=True, 
                   include_mean=False,
                   include_std=False):
    """
    Checks if a numpy array representing an ROI from an lorc polar image is valid.
    Can check using variance, mean, and standard deviation, baed on user input. 
    It is highly encouraged that at the very least the variance check is used.

    Parameters
    __________
    roi_array : np.array
        A numpy array representing a ROI from an image, meaning the values are pixels
    include_var : bool
        Choose whether to filter images based on variance. Default True.
    include_mean : bool
        Choose whether to filter images based on mean. Default True.
        Goal is to get rid of overally dark images.
    include_std : bool
        Choose whether to filter images based on standard deviation. Default True.
        Goal is to get rid of overally saturated images.
    
    Returns
    _______
    is_valid : bool
        Returns True is passes the checks, returns false otherwise.
    """
    functions = []

    if include_var:
        # Get rid of super bad images
        var_func = lambda x : False if np.var(roi_array) == 0 else True
        functions.append(var_func)
    if include_mean:
        # Get rid of overally dark images
        mean_func = lambda x : False if np.mean(roi_array) < 0.0005 else True
        functions.append(mean_func)
    if include_std:
        # Get rid over overally saturated images
        std_func = lambda x : False if np.std(roi_array) > 0.001 else True
        functions.append(std_func)

    return all(func(roi_array) for func in functions)

def is_valid_lroc_image(roi_array, include_var=True):
    """
    Checks if a numpy array representing an ROI from an lroc image is valid.
    Can check using variance, based on user input. 
    It is highly encouraged that the variance check is used.

    Parameters
    __________
    roi_array : np.array
        A numpy array representing a ROI from an image, meaning the values are pixels
    include_var : bool
        Choose whether to filter images based on variance. Default True.
    
    Returns
    _______
    is_valid : bool
        Returns True is passes the checks, returns false otherwise.
    """
    functions = []

    if include_var:
        # Get rid of super bad images
        var_func = lambda x : False if np.var(roi_array) == 0 else True
        functions.append(var_func)

    return all(func(roi_array) for func in functions)
 No newline at end of file
+2 −47
Original line number Diff line number Diff line
import json
import logging
import math
import os

import numpy as np
import shapely

from sqlalchemy import text
from autocnet.cg.cg import create_points_along_line
from autocnet.io.db.model import Images, Measures, Overlay, Points, JsonEncoder
from autocnet.io.db.model import Images, Points, JsonEncoder
from autocnet.graph.node import NetworkNode
from autocnet.spatial import isis
from autocnet.transformation import roi
from autocnet.matcher.cpu_extractor import extract_most_interesting
from autocnet.matcher.validation import is_valid_lroc_polar_image
import time

# Set up logging file
@@ -143,50 +142,6 @@ def find_points_in_centroids(radius,
            points.extend(line_points)
    return points

def is_valid_lroc_polar_image(roi_array, 
                   include_var=True, 
                   include_mean=False,
                   include_std=False):
    """
    Checks if a numpy array representing an ROI from an image is valid.
    Can check using variance, mean, and standard deviation, baed on unser input. 
    It is highly encouraged that at the very least the variance check is used.

    Parameters
    __________
    roi_array : np.array
        A numpy array representing a ROI from an image, meaning the values are pixels
    include_var : bool
        Choose whether to filter images based on variance. Default True.
    include_mean : bool
        Choose whether to filter images based on mean. Default True.
        Goal is to get rid of overally dark images.
    include_std : bool
        Choose whether to filter images based on standard deviation. Default True.
        Goal is to get rid of overally saturated images.
    
    Returns
    _______
    is_valid : bool
        Returns True is passes the checks, returns false otherwise.
    """
    functions = []

    if include_var:
        # Get rid of super bad images
        var_func = lambda x : False if np.var(roi_array) == 0 else True
        functions.append(var_func)
    if include_mean:
        # Get rid of overally dark images
        mean_func = lambda x : False if np.mean(roi_array) < 0.0005 else True
        functions.append(mean_func)
    if include_std:
        # Get rid over overally saturated images
        std_func = lambda x : False if np.std(roi_array) > 0.001 else True
        functions.append(std_func)

    return all(func(roi_array) for func in functions)

def find_intresting_point(nodes, lon, lat, size=71):
    """
    Find an intresting point close the given lon, lat given a list data structure that contains
Loading