def print_elemvar_table(table,outname): # Write the table elems= ['C','N','O','Na','Mg','Al','Si','S','K','Ca','Ti','V','Mn','Fe', 'Ni'] with open(outname,'w') as outfile: cnt= 0 for elemc in elems: # First write total tline= '%s ' % elemc ref= table[elems.index(elemc)][cnt] for ii,elem in enumerate(elems): if elem == elemc: tline+= '& %.3f' % (table[ii][cnt]) else: tline+= '& %i' % (int(round(100.*table[ii][cnt]/ref))) outfile.write(tline+'\\\\\n') cnt+= 1 if _NO_INDIV_WINDOWS: continue # Now do each individual window for jj in range(apwindow.num(elemc,pad=0)): tline= '%s%i ' % (elemc,jj+1) ref= table[elems.index(elemc)][cnt] for ii,elem in enumerate(elems): if elem == elemc: tline+= '& %.3f' % (table[ii][cnt]) else: tline+= '& %i' % (100.*table[ii][cnt]/ref) outfile.write(tline+'\\\\\n') cnt+= 1 return None
def parse_elemvar(): table= calc_elemvar_table.calc_elemvar_table('elemVariations_DR12_M67.sav') # Parse the table for easier use out1= {} out2= {} cnt= 0 for elemc in elems: ref= {} others= {} cnt+= 1 for jj in range(apwindow.num(elemc,pad=0)): ref[jj]= table[elems.index(elemc)][cnt] tothers= [] for ii,elem in enumerate(elems): if elem == elemc: continue else: tothers.append(100.*table[ii][cnt]/ref[jj]) others[jj]= tothers cnt+= 1 out1[elemc]= ref out2[elemc]= others return (out1,out2)
def windows(*args, **kwargs): """ NAME: windows PURPOSE: plot the spectral windows for a given element INPUT: Either: (a) wavelength, spectrum (\AA,spectrum units) (b) spectrum (assumed on standard APOGEE re-sampled wavelength grid) (c) location ID, APOGEE ID (default loads aspcapStar, loads extension ext(=1); apStar=True loads apStar spectrum) +element string (e.g., 'Al'); Adding 1 and 2 splits the windows into two KEYWORDS: plot_weights= (False) if True, also plot the weights for the windows (assumes that the spectrum is on the apStarWavegrid) markLines= mark the location of 'lines' (see apogee.spec.window.lines) apogee.spec.plot.waveregions keywords OUTPUT: plot to output The final axes allow one to put additional labels on the plot, e.g., for adding the APOGEE ID: bovy_plot.bovy_text(r'$\mathrm{%s}$' % '2M02420597+0837017',top_left=True) Note that an ID (e.g., the apogee ID) and Teff, logg, metallicity, and alpha-enhancement labels can be added using the keywords label* above HISTORY: 2015-01-26 - Written (based on older code) - Bovy (IAS) """ pad = kwargs.pop('pad', 3) try: si, ei = apwindow.waveregions(args[2], pad=pad, asIndex=True) except IOError: try: si, ei = apwindow.waveregions(args[2][:-1], pad=pad, asIndex=True) except IOError: raise IOError( "Windows for element %s could not be loaded, please specify an existing APOGEE element" % ((args[2].lower().capitalize()))) if args[2][-1] == '1': si = si[:len(si) // 2] ei = ei[:len(ei) // 2] else: si = si[len(si) // 2:] ei = ei[len(ei) // 2:] # Remove the number from the element newargs = (args[0], args[1], args[2][:-1]) for ii in range(len(args) - 3): newargs = newargs + (args[ii + 3], ) args = newargs # Also get the number and total width of all of the windows dlam = apwindow.total_dlambda(args[2], pad=pad) numw = apwindow.num(args[2]) # Set spacing between windows if numw > 20: kwargs['skipdx'] = 0.003 kwargs['_noskipdiags'] = True elif numw > 15: kwargs['skipdx'] = 0.01 # Set initial space to zero kwargs['_startendskip'] = 0 # Set initial figure width if not kwargs.get('overplot', False) and not 'fig_width' in kwargs: if dlam > 150.: kwargs['fig_width'] = 8.4 else: kwargs['fig_width'] = 4.2 # Don't tick x kwargs['_noxticks'] = True # Label the largest wavelength in angstrom kwargs['_labelwav'] = True # Don't label the lines unless explicitly asked for kwargs['labelLines'] = kwargs.get('labelLines', False) # Plot the weights as well if kwargs.pop('plot_weights', False): kwargs['_plotw'] = apwindow.read(args[2], apStarWavegrid=True) if kwargs.get('apStar', False): kwargs['yrange'] = kwargs.get('yrange', [0., 1.1 * numpy.nanmax(args[1])]) else: kwargs['yrange'] = kwargs.get('yrange', [0., 1.2]) # mark the 'lines' markLines = kwargs.get('markLines', not 'overplot' in kwargs) if markLines and not '_markwav' in kwargs: kwargs['_markwav'] = apwindow.lines(args[2]) # Plot waveregions(args[0], args[1], startindxs=si, endindxs=ei, *args[3:], **kwargs) # Add label bovy_plot.bovy_text(r'$\mathrm{%s}$' % ((args[2].lower().capitalize())), top_left=True, fontsize=10, backgroundcolor='w') return None
def windows(*args,**kwargs): """ NAME: windows PURPOSE: plot the spectral windows for a given element INPUT: Either: (a) wavelength, spectrum (\AA,spectrum units) (b) spectrum (assumed on standard APOGEE re-sampled wavelength grid) (c) location ID, APOGEE ID (default loads aspcapStar, loads extension ext(=1); apStar=True loads apStar spectrum) +element string (e.g., 'Al'); Adding 1 and 2 splits the windows into two KEYWORDS: plot_weights= (False) if True, also plot the weights for the windows (assumes that the spectrum is on the apStarWavegrid) markLines= mark the location of 'lines' (see apogee.spec.window.lines) apogee.spec.plot.waveregions keywords OUTPUT: plot to output The final axes allow one to put additional labels on the plot, e.g., for adding the APOGEE ID: bovy_plot.bovy_text(r'$\mathrm{%s}$' % '2M02420597+0837017',top_left=True) Note that an ID (e.g., the apogee ID) and Teff, logg, metallicity, and alpha-enhancement labels can be added using the keywords label* above HISTORY: 2015-01-26 - Written (based on older code) - Bovy (IAS) """ pad= kwargs.pop('pad',3) try: si,ei= apwindow.waveregions(args[2],pad=pad,asIndex=True) except IOError: try: si, ei= apwindow.waveregions(args[2][:-1],pad=pad,asIndex=True) except IOError: raise IOError("Windows for element %s could not be loaded, please specify an existing APOGEE element" % ((args[2].lower().capitalize()))) if args[2][-1] == '1': si= si[:len(si)//2] ei= ei[:len(ei)//2] else: si= si[len(si)//2:] ei= ei[len(ei)//2:] # Remove the number from the element newargs= (args[0],args[1],args[2][:-1]) for ii in range(len(args)-3): newargs= newargs+(args[ii+3],) args= newargs # Also get the number and total width of all of the windows dlam= apwindow.total_dlambda(args[2],pad=pad) numw= apwindow.num(args[2]) # Set spacing between windows if numw > 20: kwargs['skipdx']= 0.003 kwargs['_noskipdiags']= True elif numw > 15: kwargs['skipdx']= 0.01 # Set initial space to zero kwargs['_startendskip']= 0 # Set initial figure width if not kwargs.get('overplot',False) and not 'fig_width' in kwargs: if dlam > 150.: kwargs['fig_width']= 8.4 else: kwargs['fig_width']= 4.2 # Don't tick x kwargs['_noxticks']= True # Label the largest wavelength in angstrom kwargs['_labelwav']= True # Don't label the lines unless explicitly asked for kwargs['labelLines']= kwargs.get('labelLines',False) # Plot the weights as well if kwargs.pop('plot_weights',False): kwargs['_plotw']= apwindow.read(args[2],apStarWavegrid=True) if kwargs.get('apStar',False): kwargs['yrange']= kwargs.get('yrange', [0.,1.1*numpy.nanmax(args[1])]) else: kwargs['yrange']= kwargs.get('yrange',[0.,1.2]) # mark the 'lines' markLines= kwargs.get('markLines',not 'overplot' in kwargs) if markLines and not '_markwav' in kwargs: kwargs['_markwav']= apwindow.lines(args[2]) # Plot waveregions(args[0],args[1],startindxs=si,endindxs=ei, *args[3:],**kwargs) # Add label bovy_plot.bovy_text(r'$\mathrm{%s}$' % ((args[2].lower().capitalize())), top_left=True,fontsize=10,backgroundcolor='w') return None