Example #1
0
def getFicaModel(conn, modelID, origSpecID=None):
    curs = conn.cursor()
    
    #retrieving origSpec:
    if origSpecID != None:
        origSpec = curs.execute('select spectrum from sn_spectra where id=%s' % origSpecID)
    
    #Retrieving the Model
    (machineName, execTime, wFactor, errorString,
    abundanceID, dicaID,
    lumVphID, spectrumID) = curs.execute('select MACHINE, TIME, W, ERROR, '
                 'ABUNDANCE_ID, DICA_ID, LUMVPH_ID, SPECTRUM_ID '
                 'from FICA_MODEL where FICA_MODEL.ID=%s' % modelID).fetchall()[0]
    #getting dica params
    colNames = zip(*curs.execute('PRAGMA table_info(fica_dica)').fetchall())[1]
    colNames = map(str, colNames)
    colValues = curs.execute('select * from fica_dica where id=%s' % dicaID).fetchall()[0]
    dicaDict = dict(zip([convertFields2Dica[item] for item in colNames[1:]], colValues[1:]))
    lum, vph = curs.execute('select LUM, VPH from FICA_LUMVPH where FICA_LUMVPH.ID=%s' % lumVphID).fetchall()[0]
    dicaDict['log_lbol'] = lum
    dicaDict['v_ph'] = vph
    
    dica = param.dica(initDica=dicaDict, mode='fromDict')
    return dica
    
    #getting abundances
    colNames = zip(*curs.execute('PRAGMA table_info(fica_abundance)').fetchall())[1]
    colNames = map(str, colNames)
    colValues = curs.execute('select * from fica_abundance where id=%s' % abundanceID).fetchall()[0]
    compDict = dict(zip(colNames[1:], colValues[1:]))
    comp = param.comp(initComp=compDict, t=dica['t'])
    comp._setNiDecay()
    
    curParam = param.param(initDica=dica, initComp=comp)
Example #2
0
    def fromPath(cls, basePath=".", machineName=None, param=None, origSpec=None, fitFunc=None, t=None, execTime=None):
        if param == None:
            dicaData = fileio.dicafile(os.path.join(basePath, "dica.dat")).read_data()
            compData = fileio.compfile(os.path.join(basePath, "comp.ind")).read_data()
            dica = paramMod.dica(dicaData, mode="fromPath", t=t)
            comp = paramMod.comp(compData, t=dica["t"])
            param = paramMod.param(initDica=dica, initComp=comp)

        aSpecPath = os.path.join(basePath, "spct.dat")
        try:
            aSpec = spectrum(aSpecPath, usecols=(0, 2))
            sbib = fileio.sbibfile(os.path.join(basePath, "sbib.dat")).read_data()
            llist = sbib["llist"]
            wParams = fileio.ststfile(os.path.join(basePath, "stst.dat")).getWParams()
            specFlag = 0
        except:
            print "Creating fake Spectrum @%s" % basePath
            aSpec = spectrum(zip(np.linspace(2000, 20000, 20), range(1, 21)))
            sbib = {"llist": []}
            llist = sbib["llist"]
            wParams = []
            specFlag = -1

        log = list(file(os.path.join(basePath, "fica.log")))
        # error=list(file(os.path.join(basePath,'error.log')))

        if wParams != []:
            w = wParams[-1][0][-1]
        else:
            w = -1

        return cls(
            aSpec,
            param,
            w,
            machineName=None,
            execTime=execTime,
            wParam=wParams,
            error=None,
            ficaLog=log,
            llist=llist,
            origSpec=origSpec,
            specFlag=specFlag,
            fitFunc=fitFunc,
        )
Example #3
0
def getHistDica(id):
    dicaData=fileio.dicafile('hist/dica.bak%04d'%id).read_data()
    return param.dica(dicaData)
