*Extract the requested lightcurve from list of spectrum files*

    **Key Arguments:**
        - ``log`` -- logger
        - ``spectrumFiles`` -- list of the spectrum files
        - ``userExplosionDay`` -- explosion day for transient as set by the user in the settings file
        - ``extendLightCurveTail`` -- extend the tail of the lightcurve by extrapolating last two data points
        - ``obsmode`` -- the observation mode (generally a filter system and filter type, e.g. "sdss,g")

    **Return:**
        - ``magnitudes`` -- numpy array of the magnitudes
        - ``times`` -- numpy array of the corresponding times

def extract_lightcurve(
        log,
        spectrumFiles,
        userExplosionDay,
        extendLightCurveTail,
        obsmode):
    """
    *Extract the requested lightcurve from list of spectrum files*

    **Key Arguments:**
        - ``log`` -- logger
        - ``spectrumFiles`` -- list of the spectrum files
        - ``userExplosionDay`` -- explosion day for transient as set by the user in the settings file
        - ``extendLightCurveTail`` -- extend the tail of the lightcurve by extrapolating last two data points
        - ``obsmode`` -- the observation mode (generally a filter system and filter type, e.g. "sdss,g")

    **Return:**
        - ``magnitudes`` -- numpy array of the magnitudes
        - ``times`` -- numpy array of the corresponding times
    """
    ################ > IMPORTS ################
    ## STANDARD LIB ##
    import re
    ## THIRD PARTY ##
    import numpy as np
    ## LOCAL APPLICATION ##

    ################ > VARIABLE SETTINGS ######
    reTime = re.compile(r't((\+|\-)\d{3}\.\d{2})')
    magnitudes = []
    times = []
    fileNameTimes = []

    # log.info('spectrumFiles[-1] %s' % (spectrumFiles[-1],))
    ################ >ACTION(S) ################
    for thisFile in spectrumFiles:
        # log.warning('here is the file %s' % (thisFile,))
        # mul = 1.
        # if reTime.search(thisFile).group(2) == "-":
        #     mul = -1.
        thisTime = float(reTime.search(thisFile).group(1))
        fileNameTimes.append(thisTime)
        log.debug('time in %s is: %s' % (thisFile, thisTime))
        wavelengthArray, fluxArray = extract_spectra_from_file(log, thisFile)
        try:
            log.debug("attempting to find the magnitude from spectrum")
            thisMag = calcphot(
                log,
                wavelengthArray=wavelengthArray,
                fluxArray=fluxArray,
                obsmode=obsmode
            )
            magnitudes.append(thisMag)
            times.append(thisTime)
        except Exception as e:
            log.warning(
                "could not find the magnitude from spectrum %s using the filter %s - failed with this error: %s " %
                (thisFile, obsmode, str(e),))
            pass

    # APPEND AN EXPLOSION DAY AND MAG
    if len(magnitudes) > 3:
        finalTime = max(times)
        firstTime = min(times)
        firstMag = magnitudes[times.index(firstTime)]
        lastMag = magnitudes[times.index(finalTime)]
        log.debug('times: %s' % (times,))
        log.debug('magnitudes: %s' % (magnitudes,))
        sortedTime = sorted(times[:])
        log.debug('sortedTime: %s' % (sortedTime,))
        secondLastTime = sortedTime[-2]
        secondLastMag = magnitudes[times.index(secondLastTime)]

        iterations = 2.
        magDrop = 6.

        if (userExplosionDay is not None and userExplosionDay is not False):
            x2 = firstTime
            x1 = userExplosionDay
            y2 = firstMag
            y1 = firstMag + magDrop

            m = (y1 - y2) / (x1 - x2)
            c = y1 - m * x1
            upperTimeLimit = (firstMag - c) / m

            thisRange = upperTimeLimit - userExplosionDay
            delta = 0
            magDropNow = magDrop
            # log.debug('firstTime, userExplosionDay, increment: %s, %s, %s' % (firstTime, userExplosionDay))
            log.debug('range: %s' %
                      (np.arange(userExplosionDay, upperTimeLimit, thisRange / iterations + 1),))
            for t in np.arange(userExplosionDay, upperTimeLimit, thisRange / iterations):
                log.debug('new time: %s' % (t,))
                magDropNow -= delta
                delta = magDrop / iterations
                log.debug('magDrop, delta : %s, %s' % (magDropNow, delta,))
                times.append(t)
                magnitudes.append(firstMag + magDropNow)
                log.debug('new mag: %s' % (firstMag + magDropNow,))

        if extendLightCurveTail:
            x2 = secondLastTime
            x1 = finalTime
            y2 = secondLastMag
            y1 = lastMag

            log.debug('finalTime, lastMag: %s, %s' % (finalTime, lastMag,))
            log.debug('secondLastTime, secondLastMag: %s, %s' %
                      (secondLastTime, secondLastMag))

            m = (y1 - y2) / (x1 - x2)
            c = y1 - m * x1
            upperTimeLimit = (lastMag + 4 - c) / m

            thisRange = upperTimeLimit - finalTime
            delta = 0
            magDrop = 4
            magDropNow = 0
            for t in np.arange(finalTime, upperTimeLimit, thisRange / iterations):
                magDropNow += delta
                delta = magDrop / iterations
                times.append(t)
                magnitudes.append(lastMag + magDropNow)

    log.debug('finding magnitudes and times from spectrum : %s' % (thisFile,))
    log.debug('magnitudes, times: %s, %s' % (magnitudes, times))

    return magnitudes, times