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

11.2. TaxonPhotoSet.addArchImage(): Add one photo

Because multiple forms of birds may appear in one photo, each photo may be added under multiple names. In that case, the .addArchImage() method is called once for each name.

Hence, this method operates on not just a catalog entry (as an ArchImage object from the archindex.py module), but also on a BirdId object (from the abbr.py module) that represents the kind of bird.

catweb
# - - -   T a x o n P h o t o S e t . a d d A r c h I m a g e

    def addArchImage(self, birdId, archImage):
        '''Add one photo to the report under a given birdId
        '''

Adding a new photo to the structure always starts at the root node, by calling its .addArchImage() method. In general, this operation is recursive. It may involve the addition of multiple new taxa to the tree, starting at the top and terminating at the taxon to which the photo is referred.

Depending on whether the given birdId is referred to self's taxon or not, there are two cases.

The first order of business is to separate the two cases. The taxon attribute of a BirdId object is the taxon to which that form is referred. The comparison function (.__cmp__()) in the Taxon class compares instances according to their txKey attribute, so we can use the ordinary Python “==” comparison to see if they are the same taxon.

For the internal methods that handle the two cases, see Section 11.3, “TaxonPhotoSet._addReferred(): Basis case” and Section 11.4, “TaxonPhotoSet._addContained(): Recursive case”.

catweb
        #-- 1
        # [ if self.taxon is the same as birdId.taxon ->
        #     self.nReferred  +:=  1
        #     self._formMap  :=  self._formMap with archImage added
        #         under the name from birdId
        #   else ->
        #     self._childMap  :=  self._childMap with new descendant
        #         nodes added as necessary down to birdId.taxon,
        #         and archImage added under the name from birdId to
        #         the node for birdId.taxon ]
        if  self.taxon == birdId.taxon:
            #-- 1.1
            self._addReferred(birdId, archImage)
            self.nReferred  +=  1
        else:
            #-- 1.2
            self._addContained(birdId, archImage)

The final step is bookkeeping: counting the number of photos in this subtree.

catweb
        #-- 2
        self.nContained  +=  1