Next / Previous / Contents / TCC Help System / NM Tech homepage

10.20. hist.cgi: lumpSimpleForm

hist.cgi
# - - -   l u m p S i m p l e F o r m

def lumpSimpleForm(c, txny):
    '''Apply subspecies lumping to a single form code.

      [ (c is a pycbc.Census instance with a simple form) and
        (txny is a taxonomy as an xnomo3.Txny instance) ->
          if c.form is defined in txny ->
            if c.form is a subspecies ->
              return the code for c.form's containing species
            else -> return None
           else -> raise ScriptError ]
    '''
    #-- 1
    # [ subspDepth  :=  depth of the subspecies rank in txny
    #   spDepth  :=  depth of the species rank in txny ]
    subspDepth = txny.hier.formRank().depth
    spDepth = txny.hier.speciesRank().depth

    #-- 2
    # [ if c.form is defined in txny ->
    #     taxon  :=  the corresponding Taxon instance
    #   else -> raise ScriptError ]
    try:
        taxon = txny.lookupAbbr(c.form)
    except KeyError:
        raise lib.ScriptError("Unknown bird code in %s-%s: '%s'" %
            (c.year_no, c.year_key, c.form))

If the taxon is not at subspecies rank, return None to signify no change.

hist.cgi
    #-- 2
    if taxon.rank.depth != subspDepth:
        return None

When this module was written, there were no taxonomic ranks between species and “form” (subspecies) rank. We called it form rank because not all the forms were true subspecies, e.g., Blue Goose is a color morph of Snow Goose, not a taxonomic subspecies.

However, the long-awaited Eighth Edition of the AOU Check-List will include subspecies, so there might conceivably someday be a subspecies rank involved. It is not at all clear to the author how this will interact with codes for color morphs and such. In any case, the logic of the next step dare not assume that the direct parent of a form-rank code is a species, but it does assume that there is a species somewhere in the chain of ancestors.

hist.cgi
    #-- 3
    # [ t  :=  ancestor of taxon at species rank ]
    t = taxon.parent
    while t.rank.depth > spDepth:
        t = t.parent

    #-- 4
    return t.abbr