Example #4
0
    def fromDB(cls, conn, modelID, GARunID=None):
        curs = conn.cursor()

        # retrieving origSpec:
        if GARunID != None:
            origSpec = curs.execute("select SN_SPECTRUM from GA_RUN where id=%s" % GARunID).fetchall()[0][0]

        else:
            origSpec = None

        # Retrieving the Model
        (
            machineName,
            execTime,
            wFactor,
            errorString,
            ficaLog,
            abundanceID,
            dicaID,
            lumVphID,
            spectrumID,
        ) = curs.execute(
            "select MACHINE, TIME, W, ERROR, FICA_LOG, "
            "ABUNDANCE_ID, DICA_ID, LUMVPH_ID, SPECTRUM_ID "
            "from FICA_MODEL where FICA_MODEL.ID=%s" % modelID
        ).fetchall()[
            0
        ]
        if spectrumID == "None":
            specFlag = -1
        else:
            specFlag = 0
        # getting dica params
        colNames = zip(*curs.execute("PRAGMA table_info(fica_dica)").fetchall())[1]
        colNames = map(str, colNames)
        colValues = curs.execute("select * from fica_dica where id=%s" % dicaID).fetchall()[0]
        dicaDict = dict(zip([dalekDB.convertFields2Dica[item] for item in colNames[1:]], colValues[1:]))
        lum, vph = curs.execute("select LUM, VPH from FICA_LUMVPH where FICA_LUMVPH.ID=%s" % lumVphID).fetchall()[0]
        dicaDict["log_lbol"] = lum
        dicaDict["v_ph"] = vph

        dica = paramMod.dica(initDica=dicaDict, mode="fromDict")

        # getting abundances
        colNames = zip(*curs.execute("PRAGMA table_info(fica_abundance)").fetchall())[1]
        colNames = map(str, colNames)
        colValues = curs.execute("select * from fica_abundance where id=%s" % abundanceID).fetchall()[0]
        compDict = dict(zip(colNames[1:], colValues[1:]))
        comp = paramMod.comp(initComp=compDict, t=dica["t"])
        comp._setNiDecay()

        # getting aSpec
        if specFlag == 0:
            wl = dalekDB.createWLGrid(dicaDict["wl"] * 1e4, dicaDict["grid"] * 1e4, dicaDict["mu"])
            intens = curs.execute("select spectrum from fica_spectrum where id=%s" % abundanceID).fetchall()[0][0]
            aSpec = spectrum(wl, intens)
        elif specFlag == -1:
            aSpec = spectrum(zip(np.linspace(2000, 20000, 20), range(1, 21)))
            sbib = {"llist": []}
            llist = sbib["llist"]
            wParam = []

        # getting llist
        colValues = curs.execute(
            "select eqw, shift, rest, atom, ion, param1, param2, param3 " "from FICA_LLIST where model_id=%d" % modelID
        ).fetchall()
        # checking if llist exists for current model
        if colValues == []:
            llist = None
        else:
            colNames = zip(*curs.execute("PRAGMA table_info(fica_llist)").fetchall())[1]
            colNames = [
                (str(item.lower()), "|S2") if item == "ATOM" else (str(item.lower()), float) for item in colNames[2:]
            ]

            llist = np.array(colValues, dtype=colNames)

        """ Commented out until wParams becomes important, W is safed none the less    
        #getting wParams
        colValues = curs.execute('select XS, VS, LOGRH, TE, TR, W '
                                 'from FICA_WPARAM where FICA_WPARAM.model_id=%d' % model_id).fetchall()
        #checking if WParams exists for current model
        if colValues == []: llist = None
        else:
            colNames = zip(*curs.execute('PRAGMA table_info(fica_WPARAM)').fetchall())[1]
            colNames = [(item.lower(), '|S2') if item=='ATOM' else (item.lower(), float)
                for item in colNames[2:]]
            llist = np.array(colValues, dtype=colNames)
        """
        wParam = None

        curParam = paramMod.param(initDica=dica, initComp=comp)

        return cls(
            aSpec,
            curParam,
            wFactor,
            machineName=machineName,
            execTime=execTime,
            wParam=wParam,
            error=errorString,
            ficaLog=ficaLog,
            llist=None,
            origSpec=origSpec,
            specFlag=specFlag,
        )