Loading autocnet/cg/cg.py +16 −0 Original line number Diff line number Diff line from math import isclose, ceil import random import warnings import pandas as pd Loading Loading @@ -313,6 +314,18 @@ def xy_in_polygon(x,y, geom): """ return geom.contains(Point(x, y)) def generate_random(number, polygon): points = [] minx, miny, maxx, maxy = polygon.bounds i = 0 while len(points) < number and i < 1000: pnt = Point(random.uniform(minx, maxx), random.uniform(miny, maxy)) if polygon.contains(pnt): print(pnt.x, pnt.y) points.append([pnt.x, pnt.y]) i += 1 return np.asarray(points) def distribute_points_classic(geom, nspts, ewpts, use_mrr=True, **kwargs): """ This is a decision tree that attempts to perform a Loading Loading @@ -378,6 +391,9 @@ def distribute_points_classic(geom, nspts, ewpts, use_mrr=True, **kwargs): points = np.vstack(points) # Perform a spatial intersection check to eject points that are not valid valid = [p for p in points if xy_in_polygon(p[0], p[1], original_geom)] # The standard method failed. Attempt random placement within the geometry if not valid: valid = generate_random(ewpts * nspts, original_geom) return valid def distribute_points_new(geom, nspts, ewpts, Session): Loading autocnet/spatial/isis.py +3 −2 Original line number Diff line number Diff line Loading @@ -248,7 +248,9 @@ def point_info( ) camres = pvl.loads(cp.stdout) for r in camres['campt'].getall("GroundPoint"): if 'campt' in camres.keys(): camres = camres['campt'] for r in camres.getall("GroundPoint"): if r['Error'] is None: # convert all pixels to PLIO pixels from ISIS r["Sample"] -= .5 Loading @@ -258,7 +260,6 @@ def point_info( raise ValueError( f"ISIS campt completed, but reported an error: {r['Error']}" ) if isinstance(x, (abc.Sequence, np.ndarray)): return results else: Loading autocnet/spatial/overlap.py +11 −8 Original line number Diff line number Diff line Loading @@ -168,7 +168,7 @@ def place_points_in_overlap(overlap, geom = overlap.geom valid = compgeom.distribute_points_in_geom(geom, **distribute_points_kwargs, **kwargs) if not valid.any(): log.warning('Failed to distribute points in overlap') warnings.warn(f'Failed to distribute points in overlap {overlap.id}') return [] print(f'Have {len(valid)} potential points to place in overlap {overlap.id}.') Loading Loading @@ -201,10 +201,13 @@ def place_points_in_overlap(overlap, if cam_type == "isis": try: sample, line = isis.ground_to_image(node["image_path"], lon, lat) except CalledProcessError as e: if 'Requested position does not project in camera model' in e.stderr: print(f'point ({lon}, {lat}) does not project to reference image {node["image_path"]}') except: continue #except CalledProcessError as e: # if 'Requested position does not project in camera model' in e.stderr: # print(f'point ({lon}, {lat}) does not project to reference image {node["image_path"]}') # continue if cam_type == "csm": lon_og, lat_og = oc2og(lon, lat, semi_major, semi_minor) x, y, z = reproject([lon_og, lat_og, height], Loading Loading @@ -310,8 +313,8 @@ def place_points_in_overlap(overlap, # to find the most interesting feature. try: sample, line = isis.ground_to_image(node["image_path"], updated_lon, updated_lat) except CalledProcessError as e: if 'Requested position does not project in camera model' in e.stderr: #except CalledProcessError as e: except: # CalledProcessError is not catching the ValueError that this try/except is attempting to handle. print(f'interesting point ({updated_lon},{updated_lat}) does not project to image {node["image_path"]}') # If the current_index is greater than the reference_index, the change in list size does # not impact the positional index of the reference. If current_index is less than the Loading Loading
autocnet/cg/cg.py +16 −0 Original line number Diff line number Diff line from math import isclose, ceil import random import warnings import pandas as pd Loading Loading @@ -313,6 +314,18 @@ def xy_in_polygon(x,y, geom): """ return geom.contains(Point(x, y)) def generate_random(number, polygon): points = [] minx, miny, maxx, maxy = polygon.bounds i = 0 while len(points) < number and i < 1000: pnt = Point(random.uniform(minx, maxx), random.uniform(miny, maxy)) if polygon.contains(pnt): print(pnt.x, pnt.y) points.append([pnt.x, pnt.y]) i += 1 return np.asarray(points) def distribute_points_classic(geom, nspts, ewpts, use_mrr=True, **kwargs): """ This is a decision tree that attempts to perform a Loading Loading @@ -378,6 +391,9 @@ def distribute_points_classic(geom, nspts, ewpts, use_mrr=True, **kwargs): points = np.vstack(points) # Perform a spatial intersection check to eject points that are not valid valid = [p for p in points if xy_in_polygon(p[0], p[1], original_geom)] # The standard method failed. Attempt random placement within the geometry if not valid: valid = generate_random(ewpts * nspts, original_geom) return valid def distribute_points_new(geom, nspts, ewpts, Session): Loading
autocnet/spatial/isis.py +3 −2 Original line number Diff line number Diff line Loading @@ -248,7 +248,9 @@ def point_info( ) camres = pvl.loads(cp.stdout) for r in camres['campt'].getall("GroundPoint"): if 'campt' in camres.keys(): camres = camres['campt'] for r in camres.getall("GroundPoint"): if r['Error'] is None: # convert all pixels to PLIO pixels from ISIS r["Sample"] -= .5 Loading @@ -258,7 +260,6 @@ def point_info( raise ValueError( f"ISIS campt completed, but reported an error: {r['Error']}" ) if isinstance(x, (abc.Sequence, np.ndarray)): return results else: Loading
autocnet/spatial/overlap.py +11 −8 Original line number Diff line number Diff line Loading @@ -168,7 +168,7 @@ def place_points_in_overlap(overlap, geom = overlap.geom valid = compgeom.distribute_points_in_geom(geom, **distribute_points_kwargs, **kwargs) if not valid.any(): log.warning('Failed to distribute points in overlap') warnings.warn(f'Failed to distribute points in overlap {overlap.id}') return [] print(f'Have {len(valid)} potential points to place in overlap {overlap.id}.') Loading Loading @@ -201,10 +201,13 @@ def place_points_in_overlap(overlap, if cam_type == "isis": try: sample, line = isis.ground_to_image(node["image_path"], lon, lat) except CalledProcessError as e: if 'Requested position does not project in camera model' in e.stderr: print(f'point ({lon}, {lat}) does not project to reference image {node["image_path"]}') except: continue #except CalledProcessError as e: # if 'Requested position does not project in camera model' in e.stderr: # print(f'point ({lon}, {lat}) does not project to reference image {node["image_path"]}') # continue if cam_type == "csm": lon_og, lat_og = oc2og(lon, lat, semi_major, semi_minor) x, y, z = reproject([lon_og, lat_og, height], Loading Loading @@ -310,8 +313,8 @@ def place_points_in_overlap(overlap, # to find the most interesting feature. try: sample, line = isis.ground_to_image(node["image_path"], updated_lon, updated_lat) except CalledProcessError as e: if 'Requested position does not project in camera model' in e.stderr: #except CalledProcessError as e: except: # CalledProcessError is not catching the ValueError that this try/except is attempting to handle. print(f'interesting point ({updated_lon},{updated_lat}) does not project to image {node["image_path"]}') # If the current_index is greater than the reference_index, the change in list size does # not impact the positional index of the reference. If current_index is less than the Loading