def MakeLineListTable(ions=[], wls=[], outFile=d.TableDir + 'Table2.dat'): lines, refs = LL.getLines(elements=ions, wavelengthRange=wls,\ dataFormat=None) unused1, unused2, weights = RC.GetSolarCorrections() fp = open(outFile, 'w') fmt, db = BuildFormatString(table2Format, DataLabels=table2Labels, DataUnits=table2Units, DataExp=table2Desc, MakeBbBDesc=True) fp.write(db) allIons = sorted(set(np.array(lines)[:, 1])) lineData = [] for i in allIons: ion = np.round(i, decimals=1) (elem, state, unused) = el.getIonState(el.getIonName(ion)) ionLines = np.array( sorted([l for l in lines if np.round(l[1], decimals=1) == ion], key=lambda l: l[0])) for line in ionLines: wl = np.round(line[0], decimals=3) xp = line[2] gf = line[3] if gf < 0: gfs = '-' else: gfs = '' gf = abs(gf) try: qu = int(weights[ion][wl]) except KeyError: qu = 0 rf = line[5] lineData.append([elem, state, wl, xp, gfs, gf, qu, rf]) for line in lineData: fp.write(fmt.format(*line) + '\n') fp.close()
def MakeSolarCompTable(outFilename=k.TempAbOutFilename, headerLeft='', headerRight=''): # Function creates a LaTeX table with elemental abundances as calculated from # our Solar reference spectrum, based on a "quality" measurement of each line. # Each column of the table represents a measurement using lines of a particular # quality or better. The final column is represents all of the measured lines. corrections, lines, weights = RC.GetSolarCorrections() # We're going to create one column for each "quality" setting from the # returned weights list. Basically, each weight is a quality level. # The columnDict contains: # {weight:{ion:[ab,std,#lines],...},...} columnDict = {} for wt in k.AbWeights: columnDict[wt] = {} allIonList = sorted(lines.keys()) for ion in allIonList: ionLines = lines[ion] # A single line will not show up as a list of one item. Rather, the # entire list will be that one line's parameters...grrr. if not u.is_list(ionLines[0]): ionLines = [ionLines] for wt in k.AbWeights: wtLines = np.array([line for line in ionLines \ if line[0] in weights[ion] and weights[ion][line[0]] >= wt]) if len(wtLines) > 0: asplundCorr = PA.ptoe[int(ion) - 1][PA.abIdx] columnDict[wt][ion] = [ np.mean(wtLines[:, 5]) + asplundCorr, np.std(wtLines[:, 5]), len(wtLines) ] # Create a nice column title for each quality type: nameList = [ r'$\Delta\leq{0:1.2f}$'.format(r[1]) for r in k.AbWeightRanges[:-1] ] nameList.append('All lines') outfile = open(outFilename, 'w') latexHeader = STP.kLaTexHeader1 + '\\rhead{\\textbf{' + headerRight\ + '}}\n\\lhead{\\textbf{' + headerLeft\ + '}}\n\\begin{document}\n' outfile.write(latexHeader) outfile.write('\\begin{landscape}\n'\ + '\\hspace*{-5cm}\n'\ + '\\begin{tabular}{|l|l|l|l|l|l|l|l|l|l|') outfile.write( '}\n\\multicolumn{1}{l}{Ion} & \\multicolumn{1}{l}{Asplund (2009)}') for name in nameList: outfile.write(' & \\multicolumn{{1}}{{l}}{{{0}}}'.format(name)) outfile.write('\\\\\n\\hline\n') for ion in allIonList: outfile.write('{0} & {1:1.2f}$\pm${2:1.2f}'.format(el.getIonName(ion),\ PA.ptoe[int(ion)-1][PA.abIdx],\ PA.ptoe[int(ion)-1][PA.solarErrIdx])) for wt in k.AbWeights: if ion in columnDict[wt].keys() and columnDict[wt][ion][2] > 0: outfile.write(' & {0:1.2f}$\pm${1:1.2f} ({2:d})'.\ format(columnDict[wt][ion][0]-PA.ptoe[int(ion)-1][PA.abIdx], columnDict[wt][ion][1], columnDict[wt][ion][2])) else: outfile.write(' & \\multicolumn{1}{c|}{---} ') outfile.write('\\\\\n\\hline\n') outfile.write('\\label{{tab:SolarAbs}}\n' + '\\end{tabular}\n\\end{landscape}\n' + '\\clearpage\n') outfile.write('\\end{document}\n') outfile.close()
def PlotXPAbs(starData, clusterName='NGC-0752', ionList=kAllIonList, fileTag='', labelPlot=True, labelPoints=False, showTrendLine=False, modelAtms=None, pradks=None, referenceCorrect=False): # Make XP vs. Ab for the passed star # One element per plot. starName = starData[0] starParmTuple = tuple(starData[1:]) isGiant = RC.isGiantStar(starParmTuple) if isGiant: modelPath = k.GiantModelPath else: modelPath = k.DwarfModelPath if modelAtms == None or pradks == None: modelFiles = mk.findDataFiles(modelPath) modelAtms, pradks = mk.LoadModels(modelFiles) abdict, uncorrLines, unusedMin, unusedMax = \ AB.CalcAbsAndLines(clusterName+' '+starName, tuple(starData[1:6]), ionList=ionList, modelAtms=modelAtms, pradks=pradks) # uncorrLines: # # {elem.ion:[[Wavelength, Ex.Pot., logGf, eqw, logRW, abund],...]} if referenceCorrect: if isGiant: # Obligatory comment on bad Giant corrections, and using # Solar instead. correctDict, referenceLines, lineWeights = \ RC.GetSolarCorrections(ionList=ionList, modelAtms=modelAtms, pradks=pradks) else: correctDict, referenceLines, lineWeights = \ RC.GetDwarfCorrections(ionList=ionList, modelAtms=modelAtms, pradks=pradks) correctionsAvailable = False if len(correctDict) > 0 and len(referenceLines) > 0: correctionsAvailable = True for ion in ionList: if ion not in uncorrLines.keys(): continue # Does this element have NLTE corrections available? Note: we do # this BEFORE Solar corrections, which assumes that the same # NLTE corrections are already applied to any Solar corrections # we use. if ion in NLTEIons: LTELines = AB.CorrectNLTEAbs(ion, uncorrLines[ion], tuple(starData[1:6])) else: if ion in uncorrLines.keys(): LTELines = uncorrLines[ion] else: # Either synthesized lines, or none available LTELines = np.array([]) # Do we want the "reference corrected" abundances? if referenceCorrect and correctionsAvailable: tempAdj,tempAll = \ RC.SortAndFilterLines(LTELines, ion, tuple(starData[1:6]), solarCorrect=referenceCorrect, solarLines=referenceLines[ion], solarCorrs=correctDict[ion], lineWeights=lineWeights[ion]) # correctedLines: # [[ab, line STR score, wl, "quality"], ...] # allLines: # [[ab, line STR score, wl],...] # We want to use np.arrays, so... allLines = np.array(tempAll) correctedLines = np.array(tempAdj) if len(allLines) == 0 or len(correctedLines) == 0: correctionsAvailable = False elif len(allLines) == 1 or len(correctedLines) == 1: print('Single Line determination:{0}'.format(starData[0])) print(allLines, correctedLines) # One plot per ion. if labelPlot: plotLabel = 'XP vs Ab for [{2}/H] in {0} {1}.'.\ format(clusterName, starName, el.getIonName(ion)) else: plotLabel = '' if referenceCorrect and correctionsAvailable: tempPoints = [] for line in uncorrLines[ion]: correctedAbs = [l[0] for l in correctedLines if \ u.in_range(l[2],line[0]-0.05, line[0]+0.05)] if len(correctedAbs) > 0: tempPoints.append( [line[1], np.mean(correctedAbs), line[3], line[0]]) else: tempPoints.append([line[1], line[5], line[3], line[0]]) XPAbPoints = np.array(tempPoints) else: XPAbPoints = np.array([[line[1],line[5],line[3],line[0]]\ for line in uncorrLines[ion]]) if labelPoints: # Label the points with the wavelength pointLabels = ['{0:2.3f}'.format(point[3]) \ for point in XPAbPoints] else: pointLabels = None ps.XPAbPlot(XPAbPoints, starName, ion, fileTag=fileTag + 'XPAb', plotTitle=plotLabel, pointLabels=pointLabels, showTrendLine=showTrendLine)
def GetAbTable(clusterName='NGC-0752', starDataList=None, ions=kAllIonList, filterBlends=False, referenceCorrect=False, useDAOSpec=False, gModelAtms=None, gPradks=None, dModelAtms=None, dPradks=None): # Returns a dictionary with each star name (key) has a list of elements # (secondary key), with a list containing [Abundance in [X/H], variance in the # line measurements, count of lines measured, average quality score]: # returnDict={starName:{ion:[[X/H],stdev, count, avg.quality],...},...} if starDataList == None: starDataList = GetAllStarParms(clusterName=clusterName) # Since we're doing a bunch of lines (uh...), we'll need both giant and # dwarf references. Giant references are prefixed by a 'g', dwarfs by 'd'. if gModelAtms == None or gPradks == None: gModelFiles = mk.findDataFiles(k.GiantModelPath) gModelAtms, gPradks = mk.LoadModels(gModelFiles) if dModelAtms == None or dPradks == None: dModelFiles = mk.findDataFiles(k.DwarfModelPath) dModelAtms, dPradks = mk.LoadModels(dModelFiles) # We need iron to do relative abundances: if 26.0 not in ions: ions.append(26.0) # Turns out our giant corrections are not good # gCorrectDict, gReferenceLines, gLineWeights = \ # GetGiantCorrections(ionList=ions, # modelAtms=gModelAtms, # pradks=gPradks) # So, use the Solar corrections for now gCorrectDict, gReferenceLines, gLineWeights = \ RC.GetSolarCorrections(ionList=ions, modelAtms=dModelAtms, pradks=dPradks) dCorrectDict, dReferenceLines, dLineWeights = \ RC.GetDwarfCorrections(ionList=ions, modelAtms=dModelAtms, pradks=dPradks) tableDict = {} for starData in starDataList: starName = starData[0] starParms = tuple(starData[1:6]) if RC.isGiantStar(starParms): modelAtms = gModelAtms pradks = gPradks referenceLines = gReferenceLines referenceDict = gCorrectDict lineWeights = gLineWeights else: modelAtms = dModelAtms pradks = dPradks referenceLines = dReferenceLines referenceDict = dCorrectDict lineWeights = dLineWeights tableDict[starName] = GetAbsForStar(starData, ions=ions,\ filterBlends=filterBlends, refCorrect=referenceCorrect,\ refDict=referenceDict, refLines=referenceLines, \ lineWeights=lineWeights, useDAOSpec=useDAOSpec, \ modelAtms=modelAtms, pradks=pradks) return tableDict
def MakeVPlots(clusterName='NGC-0752', starDataList=None, fileTag='', filterBlends=False, referenceCorrect=False, useDAOSpec=False, ions=[20.0]): # Function plots V_turb vs. sigma [Ca/H] (sigma is the line-to-line # standard deviation of the measured Ca lines), for a range of V_turb values. # Intended to provide a spectroscopic confirmation/adjustment # for photometrically-determined parameters. if starDataList is None: starDataList = STP.GetAllStarParms(clusterName=clusterName) dModelFiles = mk.findDataFiles(k.DwarfModelPath) dModelAtms, dPradks = mk.LoadModels(dModelFiles) dCorrectDict, dReferenceLines, dLineWeights = \ RC.GetDwarfCorrections(ionList=ions, modelAtms=dModelAtms, pradks=dPradks) gModelFiles = mk.findDataFiles(k.GiantModelPath) gModelAtms, gPradks = mk.LoadModels(gModelFiles) # Note: We're using dwarf corrections for giant stars... # because they're better than giant corrections for the # giant stars. This needs to be fixed. :( gCorrectDict, gReferenceLines, gLineWeights = \ RC.GetSolarCorrections(ionList=ions, modelAtms=dModelAtms, pradks=dPradks) # For now, CaI appears to work best for all stars. # VI, Ti I/II, Fe I/II, Cr I/II also work, but not as well - (See Reddy, et al. 2012). # ions = [20.0] abDict = {} colorArray=['r','orange','gold','darkgreen','navy',\ 'm','saddlebrown','skyblue','hotpink'] for starParms in starDataList: if RC.isGiantStar(starParms[1:]): modelAtms = gModelAtms pradks = gPradks refLines = gReferenceLines refDict = gCorrectDict lineWeights = gLineWeights else: modelAtms = dModelAtms pradks = dPradks refLines = dReferenceLines refDict = dCorrectDict lineWeights = dLineWeights starPoints = {} for v in np.linspace(0.5, 3.0, 26): parmTuple = (starParms[0], starParms[1], starParms[2], v, \ starParms[4], starParms[5], starParms[6]) abDict[v] = STP.GetAbsForStar(parmTuple, ions=ions,\ filterBlends=filterBlends, refCorrect=referenceCorrect,\ refDict=refDict, refLines=refLines, lineWeights=lineWeights,\ useDAOSpec=useDAOSpec, modelAtms=modelAtms, pradks=pradks) for ion in abDict[v].keys(): if ion not in starPoints.keys(): starPoints[ion] = {} if abDict[v][ion][0] == 0.: continue starPoints[ion][v] = abDict[v][ion][1] colorIdx = 0 ymaxes = [] for ion in starPoints.keys(): Xs = sorted(np.array(list(starPoints[ion].keys()))) if len(Xs) == 0 or ion in STP.SynthAbsDict.keys(): continue Ys = np.array([starPoints[ion][x] for x in Xs]) if len(Xs) < 2 or len(Ys) < 2: continue Ys = Ys / min(Ys) ymaxes.append(max(Ys)) try: minV = Xs[np.where(Ys == min(Ys))[0][0]] except IndexError: continue pyplot.plot(Xs, Ys, label=r'$({1}) V_{{turb}}={0:3.1f}km/sec$'.format( minV, el.getIonName(ion)), color=colorArray[colorIdx]) pyplot.scatter(Xs, Ys, color=colorArray[colorIdx]) pyplot.axvline(minV, linestyle=':', color=colorArray[colorIdx]) colorIdx += 1 if colorIdx == len(colorArray): colorIdx = 0 ax = pyplot.gca() ax.set_xlabel(r'$V_{{turb}} km/s$') ax.set_ylabel('Normalized [X/H] variance') ax.set_ylim((0., min(5.0, max(ymaxes)))) pyplot.legend(fontsize=8) pyplot.savefig(k.ParmPlotDir + 'Vturb/' + starParms[0] + fileTag + '.png') pyplot.close()