Commit 5fa8811f authored by Lauren Adoram-Kershner's avatar Lauren Adoram-Kershner
Browse files

back propagating plio naming convention

parent d07aae4e
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -996,20 +996,20 @@ class NetworkEdge(Edge):
        session.close()
        return res

    def network_to_matches(self, active_point=True, active_measure=True, rejected_jigsaw=False):
    def network_to_matches(self, ignore_point=False, ignore_measure=False, rejected_jigsaw=False):
        """
        For the edge, take any points/measures that are in the database and
        convert them into matches on the associated edge.

        Parameters
        ----------
        active_point : bool
                       If True (default) only select the points that are
                       currently set to active.
        ignore_point : bool
                       If False (default) only select the points that are
                       not ignored (currently active).

        active_measure : bool
                         If True (default) only add the measures that are
                         currently active
        ignore_measure : bool
                         If False (default) only add the measures that are
                         not ignored (currently active).

        rejected_jigsaw : bool
                          If False (default) add any points that are not
@@ -1030,8 +1030,8 @@ class NetworkEdge(Edge):
                  Measures.line,
                  Measures.measuretype,
                  Measures.imageid).\
            filter(Points.active==active_point,
                   Measures.active==active_measure,
            filter(Points.ignore==ignore_point,
                   Measures.ignore==ignore_measure,
                   Measures.jigreject==rejected_jigsaw,
                   sqlalchemy.or_(Measures.imageid==source,
                                  Measures.imageid==destin)).join(Measures)
+18 −56
Original line number Diff line number Diff line
@@ -1447,47 +1447,32 @@ class NetworkCandidateGraph(CandidateGraph):
        for _, n in self.nodes(data='data'):
            n.generate_vrt(**kwargs)

    def to_isis(self, path, flistpath=None,points_sql = """
    def to_isis(self, path, flistpath=None,sql = """
SELECT points.id,
        points.pointtype,
        points."pointType",
        points.apriori,
        points.adjusted,
        points.active
FROM measures
INNER JOIN points ON measures.pointid = points.id
WHERE
    points.active = True AND
    measures.active=TRUE AND
    measures.jigreject=FALSE AND
    measures.imageid NOT IN
        (SELECT measures.imageid
        FROM measures
        INNER JOIN points ON measures.pointid = points.id
        WHERE measures.active = true and measures.jigreject = false AND points.active = True
        GROUP BY measures.imageid
        HAVING COUNT(DISTINCT measures.pointid)  < 3);
""",
measures_sql="""
SELECT measures.serial,
        points."pointIgnore",
        measures.serialnumber,
        measures.sample,
        measures.line,
        measures.measuretype,
        measures."measureType",
        measures.imageid,
        measures.active,
        measures.jigreject,
        measures."measureIgnore",
        measures."measureJigsawRejected",
        measures.aprioriline,
        measures.apriorisample
FROM measures
INNER JOIN points ON measures.pointid = points.id
WHERE
    points.active = True AND
    measures.active=TRUE AND
    measures.jigreject=FALSE AND
    points."pointIgnore" = False AND
    measures."measureIgnore" = FALSE AND
    measures."measureJigsawRejected" = FALSE AND
    measures.imageid NOT IN
        (SELECT measures.imageid
        FROM measures
        INNER JOIN points ON measures.pointid = points.id
        WHERE measures.active = true and measures.jigreject = false AND points.active = True
        WHERE measures."measureIgnore" = False and measures."measureJigsawRejected" = False AND points."pointIgnore" = False
        GROUP BY measures.imageid
        HAVING COUNT(DISTINCT measures.pointid)  < 3);
"""):
@@ -1512,16 +1497,7 @@ WHERE
        """
        #since measures and points tables contain some of the same attributes
        #read them in seperately and rename
        points_df = pd.read_sql(points_sql, engine)
        points_df.rename(columns={'pointtype' : 'pointType', 'jigreject' : 'pointJigsawRejected'}, inplace=True)
        points_df['pointIgnore'] = ~points_df['active']

        measures_df = pd.read_sql(measures_sql, engine)
        measures_df.rename(columns={'serial' : 'serialnumber', 'measuretype' : 'measureType',
                                    'jigreject' : 'measureJigsawRejected'}, inplace=True)
        measures_df['measureIgnore'] = ~measures_df['active']
        #combine for passing to plio
        df = pd.concat([points_df, measures_df], axis=1, sort=False)
        df = pd.read_sql(sql, engine)

        #create columns in the dataframe; zeros ensure plio (/protobuf) will
        #ignore unless populated with alternate values
@@ -1559,6 +1535,7 @@ WHERE

        cnet.to_isis(df, path, targetname=target)
        cnet.write_filelist(fpaths, path=flistpath)
        return df

    @staticmethod
    def update_from_jigsaw(session, path):
@@ -1835,21 +1812,6 @@ WHERE
        if isinstance(cnet, str):
            cnet = from_isis(cnet)

        # rename some columns
        newcols = []
        for i, c in enumerate(cnet.columns):
            if i == 1:
                newcols.append('pointtype')
            elif i == 5:
                newcols.append('pointignore')
            elif i == 6:
                newcols.append('pointjigsawRejected')
            elif i == 25:
                newcols.append('measuretype')
            else:
                newcols.append(c)
        cnet.columns = newcols

        cnetpoints = cnet.groupby('id')
        points = []
        session = Session()
@@ -1859,14 +1821,14 @@ WHERE
                res = session.query(Images).filter(Images.serial == row.serialnumber).one()
                return Measures(pointid=id,
                         imageid=int(res.id), # Need to grab this
                         measuretype=int(row.measuretype),
                         measuretype=int(row.measureType),
                         serial=row.serialnumber,
                         sample=float(row['sample']),
                         line=float(row['line']),
                         sampler=float(row.sampleResidual),
                         liner=float(row.lineResidual),
                         active=not row.ignore, # active = ~ignored
                         jigreject=row.jigsawRejected,
                         ignore=row.measureIgnore,
                         jigreject=row.measureJigsawRejected,
                         aprioriline=float(row.aprioriline),
                         apriorisample=float(row.apriorisample),
                         linesigma=float(row.linesigma),
@@ -1879,10 +1841,10 @@ WHERE
            lon, lat, alt = pyproj.transform(ecef, lla, x, y, z)

            point = Points(identifier=id,
                           active=not row.pointignore, # active = ~ignored
                           ignore=row.pointIgnore,
                           apriori= shapely.geometry.Point(float(row.aprioriX), float(row.aprioriY), float(row.aprioriZ)),
                           adjusted= shapely.geometry.Point(float(row.adjustedX),float(row.adjustedY),float(row.adjustedZ)),
                           pointtype=float(row.pointtype))
                           pointtype=float(row.pointType))

            point.measures = list(measures)
            points.append(point)
+8 −8
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ class Edges(BaseMixin, Base):
    destination = Column(Integer)
    ring = Column(ArrayType())
    fundamental = Column(ArrayType())
    active = Column(Boolean)
    ignore = Column(Boolean)
    masks = Column(Json())

class Costs(BaseMixin, Base):
@@ -187,7 +187,7 @@ class Images(BaseMixin, Base):
    name = Column(String)
    path = Column(String)
    serial = Column(String, unique=True)
    active = Column(Boolean, default=True)
    ignore = Column(Boolean, default=False)
    _footprint_latlon = Column("footprint_latlon", Geometry('MultiPolygon', srid=latitudinal_srid, dimension=2, spatial_index=True))
    footprint_bodyfixed = Column(Geometry('MULTIPOLYGON', dimension=2))
    cam_type = Column(String)
@@ -272,11 +272,11 @@ class PointType(enum.IntEnum):
class Points(BaseMixin, Base):
    __tablename__ = 'points'
    id = Column(Integer, primary_key=True, autoincrement=True)
    _pointtype = Column("pointtype", IntEnum(PointType), nullable=False)  # 2, 3, 4 - Could be an enum in the future, map str to int in a decorator
    _pointtype = Column("pointType", IntEnum(PointType), nullable=False)  # 2, 3, 4 - Could be an enum in the future, map str to int in a decorator
    identifier = Column(String, unique=True)
    _geom = Column("geom", Geometry('POINT', srid=latitudinal_srid, dimension=2, spatial_index=True))
    cam_type = Column(String)
    active = Column(Boolean, default=True)
    ignore = Column("pointIgnore", Boolean, default=False)
    _apriori = Column("apriori", Geometry('POINTZ', srid=rectangular_srid, dimension=3, spatial_index=False))
    _adjusted = Column("adjusted", Geometry('POINTZ', srid=rectangular_srid, dimension=3, spatial_index=False))
    measures = relationship('Measures')
@@ -350,14 +350,14 @@ class Measures(BaseMixin, Base):
    id = Column(Integer,primary_key=True, autoincrement=True)
    pointid = Column(Integer, ForeignKey('points.id'), nullable=False)
    imageid = Column(Integer, ForeignKey('images.id'))
    serial = Column(String, nullable=False)
    _measuretype = Column("measuretype", IntEnum(MeasureType), nullable=False)  # [0,3]  # Enum as above
    serial = Column("serialnumber", String, nullable=False)
    _measuretype = Column("measureType", IntEnum(MeasureType), nullable=False)  # [0,3]  # Enum as above
    sample = Column(Float, nullable=False)
    line = Column(Float, nullable=False)
    sampler = Column(Float)  # Sample Residual
    liner = Column(Float)  # Line Residual
    active = Column(Boolean, default=True)
    jigreject = Column(Boolean, default=False)  # jigsaw rejected
    ignore = Column("measureIgnore", Boolean, default=False)
    jigreject = Column("measureJigsawRejected", Boolean, default=False)  # jigsaw rejected
    aprioriline = Column(Float)
    apriorisample = Column(Float)
    samplesigma = Column(Float)
+3 −3
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ def test_points_exists(tables):
    {'pointtype':2, 'identifier':'123abc'},
    {'pointtype':3, 'apriori':Point(0,0,0)},
    {'pointtype':3, 'adjusted':Point(0,0,0)},
    {'pointtype':2, 'adjusted':Point(1,1,1), 'active':True}
    {'pointtype':2, 'adjusted':Point(1,1,1), 'ignore':False}
])
def test_create_point(session, data):
    p = model.Points.create(session, **data)
@@ -189,12 +189,12 @@ def test_broken_bad_geom(session):
    i = model.Images.create(session, footprint_latlon=geom,
                                      serial = 'serial')
    resp = session.query(model.Images).filter(model.Images.id==i.id).one()
    assert resp.active == False
    assert resp.ignore == True

def test_fix_bad_geom(session):
    geom = MultiPolygon([Polygon([(0,0), (0,1), (1,1), (0,1), (1,1), (1,0), (0,0) ])])
    i = model.Images.create(session, footprint_latlon=geom,
                                     serial = 'serial' )
    resp = session.query(model.Images).filter(model.Images.id==i.id).one()
    assert resp.active == True
    assert resp.ignore == False
    assert resp.footprint_latlon == MultiPolygon([Polygon([(0,0), (0,1), (1,1), (1,0), (0,0) ])])
+4 −6
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ $BODY$
      NEW.footprint_latlon = ST_MAKEVALID(NEW.footprint_latlon);
      RETURN NEW;
    EXCEPTION WHEN OTHERS THEN
      NEW.active = false;
      NEW.ignore = true;
      RETURN NEW;
END;
$BODY$
@@ -34,14 +34,14 @@ $BODY$
BEGIN
 IF (SELECT COUNT(*)
	 FROM MEASURES
	 WHERE pointid = NEW.pointid AND active = True) < 2
	 WHERE pointid = NEW.pointid AND "measureIgnore" = False) < 2
 THEN
   UPDATE points
     SET active = False
     SET "pointIgnore" = True
	 WHERE points.id = NEW.pointid;
 ELSE
   UPDATE points
   SET active = True
   SET "pointIgnore" = False
   WHERE points.id = NEW.pointid;
 END IF;

@@ -65,5 +65,3 @@ try:
  latitudinal_srid = config['spatial']['latitudinal_srid']
except:
  latitudinal_srid = None

Loading