Commit 8b17f880 authored by jay's avatar jay
Browse files

Fixes serialization

parent 999d36d9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -17,11 +17,11 @@ from autocnet.matcher import subpixel as sp
from autocnet.matcher import cpu_ring_matcher
from autocnet.transformation import fundamental_matrix as fm
from autocnet.transformation import homography as hm
from autocnet import transformation
from autocnet.vis.graph_view import plot_edge, plot_node, plot_edge_decomposition, plot_matches
from autocnet.cg import cg

from plio.io.io_gdal import GeoDataset
from plio.spatial.transformations import reproject


class Edge(dict, MutableMapping):
@@ -229,7 +229,7 @@ class Edge(dict, MutableMapping):
        # Project the points to the surface and reproject into latlon space
        for i in range(gnd.shape[0]):
            gnd[i] = camera.imageToGround(coords[i][0], coords[i][1], 0)
        lon, lat, alt = reproject(gnd.T, semimajor, semiminor,
        lon, lat, alt = transformation.spatial.reproject(gnd.T, semimajor, semiminor,
                                    'geocent', 'latlon')
        if srid:
            geoms = []
+4 −1
Original line number Diff line number Diff line
@@ -133,7 +133,10 @@ class CandidateGraph(nx.Graph):
        if sorted(self.edges()) != sorted(other.edges()):
            return False
        for s, d, e in self.edges.data('data'):
            if not e == other.edges[s, d]['data']:
            if s > d:
                s, d = d, s
            if not e == other.edges[(s, d)]['data']:
                print('echeck')
                return False
        return True

+9 −6
Original line number Diff line number Diff line
@@ -76,10 +76,11 @@ def save(network, projectname):
                    ndarrays_to_write[k] = v
                    ndarrays_to_write[k+'_idx'] = v.index
                    ndarrays_to_write[k+'_columns'] = v.columns
            # Handle the matches dataframe that is a property
            ndarrays_to_write['matches'] = data.matches
            ndarrays_to_write['matches_idx'] = data.matches.index
            ndarrays_to_write['matches_columns'] = data.matches.columns
            # Handle DataFrames that are properties
            for k in ['_matches', '_masks', '_costs']:
                ndarrays_to_write[k] = getattr(data, k, np.array([]))
                ndarrays_to_write['{}_idx'.format(k)] = getattr(data, k, pd.DataFrame()).index
                ndarrays_to_write['{}_columns'.format(k)] = getattr(data, k, pd.DataFrame()).columns
            np.savez('{}_{}.npz'.format(s, d),**ndarrays_to_write)
            pzip.write('{}_{}.npz'.format(s, d))
            os.remove('{}_{}.npz'.format(s, d))
@@ -152,8 +153,10 @@ def load(projectname):
                edge[k] = v
            try:
                nzf = np.load(BytesIO(pzip.read('{}_{}.npz'.format(s,d))))
                edge.masks = pd.DataFrame(nzf['masks'], index=nzf['masks_idx'], columns=nzf['masks_columns'])
                edge.matches = pd.DataFrame(nzf['matches'], index=nzf['matches_idx'], columns=nzf['matches_columns'])
                for j in ['_matches', '_masks', '_costs']:
                    setattr(edge, j, pd.DataFrame(nzf[j], 
                                                  index=nzf['{}_idx'.format(j)], 
                                                  columns=nzf['{}_columns'.format(j)]))
            except:
                pass
            # Add a mock edge
+2 −1
Original line number Diff line number Diff line
@@ -71,7 +71,8 @@ def compare_dicts(d, o):
    >>> compare_dicts(d,o)
    True
    """
    if o.keys() != d.keys():
    for k in o.keys():
        if k not in d.keys():
            return False
    for k, v in d.items():
        if v is None and o[k] is not None:
+2 −10
Original line number Diff line number Diff line
@@ -4,20 +4,12 @@ from autocnet.io.network import load

import numpy as np

import pandas as pd

def test_save_project(tmpdir, candidategraph):
    path = tmpdir.join('prject.proj')
    candidategraph.save(path.strpath)
    candidategraph2 = load(path.strpath)

    # Prints just help with debugging because this is probably the most 
    # fragile stuff in the code base.
    for i,n in candidategraph.nodes.data('data'):
        print('Node {}: {}'.format(i,n == candidategraph2.node[i]['data']))

    for s,d,e in candidategraph.edges.data('data'):
        print(type(candidategraph2.edges[s,d]), candidategraph2.edges[s,d].keys())
        print('Edge {}: {}'.format((s,d), e == candidategraph2.edges[s,d]['data']))
        e1 = candidategraph2.edges[s,d]['data']
    assert candidategraph == candidategraph2

def test_save_features(tmpdir, candidategraph):