Last active
August 29, 2015 14:27
-
-
Save jobovy/18c61ba261d5ee7661f8 to your computer and use it in GitHub Desktop.
Some simple scripts to look at the distance distribution of APOGEE-1 stars in different parts of the Galaxy with different color cuts, in preparation for APOGEE-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import numpy | |
from galpy.util import bovy_plot | |
import apogee.tools.read as apread | |
from matplotlib import pyplot | |
_DISTTAG= 'DISO_GAL' | |
def plot_distance_cohorts(plotfilename,region='inner'): | |
#Read the data | |
data= apread.allStar(adddist=True,distredux='v402',main=True) | |
#Cut the data to the relevant region | |
if region.lower() == 'inner': | |
data=\ | |
data[((data['GLON'] <= 45.)+(data['GLON'] >= (360.-45.)))\ | |
*(numpy.fabs(data['GLAT']) <= 15.)\ | |
*(data[_DISTTAG] >= -1.)] | |
elif region.lower() == 'innernobulge': | |
data=\ | |
data[(data['GLON'] <= 45.)*(data['GLON'] >= 20.)\ | |
*(numpy.fabs(data['GLAT']) <= 15.)\ | |
*(data[_DISTTAG] >= -1.)] | |
elif region.lower() == 'innernobulgeexpanded': | |
data=\ | |
data[(data['GLON'] <= 65.)*(data['GLON'] >= 20.)\ | |
*(numpy.fabs(data['GLAT']) <= 15.)\ | |
*(data[_DISTTAG] >= -1.)] | |
elif region.lower() == 'outer': | |
data=\ | |
data[(data['GLON'] > 45.)*(data['GLON'] < (360.-45.))\ | |
*(numpy.fabs(data['GLAT']) <= 15.)\ | |
*(data[_DISTTAG] >= -1.)] | |
elif region.lower() == 'halo': | |
data=\ | |
data[(numpy.fabs(data['GLAT']) > 15.)\ | |
*(data[_DISTTAG] >= -1.)] | |
elif region.lower() == 'allhalo': | |
data= apread.allStar(adddist=True,distredux='v402',main=False) | |
data=\ | |
data[(numpy.fabs(data['GLAT']) > 15.)\ | |
*(data[_DISTTAG] >= -1.)] | |
elif region.lower() == 'all': | |
data=\ | |
data[(data[_DISTTAG] >= -1.)] | |
#Short cohorts, 0.5 <= J-Ks < 0.8 | |
tindx= (data['H'] <= 12.2)\ | |
*(data['J0']-data['K0'] >= 0.5)\ | |
*(data['J0']-data['K0'] < 0.8) | |
nshortblue= numpy.sum(tindx) | |
chist= 1.-numpy.cumsum(numpy.ones(numpy.sum(tindx)))/float(numpy.sum(tindx)) | |
bovy_plot.bovy_print() | |
lineshortblue= bovy_plot.bovy_plot(sorted(data[_DISTTAG][tindx]),chist,'k-', | |
xrange=[0.,15.],yrange=[0.,1.05], | |
xlabel=r'$\mathrm{distance\,(kpc)}$', | |
ylabel=r'$\mathrm{fraction\ at}\ >\ \mathrm{distance}$', | |
lw=2.) | |
bovy_plot.bovy_plot([sorted(data[_DISTTAG][tindx])[numpy.argmin(numpy.fabs(chist-0.5))], | |
sorted(data[_DISTTAG][tindx])[numpy.argmin(numpy.fabs(chist-0.5))]], | |
[0.,0.5],'k-',overplot=True) | |
#Short cohorts, J-Ks >= 0.8 | |
tindx= (data['H'] <= 12.2)\ | |
*(data['J0']-data['K0'] >= 0.8) | |
nshortred= numpy.sum(tindx) | |
chist= 1.-numpy.cumsum(numpy.ones(numpy.sum(tindx)))/float(numpy.sum(tindx)) | |
lineshortred= bovy_plot.bovy_plot(sorted(data[_DISTTAG][tindx]),chist,'k--', | |
overplot=True,lw=2.) | |
bovy_plot.bovy_plot([sorted(data[_DISTTAG][tindx])[numpy.argmin(numpy.fabs(chist-0.5))], | |
sorted(data[_DISTTAG][tindx])[numpy.argmin(numpy.fabs(chist-0.5))]], | |
[0.,0.5],'k--',overplot=True) | |
#Medium cohorts, 0.5 <= J-Ks < 0.8 | |
tindx= (data['H'] > 12.2)*(data['H'] <= 12.8)\ | |
*(data['J0']-data['K0'] >= 0.5)\ | |
*(data['J0']-data['K0'] < 0.8) | |
nmediumblue= numpy.sum(tindx) | |
chist= 1.-numpy.cumsum(numpy.ones(numpy.sum(tindx)))/float(numpy.sum(tindx)) | |
bovy_plot.bovy_print() | |
linemediumblue= bovy_plot.bovy_plot(sorted(data[_DISTTAG][tindx]),chist,'r-', | |
overplot=True,lw=2.) | |
bovy_plot.bovy_plot([sorted(data[_DISTTAG][tindx])[numpy.argmin(numpy.fabs(chist-0.5))], | |
sorted(data[_DISTTAG][tindx])[numpy.argmin(numpy.fabs(chist-0.5))]], | |
[0.,0.5],'r-',overplot=True) | |
#Medium cohorts, J-Ks >= 0.8 | |
tindx= (data['H'] > 12.2)*(data['H'] <= 12.8)\ | |
*(data['J0']-data['K0'] >= 0.8) | |
nmediumred= numpy.sum(tindx) | |
chist= 1.-numpy.cumsum(numpy.ones(numpy.sum(tindx)))/float(numpy.sum(tindx)) | |
linemediumlong= bovy_plot.bovy_plot(sorted(data[_DISTTAG][tindx]),chist,'r--', | |
overplot=True,lw=2.) | |
bovy_plot.bovy_plot([sorted(data[_DISTTAG][tindx])[numpy.argmin(numpy.fabs(chist-0.5))], | |
sorted(data[_DISTTAG][tindx])[numpy.argmin(numpy.fabs(chist-0.5))]], | |
[0.,0.5],'r--',overplot=True) | |
#Long cohorts, 0.5 <= J-Ks < 0.8 | |
tindx= (data['H'] > 12.8)\ | |
*(data['J0']-data['K0'] >= 0.5)\ | |
*(data['J0']-data['K0'] < 0.8) | |
nlongblue= numpy.sum(tindx) | |
chist= 1.-numpy.cumsum(numpy.ones(numpy.sum(tindx)))/float(numpy.sum(tindx)) | |
bovy_plot.bovy_print() | |
linelongblue= bovy_plot.bovy_plot(sorted(data[_DISTTAG][tindx]),chist,'-',color='lightgreen', | |
overplot=True,lw=2.) | |
bovy_plot.bovy_plot([sorted(data[_DISTTAG][tindx])[numpy.argmin(numpy.fabs(chist-0.5))], | |
sorted(data[_DISTTAG][tindx])[numpy.argmin(numpy.fabs(chist-0.5))]], | |
[0.,0.5],'-',color='lightgreen',overplot=True) | |
#Long cohorts, J-Ks >= 0.8 | |
tindx= (data['H'] > 12.8)\ | |
*(data['J0']-data['K0'] >= 0.8) | |
nlongred= numpy.sum(tindx) | |
chist= 1.-numpy.cumsum(numpy.ones(numpy.sum(tindx)))/float(numpy.sum(tindx)) | |
if numpy.sum(tindx) > 0: | |
linelongred= bovy_plot.bovy_plot(sorted(data[_DISTTAG][tindx]),chist,'--', | |
color='lightgreen', | |
overplot=True,lw=2.) | |
bovy_plot.bovy_plot([sorted(data[_DISTTAG][tindx])[numpy.argmin(numpy.fabs(chist-0.5))], | |
sorted(data[_DISTTAG][tindx])[numpy.argmin(numpy.fabs(chist-0.5))]], | |
[0.,0.5],'--',color='lightgreen',overplot=True) | |
#Add legend | |
pyplot.legend((lineshortblue[0],linemediumblue[0],linelongblue[0]), | |
(r'$\mathrm{short\ (%i,%i)}$' % (nshortblue,nshortred), | |
r'$\mathrm{medium\ (%i,%i)}$' % (nmediumblue,nmediumred), | |
r'$\mathrm{long\ (%i,%i)}$' % (nlongblue,nlongred)), | |
loc='upper right',#bbox_to_anchor=(.91,.375), | |
numpoints=2, | |
prop={'size':14}, | |
frameon=False) | |
if region.lower() == 'inner': | |
bovy_plot.bovy_text(r'$|l| \leq 45^\circ, |b| \leq 15^\circ$', | |
bottom_left=True,size=14.) | |
elif region.lower() == 'innernobulge': | |
bovy_plot.bovy_text(r'$20 \leq l \leq 45^\circ, |b| \leq 15^\circ$', | |
bottom_left=True,size=14.) | |
elif region.lower() == 'innernobulgeexpanded': | |
bovy_plot.bovy_text(r'$20 \leq l \leq 65^\circ, |b| \leq 15^\circ$', | |
bottom_left=True,size=14.) | |
elif region.lower() == 'outer': | |
bovy_plot.bovy_text(r'$|l| > 45^\circ, |b| \leq 15^\circ$', | |
bottom_left=True,size=14.) | |
elif region.lower() == 'halo': | |
bovy_plot.bovy_text(r'$|b| > 15^\circ$', | |
bottom_left=True,size=14.) | |
bovy_plot.bovy_end_print(plotfilename) | |
return None | |
if __name__ == '__main__': | |
if len(sys.argv) > 2: | |
plot_distance_cohorts(sys.argv[1],sys.argv[2]) | |
else: | |
plot_distance_cohorts(sys.argv[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, os.path | |
import numpy | |
_TARGETFILE= os.path.join(os.getenv('DATADIR'),'bovy','apogee-srd', | |
'APOGEE2_Visit_Plan_Dec2013.csv') | |
def read_targeting(targetfile=None): | |
if targetfile is None: | |
targetfile= _TARGETFILE | |
ls= [] | |
bs= [] | |
nvis= [] | |
type= [] | |
targetfile= open(targetfile,'r') | |
for line in targetfile: | |
if line[0] == ';': continue | |
lines= line.split() | |
ls.append(float(lines[2])) | |
bs.append(float(lines[3])) | |
nvis.append(int(lines[4])) | |
type.append(lines[5]) | |
return (numpy.array(ls),numpy.array(bs),numpy.array(nvis,dtype='int'), | |
numpy.array(type)) | |
def calc_disk_targeting_numbers(targetfile=None, | |
fiber_alloc=[90,90,45], | |
fracred=0.5): | |
data= read_targeting(targetfile=targetfile) | |
#Number of visits in the various categories | |
nVis= numpy.sum((data[3] == 'disk')*(data[2] == 3))*3\ | |
+numpy.sum((data[3] == 'disk')*(data[2] == 6))*6\ | |
+numpy.sum((data[3] == 'disk')*(data[2] == 12))*12\ | |
+numpy.sum((data[3] == 'disk')*(data[2] == 24))*24 | |
nshortVis= (numpy.sum((data[3] == 'disk')*(data[2] == 3))+2*numpy.sum((data[3] == 'disk')*(data[2] == 6))+4*numpy.sum((data[3] == 'disk')*(data[2] == 12))+6*numpy.sum((data[3] == 'disk')*(data[2] == 24))) | |
nmediumVis= (numpy.sum((data[3] == 'disk')*(data[2] == 6))+2*numpy.sum((data[3] == 'disk')*(data[2] == 12))+2*numpy.sum((data[3] == 'disk')*(data[2] == 24))) | |
nlongVis= (numpy.sum((data[3] == 'disk')*(data[2] == 12))+numpy.sum((data[3] == 'disk')*(data[2] == 24))) | |
#Number of targets in the various categories | |
nshort= nshortVis*fiber_alloc[0] | |
nmedium= nmediumVis*fiber_alloc[1] | |
nlong= nlongVis*fiber_alloc[2] | |
print "Total number of stars:", nshort+nmedium+nlong | |
print "Total number of visits:", nVis | |
print "Number of short, medium, and long cohorts:", nshortVis, nmediumVis,\ | |
nlongVis | |
print "Number of short, medium, and long stars:", nshort, nmedium,\ | |
nlong | |
#Definitions | |
fracGtr5Blue= [0.15,0.4,0.5] | |
fracGtr5Red= [0.5,0.75,0.75] | |
fracGtr8Blue= [0.04,0.06,0.1] | |
fracGtr8Red= [0.15,0.3,0.3] | |
fracblue= 1.-fracred | |
#Calculate fraction of stars at > 5 kpc | |
print "Number of stars at distances > 5 kpc:",\ | |
nshort*(fracblue*fracGtr5Blue[0]+fracred*fracGtr5Red[0])\ | |
+nmedium*(fracblue*fracGtr5Blue[1]+fracred*fracGtr5Red[1])\ | |
+nlong*(fracblue*fracGtr5Blue[2]+fracred*fracGtr5Red[2]) | |
#Calculate fraction of stars at > 8 kpc | |
print "Number of stars at distances > 8 kpc:",\ | |
nshort*(fracblue*fracGtr8Blue[0]+fracred*fracGtr8Red[0])\ | |
+nmedium*(fracblue*fracGtr8Blue[1]+fracred*fracGtr8Red[1])\ | |
+nlong*(fracblue*fracGtr8Blue[2]+fracred*fracGtr8Red[2]) | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment