Example #1
0
elif opts.doLuminosity:

    names = opts.name.split(",")
    filenames = []
    legend_names = []
    for name in names:
        for ii, model in enumerate(models):
            filename = '%s/%s/%s_Lbol.dat' % (outputDir, model, name)
            if not os.path.isfile(filename):
                continue
            filenames.append(filename)
            legend_names.append(models_ref[ii])
            break

    Lbols, names = lightcurve_utils.read_files_lbol(filenames)

    if opts.doModels:

        model_data = {}
        modelfiles = opts.modelfile.split(",")
        for modelfile in modelfiles:
            modelfile = os.path.join(opts.plotDir, modelfile)
            modelfileSplit = modelfile.split("/")
            model_out = np.loadtxt(modelfile)

            errorbudget = float(modelfileSplit[-2])
            modelType = modelfileSplit[-4]
            model = modelfileSplit[-6].split("_")[0]

            if model == "BNS" and modelType == "ejecta":
Example #2
0
def calc_svd_lbol(tini,tmax,dt, n_coeff = 100, model = "BaKa2016"):

    print("Calculating SVD model of bolometric luminosity...")

    if model == "BaKa2016":    
        fileDir = "../output/barnes_kilonova_spectra"
    elif model == "Ka2017":
        fileDir = "../output/kasen_kilonova_grid"
    elif model == "RoFe2017":
        fileDir = "../output/macronovae-rosswog_wind"

    filenames = glob.glob('%s/*_Lbol.dat'%fileDir)

    lbols, names = lightcurve_utils.read_files_lbol(filenames)
    lbolkeys = lbols.keys()

    tt = np.arange(tini,tmax+dt,dt)

    for key in lbolkeys:
        keySplit = key.split("_")
        if keySplit[0] == "rpft":
            mej0 = float("0." + keySplit[1].replace("m",""))
            vej0 = float("0." + keySplit[2].replace("v",""))
            lbols[key]["mej"] = mej0
            lbols[key]["vej"] = vej0
        elif keySplit[0] == "knova":
            mej0 = float(keySplit[3].replace("m",""))
            vej0 = float(keySplit[4].replace("vk",""))
            if len(keySplit) == 6:
                Xlan0 = 10**float(keySplit[5].replace("Xlan1e",""))
            elif len(keySplit) == 7:
                if "Xlan1e" in keySplit[6]:
                    Xlan0 = 10**float(keySplit[6].replace("Xlan1e",""))
                elif "Xlan1e" in keySplit[5]:
                    Xlan0 = 10**float(keySplit[5].replace("Xlan1e",""))

            #if (mej0 == 0.05) and (vej0 == 0.2) and (Xlan0 == 1e-3):
            #    del lbols[key]
            #    continue

            lbols[key]["mej"] = mej0
            lbols[key]["vej"] = vej0
            lbols[key]["Xlan"] = Xlan0
        elif keySplit[0] == "SED":
            lbols[key]["mej"], lbols[key]["vej"], lbols[key]["Ye"] = lightcurve_utils.get_macronovae_rosswog(key)

        ii = np.where(np.isfinite(lbols[key]["Lbol"]))[0]
        f = interp.interp1d(lbols[key]["tt"][ii], np.log10(lbols[key]["Lbol"][ii]), fill_value='extrapolate')
        lbolinterp = 10**f(tt)
        lbols[key]["Lbol"]= np.log10(lbolinterp)

    lbolkeys = lbols.keys()

    lbol_array = []
    param_array = []
    for key in lbolkeys:
        lbol_array.append(lbols[key]["Lbol"])
        if model == "BaKa2016":
            param_array.append([np.log10(lbols[key]["mej"]),lbols[key]["vej"]])
        elif model == "Ka2017":
            param_array.append([np.log10(lbols[key]["mej"]),np.log10(lbols[key]["vej"]),np.log10(lbols[key]["Xlan"])])
        elif model == "RoFe2017":
            param_array.append([np.log10(lbols[key]["mej"]),lbols[key]["vej"],lbols[key]["Ye"]]) 

    param_array_postprocess = np.array(param_array)
    param_mins, param_maxs = np.min(param_array_postprocess,axis=0),np.max(param_array_postprocess,axis=0)
    for i in range(len(param_mins)):
        param_array_postprocess[:,i] = (param_array_postprocess[:,i]-param_mins[i])/(param_maxs[i]-param_mins[i]) 

    lbol_array_postprocess = np.array(lbol_array)
    mins,maxs = np.min(lbol_array_postprocess,axis=0),np.max(lbol_array_postprocess,axis=0)
    for i in range(len(mins)):
        lbol_array_postprocess[:,i] = (lbol_array_postprocess[:,i]-mins[i])/(maxs[i]-mins[i])    
    lbol_array_postprocess[np.isnan(lbol_array_postprocess)]=0.0

    UA, sA, VA = np.linalg.svd(lbol_array_postprocess, full_matrices=True)
    VA = VA.T

    n, n = UA.shape
    m, m = VA.shape

    cAmat = np.zeros((n_coeff,n))
    cAvar = np.zeros((n_coeff,n))
    for i in range(n):
        cAmat[:,i] = np.dot(lbol_array_postprocess[i,:],VA[:,:n_coeff])
        ErrorLevel = 2.0
        errors = ErrorLevel*lbol_array_postprocess[i,:]
        cAvar[:,i] = np.diag(np.dot(VA[:,:n_coeff].T,np.dot(np.diag(np.power(errors,2.)),VA[:,:n_coeff])))
    cAstd = np.sqrt(cAvar)

    nsvds, nparams = param_array_postprocess.shape
    kernel = 1.0 * RationalQuadratic(length_scale=1.0, alpha=0.1)
    gps = []
    for i in range(n_coeff):
        gp = GaussianProcessRegressor(kernel=kernel,n_restarts_optimizer=0)
        gp.fit(param_array_postprocess, cAmat[i,:])
        gps.append(gp)

    svd_model = {}
    svd_model["n_coeff"] = n_coeff
    svd_model["param_array"] = param_array
    svd_model["cAmat"] = cAmat
    svd_model["cAstd"] = cAstd
    svd_model["VA"] = VA
    svd_model["param_mins"] = param_mins
    svd_model["param_maxs"] = param_maxs
    svd_model["mins"] = mins
    svd_model["maxs"] = maxs
    svd_model["gps"] = gps
    svd_model["tt"] = tt

    print("Finished calculating SVD model of bolometric luminosity...")

    return svd_model
