Tree species basicsΒΆ
This notebook shows how to retrieve species using TreeSpecies
and inspect the underlying TreeName
objects.
[1]:
from pyforestry.base.helpers.tree_species import (
ALNUS_GLUTINOSA,
ALNUS_INCANA,
TreeName,
TreeSpecies,
parse_tree_species,
)
TreeSpecies
exposes region-specific namespaces. Each attribute is a TreeName
instance.
[2]:
TreeSpecies.Sweden.pinus_sylvestris
[2]:
TreeName(genus=TreeGenus(name='Pinus', code='PINUS'), species_name='sylvestris', code='PSYL')
[3]:
TreeSpecies.Sweden.pinus.full_name
list(TreeSpecies.Sweden.pinus)
[3]:
[TreeName(genus=TreeGenus(name='Pinus', code='PINUS'), species_name='sylvestris', code='PSYL'),
TreeName(genus=TreeGenus(name='Pinus', code='PINUS'), species_name='contorta', code='PCON'),
TreeName(genus=TreeGenus(name='Pinus', code='PINUS'), species_name='mugo', code='PMUG')]
Strings can be converted to TreeName
objects using parse_tree_species()
.
[4]:
parse_tree_species('Pinus sylvestris')
parse_tree_species('pInus sylvestris') == TreeSpecies.Sweden.pinus_sylvestris
[4]:
True
TreeName
holds genus and species information and can be compared directly. TreeSpecies
simply provides organized access to these objects.
[5]:
isinstance(TreeSpecies.Sweden.pinus_sylvestris, TreeName)
type(TreeSpecies.Sweden)
[5]:
pyforestry.base.helpers.tree_species.RegionalTreeSpecies
Genus groups act like containers. We can check membership just like in the tests.
[6]:
ALNUS_GLUTINOSA in TreeSpecies.Sweden.alnus
ALNUS_INCANA in TreeSpecies.Sweden.alnus
[6]:
True