Generates PopulationSet.

def generate(self, ra, dec, period, cadence, mags,
                 n=2e4, Teff=None, logg=None, feh=None,
                 MAfn=None,
                 rprs=None, trilegal_filename=None,
                 starmodel=None,
                 binary_starmodel=None, triple_starmodel=None,
                 heb_kws=None, eb_kws=None,
                 beb_kws=None, pl_kws=None, savefile=None,
                 hide_exceptions=False, fit_trap=True,
                 do_only=None):
        """
        Generates PopulationSet.
        """
        do_all = False
        if do_only is None:
            do_all = True
            do_only = DEFAULT_MODELS

        if MAfn is None:
            MAfn = MAInterpolationFunction(pmin=0.007, pmax=1/0.007, nzs=200, nps=400)

        if beb_kws is None:
            beb_kws = {}
        if heb_kws is None:
            heb_kws = {}
        if eb_kws is None:
            eb_kws = {}
        if pl_kws is None:
            pl_kws = {}

        if 'heb' in do_only:
            try:
                hebpop = HEBPopulation(mags=mags,
                                       Teff=Teff, logg=logg, feh=feh,
                                       period=period, cadence=cadence,
                                       starmodel=triple_starmodel,
                                       starfield=trilegal_filename,
                                       MAfn=MAfn, n=n, **heb_kws)
                if fit_trap:
                    hebpop.fit_trapezoids(MAfn=MAfn)
                if savefile is not None:
                    if do_all:
                        hebpop.save_hdf(savefile, 'heb', overwrite=True)
                    else:
                        hebpop.save_hdf(savefile, 'heb', append=True)
            except:
                logging.error('Error generating HEB population.')
                if not hide_exceptions:
                    raise

        if 'heb_Px2' in do_only:
            try:
                hebpop_Px2 = HEBPopulation_Px2(mags=mags,
                                       Teff=Teff, logg=logg, feh=feh,
                                       period=period, cadence=cadence,
                                       starmodel=triple_starmodel,
                                       starfield=trilegal_filename,
                                       MAfn=MAfn, n=n, **heb_kws)
                if fit_trap:
                    hebpop_Px2.fit_trapezoids(MAfn=MAfn)
                if savefile is not None:
                    if do_all:
                        hebpop_Px2.save_hdf(savefile, 'heb_Px2', overwrite=True)
                    else:
                        hebpop_Px2.save_hdf(savefile, 'heb_Px2', append=True)
            except:
                logging.error('Error generating HEB_Px2 population.')
                if not hide_exceptions:
                    raise

        if 'eb' in do_only:
            try:
                ebpop = EBPopulation(mags=mags,
                                     Teff=Teff, logg=logg, feh=feh,
                                     period=period, cadence=cadence,
                                     starmodel=binary_starmodel,
                                     starfield=trilegal_filename,
                                     MAfn=MAfn, n=n, **eb_kws)
                if fit_trap:
                    ebpop.fit_trapezoids(MAfn=MAfn)
                if savefile is not None:
                    ebpop.save_hdf(savefile, 'eb', append=True)
            except:
                logging.error('Error generating EB population.')
                if not hide_exceptions:
                    raise

        if 'eb_Px2' in do_only:
            try:
                ebpop_Px2 = EBPopulation_Px2(mags=mags,
                                     Teff=Teff, logg=logg, feh=feh,
                                     period=period, cadence=cadence,
                                     starmodel=binary_starmodel,
                                     starfield=trilegal_filename,
                                     MAfn=MAfn, n=n, **eb_kws)
                if fit_trap:
                    ebpop_Px2.fit_trapezoids(MAfn=MAfn)
                if savefile is not None:
                    ebpop_Px2.save_hdf(savefile, 'eb_Px2', append=True)
            except:
                logging.error('Error generating EB_Px2 population.')
                if not hide_exceptions:
                    raise

        if 'beb' in do_only:
            try:
                bebpop = BEBPopulation(trilegal_filename=trilegal_filename,
                                       ra=ra, dec=dec, period=period, cadence=cadence,
                                       mags=mags, MAfn=MAfn, n=n, **beb_kws)
                if fit_trap:
                    bebpop.fit_trapezoids(MAfn=MAfn)
                if savefile is not None:
                    bebpop.save_hdf(savefile, 'beb', append=True)
            except:
                logging.error('Error generating BEB population.')
                if not hide_exceptions:
                    raise

        if 'beb_Px2' in do_only:
            try:
                bebpop_Px2 = BEBPopulation_Px2(trilegal_filename=trilegal_filename,
                                       ra=ra, dec=dec, period=period, cadence=cadence,
                                       mags=mags, MAfn=MAfn, n=n, **beb_kws)
                if fit_trap:
                    bebpop_Px2.fit_trapezoids(MAfn=MAfn)
                if savefile is not None:
                    bebpop_Px2.save_hdf(savefile, 'beb_Px2', append=True)
            except:
                logging.error('Error generating BEB_Px2 population.')
                if not hide_exceptions:
                    raise

        if 'pl' in do_only:
            try:
                plpop = PlanetPopulation(period=period, cadence=cadence,
                                         rprs=rprs,
                                         starmodel=starmodel,
                                         MAfn=MAfn, n=n, **pl_kws)

                if fit_trap:
                    plpop.fit_trapezoids(MAfn=MAfn)
                if savefile is not None:
                    plpop.save_hdf(savefile, 'pl', append=True)
            except:
                logging.error('Error generating Planet population.')
                if not hide_exceptions:
                    raise

        if not do_all and savefile is not None:
            hebpop = HEBPopulation.load_hdf(savefile, 'heb')
            hebpop_Px2 = HEBPopulation.load_hdf(savefile, 'heb_Px2')
            ebpop = EBPopulation.load_hdf(savefile, 'eb')
            ebpop_Px2 = EBPopulation.load_hdf(savefile, 'eb_Px2')
            bebpop = BEBPopulation.load_hdf(savefile, 'beb')
            bebpop_Px2 = BEBPopulation.load_hdf(savefile, 'beb_Px2')
            plpop = PlanetPopulation.load_hdf(savefile, 'pl')


        self.poplist = [hebpop, hebpop_Px2,
                        ebpop, ebpop_Px2,
                        bebpop, bebpop_Px2, plpop]