make_tree¶
- pyinaturalist.models.make_tree(taxa, include_ranks=None, sort_key=None, root_id=None)¶
Organize a list of taxa into a taxonomic tree, defined by
children
andancestors
attributes. Expects exactly one root taxon.- Parameters:
sort_key (
Optional
[Callable
[[Taxon
],Any
]]) – Key function for sorting children; defaults to rank and nameinclude_ranks (
Optional
[List
[str
]]) – If provided, only include taxa with these ranks; otherwise, include all ranksroot_id (
Optional
[int
]) – ID of the root taxon; if provided, only that taxon and its descendants will be included. Otherwise, the root taxon is determined automatically.
- Return type:
- Returns:
Root taxon of the tree