def _make_couplings(self, block_docs, block_mask_key=None, mp=True):
     """Computes the couplings between block_docs.
     :return: a difftools.Couplings instance.
     """
     couplings = Couplings()
     for block_name, block_doc in block_docs.iteritems():
         blockPath = block_doc[self._image_key]
         blockWeightPath = block_doc[self._weight_key]
         if block_mask_key and block_mask_key in block_doc:
             mask_path = block_doc[block_mask_key]
         else:
             mask_path = None
         couplings.add_field(block_name, blockPath, blockWeightPath,
                 mask_path=mask_path)
     diffImageDir = os.path.join(self.workdir, "diffs")
     couplings.make(diffImageDir, mp=mp)
     couplings_doc = couplings.get_doc()
     self.mosaicdb.c.update({"_id": self.mosaic_name},
             {"$set": {"couplings": couplings_doc}})
     return couplings
 def __init__(self, mosaicdb, mosaic_name):
     super(ScalarResidualFlux, self).__init__()
     self.mosaic_name = mosaic_name
     mosaic_doc = mosaicdb.find({"_id": mosaic_name}, one=True)
     self.offsets = mosaic_doc['offsets']
     self.couplings = Couplings.load_doc(mosaic_doc['couplings'])
 def _reload_couplings(self, couplings_doc):
     """Attempt to create a CoupledPlanes instance from a MongoDB
     persisted document."""
     return Couplings.load_doc(couplings_doc)