Tutorial 2: Taxa

Binder

This notebook will give a quick introduction to searching taxa.

from rich import print

from pyinaturalist import (
    enable_logging,
    iNatClient,
    pprint,
)

enable_logging()
client = iNatClient()

Taxon data

As with observations, there is a lot of information in the response:

print(taxa[0])
Taxon(
    id=52747,
    ancestor_ids=[48460, 1, 47120, 372739, 47158, 184884, 47201, 124417, 326777, 48740, 52747],
    extinct=False,
    iconic_taxon_id=47158,
    iconic_taxon_name='Insecta',
    is_active=True,
    matched_term='Vespidae',
    name='Vespidae',
    observations_count=1246088,
    parent_id=48740,
    preferred_common_name='Hornets, Paper Wasps, Potter Wasps, and Allies',
    rank_level=30,
    rank='family',
    taxon_changes_count=0,
    taxon_schemes_count=2,
    wikipedia_url='http://en.wikipedia.org/wiki/Vespidae',
    ancestors=[],
    children=[],
    conservation_status=None,
    conservation_statuses=[],
    default_photo=Photo(
        id=26329814,
        license_code='CC-BY-SA',
        url='https://inaturalist-open-data.s3.amazonaws.com/photos/26329814/square.jpg'
    ),
    establishment_means=None,
    listed_taxa=[],
    taxon_photos=[]
)

Previewing data

And we can get a condensed preview with pprint():

pprint(taxa)
                                                                                        
  ID        Rank     Scientific name    Common name                                     
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 
  52747     family   🐝 Vespidae        Hornets, Paper Wasps, Potter Wasps, and Allies  
  1312989   genus    🐠 Trichosomus                                                     
  84737     genus    🦋 Vespina                                                         
  250566    genus    🐝 Vespita                                                         
  646195    genus    🪰 Vespiodes                                                       
  1399531   genus    🪲 Vespinitocris                                                   
  1007575   genus    🦋 Vespitinea                                                      
                                                                                        

Searching by parent ID

Oh, that’s right, it was ‘Vespidae’! Now let’s find all of its subfamilies. We can run another search by parent ID, using the taxon ID from the results above:

subfamilies = client.taxa.search(parent_id=52747).all()
pprint(subfamilies)
                                                                       
  ID        Rank        Scientific name     Common name                
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 
  343248    subfamily   🐝 Polistinae       Paper Wasps                
  84738     subfamily   🐝 Vespinae         Hornets and Yellowjackets  
  119344    subfamily   🐝 Eumeninae        Potter and Mason Wasps     
  121511    subfamily   🐝 Masarinae        Pollen Wasps               
  522215    subfamily   🐝 Stenogastrinae   Hover Wasps                
  343388    subfamily   🐝 Euparagiinae                                
  1633740   genus       🐝 Ischnogaster