Example #3
0
def calc_svd_lbol(tini, tmax, dt, n_coeff=100, model="BaKa2016"):

    print("Calculating SVD model of bolometric luminosity...")

    if model == "BaKa2016":
        fileDir = "../output/barnes_kilonova_spectra"
    elif model == "Ka2017":
        fileDir = "../output/kasen_kilonova_grid"
    elif model == "RoFe2017":
        fileDir = "../output/macronovae-rosswog_wind"
    elif model == "Bu2019":
        fileDir = "../output/bulla_1D"
        fileDir = "../output/bulla_1D_phi0"
        fileDir = "../output/bulla_1D_phi90"
    elif model == "Bu2019inc":
        fileDir = "../output/bulla_2D"
    elif model == "Bu2019lf":
        fileDir = "../output/bulla_2Component_lfree"
    elif model == "Bu2019lr":
        fileDir = "../output/bulla_2Component_lrich"
    elif model == "Bu2019lm":
        fileDir = "../output/bulla_2Component_lmid"
    elif model == "Bu2019lw":
        fileDir = "../output/bulla_2Component_lmid_0p005"
    elif model == "Bu2019bc":
        fileDir = "../output/bulla_blue_cone"
    elif model == "Bu2019re":
        fileDir = "../output/bulla_red_ellipse"
    elif model == "Bu2019op":
        fileDir = "../output/bulla_opacity"
    elif model == "Bu2019ops":
        fileDir = "../output/bulla_opacity_slim"
    elif model == "Bu2019rp":
        fileDir = "../output/bulla_reprocess"
    elif model == "Bu2019rps":
        fileDir = "../output/bulla_reprocess_slim"

    filenames = glob.glob('%s/*_Lbol.dat' % fileDir)

    lbols, names = lightcurve_utils.read_files_lbol(filenames)
    lbolkeys = lbols.keys()

    tt = np.arange(tini, tmax + dt, dt)

    for key in lbolkeys:
        keySplit = key.split("_")
        if keySplit[0] == "rpft":
            mej0 = float("0." + keySplit[1].replace("m", ""))
            vej0 = float("0." + keySplit[2].replace("v", ""))
            lbols[key]["mej"] = mej0
            lbols[key]["vej"] = vej0
        elif keySplit[0] == "knova":
            mej0 = float(keySplit[3].replace("m", ""))
            vej0 = float(keySplit[4].replace("vk", ""))
            if len(keySplit) == 6:
                Xlan0 = 10**float(keySplit[5].replace("Xlan1e", ""))
            elif len(keySplit) == 7:
                if "Xlan1e" in keySplit[6]:
                    Xlan0 = 10**float(keySplit[6].replace("Xlan1e", ""))
                elif "Xlan1e" in keySplit[5]:
                    Xlan0 = 10**float(keySplit[5].replace("Xlan1e", ""))

            #if (mej0 == 0.05) and (vej0 == 0.2) and (Xlan0 == 1e-3):
        #    del lbols[key]
        #    continue

            lbols[key]["mej"] = mej0
            lbols[key]["vej"] = vej0
            lbols[key]["Xlan"] = Xlan0
        elif keySplit[0] == "SED":
            lbols[key]["mej"], lbols[key]["vej"], lbols[key][
                "Ye"] = lightcurve_utils.get_macronovae_rosswog(key)
        elif "gamma" in key:
            kappaLF = float(keySplit[2].replace("kappaLF", ""))
            gammaLF = float(keySplit[3].replace("gammaLF", ""))
            kappaLR = float(keySplit[4].replace("kappaLR", ""))
            gammaLR = float(keySplit[5].replace("gammaLR", ""))
            theta = float(keySplit[6])

            lbols[key]["kappaLF"] = kappaLF
            lbols[key]["gammaLF"] = gammaLF
            lbols[key]["kappaLR"] = kappaLR
            lbols[key]["gammaLR"] = gammaLR
            lbols[key]["theta"] = theta

        elif "nsns" in key:

            mejdyn = float(keySplit[2].replace("mejdyn", ""))
            mejwind = float(keySplit[3].replace("mejwind", ""))
            phi0 = float(keySplit[4].replace("phi", ""))
            theta = float(keySplit[5])

            lbols[key]["mej_dyn"] = mejdyn
            lbols[key]["mej_wind"] = mejwind
            lbols[key]["phi"] = phi0
            lbols[key]["theta"] = theta

        elif "mejdyn" in key:

            mejdyn = float(keySplit[1].replace("mejdyn", ""))
            mejwind = float(keySplit[2].replace("mejwind", ""))
            phi0 = float(keySplit[4].replace("phi", ""))
            theta = float(keySplit[5])

            lbols[key]["mej_dyn"] = mejdyn
            lbols[key]["mej_wind"] = mejwind
            lbols[key]["phi"] = phi0
            lbols[key]["theta"] = theta

        elif "bluecone" in key:

            mej = float(keySplit[2].replace("mej", ""))
            phi0 = float(keySplit[3].replace("th", ""))
            theta = float(keySplit[4])

            lbols[key]["mej"] = mej
            lbols[key]["phi"] = 90 - phi0
            lbols[key]["theta"] = theta

        elif "redellips" in key:

            mej = float(keySplit[2].replace("mej", ""))
            a0 = float(keySplit[3].replace("a", ""))
            theta = float(keySplit[4])

            lbols[key]["mej"] = mej
            lbols[key]["a"] = a0
            lbols[key]["theta"] = theta

        elif keySplit[0] == "nph1.0e+06":

            mej0 = float(keySplit[1].replace("mej", ""))
            phi0 = float(keySplit[2].replace("phi", ""))
            theta = float(keySplit[3])

            lbols[key]["mej"] = mej0
            lbols[key]["phi"] = phi0
            #lbols[key]["T"] = T0
            lbols[key]["theta"] = theta

        elif keySplit[0] == "kasenReprocess":

            mej1 = float(keySplit[2].replace("mejcone", ""))
            mej2 = float(keySplit[3].replace("mejell", ""))
            phi = float(keySplit[4].replace("th", ""))
            a = float(keySplit[5].replace("a", ""))
            theta = float(keySplit[6])

            lbols[key]["mej_1"] = mej1
            lbols[key]["mej_2"] = mej2
            lbols[key]["phi"] = phi
            lbols[key]["a"] = a
            lbols[key]["theta"] = theta

        ii = np.where(np.isfinite(lbols[key]["Lbol"]))[0]
        f = interp.interp1d(lbols[key]["tt"][ii],
                            np.log10(lbols[key]["Lbol"][ii]),
                            fill_value='extrapolate')
        lbolinterp = 10**f(tt)
        lbols[key]["Lbol"] = np.log10(lbolinterp)

    lbolkeys = lbols.keys()

    lbol_array = []
    param_array = []
    for key in lbolkeys:
        lbol_array.append(lbols[key]["Lbol"])
        if model == "BaKa2016":
            param_array.append(
                [np.log10(lbols[key]["mej"]), lbols[key]["vej"]])
        elif model == "Ka2017":
            param_array.append([
                np.log10(lbols[key]["mej"]),
                np.log10(lbols[key]["vej"]),
                np.log10(lbols[key]["Xlan"])
            ])
        elif model == "RoFe2017":
            param_array.append([
                np.log10(lbols[key]["mej"]), lbols[key]["vej"],
                lbols[key]["Ye"]
            ])
        elif model == "Bu2019":
            param_array.append(
                [np.log10(lbols[key]["mej"]),
                 np.log10(lbols[key]["T"])])
        elif model == "Bu2019inc":
            param_array.append([
                np.log10(lbols[key]["mej"]), lbols[key]["phi"],
                lbols[key]["theta"]
            ])
        elif model in ["Bu2019lf", "Bu2019lr", "Bu2019lm"]:
            param_array.append([
                np.log10(lbols[key]["mej_dyn"]),
                np.log10(lbols[key]["mej_wind"]), lbols[key]["phi"],
                lbols[key]["theta"]
            ])
        elif model in ["Bu2019lw"]:
            param_array.append([
                np.log10(lbols[key]["mej_wind"]), lbols[key]["phi"],
                lbols[key]["theta"]
            ])
        elif model == "Bu2019bc":
            param_array.append([
                np.log10(lbols[key]["mej"]), lbols[key]["phi"],
                lbols[key]["theta"]
            ])
        elif model == "Bu2019re":
            param_array.append([
                np.log10(lbols[key]["mej"]), lbols[key]["a"],
                lbols[key]["theta"]
            ])
        elif model == "Bu2019op":
            param_array.append([
                np.log10(lbols[key]["kappaLF"]), lbols[key]["gammaLF"],
                np.log10(lbols[key]["kappaLR"]), lbols[key]["gammaLR"]
            ])
        elif model == "Bu2019ops":
            param_array.append([
                np.log10(lbols[key]["kappaLF"]),
                np.log10(lbols[key]["kappaLR"]), lbols[key]["gammaLR"]
            ])
        elif model == "Bu2019rp":
            param_array.append([
                np.log10(lbols[key]["mej_1"]),
                np.log10(lbols[key]["mej_2"]), lbols[key]["phi"],
                lbols[key]["a"], lbols[key]["theta"]
            ])
        elif model == "Bu2019rps":
            param_array.append([
                np.log10(lbols[key]["mej_1"]),
                np.log10(lbols[key]["mej_2"]), lbols[key]["a"]
            ])

    param_array_postprocess = np.array(param_array)
    param_mins, param_maxs = np.min(param_array_postprocess,
                                    axis=0), np.max(param_array_postprocess,
                                                    axis=0)
    for i in range(len(param_mins)):
        param_array_postprocess[:, i] = (param_array_postprocess[:, i] -
                                         param_mins[i]) / (param_maxs[i] -
                                                           param_mins[i])

    lbol_array_postprocess = np.array(lbol_array)
    mins, maxs = np.min(lbol_array_postprocess,
                        axis=0), np.max(lbol_array_postprocess, axis=0)
    for i in range(len(mins)):
        lbol_array_postprocess[:, i] = (lbol_array_postprocess[:, i] -
                                        mins[i]) / (maxs[i] - mins[i])
    lbol_array_postprocess[np.isnan(lbol_array_postprocess)] = 0.0

    UA, sA, VA = np.linalg.svd(lbol_array_postprocess, full_matrices=True)
    VA = VA.T

    n, n = UA.shape
    m, m = VA.shape

    cAmat = np.zeros((n_coeff, n))
    cAvar = np.zeros((n_coeff, n))
    for i in range(n):
        cAmat[:, i] = np.dot(lbol_array_postprocess[i, :], VA[:, :n_coeff])
        ErrorLevel = 2.0
        errors = ErrorLevel * lbol_array_postprocess[i, :]
        cAvar[:, i] = np.diag(
            np.dot(VA[:, :n_coeff].T,
                   np.dot(np.diag(np.power(errors, 2.)), VA[:, :n_coeff])))
    cAstd = np.sqrt(cAvar)

    nsvds, nparams = param_array_postprocess.shape
    kernel = 1.0 * RationalQuadratic(length_scale=1.0, alpha=0.1)
    gps = []
    for i in range(n_coeff):
        gp = GaussianProcessRegressor(kernel=kernel, n_restarts_optimizer=0)
        gp.fit(param_array_postprocess, cAmat[i, :])
        gps.append(gp)

    svd_model = {}
    svd_model["n_coeff"] = n_coeff
    svd_model["param_array"] = param_array
    svd_model["cAmat"] = cAmat
    svd_model["cAstd"] = cAstd
    svd_model["VA"] = VA
    svd_model["param_mins"] = param_mins
    svd_model["param_maxs"] = param_maxs
    svd_model["mins"] = mins
    svd_model["maxs"] = maxs
    svd_model["gps"] = gps
    svd_model["tt"] = tt

    print("Finished calculating SVD model of bolometric luminosity...")

    return svd_model
