{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Getting Setup\n",
    "This section goes through various steps to get setup for outlier detection. For more details see the ingesting ISIS control networks tutorial."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Required for autocnet imports\n",
    "import os\n",
    "os.environ['ISISROOT'] = '/usgs/cpkgs/anaconda3_linux/envs/isis4.2.0'\n",
    "\n",
    "# Autocnet Imports\n",
    "from autocnet.graph.network import NetworkCandidateGraph\n",
    "from autocnet.graph.edge import NetworkEdge\n",
    "from autocnet.io.db.model import Matches, Points\n",
    "from autocnet.transformation.roi import Roi\n",
    "\n",
    "# Helpful Python Modules\n",
    "import matplotlib.pyplot as plt  #     plotting package\n",
    "import numpy as np               #     numerical computing package"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setting up the NetworkCandidateGraph"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Config\n",
    "\n",
    "The config various settings that autocnet will use when connecting to other services. Primarily, the config is used to define:\n",
    "\n",
    "- The database your NetworkCandidateGraph will use\n",
    "- The redis queue and slurm settings for cluster based processing\n",
    "- The spatial reference system for geometries such as image footprints"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "config_path = 'config.yml'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Loading the control network\n",
    "This cell will check if the database your config file points to already has a control network ingested in it. If it doesn't then it goes through the steps from the ingesting ISIS control networks tutorial."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Network already in database\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/work/users/jmapel/anaconda_local/envs/autocnet_local/lib/python3.7/site-packages/sqlalchemy/orm/relationships.py:1997: SAWarning: Setting backref / back_populates on relationship Overlay.points to refer to viewonly relationship Points.overlay should include sync_backref=False set on the Overlay.points relationship.  (this warning may be suppressed after 10 occurrences)\n",
      "  (rel_b, rel_a, rel_b),\n",
      "/work/users/jmapel/anaconda_local/envs/autocnet_local/lib/python3.7/site-packages/sqlalchemy/orm/relationships.py:1997: SAWarning: Setting backref / back_populates on relationship Points.overlay to refer to viewonly relationship Overlay.points should include sync_backref=False set on the Points.overlay relationship.  (this warning may be suppressed after 10 occurrences)\n",
      "  (rel_b, rel_a, rel_b),\n"
     ]
    }
   ],
   "source": [
    "data_directory = \"/work/projects/control_network_metrics/tutorials/isis_ingestion\"\n",
    "lis_path = os.path.join(data_directory, \"apollo_lronac_cubes.lis\")\n",
    "cnet_path = os.path.join(data_directory, \"AS15_landingsite_apollolro_jig1.net\")\n",
    "\n",
    "ncg = NetworkCandidateGraph()\n",
    "ncg.config_from_file(config_path)\n",
    "ncg.from_database()\n",
    "if len(ncg) == 0:\n",
    "    print(f'Ingesting control network {cnet_path}.')\n",
    "    ncg = NetworkCandidateGraph.from_cnet(cnet_path, lis_path, config_path)\n",
    "else:\n",
    "    print('Network already in database')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Check network\n",
    "Look at the graph of the network to ensure it isn't malformed. Each image in the network is represented by a node and overlapping images have an edge between their nodes. We will be doing pair-wise outlier detection, so we will check each edge in the network graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 37804 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ncg.plot()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Getting the pairwise image matches\n",
    "The first process we need to do is collect all of the pairwise matches between images. Our control network currently contains control points and all of the measurements of them. We need to convert these multi-image relationships into all of the common points between each pair of images.\n",
    "\n",
    "To do this, we're going to use Autocnet's apply function to run parallel processing on each edge of the NetworkCandidateGraph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "?NetworkCandidateGraph.apply"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### SLURM parameters\n",
    "These parameters will be used when creating SLURM jobs for cluster processing via the apply function. Depending on the complexity of the jobs you are running, you may want to change the walltime and arraychunk parameters."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "walltime=\"00:30:00\"\n",
    "log_dir = '/scratch/jmapel/autocnet_tut/logs'\n",
    "arraychunk=75\n",
    "chunksize=16723"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Convert control measures and points to image matches\n",
    "This cell uses apply to run the network_to_matches function on each edge. It is very important that this function only get run once per edge or it will add duplicate matches. So, this cell also contains a check that skips the function if the database already has matches in it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "?NetworkEdge.network_to_matches"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loading matches table\n"
     ]
    }
   ],
   "source": [
    "with ncg.session_scope() as session:\n",
    "    num_matches = session.query(Matches).count()\n",
    "if num_matches == 0:\n",
    "    print(\"Loading matches table\")\n",
    "    njobs = ncg.apply('network_to_matches', \n",
    "                      on='edges',\n",
    "                      # SLURM kwargs\n",
    "                      walltime=walltime,\n",
    "                      log_dir=os.path.join(log_dir, 'matches'),\n",
    "                      arraychunk=arraychunk,\n",
    "                      chunksize=chunksize)\n",
    "else:\n",
    "    print(\"Matches table already populated\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Looking at the matches\n",
    "The pairwise image matches are stored on the edges of the graph and can be accessed via the networkX graph or the matches table in the database"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Edge (10, 6) has 440 matches\n",
      "Edge (10, 3) has 4 matches\n",
      "Edge (10, 4) has 4 matches\n",
      "Edge (10, 2) has 4 matches\n",
      "Edge (10, 11) has 39 matches\n",
      "Edge (10, 8) has 477 matches\n",
      "Edge (10, 5) has 4 matches\n",
      "Edge (10, 7) has 54 matches\n",
      "Edge (1, 3) has 178 matches\n",
      "Edge (1, 4) has 82 matches\n",
      "Edge (1, 2) has 197 matches\n",
      "Edge (1, 5) has 19 matches\n",
      "Edge (6, 3) has 4 matches\n",
      "Edge (6, 4) has 4 matches\n",
      "Edge (6, 2) has 4 matches\n",
      "Edge (6, 11) has 38 matches\n",
      "Edge (6, 8) has 419 matches\n",
      "Edge (6, 5) has 4 matches\n",
      "Edge (6, 7) has 46 matches\n",
      "Edge (3, 9) has 3 matches\n",
      "Edge (3, 4) has 271 matches\n",
      "Edge (3, 2) has 274 matches\n",
      "Edge (3, 11) has 5 matches\n",
      "Edge (3, 8) has 4 matches\n",
      "Edge (3, 5) has 181 matches\n",
      "Edge (3, 7) has 2 matches\n",
      "Edge (9, 4) has 3 matches\n",
      "Edge (9, 2) has 3 matches\n",
      "Edge (9, 11) has 239 matches\n",
      "Edge (9, 8) has 42 matches\n",
      "Edge (9, 5) has 3 matches\n",
      "Edge (9, 7) has 213 matches\n",
      "Edge (4, 2) has 166 matches\n",
      "Edge (4, 11) has 5 matches\n",
      "Edge (4, 8) has 4 matches\n",
      "Edge (4, 5) has 199 matches\n",
      "Edge (4, 7) has 2 matches\n",
      "Edge (2, 11) has 5 matches\n",
      "Edge (2, 8) has 4 matches\n",
      "Edge (2, 5) has 89 matches\n",
      "Edge (2, 7) has 2 matches\n",
      "Edge (11, 8) has 171 matches\n",
      "Edge (11, 5) has 5 matches\n",
      "Edge (11, 7) has 275 matches\n",
      "Edge (8, 5) has 4 matches\n",
      "Edge (8, 7) has 184 matches\n",
      "Edge (5, 7) has 2 matches\n"
     ]
    }
   ],
   "source": [
    "for source, dest, edge in ncg.edges(data='data'):\n",
    "    print(f'Edge ({source}, {dest}) has {len(edge.matches)} matches')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Outlier Detection"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Reprojective Error\n",
    "These two functions check for outliers by attempting to reproject measures between images. Any pair of measures that do not repoject to each other wth in a given tolerance are flagged."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "?NetworkEdge.compute_fundamental_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "?NetworkEdge.compute_homography"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "These cells also demonstrate how to pass kwargs through apply. Any kwargs that are not specific to the apply function are passed on to the function being applied."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "njobs = ncg.apply('compute_fundamental_matrix', \n",
    "                  on='edges',\n",
    "                  # homography kwargs\n",
    "                  method='mle',\n",
    "                  reproj_threshold=5,\n",
    "                  # SLURM kwargs\n",
    "                  walltime=walltime,\n",
    "                  log_dir=os.path.join(log_dir, 'fundamental'),\n",
    "                  arraychunk=arraychunk,\n",
    "                  chunksize=chunksize)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "njobs = ncg.apply('compute_homography', \n",
    "                  on='edges',\n",
    "                  # fundamental matrix kwargs\n",
    "                  method='lmeds',\n",
    "                  reproj_threshold=5,\n",
    "                  # SLURM kwargs\n",
    "                  walltime=walltime,\n",
    "                  log_dir=os.path.join(log_dir, 'homography'),\n",
    "                  arraychunk=arraychunk,\n",
    "                  chunksize=chunksize)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can check the queue_length property on the NetworkCandidateGraph object to see how many jobs are either waiting to be processed or in process. You can also use the squeue command on a command line or in your notebook to check what jobs slurm has."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ncg.queue_length"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             JOBID PARTITION     NAME     USER ST       TIME  NODES NODELIST(REASON) \r\n",
      "          17780111   longall jupyter-   jmapel  R    2:09:58      1 neb16 \r\n",
      "        17796596_1  shortall AutoCNet   jmapel  R       0:03      1 neb14 \r\n",
      "        17796596_2  shortall AutoCNet   jmapel  R       0:03      1 neb14 \r\n",
      "        17796596_3  shortall AutoCNet   jmapel  R       0:03      1 neb14 \r\n",
      "        17796596_4  shortall AutoCNet   jmapel  R       0:03      1 neb14 \r\n",
      "        17796596_5  shortall AutoCNet   jmapel  R       0:03      1 neb14 \r\n",
      "        17796596_6  shortall AutoCNet   jmapel  R       0:03      1 neb14 \r\n",
      "        17796596_7  shortall AutoCNet   jmapel  R       0:03      1 neb14 \r\n",
      "        17796596_8  shortall AutoCNet   jmapel  R       0:03      1 neb14 \r\n",
      "        17796596_9  shortall AutoCNet   jmapel  R       0:03      1 neb14 \r\n",
      "       17796596_10  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_11  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_12  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_13  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_14  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_15  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_16  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_17  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_18  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_19  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_20  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_21  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_22  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_23  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_24  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_25  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_26  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_27  shortall AutoCNet   jmapel  R       0:03      1 neb15 \r\n",
      "       17796596_28  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_29  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_30  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_31  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_32  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_33  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_34  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_35  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_36  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_37  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_38  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_39  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_40  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_41  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_42  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_43  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_44  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_45  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_46  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n",
      "       17796596_47  shortall AutoCNet   jmapel  R       0:03      1 neb16 \r\n"
     ]
    }
   ],
   "source": [
    "!squeue -u jmapel"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Looking at the results\n",
    "The reprojective error checks add a property to each called masks. This is a Pandas dataframe that contains a column for each check that has been done on the edge. If the row for a match has a true in it, then that match passed the column's check. Conversely, if the row for a match has a false in it, then that match failsed the column's check. We can use some dataframe techniques to look at our results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "edge (10, 6)\n",
      "num matches: 440\n",
      "passed homography: 440\n",
      "passed fundamental: 426\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (10, 11)\n",
      "num matches: 39\n",
      "passed homography: 30\n",
      "passed fundamental: 38\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (10, 8)\n",
      "num matches: 477\n",
      "passed homography: 369\n",
      "passed fundamental: 447\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (10, 7)\n",
      "num matches: 54\n",
      "passed homography: 45\n",
      "passed fundamental: 54\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (1, 3)\n",
      "num matches: 178\n",
      "passed homography: 138\n",
      "passed fundamental: 91\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (1, 4)\n",
      "num matches: 82\n",
      "passed homography: 61\n",
      "passed fundamental: 52\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (1, 2)\n",
      "num matches: 197\n",
      "passed homography: 152\n",
      "passed fundamental: 134\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (1, 5)\n",
      "num matches: 19\n",
      "passed homography: 17\n",
      "passed fundamental: 16\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (6, 11)\n",
      "num matches: 38\n",
      "passed homography: 37\n",
      "passed fundamental: 38\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (6, 8)\n",
      "num matches: 419\n",
      "passed homography: 419\n",
      "passed fundamental: 393\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (6, 7)\n",
      "num matches: 46\n",
      "passed homography: 39\n",
      "passed fundamental: 45\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (3, 4)\n",
      "num matches: 271\n",
      "passed homography: 255\n",
      "passed fundamental: 177\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (3, 2)\n",
      "num matches: 274\n",
      "passed homography: 237\n",
      "passed fundamental: 174\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (3, 5)\n",
      "num matches: 181\n",
      "passed homography: 162\n",
      "passed fundamental: 93\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (9, 11)\n",
      "num matches: 239\n",
      "passed homography: 154\n",
      "passed fundamental: 193\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (9, 8)\n",
      "num matches: 42\n",
      "passed homography: 38\n",
      "passed fundamental: 39\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (9, 7)\n",
      "num matches: 213\n",
      "passed homography: 138\n",
      "passed fundamental: 191\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (4, 2)\n",
      "num matches: 166\n",
      "passed homography: 157\n",
      "passed fundamental: 98\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (4, 5)\n",
      "num matches: 199\n",
      "passed homography: 169\n",
      "passed fundamental: 133\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (2, 5)\n",
      "num matches: 89\n",
      "passed homography: 81\n",
      "passed fundamental: 62\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (11, 8)\n",
      "num matches: 171\n",
      "passed homography: 171\n",
      "passed fundamental: 154\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (11, 7)\n",
      "num matches: 275\n",
      "passed homography: 190\n",
      "passed fundamental: 272\n",
      "too few matches to compute fundamental matrix\n",
      "\n",
      "edge (8, 7)\n",
      "num matches: 184\n",
      "passed homography: 117\n",
      "passed fundamental: 167\n",
      "too few matches to compute fundamental matrix\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for source, dest, edge in ncg.edges(data=\"data\"):\n",
    "    num_matches = len(edge.matches)\n",
    "    # MLE requires at least 8 points so skip anything with too few\n",
    "    if num_matches < 8:\n",
    "        continue\n",
    "    print(f'edge ({source}, {dest})')\n",
    "    print('num matches:', num_matches)\n",
    "    print('passed homography:', sum(edge.masks['homography']))\n",
    "    print('passed fundamental:', sum(edge.masks['fundamental']))\n",
    "    print('too few matches to compute fundamental matrix')\n",
    "    print('')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Digging in on edge (9, 7)\n",
    "Edge (9, 7) has a lot of matches but many failures; let's take a closer look at it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "        Source Image Index: 7\n",
      "        Destination Image Index: 9\n",
      "        Available Masks:           fundamental  homography\n",
      "match_id                         \n",
      "1171             True       False\n",
      "1172             True       False\n",
      "1173             True       False\n",
      "1174             True       False\n",
      "1175             True       False\n",
      "...               ...         ...\n",
      "1455             True        True\n",
      "1457             True        True\n",
      "1458             True        True\n",
      "1460             True        True\n",
      "1462             True       False\n",
      "\n",
      "[213 rows x 2 columns]\n",
      "        \n",
      "{'data': \n",
      "        NodeID: 9\n",
      "        Image Name: /work/projects/control_network_metrics/tutorials/isis_ingestion/M102135625RE.lev1_8b.cub\n",
      "        Image PATH: /work/projects/control_network_metrics/tutorials/isis_ingestion/M102135625RE.lev1_8b.cub\n",
      "        Number Keypoints: 0\n",
      "        Available Masks : Empty DataFrame\n",
      "Columns: []\n",
      "Index: []\n",
      "        Type: <class 'autocnet.graph.node.NetworkNode'>\n",
      "        }\n",
      "{'data': \n",
      "        NodeID: 7\n",
      "        Image Name: /work/projects/control_network_metrics/tutorials/isis_ingestion/M102128467RE.lev1_8b.cub\n",
      "        Image PATH: /work/projects/control_network_metrics/tutorials/isis_ingestion/M102128467RE.lev1_8b.cub\n",
      "        Number Keypoints: 0\n",
      "        Available Masks : Empty DataFrame\n",
      "Columns: []\n",
      "Index: []\n",
      "        Type: <class 'autocnet.graph.node.NetworkNode'>\n",
      "        }\n"
     ]
    }
   ],
   "source": [
    "edge_9_7 = ncg.edges[(9, 7)]['data']\n",
    "image_9 = ncg.nodes[9]\n",
    "image_7 = ncg.nodes[7]\n",
    "print(edge_9_7)\n",
    "print(image_9)\n",
    "print(image_7)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Looking at the matches that failed outlier detection\n",
    "We can use the masks dataframe to index the matches dataframe on our edge and see the matches that failed each check"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>geom</th>\n",
       "      <th>point_id</th>\n",
       "      <th>source_measure_id</th>\n",
       "      <th>destin_measure_id</th>\n",
       "      <th>source</th>\n",
       "      <th>source_idx</th>\n",
       "      <th>destination</th>\n",
       "      <th>destination_idx</th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>...</th>\n",
       "      <th>source_apriori_x</th>\n",
       "      <th>source_apriori_y</th>\n",
       "      <th>destination_x</th>\n",
       "      <th>destination_y</th>\n",
       "      <th>destination_apriori_x</th>\n",
       "      <th>destination_apriori_y</th>\n",
       "      <th>shift_x</th>\n",
       "      <th>shift_y</th>\n",
       "      <th>original_destination_x</th>\n",
       "      <th>original_destination_y</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1178</th>\n",
       "      <td>None</td>\n",
       "      <td>788</td>\n",
       "      <td>2324</td>\n",
       "      <td>2325</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2231.12</td>\n",
       "      <td>16213.7</td>\n",
       "      <td>180.316</td>\n",
       "      <td>16595.5</td>\n",
       "      <td>204.205</td>\n",
       "      <td>16599.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1228</th>\n",
       "      <td>None</td>\n",
       "      <td>1269</td>\n",
       "      <td>3678</td>\n",
       "      <td>3677</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3082.24</td>\n",
       "      <td>6807.21</td>\n",
       "      <td>1001.12</td>\n",
       "      <td>7160.22</td>\n",
       "      <td>978.351</td>\n",
       "      <td>7163.4</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1230</th>\n",
       "      <td>None</td>\n",
       "      <td>1271</td>\n",
       "      <td>3684</td>\n",
       "      <td>3683</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3908.22</td>\n",
       "      <td>6813.23</td>\n",
       "      <td>1773.38</td>\n",
       "      <td>7180.67</td>\n",
       "      <td>1797.61</td>\n",
       "      <td>7184.37</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1214</th>\n",
       "      <td>None</td>\n",
       "      <td>1243</td>\n",
       "      <td>3610</td>\n",
       "      <td>3609</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3983.41</td>\n",
       "      <td>1699.58</td>\n",
       "      <td>1877.61</td>\n",
       "      <td>2095.96</td>\n",
       "      <td>1840.91</td>\n",
       "      <td>2099.48</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1222</th>\n",
       "      <td>None</td>\n",
       "      <td>1261</td>\n",
       "      <td>3653</td>\n",
       "      <td>3652</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2674.81</td>\n",
       "      <td>5831.07</td>\n",
       "      <td>493.5</td>\n",
       "      <td>6213.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1223</th>\n",
       "      <td>None</td>\n",
       "      <td>1262</td>\n",
       "      <td>3655</td>\n",
       "      <td>3654</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3078.79</td>\n",
       "      <td>5826.54</td>\n",
       "      <td>893.047</td>\n",
       "      <td>6201.25</td>\n",
       "      <td>918.537</td>\n",
       "      <td>6205.46</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1238</th>\n",
       "      <td>None</td>\n",
       "      <td>1283</td>\n",
       "      <td>3716</td>\n",
       "      <td>3715</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2557.44</td>\n",
       "      <td>8894.67</td>\n",
       "      <td>398.233</td>\n",
       "      <td>9273.58</td>\n",
       "      <td>424.971</td>\n",
       "      <td>9277.79</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1246</th>\n",
       "      <td>None</td>\n",
       "      <td>1296</td>\n",
       "      <td>3750</td>\n",
       "      <td>3749</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3361.97</td>\n",
       "      <td>10921</td>\n",
       "      <td>1318.89</td>\n",
       "      <td>11293.3</td>\n",
       "      <td>1356.33</td>\n",
       "      <td>11296.8</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1247</th>\n",
       "      <td>None</td>\n",
       "      <td>1297</td>\n",
       "      <td>3753</td>\n",
       "      <td>3752</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>4664.18</td>\n",
       "      <td>10913.2</td>\n",
       "      <td>2828.5</td>\n",
       "      <td>11267.7</td>\n",
       "      <td>2791.51</td>\n",
       "      <td>11270.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1250</th>\n",
       "      <td>None</td>\n",
       "      <td>1304</td>\n",
       "      <td>3769</td>\n",
       "      <td>3768</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2488.51</td>\n",
       "      <td>12971.5</td>\n",
       "      <td>411.565</td>\n",
       "      <td>13351.7</td>\n",
       "      <td>429.924</td>\n",
       "      <td>13355.6</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1251</th>\n",
       "      <td>None</td>\n",
       "      <td>1305</td>\n",
       "      <td>3772</td>\n",
       "      <td>3771</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2955.16</td>\n",
       "      <td>12943.5</td>\n",
       "      <td>1011.06</td>\n",
       "      <td>13290.9</td>\n",
       "      <td>991.051</td>\n",
       "      <td>13294</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1252</th>\n",
       "      <td>None</td>\n",
       "      <td>1306</td>\n",
       "      <td>3774</td>\n",
       "      <td>3773</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3363.38</td>\n",
       "      <td>12945.5</td>\n",
       "      <td>1387.89</td>\n",
       "      <td>13317.5</td>\n",
       "      <td>1405.88</td>\n",
       "      <td>13321.7</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1256</th>\n",
       "      <td>None</td>\n",
       "      <td>1318</td>\n",
       "      <td>3802</td>\n",
       "      <td>3801</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2520.43</td>\n",
       "      <td>15001.8</td>\n",
       "      <td>471.544</td>\n",
       "      <td>15381</td>\n",
       "      <td>495.315</td>\n",
       "      <td>15385</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1264</th>\n",
       "      <td>None</td>\n",
       "      <td>1328</td>\n",
       "      <td>3829</td>\n",
       "      <td>3828</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>4237.17</td>\n",
       "      <td>16023.8</td>\n",
       "      <td>2321.67</td>\n",
       "      <td>16425.3</td>\n",
       "      <td>2309.89</td>\n",
       "      <td>16428.2</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1267</th>\n",
       "      <td>None</td>\n",
       "      <td>1333</td>\n",
       "      <td>3841</td>\n",
       "      <td>3843</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3323.35</td>\n",
       "      <td>17014</td>\n",
       "      <td>1364.5</td>\n",
       "      <td>17390.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1269</th>\n",
       "      <td>None</td>\n",
       "      <td>1335</td>\n",
       "      <td>3847</td>\n",
       "      <td>3849</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>4195</td>\n",
       "      <td>17097.3</td>\n",
       "      <td>2265.5</td>\n",
       "      <td>17466.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1278</th>\n",
       "      <td>None</td>\n",
       "      <td>1341</td>\n",
       "      <td>3865</td>\n",
       "      <td>3864</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3774.68</td>\n",
       "      <td>18065.9</td>\n",
       "      <td>1926.82</td>\n",
       "      <td>18441.7</td>\n",
       "      <td>1900.79</td>\n",
       "      <td>18444.7</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1280</th>\n",
       "      <td>None</td>\n",
       "      <td>1345</td>\n",
       "      <td>3875</td>\n",
       "      <td>3874</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2409.25</td>\n",
       "      <td>19093</td>\n",
       "      <td>414.645</td>\n",
       "      <td>19472.6</td>\n",
       "      <td>439.25</td>\n",
       "      <td>19476.8</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1312</th>\n",
       "      <td>None</td>\n",
       "      <td>1380</td>\n",
       "      <td>3977</td>\n",
       "      <td>3976</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>4117.91</td>\n",
       "      <td>24208.4</td>\n",
       "      <td>2376.63</td>\n",
       "      <td>24604</td>\n",
       "      <td>2353.01</td>\n",
       "      <td>24607.2</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1324</th>\n",
       "      <td>None</td>\n",
       "      <td>1392</td>\n",
       "      <td>4011</td>\n",
       "      <td>4010</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3231.98</td>\n",
       "      <td>26258.6</td>\n",
       "      <td>1420.5</td>\n",
       "      <td>26633.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1325</th>\n",
       "      <td>None</td>\n",
       "      <td>1393</td>\n",
       "      <td>4014</td>\n",
       "      <td>4013</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3602.89</td>\n",
       "      <td>26266.7</td>\n",
       "      <td>1781.33</td>\n",
       "      <td>26634.1</td>\n",
       "      <td>1807.03</td>\n",
       "      <td>26638.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1334</th>\n",
       "      <td>None</td>\n",
       "      <td>1398</td>\n",
       "      <td>4028</td>\n",
       "      <td>4027</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3667.78</td>\n",
       "      <td>27259.9</td>\n",
       "      <td>1867.94</td>\n",
       "      <td>27626.6</td>\n",
       "      <td>1892.47</td>\n",
       "      <td>27630.9</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>22 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      geom point_id source_measure_id destin_measure_id source source_idx  \\\n",
       "id                                                                          \n",
       "1178  None      788              2324              2325      7          0   \n",
       "1228  None     1269              3678              3677      7          0   \n",
       "1230  None     1271              3684              3683      7          0   \n",
       "1214  None     1243              3610              3609      7          0   \n",
       "1222  None     1261              3653              3652      7          0   \n",
       "1223  None     1262              3655              3654      7          0   \n",
       "1238  None     1283              3716              3715      7          0   \n",
       "1246  None     1296              3750              3749      7          0   \n",
       "1247  None     1297              3753              3752      7          0   \n",
       "1250  None     1304              3769              3768      7          0   \n",
       "1251  None     1305              3772              3771      7          0   \n",
       "1252  None     1306              3774              3773      7          0   \n",
       "1256  None     1318              3802              3801      7          0   \n",
       "1264  None     1328              3829              3828      7          0   \n",
       "1267  None     1333              3841              3843      7          0   \n",
       "1269  None     1335              3847              3849      7          0   \n",
       "1278  None     1341              3865              3864      7          0   \n",
       "1280  None     1345              3875              3874      7          0   \n",
       "1312  None     1380              3977              3976      7          0   \n",
       "1324  None     1392              4011              4010      7          0   \n",
       "1325  None     1393              4014              4013      7          0   \n",
       "1334  None     1398              4028              4027      7          0   \n",
       "\n",
       "     destination destination_idx   lat   lon  ... source_apriori_x  \\\n",
       "id                                            ...                    \n",
       "1178           9               0  None  None  ...          2231.12   \n",
       "1228           9               0  None  None  ...          3082.24   \n",
       "1230           9               0  None  None  ...          3908.22   \n",
       "1214           9               0  None  None  ...          3983.41   \n",
       "1222           9               0  None  None  ...          2674.81   \n",
       "1223           9               0  None  None  ...          3078.79   \n",
       "1238           9               0  None  None  ...          2557.44   \n",
       "1246           9               0  None  None  ...          3361.97   \n",
       "1247           9               0  None  None  ...          4664.18   \n",
       "1250           9               0  None  None  ...          2488.51   \n",
       "1251           9               0  None  None  ...          2955.16   \n",
       "1252           9               0  None  None  ...          3363.38   \n",
       "1256           9               0  None  None  ...          2520.43   \n",
       "1264           9               0  None  None  ...          4237.17   \n",
       "1267           9               0  None  None  ...          3323.35   \n",
       "1269           9               0  None  None  ...             4195   \n",
       "1278           9               0  None  None  ...          3774.68   \n",
       "1280           9               0  None  None  ...          2409.25   \n",
       "1312           9               0  None  None  ...          4117.91   \n",
       "1324           9               0  None  None  ...          3231.98   \n",
       "1325           9               0  None  None  ...          3602.89   \n",
       "1334           9               0  None  None  ...          3667.78   \n",
       "\n",
       "     source_apriori_y destination_x destination_y destination_apriori_x  \\\n",
       "id                                                                        \n",
       "1178          16213.7       180.316       16595.5               204.205   \n",
       "1228          6807.21       1001.12       7160.22               978.351   \n",
       "1230          6813.23       1773.38       7180.67               1797.61   \n",
       "1214          1699.58       1877.61       2095.96               1840.91   \n",
       "1222          5831.07         493.5        6213.5                  -0.5   \n",
       "1223          5826.54       893.047       6201.25               918.537   \n",
       "1238          8894.67       398.233       9273.58               424.971   \n",
       "1246            10921       1318.89       11293.3               1356.33   \n",
       "1247          10913.2        2828.5       11267.7               2791.51   \n",
       "1250          12971.5       411.565       13351.7               429.924   \n",
       "1251          12943.5       1011.06       13290.9               991.051   \n",
       "1252          12945.5       1387.89       13317.5               1405.88   \n",
       "1256          15001.8       471.544         15381               495.315   \n",
       "1264          16023.8       2321.67       16425.3               2309.89   \n",
       "1267            17014        1364.5       17390.5                  -0.5   \n",
       "1269          17097.3        2265.5       17466.5                  -0.5   \n",
       "1278          18065.9       1926.82       18441.7               1900.79   \n",
       "1280            19093       414.645       19472.6                439.25   \n",
       "1312          24208.4       2376.63         24604               2353.01   \n",
       "1324          26258.6        1420.5       26633.5                  -0.5   \n",
       "1325          26266.7       1781.33       26634.1               1807.03   \n",
       "1334          27259.9       1867.94       27626.6               1892.47   \n",
       "\n",
       "     destination_apriori_y shift_x shift_y original_destination_x  \\\n",
       "id                                                                  \n",
       "1178               16599.5    None    None                   None   \n",
       "1228                7163.4    None    None                   None   \n",
       "1230               7184.37    None    None                   None   \n",
       "1214               2099.48    None    None                   None   \n",
       "1222                  -0.5    None    None                   None   \n",
       "1223               6205.46    None    None                   None   \n",
       "1238               9277.79    None    None                   None   \n",
       "1246               11296.8    None    None                   None   \n",
       "1247               11270.5    None    None                   None   \n",
       "1250               13355.6    None    None                   None   \n",
       "1251                 13294    None    None                   None   \n",
       "1252               13321.7    None    None                   None   \n",
       "1256                 15385    None    None                   None   \n",
       "1264               16428.2    None    None                   None   \n",
       "1267                  -0.5    None    None                   None   \n",
       "1269                  -0.5    None    None                   None   \n",
       "1278               18444.7    None    None                   None   \n",
       "1280               19476.8    None    None                   None   \n",
       "1312               24607.2    None    None                   None   \n",
       "1324                  -0.5    None    None                   None   \n",
       "1325               26638.5    None    None                   None   \n",
       "1334               27630.9    None    None                   None   \n",
       "\n",
       "     original_destination_y  \n",
       "id                           \n",
       "1178                   None  \n",
       "1228                   None  \n",
       "1230                   None  \n",
       "1214                   None  \n",
       "1222                   None  \n",
       "1223                   None  \n",
       "1238                   None  \n",
       "1246                   None  \n",
       "1247                   None  \n",
       "1250                   None  \n",
       "1251                   None  \n",
       "1252                   None  \n",
       "1256                   None  \n",
       "1264                   None  \n",
       "1267                   None  \n",
       "1269                   None  \n",
       "1278                   None  \n",
       "1280                   None  \n",
       "1312                   None  \n",
       "1324                   None  \n",
       "1325                   None  \n",
       "1334                   None  \n",
       "\n",
       "[22 rows x 22 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "failed_fundamental = edge_9_7.matches.loc[(~edge_9_7.masks[['fundamental']]).all(axis=1)]\n",
    "failed_fundamental"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>geom</th>\n",
       "      <th>point_id</th>\n",
       "      <th>source_measure_id</th>\n",
       "      <th>destin_measure_id</th>\n",
       "      <th>source</th>\n",
       "      <th>source_idx</th>\n",
       "      <th>destination</th>\n",
       "      <th>destination_idx</th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>...</th>\n",
       "      <th>source_apriori_x</th>\n",
       "      <th>source_apriori_y</th>\n",
       "      <th>destination_x</th>\n",
       "      <th>destination_y</th>\n",
       "      <th>destination_apriori_x</th>\n",
       "      <th>destination_apriori_y</th>\n",
       "      <th>shift_x</th>\n",
       "      <th>shift_y</th>\n",
       "      <th>original_destination_x</th>\n",
       "      <th>original_destination_y</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1177</th>\n",
       "      <td>None</td>\n",
       "      <td>787</td>\n",
       "      <td>2321</td>\n",
       "      <td>2322</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2193.72</td>\n",
       "      <td>15099.1</td>\n",
       "      <td>124.431</td>\n",
       "      <td>15480.9</td>\n",
       "      <td>148.703</td>\n",
       "      <td>15485.1</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1180</th>\n",
       "      <td>None</td>\n",
       "      <td>790</td>\n",
       "      <td>2331</td>\n",
       "      <td>2332</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2058.33</td>\n",
       "      <td>21232.2</td>\n",
       "      <td>76.913</td>\n",
       "      <td>21614.3</td>\n",
       "      <td>101.831</td>\n",
       "      <td>21618.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1181</th>\n",
       "      <td>None</td>\n",
       "      <td>791</td>\n",
       "      <td>2335</td>\n",
       "      <td>2336</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2055.99</td>\n",
       "      <td>22259.5</td>\n",
       "      <td>90.9603</td>\n",
       "      <td>22641.3</td>\n",
       "      <td>115.847</td>\n",
       "      <td>22645.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1182</th>\n",
       "      <td>None</td>\n",
       "      <td>792</td>\n",
       "      <td>2338</td>\n",
       "      <td>2339</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2077.71</td>\n",
       "      <td>23322.8</td>\n",
       "      <td>233.419</td>\n",
       "      <td>23718.5</td>\n",
       "      <td>208.588</td>\n",
       "      <td>23721.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1358</th>\n",
       "      <td>None</td>\n",
       "      <td>1416</td>\n",
       "      <td>4073</td>\n",
       "      <td>4072</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>4388.95</td>\n",
       "      <td>37514.9</td>\n",
       "      <td>3240.27</td>\n",
       "      <td>37842</td>\n",
       "      <td>3225.51</td>\n",
       "      <td>37843.1</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1288</th>\n",
       "      <td>None</td>\n",
       "      <td>1354</td>\n",
       "      <td>3901</td>\n",
       "      <td>3900</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>4633.26</td>\n",
       "      <td>20103.5</td>\n",
       "      <td>2761.5</td>\n",
       "      <td>20468.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1289</th>\n",
       "      <td>None</td>\n",
       "      <td>1356</td>\n",
       "      <td>3906</td>\n",
       "      <td>3905</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2449.74</td>\n",
       "      <td>21087.8</td>\n",
       "      <td>490.169</td>\n",
       "      <td>21466.9</td>\n",
       "      <td>514.354</td>\n",
       "      <td>21471</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1290</th>\n",
       "      <td>None</td>\n",
       "      <td>1357</td>\n",
       "      <td>3909</td>\n",
       "      <td>3908</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2893.79</td>\n",
       "      <td>21162.4</td>\n",
       "      <td>958.412</td>\n",
       "      <td>21537.6</td>\n",
       "      <td>983.276</td>\n",
       "      <td>21541.8</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1291</th>\n",
       "      <td>None</td>\n",
       "      <td>1358</td>\n",
       "      <td>3912</td>\n",
       "      <td>3911</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3285.83</td>\n",
       "      <td>21131.4</td>\n",
       "      <td>1388.39</td>\n",
       "      <td>21530.8</td>\n",
       "      <td>1364.02</td>\n",
       "      <td>21533.8</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1292</th>\n",
       "      <td>None</td>\n",
       "      <td>1359</td>\n",
       "      <td>3915</td>\n",
       "      <td>3914</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3685.25</td>\n",
       "      <td>21185.8</td>\n",
       "      <td>1808.5</td>\n",
       "      <td>21558.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>75 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      geom point_id source_measure_id destin_measure_id source source_idx  \\\n",
       "id                                                                          \n",
       "1177  None      787              2321              2322      7          0   \n",
       "1180  None      790              2331              2332      7          0   \n",
       "1181  None      791              2335              2336      7          0   \n",
       "1182  None      792              2338              2339      7          0   \n",
       "1358  None     1416              4073              4072      7          0   \n",
       "...    ...      ...               ...               ...    ...        ...   \n",
       "1288  None     1354              3901              3900      7          0   \n",
       "1289  None     1356              3906              3905      7          0   \n",
       "1290  None     1357              3909              3908      7          0   \n",
       "1291  None     1358              3912              3911      7          0   \n",
       "1292  None     1359              3915              3914      7          0   \n",
       "\n",
       "     destination destination_idx   lat   lon  ... source_apriori_x  \\\n",
       "id                                            ...                    \n",
       "1177           9               0  None  None  ...          2193.72   \n",
       "1180           9               0  None  None  ...          2058.33   \n",
       "1181           9               0  None  None  ...          2055.99   \n",
       "1182           9               0  None  None  ...          2077.71   \n",
       "1358           9               0  None  None  ...          4388.95   \n",
       "...          ...             ...   ...   ...  ...              ...   \n",
       "1288           9               0  None  None  ...          4633.26   \n",
       "1289           9               0  None  None  ...          2449.74   \n",
       "1290           9               0  None  None  ...          2893.79   \n",
       "1291           9               0  None  None  ...          3285.83   \n",
       "1292           9               0  None  None  ...          3685.25   \n",
       "\n",
       "     source_apriori_y destination_x destination_y destination_apriori_x  \\\n",
       "id                                                                        \n",
       "1177          15099.1       124.431       15480.9               148.703   \n",
       "1180          21232.2        76.913       21614.3               101.831   \n",
       "1181          22259.5       90.9603       22641.3               115.847   \n",
       "1182          23322.8       233.419       23718.5               208.588   \n",
       "1358          37514.9       3240.27         37842               3225.51   \n",
       "...               ...           ...           ...                   ...   \n",
       "1288          20103.5        2761.5       20468.5                  -0.5   \n",
       "1289          21087.8       490.169       21466.9               514.354   \n",
       "1290          21162.4       958.412       21537.6               983.276   \n",
       "1291          21131.4       1388.39       21530.8               1364.02   \n",
       "1292          21185.8        1808.5       21558.5                  -0.5   \n",
       "\n",
       "     destination_apriori_y shift_x shift_y original_destination_x  \\\n",
       "id                                                                  \n",
       "1177               15485.1    None    None                   None   \n",
       "1180               21618.5    None    None                   None   \n",
       "1181               22645.5    None    None                   None   \n",
       "1182               23721.5    None    None                   None   \n",
       "1358               37843.1    None    None                   None   \n",
       "...                    ...     ...     ...                    ...   \n",
       "1288                  -0.5    None    None                   None   \n",
       "1289                 21471    None    None                   None   \n",
       "1290               21541.8    None    None                   None   \n",
       "1291               21533.8    None    None                   None   \n",
       "1292                  -0.5    None    None                   None   \n",
       "\n",
       "     original_destination_y  \n",
       "id                           \n",
       "1177                   None  \n",
       "1180                   None  \n",
       "1181                   None  \n",
       "1182                   None  \n",
       "1358                   None  \n",
       "...                     ...  \n",
       "1288                   None  \n",
       "1289                   None  \n",
       "1290                   None  \n",
       "1291                   None  \n",
       "1292                   None  \n",
       "\n",
       "[75 rows x 22 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "failed_homography = edge_9_7.matches.loc[(~edge_9_7.masks[['homography']]).all(axis=1)]\n",
    "failed_homography"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can even use some techniques to see the matches that failed both checks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>geom</th>\n",
       "      <th>point_id</th>\n",
       "      <th>source_measure_id</th>\n",
       "      <th>destin_measure_id</th>\n",
       "      <th>source</th>\n",
       "      <th>source_idx</th>\n",
       "      <th>destination</th>\n",
       "      <th>destination_idx</th>\n",
       "      <th>lat</th>\n",
       "      <th>lon</th>\n",
       "      <th>...</th>\n",
       "      <th>source_apriori_x</th>\n",
       "      <th>source_apriori_y</th>\n",
       "      <th>destination_x</th>\n",
       "      <th>destination_y</th>\n",
       "      <th>destination_apriori_x</th>\n",
       "      <th>destination_apriori_y</th>\n",
       "      <th>shift_x</th>\n",
       "      <th>shift_y</th>\n",
       "      <th>original_destination_x</th>\n",
       "      <th>original_destination_y</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1178</th>\n",
       "      <td>None</td>\n",
       "      <td>788</td>\n",
       "      <td>2324</td>\n",
       "      <td>2325</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2231.12</td>\n",
       "      <td>16213.7</td>\n",
       "      <td>180.316</td>\n",
       "      <td>16595.5</td>\n",
       "      <td>204.205</td>\n",
       "      <td>16599.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1228</th>\n",
       "      <td>None</td>\n",
       "      <td>1269</td>\n",
       "      <td>3678</td>\n",
       "      <td>3677</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3082.24</td>\n",
       "      <td>6807.21</td>\n",
       "      <td>1001.12</td>\n",
       "      <td>7160.22</td>\n",
       "      <td>978.351</td>\n",
       "      <td>7163.4</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1230</th>\n",
       "      <td>None</td>\n",
       "      <td>1271</td>\n",
       "      <td>3684</td>\n",
       "      <td>3683</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3908.22</td>\n",
       "      <td>6813.23</td>\n",
       "      <td>1773.38</td>\n",
       "      <td>7180.67</td>\n",
       "      <td>1797.61</td>\n",
       "      <td>7184.37</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1214</th>\n",
       "      <td>None</td>\n",
       "      <td>1243</td>\n",
       "      <td>3610</td>\n",
       "      <td>3609</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3983.41</td>\n",
       "      <td>1699.58</td>\n",
       "      <td>1877.61</td>\n",
       "      <td>2095.96</td>\n",
       "      <td>1840.91</td>\n",
       "      <td>2099.48</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1222</th>\n",
       "      <td>None</td>\n",
       "      <td>1261</td>\n",
       "      <td>3653</td>\n",
       "      <td>3652</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>2674.81</td>\n",
       "      <td>5831.07</td>\n",
       "      <td>493.5</td>\n",
       "      <td>6213.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1223</th>\n",
       "      <td>None</td>\n",
       "      <td>1262</td>\n",
       "      <td>3655</td>\n",
       "      <td>3654</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3078.79</td>\n",
       "      <td>5826.54</td>\n",
       "      <td>893.047</td>\n",
       "      <td>6201.25</td>\n",
       "      <td>918.537</td>\n",
       "      <td>6205.46</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1264</th>\n",
       "      <td>None</td>\n",
       "      <td>1328</td>\n",
       "      <td>3829</td>\n",
       "      <td>3828</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>4237.17</td>\n",
       "      <td>16023.8</td>\n",
       "      <td>2321.67</td>\n",
       "      <td>16425.3</td>\n",
       "      <td>2309.89</td>\n",
       "      <td>16428.2</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1267</th>\n",
       "      <td>None</td>\n",
       "      <td>1333</td>\n",
       "      <td>3841</td>\n",
       "      <td>3843</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>3323.35</td>\n",
       "      <td>17014</td>\n",
       "      <td>1364.5</td>\n",
       "      <td>17390.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      geom point_id source_measure_id destin_measure_id source source_idx  \\\n",
       "id                                                                          \n",
       "1178  None      788              2324              2325      7          0   \n",
       "1228  None     1269              3678              3677      7          0   \n",
       "1230  None     1271              3684              3683      7          0   \n",
       "1214  None     1243              3610              3609      7          0   \n",
       "1222  None     1261              3653              3652      7          0   \n",
       "1223  None     1262              3655              3654      7          0   \n",
       "1264  None     1328              3829              3828      7          0   \n",
       "1267  None     1333              3841              3843      7          0   \n",
       "\n",
       "     destination destination_idx   lat   lon  ... source_apriori_x  \\\n",
       "id                                            ...                    \n",
       "1178           9               0  None  None  ...          2231.12   \n",
       "1228           9               0  None  None  ...          3082.24   \n",
       "1230           9               0  None  None  ...          3908.22   \n",
       "1214           9               0  None  None  ...          3983.41   \n",
       "1222           9               0  None  None  ...          2674.81   \n",
       "1223           9               0  None  None  ...          3078.79   \n",
       "1264           9               0  None  None  ...          4237.17   \n",
       "1267           9               0  None  None  ...          3323.35   \n",
       "\n",
       "     source_apriori_y destination_x destination_y destination_apriori_x  \\\n",
       "id                                                                        \n",
       "1178          16213.7       180.316       16595.5               204.205   \n",
       "1228          6807.21       1001.12       7160.22               978.351   \n",
       "1230          6813.23       1773.38       7180.67               1797.61   \n",
       "1214          1699.58       1877.61       2095.96               1840.91   \n",
       "1222          5831.07         493.5        6213.5                  -0.5   \n",
       "1223          5826.54       893.047       6201.25               918.537   \n",
       "1264          16023.8       2321.67       16425.3               2309.89   \n",
       "1267            17014        1364.5       17390.5                  -0.5   \n",
       "\n",
       "     destination_apriori_y shift_x shift_y original_destination_x  \\\n",
       "id                                                                  \n",
       "1178               16599.5    None    None                   None   \n",
       "1228                7163.4    None    None                   None   \n",
       "1230               7184.37    None    None                   None   \n",
       "1214               2099.48    None    None                   None   \n",
       "1222                  -0.5    None    None                   None   \n",
       "1223               6205.46    None    None                   None   \n",
       "1264               16428.2    None    None                   None   \n",
       "1267                  -0.5    None    None                   None   \n",
       "\n",
       "     original_destination_y  \n",
       "id                           \n",
       "1178                   None  \n",
       "1228                   None  \n",
       "1230                   None  \n",
       "1214                   None  \n",
       "1222                   None  \n",
       "1223                   None  \n",
       "1264                   None  \n",
       "1267                   None  \n",
       "\n",
       "[8 rows x 22 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "failed_both = edge_9_7.matches.loc[(~edge_9_7.masks[['fundamental', 'homography']]).all(axis=1)]\n",
    "failed_both"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Viewing individual matches\n",
    "Let's take a closer look at the matches that failed both checks. We're going to use the Roi (Region of Interest) objects in Autocnet that allow you to look at a small portion of an image."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 19468 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 19628 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 19388 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 19492 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 18900 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 19304 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 18504 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 19624 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "roi_size = 25\n",
    "for idx, match in failed_both.iterrows():\n",
    "    with ncg.session_scope() as session:\n",
    "        point_name = session.query(Points).filter(Points.id == match[\"point_id\"]).first().identifier\n",
    "\n",
    "    source_image = ncg.nodes[match['source']]['data']\n",
    "    dest_image = ncg.nodes[match['destination']]['data']\n",
    "    source_roi = Roi(source_image.geodata, match['source_x'], match['source_y'], size_x=roi_size, size_y=roi_size)\n",
    "    dest_roi = Roi(dest_image.geodata, match['destination_x'], match['destination_y'], size_x=roi_size, size_y=roi_size)\n",
    "\n",
    "    fig, (ax1, ax2) = plt.subplots(1,2)\n",
    "    fig.suptitle(point_name)\n",
    "    ax1.imshow(source_roi.array, cmap='gray')\n",
    "    ax1.plot(source_roi.center[0] + source_roi.axr, source_roi.center[1] + source_roi.ayr, 'ro')\n",
    "    ax1.title.set_text(os.path.split(source_image['image_name'])[-1])\n",
    "    ax2.imshow(dest_roi.array, cmap='gray')\n",
    "    ax2.plot(dest_roi.center[0] + dest_roi.axr, dest_roi.center[1] + dest_roi.ayr, 'bo')\n",
    "    ax2.title.set_text(os.path.split(dest_image['image_name'])[-1])\n",
    "    fig.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
