Skip to content
Snippets Groups Projects
Commit b222c8ad authored by jlaura's avatar jlaura Committed by GitHub
Browse files

Fixes 126 and PVL grammar issue (#167)

* Fixes 126 and PVL grammar issue

* Adds changelog.md

* Updates meta.yml for pvl version
parent d33eb93b
No related branches found
No related tags found
No related merge requests found
# Changelog
All changes that impact users of this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
<!---
This document is intended for users of the applications and API. Changes to things
like tests should not be noted in this document.
When updating this file for a PR, add an entry for your change under Unreleased
and one of the following headings:
- Added - for new features.
- Changed - for changes in existing functionality.
- Deprecated - for soon-to-be removed features.
- Removed - for now removed features.
- Fixed - for any bug fixes.
- Security - in case of vulnerabilities.
If the heading does not yet exist under Unreleased, then add it as a 3rd heading,
with three #.
When preparing for a public release candidate add a new 2nd heading, with two #, under
Unreleased with the version number and the release date, in year-month-day
format. Then, add a link for the new version at the bottom of this document and
update the Unreleased link so that it compares against the latest release tag.
When preparing for a bug fix release create a new 2nd heading above the Fixed
heading to indicate that only the bug fixes and security fixes are in the bug fix
release.
-->
## [Unreleased]
### Added
- Added this CHANGELOG.md file to track changes to the library
- Added a warning when to_isis is called without a target name fixing [#126](https://github.com/USGS-Astrogeology/plio/issues/126).
......@@ -8,7 +8,7 @@ dependencies:
- numpy
- pyproj
- h5py
- pvl >= 1.0
- pvl >= 1.3.0
- scipy
- protobuf
- affine
......
......@@ -122,6 +122,10 @@ def to_isis(obj, path, mode='wb', version=2,
description='None', username=DEFAULTUSERNAME,
creation_date=None, modified_date=None,
pointid_prefix=None, pointid_suffix=None):
if targetname == 'None':
warnings.warn("Users should provide a targetname to this function such as 'Moon' or 'Mars' in order to generate a valid ISIS control network.")
with IsisStore(path, mode) as store:
if not creation_date:
creation_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
......@@ -220,7 +224,7 @@ class IsisStore(object):
Given an ISIS store, read the underlying ISIS3 compatible control network and
return an IsisControlNetwork dataframe.
"""
pvl_header = pvl.load(self._path)
pvl_header = pvl.load(self._path, grammar=pvl.grammar.ISISGrammar())
header_start_byte = find_in_dict(pvl_header, 'HeaderStartByte')
header_bytes = find_in_dict(pvl_header, 'HeaderBytes')
point_start_byte = find_in_dict(pvl_header, 'PointsStartByte')
......
......@@ -56,6 +56,10 @@ def test_log_error():
with pytest.raises(TypeError) as err:
io_controlnetwork.MeasureLog(2, 'foo')
def test_to_isis_wo_targetname(cnet_dataframe, tmpdir):
with pytest.warns(UserWarning, match="Users should provide a targetname"):
io_controlnetwork.to_isis(cnet_dataframe, tmpdir.join('test.net'), mode='wb', targetname='None') # 'None' is the default.
def test_to_protobuf():
value = 1.25
int_dtype = 2
......@@ -87,7 +91,7 @@ def cnet_dataframe(tmpdir):
df.creation_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
df.modified_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
io_controlnetwork.to_isis(df, tmpdir.join('test.net'), mode='wb', targetname='Moon')
#io_controlnetwork.to_isis(df, tmpdir.join('test.net'), mode='wb', targetname='Moon')
df.header_message_size = 78
df.point_start_byte = 65614 # 66949
......@@ -97,6 +101,8 @@ def cnet_dataframe(tmpdir):
return df
def test_create_buffer_header(cnet_dataframe, tmpdir):
# Write the cnet
io_controlnetwork.to_isis(cnet_dataframe, tmpdir.join('test.net'), mode='wb', targetname='Moon')
with open(tmpdir.join('test.net'), 'rb') as f:
f.seek(io_controlnetwork.HEADERSTARTBYTE)
......@@ -114,6 +120,8 @@ def test_create_buffer_header(cnet_dataframe, tmpdir):
assert cnet_dataframe.measure_size == header_protocol.pointMessageSizes
def test_create_point(cnet_dataframe, tmpdir):
# Write the cnet
io_controlnetwork.to_isis(cnet_dataframe, tmpdir.join('test.net'), mode='wb', targetname='Moon')
with open(tmpdir.join('test.net'), 'rb') as f:
f.seek(cnet_dataframe.point_start_byte)
for i, length in enumerate(cnet_dataframe.measure_size):
......@@ -148,9 +156,10 @@ def test_create_point_wo_reference_index(cnet_dataframe, tmpdir):
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)
# Write the cnet
io_controlnetwork.to_isis(cnet_dataframe, tmpdir.join('test.net'), mode='wb', targetname='Moon')
with open(tmpdir.join('test.net'), 'rb') as stream:
pvl_header = pvl.load(stream, grammar=pvl.grammar.ISISGrammar())
npoints = find_in_dict(pvl_header, 'NumberOfPoints')
assert 5 == npoints
......
......@@ -20,7 +20,7 @@ requirements:
- python
- setuptools
- numpy
- pvl
- pvl >= 1.3.0
- protobuf
- gdal
- icu
......@@ -36,7 +36,7 @@ requirements:
- python
- setuptools
- numpy
- pvl >= 1.0
- pvl >= 1.3.0
- protobuf
- gdal
- icu
......
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