[docs]classDonutList:""" Manages a collection of Donut objects and combines them into a single 2D model. This class allows adding multiple donut models together, normalizing the result, and retrieving the combined image. """def__init__(self,donuts):""" Initialize the DonutList with a list of Donut objects. Parameters ---------- donuts : list of Donut A list of Donut instances to be combined. Raises ------ ValueError If the list is empty or if the shapes of the donut models do not match. """ifnotdonuts:raiseValueError("The list of donuts cannot be empty.")self.donuts=donutsself.height,self.width=self.donuts[0].model.shapefordonutinself.donuts:ifdonut.model.shape!=(self.height,self.width):raiseValueError("All donuts must have the same shape.")self.combined=np.zeros((self.height,self.width),dtype=np.float32)self.combine()
[docs]defcombine(self):""" Combine all Donut models in the list into one by summing their intensity arrays. """fordonutinself.donuts:self.combined+=donut.model
[docs]defadd_donut(self,donut):""" Add a new Donut model to the combined image. Parameters ---------- donut : Donut A new Donut instance to be added. Raises ------ ValueError If the shape of the donut model does not match the combined image. """ifdonut.shape!=(self.height,self.width):raiseValueError("Donut shape does not match the list shape.")self.combined+=donut.model
[docs]defget_combined(self):""" Retrieve the combined image of all Donuts. Returns ------- numpy.ndarray The combined 2D intensity model. """returnself.combined
[docs]defnormalize(self):""" Normalize the combined image so that its maximum value is 1. """max_val=np.max(self.combined)ifmax_val>0:self.combined/=max_val