Skip to content
Snippets Groups Projects
Commit 1c23dd90 authored by AustinSanders's avatar AustinSanders Committed by GitHub
Browse files

Merge pull request #155 from AustinSanders/master

Updated for PVL 1.0
parents e3b3b557 57496f9b
No related branches found
No related tags found
No related merge requests found
...@@ -55,8 +55,8 @@ after_success: ...@@ -55,8 +55,8 @@ after_success:
- source deactivate - source deactivate
- conda install -q conda-build anaconda-client - conda install -q conda-build anaconda-client
- conda config --set anaconda_upload no - conda config --set anaconda_upload no
- conda build recipe -q - travis_wait conda build recipe -q
- builddir=(`conda build recipe --output`) - travis_wait builddir=(`conda build recipe --output`)
- | - |
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
anaconda -t="$CONDA_UPLOAD_TOKEN" upload $builddir --force; anaconda -t="$CONDA_UPLOAD_TOKEN" upload $builddir --force;
......
...@@ -148,7 +148,7 @@ def to_isis(obj, path, mode='wb', version=2, ...@@ -148,7 +148,7 @@ def to_isis(obj, path, mode='wb', version=2,
buffer_header_size, points_bytes, buffer_header_size, points_bytes,
creation_date, modified_date) creation_date, modified_date)
store.write(header) store.write(header.encode('utf-8'))
class IsisStore(object): class IsisStore(object):
""" """
...@@ -292,8 +292,8 @@ class IsisStore(object): ...@@ -292,8 +292,8 @@ class IsisStore(object):
""" """
Parameters Parameters
---------- ----------
data : str data : bytes
to be written to the file Encoded header to be written to the file
offset : int offset : int
The byte offset into the output binary The byte offset into the output binary
""" """
...@@ -461,7 +461,7 @@ class IsisStore(object): ...@@ -461,7 +461,7 @@ class IsisStore(object):
An ISIS compliant PVL header object An ISIS compliant PVL header object
""" """
encoder = pvl.encoder.IsisCubeLabelEncoder encoder = pvl.encoder.ISISEncoder(end_delimiter=False)
header_bytes = buffer_header_size header_bytes = buffer_header_size
points_start_byte = HEADERSTARTBYTE + buffer_header_size points_start_byte = HEADERSTARTBYTE + buffer_header_size
...@@ -489,4 +489,4 @@ class IsisStore(object): ...@@ -489,4 +489,4 @@ class IsisStore(object):
) )
]) ])
return pvl.dumps(header, cls=encoder) return pvl.dumps(header, encoder=encoder)
...@@ -100,7 +100,7 @@ class Spectral_Profiler(object): ...@@ -100,7 +100,7 @@ class Spectral_Profiler(object):
"^SP_SPECTRUM_REF1", "^SP_SPECTRUM_QA", "^L2D_RESULT_ARRAY", "^SP_SPECTRUM_REF1", "^SP_SPECTRUM_QA", "^L2D_RESULT_ARRAY",
"^SP_SPECTRUM_RAD"]: "^SP_SPECTRUM_RAD"]:
continue continue
if isinstance(v, pvl._collections.Units): if isinstance(v, pvl.collections.Quantity):
k = "{}_{}".format(k, v.units) k = "{}_{}".format(k, v.units)
v = v.value v = v.value
keys.append(k) keys.append(k)
......
...@@ -239,7 +239,7 @@ class Tes(object): ...@@ -239,7 +239,7 @@ class Tes(object):
with open(var_file, "rb") as var: with open(var_file, "rb") as var:
buffer = var.read() buffer = var.read()
def process_rad(index): def process_rad(index):
if index is -1: if index == -1:
return None return None
length = np.frombuffer(buffer[index:index+2], dtype='>u2')[0] length = np.frombuffer(buffer[index:index+2], dtype='>u2')[0]
......
...@@ -2,6 +2,7 @@ import warnings ...@@ -2,6 +2,7 @@ import warnings
import pvl import pvl
from pvl.collections import PVLModule from pvl.collections import PVLModule
from itertools import chain
import plio import plio
from plio.data import get_data from plio.data import get_data
...@@ -70,7 +71,7 @@ def generate_serial_number(label): ...@@ -70,7 +71,7 @@ def generate_serial_number(label):
The ISIS compatible serial number The ISIS compatible serial number
""" """
if not isinstance(label, PVLModule): if not isinstance(label, PVLModule):
label = pvl.load(label, cls=SerialNumberDecoder) label = pvl.load(label, decoder=SerialNumberDecoder())
# Get the translation information # Get the translation information
translation = get_isis_translation(label) translation = get_isis_translation(label)
...@@ -99,6 +100,7 @@ def generate_serial_number(label): ...@@ -99,6 +100,7 @@ def generate_serial_number(label):
serial_number.append(serial_entry) serial_number.append(serial_entry)
except: except:
pass pass
return '/'.join(serial_number) return '/'.join(serial_number)
...@@ -108,13 +110,69 @@ class SerialNumberDecoder(pvl.decoder.PVLDecoder): ...@@ -108,13 +110,69 @@ class SerialNumberDecoder(pvl.decoder.PVLDecoder):
serial number. Inherits from the PVLDecoder in planetarypy's pvl module. serial number. Inherits from the PVLDecoder in planetarypy's pvl module.
""" """
def cast_unquoated_string(self, value): def decode_simple_value(self, value: str):
"""Returns a Python object based on *value*, assuming
that *value* can be decoded as a PVL Simple Value::
<Simple-Value> ::= (<Numeric> | <String>)
Modified from https://pvl.readthedocs.io/en/stable/_modules/pvl/decoder.html#PVLDecoder.decode_simple_value
Modification entails stripping datetime from list of functions.
""" """
Overrides the parent class's method so that any un-quoted string type value found in the for d in (
parsed pvl will just return the original value. This is needed so that keyword values self.decode_quoted_string,
are not re-formatted from what is originally in the ISIS cube label. self.decode_non_decimal,
self.decode_decimal,
):
try:
return d(value)
except ValueError:
pass
if value.casefold() == self.grammar.none_keyword.casefold():
return None
if value.casefold() == self.grammar.true_keyword.casefold():
return True
if value.casefold() == self.grammar.false_keyword.casefold():
return False
return self.decode_unquoted_string(value)
def decode_unquoted_string(self, value: str) -> str:
"""Returns a Python ``str`` if *value* can be decoded
as an unquoted string, based on this decoder's grammar.
Raises a ValueError otherwise.
Note: This affects value types that are recognized as null, boolean, number, datetime, Modified from: https://pvl.readthedocs.io/en/stable/_modules/pvl/decoder.html#PVLDecoder.decode_unquoted_string
et at. Modification entails removal of decode_datetime call
""" """
return value.decode('utf-8') for coll in (
("a comment", chain.from_iterable(self.grammar.comments)),
("some whitespace", self.grammar.whitespace),
("a special character", self.grammar.reserved_characters),
):
for item in coll[1]:
if item in value:
raise ValueError(
"Expected a Simple Value, but encountered "
f'{coll[0]} in "{self}": "{item}".'
)
agg_keywords = self.grammar.aggregation_keywords.items()
for kw in chain.from_iterable(agg_keywords):
if kw.casefold() == value.casefold():
raise ValueError(
"Expected a Simple Value, but encountered "
f'an aggregation keyword: "{value}".'
)
for es in self.grammar.end_statements:
if es.casefold() == value.casefold():
raise ValueError(
"Expected a Simple Value, but encountered "
f'an End-Statement: "{value}".'
)
return str(value)
...@@ -240,7 +240,7 @@ def split_all_ext(path): ...@@ -240,7 +240,7 @@ def split_all_ext(path):
""" """
base, ext = os.path.splitext(path) base, ext = os.path.splitext(path)
while len(ext) is not 0: while len(ext) != 0:
base, ext = os.path.splitext(base) base, ext = os.path.splitext(base)
return base return base
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment