Skip to content

Commit

Permalink
Adds dynamic reference indices to ISIS network writes (#157)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jlaura committed May 28, 2021
1 parent 88b3aa2 commit 383a1b9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 89 deletions.
80 changes: 0 additions & 80 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
- numpy
- pyproj
- h5py
- pvl
- pvl >= 1.0
- scipy
- protobuf
- affine
Expand Down
7 changes: 5 additions & 2 deletions plio/io/io_controlnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ def _set_pid(pointid):
#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)
Expand All @@ -356,8 +361,6 @@ def _set_pid(pointid):
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():
Expand Down
25 changes: 22 additions & 3 deletions plio/io/tests/test_io_controlnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -121,13 +122,31 @@ 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):
assert m.serialnumber in cnet_dataframe.serials.values()
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)
Expand Down
2 changes: 1 addition & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ requirements:
- python
- setuptools
- numpy
- pvl
- pvl >= 1.0
- protobuf
- gdal
- icu
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
def setup_package():
setup(
name = "plio",
version = '1.2.4',
author = "Jay Laura",
version = '1.3.0',
author = "USGS Astrogeology",
author_email = "jlaura@usgs.gov",
description = ("I/O API to support planetary data formats."),
long_description = long_description,
Expand Down

0 comments on commit 383a1b9

Please sign in to comment.