Example #4
0
def calc_svd_lbol(tini,tmax,dt, n_coeff = 100, model = "BaKa2016",
                  gptype="sklearn"):

    print("Calculating SVD model of bolometric luminosity...")

    if model == "BaKa2016":    
        fileDir = "../output/barnes_kilonova_spectra"
    elif model == "Ka2017":
        fileDir = "../output/kasen_kilonova_grid"
    elif model == "RoFe2017":
        fileDir = "../output/macronovae-rosswog_wind"
    elif model == "Bu2019":
        fileDir = "../output/bulla_1D"
        fileDir = "../output/bulla_1D_phi0"
        fileDir = "../output/bulla_1D_phi90"
    elif model == "Bu2019inc":
        fileDir = "../output/bulla_2D"
    elif model == "Bu2019lf":
        fileDir = "../output/bulla_2Component_lfree"
    elif model == "Bu2019lr":
        fileDir = "../output/bulla_2Component_lrich"
    elif model == "Bu2019lm":
        fileDir = "../output/bulla_2Component_lmid"
    elif model == "Bu2019lw":
        fileDir = "../output/bulla_2Component_lmid_0p005"
    elif model == "Bu2019bc":
        fileDir = "../output/bulla_blue_cone"
    elif model == "Bu2019re":
        fileDir = "../output/bulla_red_ellipse"
    elif model == "Bu2019op":
        fileDir = "../output/bulla_opacity"
    elif model == "Bu2019ops":
        fileDir = "../output/bulla_opacity_slim"
    elif model == "Bu2019rp":
        fileDir = "../output/bulla_reprocess"
    elif model == "Bu2019rps":
        fileDir = "../output/bulla_reprocess_slim"
    elif model == "Bu2019rpd":
        fileDir = "../output/bulla_reprocess_decimated"
    elif model == "Bu2019nsbh":
        fileDir = "../output/bulla_2Component_lnsbh"
    elif model == "Wo2020dyn":
        fileDir = "../output/bulla_rosswog_dynamical"
    elif model == "Wo2020dw":
        fileDir = "../output/bulla_rosswog_wind"


    filenames = glob.glob('%s/*_Lbol.dat'%fileDir)

    lbols, names = lightcurve_utils.read_files_lbol(filenames)
    lbolkeys = lbols.keys()

    tt = np.arange(tini,tmax+dt,dt)

    for key in lbolkeys:
        keySplit = key.split("_")
        if keySplit[0] == "rpft":
            mej0 = float("0." + keySplit[1].replace("m",""))
            vej0 = float("0." + keySplit[2].replace("v",""))
            lbols[key]["mej"] = mej0
            lbols[key]["vej"] = vej0
        elif keySplit[0] == "knova":
            mej0 = float(keySplit[3].replace("m",""))
            vej0 = float(keySplit[4].replace("vk",""))
            if len(keySplit) == 6:
                Xlan0 = 10**float(keySplit[5].replace("Xlan1e",""))
            elif len(keySplit) == 7:
                if "Xlan1e" in keySplit[6]:
                    Xlan0 = 10**float(keySplit[6].replace("Xlan1e",""))
                elif "Xlan1e" in keySplit[5]:
                    Xlan0 = 10**float(keySplit[5].replace("Xlan1e",""))

            #if (mej0 == 0.05) and (vej0 == 0.2) and (Xlan0 == 1e-3):
          #    del lbols[key]
            #    continue

            lbols[key]["mej"] = mej0
            lbols[key]["vej"] = vej0
            lbols[key]["Xlan"] = Xlan0
        elif keySplit[0] == "SED":
            lbols[key]["mej"], lbols[key]["vej"], lbols[key]["Ye"] = lightcurve_utils.get_macronovae_rosswog(key)
        elif "gamma" in key:
            kappaLF = float(keySplit[2].replace("kappaLF",""))
            gammaLF = float(keySplit[3].replace("gammaLF",""))
            kappaLR = float(keySplit[4].replace("kappaLR",""))
            gammaLR = float(keySplit[5].replace("gammaLR",""))
            theta = float(keySplit[6])

            lbols[key]["kappaLF"] = kappaLF
            lbols[key]["gammaLF"] = gammaLF
            lbols[key]["kappaLR"] = kappaLR
            lbols[key]["gammaLR"] = gammaLR
            lbols[key]["theta"] = theta

        elif "nsns" in key:

            mejdyn = float(keySplit[2].replace("mejdyn",""))
            mejwind = float(keySplit[3].replace("mejwind",""))
            phi0 = float(keySplit[4].replace("phi",""))
            theta = float(keySplit[5])

            lbols[key]["mej_dyn"] = mejdyn
            lbols[key]["mej_wind"] = mejwind
            lbols[key]["phi"] = phi0
            lbols[key]["theta"] = theta

        elif keySplit[0] == "nsbh":

            mej_dyn = float(keySplit[2].replace("mejdyn",""))
            mej_wind = float(keySplit[3].replace("mejwind",""))
            phi = float(keySplit[4].replace("phi",""))
            theta = float(keySplit[5])

            lbols[key]["mej_dyn"] = mej_dyn
            lbols[key]["mej_wind"] = mej_wind
            #lbols[key]["phi"] = phi
            lbols[key]["theta"] = theta

        elif "mejdyn" in key:

            mejdyn = float(keySplit[1].replace("mejdyn",""))
            mejwind = float(keySplit[2].replace("mejwind",""))
            phi0 = float(keySplit[4].replace("phi",""))
            theta = float(keySplit[5])

            lbols[key]["mej_dyn"] = mejdyn
            lbols[key]["mej_wind"] = mejwind
            lbols[key]["phi"] = phi0
            lbols[key]["theta"] = theta

        elif "bluecone" in key:

            mej = float(keySplit[2].replace("mej",""))
            phi0 = float(keySplit[3].replace("th",""))
            theta = float(keySplit[4])

            lbols[key]["mej"] = mej
            lbols[key]["phi"] = 90-phi0
            lbols[key]["theta"] = theta

        elif "redellips" in key:

            mej = float(keySplit[2].replace("mej",""))
            a0 = float(keySplit[3].replace("a",""))
            theta = float(keySplit[4])

            lbols[key]["mej"] = mej
            lbols[key]["a"] = a0
            lbols[key]["theta"] = theta

        elif keySplit[0] == "nph1.0e+06":
 
            mej0 = float(keySplit[1].replace("mej",""))
            phi0 = float(keySplit[2].replace("phi",""))
            theta = float(keySplit[3])

            lbols[key]["mej"] = mej0
            lbols[key]["phi"] = phi0
            #lbols[key]["T"] = T0
            lbols[key]["theta"] = theta

        elif keySplit[0] == "kasenReprocess":

            mej1 = float(keySplit[2].replace("mejcone",""))
            mej2 = float(keySplit[3].replace("mejell",""))
            phi = float(keySplit[4].replace("th",""))
            a = float(keySplit[5].replace("a",""))
            theta = float(keySplit[6])

            lbols[key]["mej_1"] = mej1
            lbols[key]["mej_2"] = mej2
            lbols[key]["phi"] = phi
            lbols[key]["a"] = a
            lbols[key]["theta"] = theta

        elif keySplit[0] == "RGAdyn":
            
            mej = float(keySplit[2].replace("mej",""))
            a = float(keySplit[3].replace("a",""))
            sd = float(keySplit[4].replace("sd",""))
            theta = float(keySplit[5])

            lbols[key]["mej"] = mej
            lbols[key]["a"] = a
            lbols[key]["sd"] = sd
            lbols[key]["theta"] = theta

        elif keySplit[0] == "WoWind":

            mej = float(keySplit[2].replace("mej",""))
            rwind = float(keySplit[3].replace("v",""))
            theta = float(keySplit[4])

            lbols[key]["mej"] = mej
            lbols[key]["rwind"] = rwind
            lbols[key]["theta"] = theta
        
        ii = np.where(np.isfinite(lbols[key]["Lbol"]))[0]
        f = interp.interp1d(lbols[key]["tt"][ii], np.log10(lbols[key]["Lbol"][ii]), fill_value='extrapolate')
        lbolinterp = 10**f(tt)
        lbols[key]["Lbol"]= np.log10(lbolinterp)

    lbolkeys = lbols.keys()

    lbol_array = []
    param_array = []
    for key in lbolkeys:
        lbol_array.append(lbols[key]["Lbol"])
        if model == "BaKa2016":
            param_array.append([np.log10(lbols[key]["mej"]),lbols[key]["vej"]])
        elif model == "Ka2017":
            param_array.append([np.log10(lbols[key]["mej"]),np.log10(lbols[key]["vej"]),np.log10(lbols[key]["Xlan"])])
        elif model == "RoFe2017":
            param_array.append([np.log10(lbols[key]["mej"]),lbols[key]["vej"],lbols[key]["Ye"]]) 
        elif model == "Bu2019":
            param_array.append([np.log10(lbols[key]["mej"]),np.log10(lbols[key]["T"])])
        elif model == "Bu2019inc":
            param_array.append([np.log10(lbols[key]["mej"]),lbols[key]["phi"],lbols[key]["theta"]])
        elif model in ["Bu2019lf","Bu2019lr","Bu2019lm"]:
            param_array.append([np.log10(lbols[key]["mej_dyn"]),np.log10(lbols[key]["mej_wind"]),lbols[key]["phi"],lbols[key]["theta"]])
        elif model in ["Bu2019nsbh"]:
            param_array.append([np.log10(lbols[key]["mej_dyn"]),np.log10(lbols[key]["mej_wind"]),lbols[key]["theta"]])
        elif model in ["Bu2019lw"]:
            param_array.append([np.log10(lbols[key]["mej_wind"]),lbols[key]["phi"],lbols[key]["theta"]])
        elif model == "Bu2019bc":
            param_array.append([np.log10(lbols[key]["mej"]),lbols[key]["phi"],lbols[key]["theta"]])
        elif model == "Bu2019re":
            param_array.append([np.log10(lbols[key]["mej"]),lbols[key]["a"],lbols[key]["theta"]])
        elif model == "Bu2019op":
            param_array.append([np.log10(lbols[key]["kappaLF"]),lbols[key]["gammaLF"],np.log10(lbols[key]["kappaLR"]),lbols[key]["gammaLR"]])
        elif model == "Bu2019ops":
            param_array.append([np.log10(lbols[key]["kappaLF"]),np.log10(lbols[key]["kappaLR"]),lbols[key]["gammaLR"]])
        elif model in ["Bu2019rp","Bu2019rpd"]:
            param_array.append([np.log10(lbols[key]["mej_1"]),np.log10(lbols[key]["mej_2"]),lbols[key]["phi"],lbols[key]["a"],lbols[key]["theta"]])
        elif model == "Bu2019rps":
            param_array.append([np.log10(lbols[key]["mej_1"]),np.log10(lbols[key]["mej_2"]),lbols[key]["a"]])
        elif model == "Wo2020dyn":
            param_array.append([np.log10(lbols[key]["mej"]),lbols[key]["a"],lbols[key]["sd"],lbols[key]["theta"]])
        elif model == "Wo2020dw":
            param_array.append([np.log10(lbols[key]["mej"]),lbols[key]["rwind"],lbols[key]["theta"]])
    param_array_postprocess = np.array(param_array)
    param_mins, param_maxs = np.min(param_array_postprocess,axis=0),np.max(param_array_postprocess,axis=0)
    for i in range(len(param_mins)):
        param_array_postprocess[:,i] = (param_array_postprocess[:,i]-param_mins[i])/(param_maxs[i]-param_mins[i]) 

    lbol_array_postprocess = np.array(lbol_array)
    mins,maxs = np.min(lbol_array_postprocess,axis=0),np.max(lbol_array_postprocess,axis=0)
    for i in range(len(mins)):
        lbol_array_postprocess[:,i] = (lbol_array_postprocess[:,i]-mins[i])/(maxs[i]-mins[i])    
    lbol_array_postprocess[np.isnan(lbol_array_postprocess)]=0.0

    UA, sA, VA = np.linalg.svd(lbol_array_postprocess, full_matrices=True)
    VA = VA.T

    n, n = UA.shape
    m, m = VA.shape

    cAmat = np.zeros((n_coeff,n))
    cAvar = np.zeros((n_coeff,n))
    for i in range(n):
        cAmat[:,i] = np.dot(lbol_array_postprocess[i,:],VA[:,:n_coeff])
        ErrorLevel = 2.0
        errors = ErrorLevel*lbol_array_postprocess[i,:]
        cAvar[:,i] = np.diag(np.dot(VA[:,:n_coeff].T,np.dot(np.diag(np.power(errors,2.)),VA[:,:n_coeff])))
    cAstd = np.sqrt(cAvar)

    nsvds, nparams = param_array_postprocess.shape
    if gptype == "sklearn":
        kernel = 1.0 * RationalQuadratic(length_scale=1.0, alpha=0.1)
        gps = []
        for i in range(n_coeff):
            gp = GaussianProcessRegressor(kernel=kernel,n_restarts_optimizer=0)
            gp.fit(param_array_postprocess, cAmat[i,:])
            gps.append(gp)
    elif gptype == "gpytorch":
        # initialize likelihood and model
        likelihood = gpytorch.likelihoods.GaussianLikelihood()
        #training_iter = 10
        training_iter = 1

        gps = []
        for i in range(n_coeff):
            if np.mod(i,5) == 0:
                print('Coefficient %d/%d...' % (i, n_coeff))

            train_x = torch.from_numpy(param_array_postprocess).float()
            train_y = torch.from_numpy(cAmat[i,:]).float()

            if torch.cuda.is_available():
                train_x = train_x.cuda()
                train_y = train_y.cuda()
                likelihood = likelihood.cuda()

            model = ExactGPModel(train_x, train_y, likelihood)
            if torch.cuda.is_available():
                model = model.cuda()

            # Find optimal model hyperparameters
            model.train()
            likelihood.train()

            # Use the adam optimizer
            optimizer = torch.optim.Adam([{'params': model.parameters()}],
                                         lr=0.1)

            # "Loss" for GPs - the marginal log likelihood
            mll = gpytorch.mlls.ExactMarginalLogLikelihood(likelihood,
                                                           model)

            for j in range(training_iter):
                # Zero gradients from previous iteration
                optimizer.zero_grad()
                # Output from model
                output = model(train_x)
                # Calc loss and backprop gradients
                loss = -mll(output, train_y)
                loss.backward()
                #print('Coeff %d/%d Iter %d/%d - Loss: %.3f   lengthscale: %.3f   noise: %.3f' % (i+1, n_coeff, j + 1, training_iter, loss.item(), model.covar_module.base_kernel.lengthscale.item(), model.likelihood.noise.item()))
                optimizer.step()

            gps.append(model.state_dict())

    svd_model = {}
    svd_model["n_coeff"] = n_coeff
    svd_model["param_array"] = param_array
    svd_model["param_array_postprocess"] = param_array_postprocess
    svd_model["cAmat"] = cAmat
    svd_model["cAstd"] = cAstd
    svd_model["VA"] = VA
    svd_model["param_mins"] = param_mins
    svd_model["param_maxs"] = param_maxs
    svd_model["mins"] = mins
    svd_model["maxs"] = maxs
    svd_model["gps"] = gps
    svd_model["tt"] = tt

    print("Finished calculating SVD model of bolometric luminosity...")

    return svd_model