Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
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
...@@ -8,7 +8,7 @@ dependencies: ...@@ -8,7 +8,7 @@ dependencies:
- numpy - numpy
- pyproj - pyproj
- h5py - h5py
- pvl - pvl >= 1.0
- scipy - scipy
- protobuf - protobuf
- affine - affine
......
...@@ -335,6 +335,11 @@ class IsisStore(object): ...@@ -335,6 +335,11 @@ class IsisStore(object):
#point_spec.id = _set_pid(i) #point_spec.id = _set_pid(i)
point_spec.id = _set_pid(i) point_spec.id = _set_pid(i)
point_spec.type = g.iloc[0].pointType 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: for attr, attrtype in self.point_attrs:
# Un-mangle common attribute names between points and measures # Un-mangle common attribute names between points and measures
df_attr = self.point_field_map.get(attr, attr) df_attr = self.point_field_map.get(attr, attr)
...@@ -356,8 +361,6 @@ class IsisStore(object): ...@@ -356,8 +361,6 @@ class IsisStore(object):
else: else:
setattr(point_spec, attr, attrtype(g.iloc[0][df_attr])) 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 # A single extend call is cheaper than many add calls to pack points
measure_iterable = [] measure_iterable = []
for node_id, m in g.iterrows(): for node_id, m in g.iterrows():
......
...@@ -72,15 +72,16 @@ def cnet_dataframe(tmpdir): ...@@ -72,15 +72,16 @@ def cnet_dataframe(tmpdir):
serials = {i:'APOLLO15/METRIC/{}'.format(j) for i, j in enumerate(serial_times.values())} serials = {i:'APOLLO15/METRIC/{}'.format(j) for i, j in enumerate(serial_times.values())}
columns = ['id', 'pointType', 'serialnumber', 'measureType', columns = ['id', 'pointType', 'serialnumber', 'measureType',
'sample', 'line', 'image_index', 'pointLog', 'measureLog', 'sample', 'line', 'image_index', 'pointLog', 'measureLog',
'aprioriCovar'] 'aprioriCovar', 'referenceIndex']
data = [] data = []
for i in range(npts): for i in range(npts):
aprioriCovar = None aprioriCovar = None
if i == npts - 1: if i == npts - 1:
aprioriCovar = np.ones((2,3)) aprioriCovar = np.ones((2,3))
data.append((i, 2, serials[0], 2, 0, 0, 0, [], [], aprioriCovar)) reference_idx = i % 2
data.append((i, 2, serials[1], 2, 0, 0, 1, [], [io_controlnetwork.MeasureLog(2, 0.5)],aprioriCovar)) 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) df = pd.DataFrame(data, columns=columns)
...@@ -121,6 +122,9 @@ def test_create_point(cnet_dataframe, tmpdir): ...@@ -121,6 +122,9 @@ def test_create_point(cnet_dataframe, tmpdir):
point_protocol.ParseFromString(raw_point) point_protocol.ParseFromString(raw_point)
assert str(i) == point_protocol.id assert str(i) == point_protocol.id
assert 2 == point_protocol.type assert 2 == point_protocol.type
assert i % 2 == point_protocol.referenceIndex
if i == cnet_dataframe.npts - 1: if i == cnet_dataframe.npts - 1:
assert point_protocol.aprioriCovar == [1.0, 1.0, 1.0, 1.0, 1.0, 1.0] assert point_protocol.aprioriCovar == [1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
for j, m in enumerate(point_protocol.measures): for j, m in enumerate(point_protocol.measures):
...@@ -128,6 +132,21 @@ def test_create_point(cnet_dataframe, tmpdir): ...@@ -128,6 +132,21 @@ def test_create_point(cnet_dataframe, tmpdir):
assert 2 == m.type assert 2 == m.type
assert len(m.log) == j # Only the second measure has a message 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): def test_create_pvl_header(cnet_dataframe, tmpdir):
with open(tmpdir.join('test.net'), 'rb') as f: with open(tmpdir.join('test.net'), 'rb') as f:
pvl_header = pvl.load(f) pvl_header = pvl.load(f)
......
...@@ -36,7 +36,7 @@ requirements: ...@@ -36,7 +36,7 @@ requirements:
- python - python
- setuptools - setuptools
- numpy - numpy
- pvl - pvl >= 1.0
- protobuf - protobuf
- gdal - gdal
- icu - icu
......
...@@ -8,8 +8,8 @@ with open('README.md', 'r') as f: ...@@ -8,8 +8,8 @@ with open('README.md', 'r') as f:
def setup_package(): def setup_package():
setup( setup(
name = "plio", name = "plio",
version = '1.2.4', version = '1.3.0',
author = "Jay Laura", author = "USGS Astrogeology",
author_email = "jlaura@usgs.gov", author_email = "jlaura@usgs.gov",
description = ("I/O API to support planetary data formats."), description = ("I/O API to support planetary data formats."),
long_description = long_description, long_description = long_description,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment