<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def fit_trapezoids(self, MAfn=None, msg=None, use_pbar=True, **kwargs):
 """ Fit trapezoid shape to each eclipse in population For each instance in the population, first the correct, physical Mandel-Agol transit shape is simulated, and then this curve is fit with a trapezoid model :param MAfn: :class:`transit_basic.MAInterpolationFunction` object. If not passed, then one with default parameters will be created. :param msg: Message to be displayed for progressbar output. :param **kwargs: Additional keyword arguments passed to :func:`fitebs.fitebs`. """

        logging.info('Fitting trapezoid models for {}...'.format(self.model))

        if msg is None:
            msg = '{}: '.format(self.model)

        n = len(self.stars)
        deps, durs, slopes = (np.zeros(n), np.zeros(n), np.zeros(n))
        secs = np.zeros(n, dtype=bool)
        dsec = np.zeros(n)

        if use_pbar and pbar_ok:
            widgets = [msg+'fitting shape parameters for %i systems: ' % n,Percentage(),
                       ' ',Bar(marker=RotatingMarker()),' ',ETA()]
            pbar = ProgressBar(widgets=widgets,maxval=n)
            pbar.start()

        for i in range(n):
            logging.debug('Fitting star {}'.format(i))
            pri = (self.stars['dpri'][i] > self.stars['dsec'][i] or
                   np.isnan(self.stars['dsec'][i]))
            sec = not pri
            secs[i] = sec
            if sec:
                dsec[i] = self.stars['dpri'][i]
            else:
                dsec[i] = self.stars['dsec'][i]

            try:
                trap_pars = self.eclipse_trapfit(i, secondary=sec, **kwargs)

            except NoEclipseError:
                logging.error('No eclipse registered for star {}'.format(i))
                trap_pars = (np.nan, np.nan, np.nan)
            except NoFitError:
                logging.error('Fit did not converge for star {}'.format(i))
                trap_pars = (np.nan, np.nan, np.nan)
            except KeyboardInterrupt:
                raise
            except:
                logging.error('Unknown error for star {}'.format(i))
                trap_pars = (np.nan, np.nan, np.nan)

            if use_pbar and pbar_ok:
                pbar.update(i)
            durs[i], deps[i], slopes[i] = trap_pars

        logging.info('Done.')

        self.stars['depth'] = deps
        self.stars['duration'] = durs
        self.stars['slope'] = slopes
        self.stars['secdepth'] = dsec
        self.stars['secondary'] = secs

        self._make_kde()