Commit e7263e77 authored by jlaura's avatar jlaura Committed by GitHub
Browse files

adds tests to isis2socet (#64)

* adds tests to isis2socet

* adds pyproj to appveyor
parent 398f1178
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ install:
  - cmd: conda create -q -n test_env python=%PYTHON_VERSION%
  - cmd: activate test_env
  - cmd: conda config --add channels conda-forge
  - cmd: conda install -c conda-forge pvl protobuf gdal numpy pandas sqlalchemy pyyaml networkx affine h5py scipy
  - cmd: conda install -c conda-forge pvl protobuf gdal numpy pandas sqlalchemy pyyaml networkx affine h5py scipy pyproj
  - cmd: conda install -c conda-forge pytest pytest-cov
  # https://pythonhosted.org/CodeChat/appveyor.yml.html
  - cmd: python -m pip install -U pip
+0 −0

Empty file added.

+74 −0
Original line number Diff line number Diff line

import pytest
from plio.examples import get_path
from plio.spatial import transformations as trans

@pytest.mark.parametrize("stat, expected",
                         [({'stat':0}, True),
                          ({'stat':1}, False),
                          ({'stat':True}, False),  # Is this the desired result?
                          ({'stat':False}, True)])
def test_stat_toggle(stat, expected):
    assert trans.stat_toggle(stat) == expected

@pytest.mark.parametrize("stat, expected",
                         [({'stat':True}, 0),
                          ({'stat':False}, 1),
                          ({'stat':False}, True),  # Is this the desired result?
                          ({'stat':True}, False)])
def test_ignore_toggle(stat, expected):
    assert trans.ignore_toggle(stat) == expected

def test_get_axis():
    fname = get_path('CTX_Athabasca_Middle.prj')
    erad, prad = trans.get_axis(fname)
    assert erad == 3.39619000000000e+006
    assert prad == 3.3762000000000866e+006

@pytest.mark.parametrize("og, major, minor, oc",
                         [(0, 3396190, 3376200, 0),
                          (90, 3396190, 3376200, 90),
                          (-90, 3396190, 3376200, -90),
                          (45, 3396190, 3376200, 44.6617680)])
def test_og2oc(og, major, minor, oc):
    assert trans.og2oc(og, major, minor) == pytest.approx(oc)

@pytest.mark.parametrize("og, major, minor, oc",
                         [(0, 3396190, 3376200, 0),
                          (90, 3396190, 3376200, 90),
                          (-90, 3396190, 3376200, -90),
                          (45.338231, 3396190, 3376200, 45)])
def test_oc2og(og, major, minor, oc):
    assert trans.oc2og(oc, major, minor) == pytest.approx(og)


@pytest.mark.parametrize("known, expected",
                         [({'known':0},'Free'),
                          ({'known':1},'Constrained'),
                          ({'known':2},'Constrained'),
                          ({'known':3},'Constrained'),
                          ({'known':False},'Free'),  # Is this the desired result?
                          ({'known':True},'Constrained')])
def test_known(known, expected):
    assert trans.known(known) == expected


@pytest.mark.parametrize("known, expected",
                         [({'known':0},0),
                          ({'known':2},0),
                          ({'known':1},3),
                          ({'known':3},3),
                          ({'known':4},3),
                          ({'known':False},0),  # Is this the desired result?
                          ({'known':True},3)])
def test_known(known, expected):
    assert trans.reverse_known(known) == expected

@pytest.mark.parametrize("num, expected",
                         [(0, 0),
                          (-180, 180),
                          (370, 10),
                          (-90, 270), 
                          (90, 90)])
def test_to_360(num, expected):
    assert trans.to_360(num) == expected
 No newline at end of file
+28 −24
Original line number Diff line number Diff line
@@ -64,11 +64,35 @@ def known(record):
    : str
      String representation of a known field
    """
    if record['known'] == 0:
        return 'Free'

    elif record['known'] == 1 or record['known'] == 2 or record['known'] == 3:
        return 'Constrained'
    lookup = {0: 'Free',
              1: 'Constrained',
              2: 'Constrained',
              3: 'Constrained'}
    return lookup[record['known']]

def reverse_known(record):
    """
    Converts the known field from an isis dataframe into the
    socet known column

    Parameters
    ----------
    record : object
             Pandas series object

    Returns
    -------
    : str
      String representation of a known field
    """
    lookup = {0:0,
              2:0,
              1:3,
              3:3,
              4:3}
    record_type = record['known']
    return lookup[record_type]

def to_360(num):
    """
@@ -393,27 +417,7 @@ def compute_cov_matrix(record, semimajor_axis):
    cov_matrix = compute_sigma_covariance_matrix(record['lat_Y_North'], record['long_X_East'], record['ht'], record['sig0'], record['sig1'], record['sig2'], semimajor_axis)
    return cov_matrix.ravel().tolist()

def reverse_known(record):
    """
    Converts the known field from an isis dataframe into the
    socet known column

    Parameters
    ----------
    record : object
             Pandas series object

    Returns
    -------
    : str
      String representation of a known field
    """
    record_type = record['known']
    if record_type == 0 or record_type == 2:
        return 0

    elif record_type == 1 or record_type == 3 or record_type == 4:
        return 3

def fix_sample_line(record, serial_dict, cub_dict):
    """