Commit a4335246 authored by kberry's avatar kberry
Browse files

Merge branch 'matching'

parents d51411f6 d6823689
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ python:
  - "3.5"

before_install:

install:
  # We do this conditionally because it saves us some downloading if the
  # version is the same.
@@ -26,11 +27,12 @@ install:
  - conda info -a

  # Create a virtual env and install dependencies
  - conda create -y -q -n test-env python=$TRAVIS_PYTHON_VERSION nose gdal numpy scipy pandas
  - conda create -y -q -n test-env python=$TRAVIS_PYTHON_VERSION nose gdal numpy pillow scipy pandas networkx
  # Activate the env
  - source activate test-env

  # Install the non-conda packages if required, requirements.txt duplicates are ignored
  - conda install -c https://conda.binstar.org/menpo opencv3
  - conda install -c osgeo proj4
  - pip install -r requirements.txt
  - pip install coverage
+0 −0

File moved.

+90 −0
Original line number Diff line number Diff line
from time import gmtime, strftime

import pandas as pd


class CSeries(pd.Series):
    """
    A custom pandas series that can accept additional methods
    """
    @property
    def _constructor(self):
        return CustomSeries # pragma: no cover


class C(pd.DataFrame):
    """
    Control network.

    Parameters
    ----------

    Attributes
    ----------

    n : int
        Number of control points

    m : int
        Number of control measures

    creationdate : str
                   The date that this control network was created.

    modifieddate : str
                   The date that this control network was last modified.

    Examples
    --------
    This example illustrates the manual creation of a pandas dataframe with
    a multi-index (created from a list of tuples).

    >>> ids = ['pt1','pt1', 'pt1', 'pt2', 'pt2']
    >>> ptype = [2,2,2,2,2]
    >>> serials = ['a', 'b', 'c', 'b', 'c']
    >>> mtype = [2,2,2,2,2]
    >>> multi_index = pd.MultiIndex.from_tuples(list(zip(ids, ptype, serials, mtype)),\
                                    names=['Id', 'Type', 'Serial Number', 'Measure Type'])
    >>> columns = ['Random Number']
    >>> data_length = 5
    >>> data = np.random.randn(data_length)
    >>> C = control.C(data, index=multi_index, columns=columns)

    """
    def __init__(self, *args, **kwargs):
        super(C, self).__init__(*args, **kwargs)
        self._creationdate = strftime("%Y-%m-%d %H:%M:%S", gmtime())

    @property
    def _constructor(self):
        return C

    _constructor_sliced = CSeries

    @property
    def n(self):
        if not getattr(self, '_n', None):
            self._n = len(self.index.levels[0])
        return self._n

    @property
    def m(self):
        if not getattr(self, '_m', None):
            self._m = len(self)
        return self._m

    @property
    def creationdate(self):
        return self._creationdate

    @property
    def modifieddate(self):
        if not getattr(self, '_modifieddate', None):
            self._modifieddate = 'Not modified'
        return self._modifieddate

    '''
    @modifieddate.setter
    def update_modifieddate(self):
        self._modifieddate = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    '''
 No newline at end of file
+0 −0

Empty file added.

+42 −0
Original line number Diff line number Diff line
import os
import sys
from time import gmtime, strftime
import unittest

import numpy as np
import pandas as pd

sys.path.insert(0, os.path.abspath('..'))

from autocnet.control import control


class TestC(unittest.TestCase):

    def setUp(self):
        ids = ['pt1','pt1', 'pt1', 'pt2', 'pt2']
        ptype = [2,2,2,2,2]
        serials = ['a', 'b', 'c', 'b', 'c']
        mtype = [2,2,2,2,2]

        multi_index = pd.MultiIndex.from_tuples(list(zip(ids, ptype, serials, mtype)),
                                    names=['Id', 'Type', 'Serial Number', 'Measure Type'])


        columns = ['Random Number']
        self.data_length = 5
        data = np.random.randn(self.data_length)

        self.C = control.C(data, index=multi_index, columns=columns)

    def test_n_point(self):
        self.assertEqual(self.C.n,2)

    def test_n_measures(self):
        self.assertEqual(self.C.m, self.data_length)

    def test_modified_date(self):
        self.assertEqual(self.C.modifieddate, 'Not modified')

    def test_creation_date(self):
        self.assertEqual(self.C.creationdate, strftime("%Y-%m-%d %H:%M:%S", gmtime()))
 No newline at end of file
Loading