Commit 383a1b93 authored by jlaura's avatar jlaura Committed by GitHub
Browse files

Adds dynamic reference indices to ISIS network writes (#157)

* Adds dynamic reference indices to ISIS network writes

* Updates for comments

* Stub failing test

* Adds tests for referenceIndex in cnets

* Updates tests to check for warnings

* Removes travis
parent 88b3aa20
Loading
Loading
Loading
Loading

.travis.yml

deleted100644 → 0
+0 −80
Original line number Diff line number Diff line
language: generic
sudo: false

branches:
  only:
    - master

os:
  - linux
  - osx

env:
  - PYTHON_VERSION=3.6 HAS_GDAL=true
  - PYTHON_VERSION=3.6 HAS_GDAL=false
  - PYTHON_VERSION=3.7 HAS_GDAL=true
  - PYTHON_VERSION=3.7 HAS_GDAL=false
  - PYTHON_VERSION=3.8 HAS_GDAL=true
  - PYTHON_VERSION=3.8 HAS_GDAL=false
before_install:
  # We do this conditionally because it saves us some downloading if the
  # version is the same.
  - if [ "$TRAVIS_OS_NAME" == "linux" ]; then
      wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
    else
      curl -o miniconda.sh  https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh;
    fi
  - bash miniconda.sh -b -p $HOME/miniconda
  - export PATH="$HOME/miniconda/bin:$PATH"
  - hash -r
  - conda config --set always_yes yes --set changeps1 no
  - conda update -q conda
  # Useful for debugging any issues with conda
  - conda info -a
  # Create the env
  - conda create -q -n test python=$PYTHON_VERSION
  - source activate test
  # https://github.com/travis-ci/travis-ci/issues/8982
  - python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)"

install:
  - conda config --add channels usgs-astrogeology
  - conda config --add channels conda-forge
  - if $HAS_GDAL; then
      conda env update -n test -f environment.yml;
    else
      conda env update -n test -f environment_noGDAL.yml;
    fi

script:
  - pytest --cov=plio

after_success:
  - coveralls
  # Need to do the build in the root
  - source deactivate
  - conda install -q conda-build anaconda-client
  - conda config --set anaconda_upload no
  - travis_wait conda build recipe -q
  - travis_wait builddir=(`conda build recipe --output`)
  - |
    if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
      anaconda -t="$CONDA_UPLOAD_TOKEN" upload -l dev --force $builddir;
    fi

  # Docs to gh-pages
  - source activate test  # Reactivate the env to have all deps installed.
  - pip install travis-sphinx
  - travis-sphinx build --source=docs --nowarn # The sphinx build script
  - travis-sphinx deploy

notifications:
  webhooks:
    on_success: always
    on_failure: always
    on_start: never
  email:
      recipients:
        - jlaura@usgs.gov
      on_success: always
      on_failure: always
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ dependencies:
  - numpy 
  - pyproj 
  - h5py 
  - pvl 
  - pvl >= 1.0 
  - scipy 
  - protobuf 
  - affine 
+5 −2
Original line number Diff line number Diff line
@@ -335,6 +335,11 @@ class IsisStore(object):
            #point_spec.id = _set_pid(i)
            point_spec.id = _set_pid(i)
            point_spec.type = g.iloc[0].pointType
            try:
                point_spec.referenceIndex = g.iloc[0].referenceIndex
            except:
                warnings.warn(f'Unable to identify referenceIndex for point {point_spec.id}. Defaulting to index 0.')
                point_spec.referenceIndex = 0
            for attr, attrtype in self.point_attrs:
                # Un-mangle common attribute names between points and measures
                df_attr = self.point_field_map.get(attr, attr)
@@ -356,8 +361,6 @@ class IsisStore(object):
                    else:
                        setattr(point_spec, attr, attrtype(g.iloc[0][df_attr]))

            # The reference index should always be the image with the lowest index
            point_spec.referenceIndex = 0
            # A single extend call is cheaper than many add calls to pack points
            measure_iterable = []
            for node_id, m in g.iterrows():
+22 −3
Original line number Diff line number Diff line
@@ -72,15 +72,16 @@ def cnet_dataframe(tmpdir):
    serials = {i:'APOLLO15/METRIC/{}'.format(j) for i, j in enumerate(serial_times.values())}
    columns = ['id', 'pointType', 'serialnumber', 'measureType',
               'sample', 'line', 'image_index', 'pointLog', 'measureLog',
               'aprioriCovar']
               'aprioriCovar', 'referenceIndex']

    data = []
    for i in range(npts):
        aprioriCovar = None
        if i == npts - 1:
            aprioriCovar = np.ones((2,3))
        data.append((i, 2, serials[0], 2, 0, 0, 0, [], [], aprioriCovar))
        data.append((i, 2, serials[1], 2, 0, 0, 1, [], [io_controlnetwork.MeasureLog(2, 0.5)],aprioriCovar))
        reference_idx = i % 2
        data.append((i, 2, serials[0], 2, 0, 0, 0, [], [], aprioriCovar,reference_idx))
        data.append((i, 2, serials[1], 2, 0, 0, 1, [], [io_controlnetwork.MeasureLog(2, 0.5)],aprioriCovar, reference_idx))

    df = pd.DataFrame(data, columns=columns)
    
@@ -121,6 +122,9 @@ def test_create_point(cnet_dataframe, tmpdir):
            point_protocol.ParseFromString(raw_point)
            assert str(i) == point_protocol.id
            assert 2 == point_protocol.type

            assert i % 2 == point_protocol.referenceIndex

            if i == cnet_dataframe.npts - 1:
                assert point_protocol.aprioriCovar == [1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
            for j, m in enumerate(point_protocol.measures):
@@ -128,6 +132,21 @@ def test_create_point(cnet_dataframe, tmpdir):
                assert 2 == m.type
                assert len(m.log) == j  # Only the second measure has a message

def test_create_point_wo_reference_index(cnet_dataframe, tmpdir):
    # cnet_dataframe has 5 points. Set the reference on one of those to be 
    # the second measure.
    reference_idx = [0,0,0,0,0,0,0,0,0,0]
    new_cnet_dataframe = cnet_dataframe.drop(columns='referenceIndex')
    cnet_file = tmpdir.join('test_w_reference.net')

    # Check that the warn is raised properly
    with pytest.warns(UserWarning, match='Unable to identify referenceIndex (.*)'):
        io_controlnetwork.to_isis(new_cnet_dataframe, cnet_file, mode='wb', targetname='Moon')
        
    # Check that nothing in == zeros out
    test_cnet = io_controlnetwork.from_isis(cnet_file)
    assert (test_cnet.referenceIndex == reference_idx).all()

def test_create_pvl_header(cnet_dataframe, tmpdir):
    with open(tmpdir.join('test.net'), 'rb') as f:
        pvl_header = pvl.load(f)
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ requirements:
    - python
    - setuptools
    - numpy
    - pvl
    - pvl >= 1.0
    - protobuf
    - gdal
    - icu
Loading