Tree species basics#
Notebook Objectives#
Demonstrate how to discover and inspect species metadata with
TreeSpeciesandTreeName.Provide runnable, copy-safe snippets that work in the docs build environment.
Prerequisites#
Python environment with
pyforestryinstalled from this repository.Execute cells in order; random components should use fixed seeds where shown.
Sources#
pyforestry base species metadata (
pyforestry.base.helpers.tree_species).
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]:
print(TreeSpecies.Sweden.pinus.full_name)
print(list(TreeSpecies.Sweden.pinus))
pinus
[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]:
print(parse_tree_species("Pinus sylvestris"))
print(parse_tree_species("pInus sylvestris") == TreeSpecies.Sweden.pinus_sylvestris)
TreeName(genus=TreeGenus(name='Pinus', code='PINUS'), species_name='sylvestris', code='PSYL')
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