def getOrigSpec(path=None, preProcess=False): from pyspec.spectrum import spectrum mainPath = getCurMainDir(path) origSpec = spectrum(os.path.join(mainPath, "spectra", "origspect.dat")) if preProcess: origSpec = initialize.preProcessOrigSpec(origSpec) return origSpec
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, )
def importOldSNDir(path, conn): #importing the old sn directory to sqlite from before the sqlite era snSpectraDirs = glob(os.path.join(os.path.abspath(path), '????-??-??T??-??-??')) for specDir in snSpectraDirs: snSpec = spectrum(os.path.join(os.path.abspath(specDir), 'spectra','origspect.dat')) snDate = datetime.datetime.strptime(os.path.basename(specDir), '%Y-%m-%dT%H-%M-%S') conn.execute('insert into SN_SPECTRA (DATE, SPECTRUM) ' 'values (?, ?)', (snDate, makeZipPickle(snSpec)))
def runElementRatio(dica,comp,element,ratios=[0.5,2],ax=None): abundance=comp[element] ratioSpec=[] for ratio in ratios+[1]: comp[element]=ratio*abundance runManual(dica,comp,origspec,backup=False) ratioSpec.append(spectrum('spct.dat',usecols=(0,2))) if ax==None: fig=pylab.figure(1) fig.clf() ax=fig.add_subplot(111) ax.plot(origspec.x,origspec.y,lw=3,color='blue') for ratio,spec in zip(ratios+[1],ratioSpec): ax.plot(spec.x,spec.y,label='%s = %s'%(element,ratio*abundance)) ax.legend()
def getHistSpec(id): return spectrum('hist/spct.bak%04d'%id,usecols=(0,2))
def getCurSpectrum(): return spectrum('spct.dat',usecols=(0,2))
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, )