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

10.18. hist.cgi: subspLumper()—Lump subspecies

hist.cgi
# - - -   s u b s p L u m p e r

def subspLumper(c, txny):
    '''Implement subspecies lumping as a census-filter.

      [ (c is a pycbc.Census instance) and
        (txny is a taxonomy as an xnomo3.Txny instance) ->
          if the form in c is not in txny ->
            raise ScriptError
          else if the form in c is a subspecies in txny ->
            return a pycbc.Census instance representing the values from
            (c) but with the form replaced by the code for the
            containing species in txny
          else -> return c ]
    '''

The first level of analysis is to distinguish between composite forms (where the rel code is nonblank) and simple forms.

Note

Because MySQL deblanks the census.rel field, we must use a test that works for either one space or an empty string.

hist.cgi
    #-- 1
    # [ if c is a composite form ->
    #     if c.form and c.alt_form are defined in txny ->
    #       if c.form and c.alt_form are subspecies of
    #       the same species ->
    #         newForm  :=  abbr for that species
    #       else -> return c
    #     else -> raise ScriptError
    #   else if c.form is defined in txny ->
    #     if c.form is a subspecies ->
    #       newForm  :=  abbr for the species containing c.form
    #     else -> return census
    #   else -> raise Value Error ] 
    if c.rel.strip() != '':
        #-- 1.1
        # [ if c.form and c.alt_form are defined in txny ->
        #     if c.form and c.alt_form are subspecies of
        #     the same species ->
        #       newForm  :=  code for that species
        #     else ->
        #       newForm  :=  None
        #    else -> raise ScriptError ]
        newForm = lumpCompoundForm(c, txny)
    else:
        #-- 1.2
        # [ if c.form is defined in txny ->
        #     if c.form is a subspecies ->
        #       newForm  :=  code for the containing species
        #     else ->
        #       newForm  :=  None
        #   else -> raise ScriptError ]
        newForm = lumpSimpleForm(c, txny)

If newForm is None at this point, we know that no lumping occurred, so we can return our argument unchanged.

When subspecies lumping has taken place, the result is always a simple form, and newForm is the code for that form.

hist.cgi
    #-- 2
    if newForm is None:
        return c
    else:
        return lib.pycbc.CBCData.Census(c.lat, c.lon,
        c.year_no, c.year_key, c.seq_no,
        newForm, abbrMod.REL_SIMPLE, abbrMod.BLANK_ABBR,
        c.age, c.sex, c.plus, c.q, c.census)