Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Plio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aflab
astrogeology
Plio
Commits
238966c0
Commit
238966c0
authored
4 years ago
by
Austin Sanders
Browse files
Options
Downloads
Patches
Plain Diff
Added logic to skip conversion from str to datetime
parent
08d7045f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plio/io/isis_serial_number.py
+64
-11
64 additions, 11 deletions
plio/io/isis_serial_number.py
with
64 additions
and
11 deletions
plio/io/isis_serial_number.py
+
64
−
11
View file @
238966c0
...
...
@@ -2,6 +2,7 @@ import warnings
import
pvl
from
pvl.collections
import
PVLModule
from
itertools
import
chain
import
plio
from
plio.data
import
get_data
...
...
@@ -97,10 +98,6 @@ def generate_serial_number(label):
serial_entry
=
search_translation
[
serial_entry
]
elif
'
*
'
in
search_translation
.
keys
()
and
search_translation
[
'
*
'
]
!=
'
*
'
:
serial_entry
=
search_translation
[
'
*
'
]
try
:
serial_entry
=
serial_entry
.
strftime
(
"
%Y-%m-%dT%H:%M:%S.%f
"
)[:
-
3
]
except
:
pass
serial_number
.
append
(
serial_entry
)
except
:
pass
...
...
@@ -114,13 +111,69 @@ class SerialNumberDecoder(pvl.decoder.PVLDecoder):
serial number. Inherits from the PVLDecoder in planetarypy
'
s pvl module.
"""
def
cast_unquoted_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
parsed pvl will just return the original value. This is needed so that keyword values
are not re-formatted from what is originally in the ISIS cube label.
for
d
in
(
self
.
decode_quoted_string
,
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,
et at.
Modified from: https://pvl.readthedocs.io/en/stable/_modules/pvl/decoder.html#PVLDecoder.decode_unquoted_string
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment