*Given a redshift generate a dictionary of k-correction polynomials for the MCS.*

    **Key Arguments:**
        - ``log`` -- logger
        - ``pathToOutputDirectory`` -- path to the output directory (provided by the user)
        - ``pathToSpectralDatabase`` -- path to the directory containing the spectral database
        - ``model`` -- name of the object/model required
        - ``restFrameFilter`` -- the filter to generate the K-corrections against
        - ``redshift`` -- the redshift at which to generate the k-corrections for
        - ``temporalResolution`` -- temporal resolution at which to calculate the k-correcions

    **Return:**
        - None

def generate_single_kcorrection_listing(
        log,
        pathToOutputDirectory,
        pathToSpectralDatabase,
        model,
        restFrameFilter,
        redshift,
        temporalResolution=4.0):
    """
    *Given a redshift generate a dictionary of k-correction polynomials for the MCS.*

    **Key Arguments:**
        - ``log`` -- logger
        - ``pathToOutputDirectory`` -- path to the output directory (provided by the user)
        - ``pathToSpectralDatabase`` -- path to the directory containing the spectral database
        - ``model`` -- name of the object/model required
        - ``restFrameFilter`` -- the filter to generate the K-corrections against
        - ``redshift`` -- the redshift at which to generate the k-corrections for
        - ``temporalResolution`` -- temporal resolution at which to calculate the k-correcions

    **Return:**
        - None
    """
    ################ > IMPORTS ################
    ## STANDARD LIB ##
    import re
    import os
    import glob

    ## THIRD PARTY ##
    import yaml
    import pysynphot as syn
    ## LOCAL APPLICATION ##

    ################ >ACTION(S) ################
    # GET THE PEAK MAGNITUDE DETAILS FROM YAML FILE
    fileName = pathToOutputDirectory + "/transient_light_curves.yaml"
    stream = file(fileName, 'r')
    generatedLCs = yaml.load(stream)
    filterData = generatedLCs[model]
    peakMag = generatedLCs[model][restFrameFilter]['Peak Magnitude']
    peakTime = generatedLCs[model][restFrameFilter]['Peak Time in Spectra']
    stream.close()

    pwd = os.getcwd()
    path = pathToSpectralDatabase + "/" + model + "/"

    title = "%s Objects" % (model,)
    os.chdir(path)
    spectrumFiles = []
    for thisFile in glob.glob("*.spec"):

        thisFile = path + thisFile
        spectrumFiles.append(thisFile)

    os.chdir(pwd)

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

    ################ >ACTION(S) ################
    # CREATE THE REQUIRED DIRECTORIES
    filters = ["g", "i", "r", "z"]

    for thisFilter in filters:
        strRed = "%0.3f" % (redshift,)
        try:
            log.debug("attempting to create directories")
            dataDir = pathToOutputDirectory + \
                "/k_corrections/%s/%s" % (model, thisFilter)
            os.makedirs(dataDir)
        except Exception as e:
            log.debug(
                "could not create directories - failed with this error: %s " % (str(e),))

        try:
            log.debug("attempting to clear the k-correction yaml file")
            fileName = dataDir + "/z" + \
                str(strRed).replace(".", "pt") + ".yaml"
            stream = file(fileName, 'w')
            stream.close()
        except Exception as e:
            log.critical(
                "could not clear the k-correction yaml file - failed with this error: %s " % (str(e),))
            return -1

    timesList = []
    fileDictionary = {}
    for thisFile in spectrumFiles:
        thisTime = float(reTime.search(thisFile).group(1))
        fileDictionary[thisTime] = thisFile

    import collections
    ofileDictionary = collections.OrderedDict(sorted(fileDictionary.items()))

    nextTime = -999999999.9
    for thisTime, thisFile in ofileDictionary.iteritems():
        log.debug('thisTime: %(thisTime)s, thisFile: %(thisFile)s' % locals())
        if thisTime < nextTime:
            log.debug('skipping the file: %(thisFile)s' % locals())
            continue
        else:
            nextTime = thisTime + temporalResolution
            thisTime -= peakTime
            wavelengthArray, fluxArray = extract_spectra_from_file(
                log, thisFile)
            spRest = syn.ArraySpectrum(
                wave=wavelengthArray, flux=fluxArray, waveunits='angstrom', fluxunits='flam')
            try:
                log.debug("attempting to determine the rest %s-magnitude" %
                          (restFrameFilter,))
                if restFrameFilter in ["g", "r", "i", "z"]:
                    obsmode = "sdss,%s" % (restFrameFilter,)
                else:
                    obsmode = restFrameFilter
                gRest = calcphot(
                    log,
                    wavelengthArray=wavelengthArray,
                    fluxArray=fluxArray,
                    obsmode=obsmode
                )
            except Exception as e:
                if "Integrated flux is <= 0" in str(e):
                    log.warning(
                        "could not determine the rest-magnitude using calcphot - filter, model, time, file %s, %s, %s, %s - failed with this error: %s " %
                        (restFrameFilter, model, thisTime, thisFile, str(e),))
                    continue
                elif "Spectrum and bandpass do not fully overlap" in str(e):
                    log.warning(
                        "could not determine the rest-magnitude using calcphot - filter, model, time, file %s, %s, %s, %s - failed with this error: %s " %
                        (restFrameFilter, model, thisTime, thisFile, str(e),))
                    continue
                else:
                    log.warning(
                        "could not determine the rest-magnitude using calcphot - filter, model, time, file %s, %s, %s, %s - failed with this error: %s " %
                        (restFrameFilter, model, thisTime, thisFile, str(e),))
                pass

            for thisFilter in filters:
                strRed = "%0.3f" % (redshift,)
                spRest.convert('photnu')
                spObs = spRest.redshift(redshift)
                spObs.convert('flam')
                spRest.convert('flam')

                dataDir = pathToOutputDirectory + \
                    "/k_corrections/%s/%s" % (model, thisFilter)
                try:
                    log.debug(
                        "attempting to open the yaml file to append k-correction data")
                    fileName = dataDir + "/z" + \
                        str(strRed).replace(".", "pt") + ".yaml"
                    stream = file(fileName, 'a')
                except Exception as e:
                    log.critical(
                        "could not open the yaml file to append k-correction data - failed with this error: %s " % (str(e),))
                    return -1

                try:
                    log.debug(
                        "attempting to determine the magnitude of the object using calcphot - redshift, filter, model %s, %s, %s" %
                        (strRed, thisFilter, model))
                    if thisFilter in ["g", "r", "i", "z"]:
                        obsmode = "sdss,%s" % (thisFilter,)
                    else:
                        obsmode = thisFilter
                    filterObs = calcphot(
                        log,
                        wavelengthArray=spObs.wave,
                        fluxArray=spObs.flux,
                        obsmode=obsmode
                    )
                except Exception as e:
                    if "Integrated flux is <= 0" in str(e):
                        log.warning(
                            "could not determine the magnitude of the object using calcphot - redshift, filter, model %s, %s, %s - failed with this error: %s " %
                            (strRed, thisFilter, model, str(e),))
                        continue
                    elif "Spectrum and bandpass do not fully overlap" in str(e):
                        log.warning(
                            "could not determine the magnitude of the object using calcphot - redshift, filter, model %s, %s, %s - failed with this error: %s " %
                            (strRed, thisFilter, model, str(e),))
                        continue
                    elif "disjoint" in str(e):
                        log.warning(
                            "could not determine the magnitude of the object using calcphot - redshift, filter, model %s, %s, %s - failed with this error: %s " %
                            (strRed, thisFilter, model, str(e),))
                        continue
                    else:
                        log.warning(
                            "could not determine the magnitude of the object using calcphot - redshift, filter, model %s, %s, %s - failed with this error: %s " %
                            (strRed, thisFilter, model, str(e),))
                    pass
                kCor = gRest - filterObs
                kcName = 'K_%s%s' % (restFrameFilter, thisFilter,)
                thisKcor = {}
                thisKcor["Rest Frame Days"] = thisTime
                thisKcor[kcName] = kCor
                yamlList = [thisKcor]
                yaml.dump(yamlList, stream, default_flow_style=False)
                stream.close()

    return