diff --git a/appveyor.yml b/appveyor.yml index f095e330aac99385ab6f916b06dabe869824815b..4f9ecaafb3c880b6f535611f627012bad2bafd6b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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 diff --git a/plio/spatial/__init__.py b/plio/spatial/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/plio/spatial/tests/test_transformations.py b/plio/spatial/tests/test_transformations.py new file mode 100644 index 0000000000000000000000000000000000000000..5c37fa992a7632d3952cb7e67e92eacc846ac994 --- /dev/null +++ b/plio/spatial/tests/test_transformations.py @@ -0,0 +1,74 @@ + +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 diff --git a/plio/spatial/transformations.py b/plio/spatial/transformations.py index a624f3f4a4a527b0602680d6b02b2cd10484c2a5..9dc4a6749cb373c7f2c81298e0ab6fa662aef854 100644 --- a/plio/spatial/transformations.py +++ b/plio/spatial/transformations.py @@ -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): """