Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Roelofsen, Hans
benb_utils
Commits
261d24c1
Commit
261d24c1
authored
Jun 10, 2021
by
Roelofsen, Hans
Browse files
tool 4 MNP species code 2 taxon group
parent
a282c69a
Changes
2
Hide whitespace changes
Inline
Side-by-side
fix_bt.py
View file @
261d24c1
...
...
@@ -25,12 +25,14 @@ def fix_bt(code_in, as_mnp=False):
# Identify parts of code
parts
=
code_in
.
split
(
"."
)
if
len
(
parts
)
==
1
:
raise
Exception
(
"Unexpected BT code: {}"
.
format
(
code_in
))
raise
AssertionError
(
"Unexpected BT code: {}"
.
format
(
code_in
))
elif
len
(
parts
)
==
2
:
top
,
sub
=
parts
neer
=
None
elif
len
(
parts
)
==
3
:
top
,
sub
,
neer
=
parts
else
:
raise
AssertionError
(
"Unexpected BT code: {}"
.
format
(
code_in
))
# Verify TOP and add "N" is required
if
top
.
isdigit
():
...
...
@@ -39,16 +41,12 @@ def fix_bt(code_in, as_mnp=False):
assert
top
[
0
].
isupper
(),
"Unexpected BT Code format: {}"
.
format
(
code_in
)
# Verify SUB
assert
sub
.
isdigit
and
len
(
sub
)
==
2
,
"Unexpected BT Code format: {}"
.
format
(
code_in
)
assert
sub
.
isdigit
and
len
(
sub
)
==
2
,
"Unexpected BT Code format: {}"
.
format
(
code_in
)
# Verify NEER and check if it is neergeschaald or not
keep_neer
=
False
if
neer
:
assert
neer
.
isdigit
and
len
(
neer
)
==
2
,
"Unexpected BT Code format: {}"
.
format
(
code_in
)
assert
neer
.
isdigit
and
len
(
neer
)
==
2
,
"Unexpected BT Code format: {}"
.
format
(
code_in
)
if
int
(
neer
)
>
0
:
keep_neer
=
True
...
...
speciescode2taxon.py
0 → 100644
View file @
261d24c1
def
speciescode2taxon
(
code
):
"""
The Taxonomic class of an MNP species is embedded in its species code:
S02xxxxxx --> vogels V
S06xxxxxx --> vlinders E
S09xxxxxx --> planten P
:param code: MNP species code
:return: taxon class {V, E, P}
"""
d
=
{
'S02'
:
'V'
,
'S06'
:
'E'
,
'S09'
:
'P'
}
try
:
return
d
[
code
[:
3
]]
except
KeyError
:
raise
Exception
(
'invalid species code presented: {}'
.
format
(
code
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment