def generate_model_lightcurves(
        log,
        pathToSpectralDatabase,
        pathToOutputDirectory,
        pathToOutputPlotDirectory,
        explosionDaysFromSettings,
        extendLightCurveTail,
        polyOrder
):
    """
    *Generate the lightcurve plots and polynomials by extracting the data from the provided spectra.*

    **Key Arguments:**
        - ``log`` -- logger
        - ``pathToSpectralDatabase`` -- path to the nested-folders and files spectral database (provided by the user)
        - ``pathToOutputDirectory`` -- path to the output directory (provided by the user)
        - ``pathToOutputPlotDirectory`` -- path to add plots to
        - ``explosionDaysFromSettings`` -- explosion days for transients as set by the user in the settings file
        - ``extendLightCurveTail`` -- extend the tail of the lightcurve by extrapolating last two data points
        - ``polyOrder`` -- order of the polynomial used to fit the lightcurve

    **Return:**
        - None
    """
    ################ > IMPORTS ################
    ## STANDARD LIB ##
    import glob
    import os
    ## THIRD PARTY ##
    import yaml
    ## LOCAL APPLICATION ##

    ################ >ACTION(S) ################
    # WRITE CODE HERE
    pwd = os.getcwd()
    pathToSpectralDatabase

    spectralDatabase = {}

    basePath = pathToSpectralDatabase
    for d in os.listdir(basePath):
        if os.path.isdir(os.path.join(basePath, d)):
            spectralDatabase[d] = os.path.join(basePath, d) + "/"

    # spectralDatabase = {"he130": he130}
    filters = ['g', 'r', 'i', 'z']
    # filters = ['g']

    extractedLightCurveDict = {}
    for model, path in spectralDatabase.iteritems():
        extractedLightCurveDict[model] = {}
        os.chdir(path)
        spectrumFiles = []
        for thisFile in glob.glob("*.spec"):
            thisFile = path + thisFile
            spectrumFiles.append(thisFile)

        os.chdir(pwd)

        # LIGHTCURVES PLOTTING CODE
        peakDict = {}
        for ffilter in filters:
            extractedLightCurveDict[model][ffilter] = {}
            title = "%s - %s-band" % (model, ffilter)
            # EXTRACT LIGHTCURVES FROM SPECTRA

            if ffilter in ["g", "r", "i", "z"]:
                obsmode = "sdss,%s" % (ffilter,)
            else:
                obsmode = ffilter

            magnitudes, times = extract_lightcurve(
                log,
                spectrumFiles,
                userExplosionDay=explosionDaysFromSettings[model],
                extendLightCurveTail=extendLightCurveTail[model],
                obsmode=obsmode
            )

            filterDict = {}

            # CREATE A FIRST POLY LIGHTCURVE TO EXTRACT MAX PEAK AND TIME
            lightCurveList = [
                [magnitudes, times, '%s-band data' % (ffilter,), ffilter, model, title], ]
            curveDict = plotLightCurves(
                log,
                lightCurves=lightCurveList,
                polyOrder=polyOrder,
                pathToOutputDirectory=pathToOutputPlotDirectory
            )

            # log.debug('lightCurveList: %s' % (lightCurveList,))

            wavelengthArray, fluxArray = extract_spectra_from_file(
                log, pathToSpectrum=thisFile)
            for k, v in curveDict.iteritems():
                poly = v

                if poly is None:
                    log.warning(
                        'could not generate a polynomial for %s in %s-band - enough data could not be extracted from spectra' % (model, ffilter))
                    continue
                start = int(min(times))
                end = int(max(times))
                log.debug('times: %s' % (times,))
                log.debug('model, start, end: %s, %s, %s' %
                          (model, start, end,))

                if poly is not None:
                    peakMag, peakTime, explosionMag, explosionDay = find_peak_magnitude(
                        log,
                        poly=poly,
                        model=model,
                        start=int(min(times)),
                        end=int(max(times))
                    )
                else:
                    peakMag, peakTime, explosionMag, explosionDay = None, None, None, None

                if peakTime is not None:
                    extractedLightCurveDict[model][
                        ffilter]['Peak Magnitude'] = peakMag
                    extractedLightCurveDict[model][ffilter][
                        'Peak Time in Spectra'] = peakTime
                    extractedLightCurveDict[model][ffilter][
                        'Explosion Day Relative to Peak'] = - peakTime + explosionDay
                    for i in range(len(times)):
                        times[i] = times[i] - peakTime
                else:
                    extractedLightCurveDict[model][
                        ffilter]['Peak Magnitude'] = None
                    extractedLightCurveDict[model][
                        ffilter]['Peak Time in Spectra'] = None
                    extractedLightCurveDict[model][ffilter][
                        'Explosion Day Relative to Peak'] = None

            # CREATE A SECOND POLY LIGHTCURVE NORMALISED TO PEAK MAG AND TIME
            lightCurveList = [
                [magnitudes, times, '%s-band data' % (ffilter,), ffilter, model, title], ]
            curveDict = plotLightCurves(
                log,
                lightCurves=lightCurveList,
                polyOrder=polyOrder,
                pathToOutputDirectory=pathToOutputPlotDirectory
            )

            for k, v in curveDict.iteritems():
                extractedLightCurveDict[model][ffilter][k] = v

    yamlDict = extractedLightCurveDict
    fileName = pathToOutputDirectory + "/transient_light_curves.yaml"
    stream = file(fileName, 'w')
    yaml.dump(yamlDict, stream, default_flow_style=False)
    stream.close()

    return extractedLightCurveDict