Unverified Commit 0d22bd05 authored by Lauren Adoram-Kershner's avatar Lauren Adoram-Kershner Committed by GitHub
Browse files

Adding functions and NB for overlap connectivity check (#504)

* initial commit

* Getting PR to work locally

* initial commit

* cleaning nb

* updating installation docs

* Addressing PR comments
parent 70e77e73
Loading
Loading
Loading
Loading
+80 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import shapely

import geoalchemy2
from sqlalchemy.ext.declarative.api import DeclarativeMeta
from sqlalchemy.sql import func
import shapely.affinity
import shapely.geometry
import shapely.wkt as swkt
@@ -2221,6 +2222,85 @@ class NetworkCandidateGraph(CandidateGraph):
        """
        self.redis_queue.flushdb()

    def empty_overlays(self, filters={'ignore': False}, size_threshold=0):
        """
        Find overlaps that do not contain valid points. By default, valid points
        include not ignored points, but additional point properties can be used to
        further define a valid point. For example, to look at not ignored, free
        (not ground) points; filters = {'ignored': False, 'pointtype': 2}.

        Parameters
        ----------
        filters: dict
                 Points object properties for point filtering.

        size_threshold: float
                        Minimum area requirment for returned overlaps. Units are
                        determined by spatial reference system.

        Returns
        -------
        overlays: list of Overlay objects
                  Model information associated with overlaps that contain no valid points

        See Also
        --------
        autocnet.io.db.model.Overlay: for description of information associated with Overlay class
        autocnet.io.db.model.Points: for description of information associated with Points class
        """
        with self.session_scope() as session:
            # Find overlap ids that contain one or more valid points
            sq = session.query(Overlay.id).join(Points, func.ST_Contains(Overlay.geom, Points.geom))
            for attr, value in filters.items():
                sq = sq.filter(getattr(Points, attr)==value)
            sq = sq.group_by(Overlay.id)

            # find overlap information not satisfying previous query
            q = session.query(Overlay).filter(Overlay.id.notin_(sq)).filter(func.ST_Area(Overlay.geom)>=size_threshold)
            overlays = q.all()
            session.expunge_all()
            return overlays


    def connected_overlays(self, filters={'ignore': False}, size_threshold=0):
        """
        Find overlaps that contain valid points. By default, valid points
        include not ignored points, but additional point properties can be used to
        further define a valid point. For example, to look at not ignored, free
        (not ground) points; filters = {'ignored': False, 'pointtype': 2}.

        Parameters
        ----------
        filters: dict
                 Points object properties for point filtering.

        size_threshold: float
                        Minimum area requirment for returned overlaps. Units are
                        determined by spatial reference system.

        Returns
        -------
        overlays: list of Overlay objects
                 Model information associated with overlaps that contain one or more valid points

        See Also
        --------
        autocnet.io.db.model.Overlay: for description of information associated with Overlay class
        autocnet.io.db.model.Points: for description of information associated with Points class
        """
        with self.session_scope() as session:
            # Find overlap ids that contain one or more valid points
            sq = session.query(Overlay.id).join(Points, func.ST_Contains(Overlay.geom, Points.geom))
            for attr, value in filters.items():
                sq = sq.filter(getattr(Points, attr)==value)
            sq = sq.group_by(Overlay.id)

            # find overlap information satisfying previous query
            q = session.query(Overlay).filter(Overlay.id.in_(sq)).filter(func.ST_Area(Overlay.geom)>=size_threshold)
            overlays = q.all()
            session.expunge_all()
            return overlays

    def cluster_propagate_control_network(self,
                                          base_cnet,
                                          walltime='00:20:00',
+5 −5
Original line number Diff line number Diff line
@@ -10,12 +10,12 @@ Via Conda
1. [Download](https://www.continuum.io/downloads) and install the Python 3.x Miniconda installer.  Respond ``Yes`` when
   prompted to add conda to your BASH profile.
1. (Optional) We like to sequester applications in their own environments to avoid any dependency conflicts.  To do this:
  * ``conda create -n <your_environment_name> python=3 && source activate <your_environment_name>``
  * ``conda create -n <your_environment_name> && source activate <your_environment_name>``
1. Bring up a command line and add three channels to your conda config (``~/condarc``):
  * ``conda config --add channels usgs-astrogeology``
  * ``conda config --add channels conda-forge``
  * ``conda config --add channels jlaura``
  * ``conda config --add channels menpo``
1. Finally, install autocnet: ``conda install -c jlaura autocnet-dev``
1. Finally, install autocnet: ``conda install -c usgs-astrogeology autocnet``

Via setup.py
------------
@@ -28,9 +28,9 @@ Manual Development Environment
------------------------------
To manually install AutoCnet (for example in a development environment) we must install the necessary dependencies.

1. Create a virtual environment:  ``conda create -n autocnet python=3.5 && source activate autocnet``
1. Create a virtual environment:  ``conda create -n autocnet && source activate autocnet``
2. As above, add conda-forge to the channel list.
3. To install the planetary I/O module and the OpenCV computer vision module: ``conda install -c jlaura plio opencv3``
3. To install the planetary I/O module and the OpenCV computer vision module: ``conda install -c usgs-astrogeology plio opencv3``
4. To install the optional VLFeature module (for SIFT): ``conda install -c conda-forge vlfeat``
4a. To install the Cython wrapper to vlfeat: ``conda install -c menpo cyvlfeat``
5. To install PIL and PySAL: ``pip install pillow pysal``
+2 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ Working With ISIS Control Networks
-------------------------------
.. toctree::
   :maxdepth: 1

    Ingesting from ISIS control network<isis_ingest/from_cnet.ipynb>


+236 −0

File added.

Preview size limit exceeded, changes collapsed.