Commit 19083482 authored by Roelofsen, Hans's avatar Roelofsen, Hans
Browse files

Merge branch 'taxon' into 'master'

tool 4 MNP species code 2 taxon group

See merge request !7
parents 0e487de6 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
......
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))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment