In [1]:
# This changes the current directory to the base saga directory - make sure to run this first!
# This is necessary to be able to import the py files and use the right directories,
# while keeping all the notebooks in their own directory.
import os
import sys
import numpy as np
if 'saga_base_dir' not in locals():
saga_base_dir = os.path.abspath('..')
if saga_base_dir not in sys.path:
os.chdir(saga_base_dir)
In [2]:
%matplotlib inline
from matplotlib import pyplot as plt
from matplotlib import rcParams
from matplotlib import style
In [3]:
from __future__ import division, print_function
import os
import numpy as np
from astropy import units as u
from astropy import constants as cnst
from astropy.coordinates import SkyCoord, Distance
from astropy.wcs import WCS
from astropy.io import fits, ascii
from astropy.table import Table
In [58]:
# changes values into steps that can be passed into plt.plot
def vals_to_steps(vals, lower, upper, reverse=False):
svals = np.sort(vals)[::-1] if reverse else np.sort(vals)
vsr = np.repeat(svals, 2)
ns = np.repeat(np.arange(len(vals) + 1), 2)[1:-1]
vsr = np.insert(vsr, 0, lower if reverse else upper)
vsr = np.append(vsr, upper if reverse else lower)
ns = np.insert(ns, [0, -1], [0, ns[-1]])
return vsr, ns
In [4]:
#special import magic w/ cding
pwd = os.path.abspath(os.curdir)
os.chdir(os.environ['HOME']+'/astrodata/mcconn12_nearbydwarfs/')
import nearbygals
ngtab = nearbygals.get_table()
os.chdir(pwd)
In [5]:
ng_MV = ngtab['Vmag'] - ngtab['distmod']#-3.1*ngtab['EBmV']
#fix LMC/SMC manually
#ng_MV[ngtab['name']=='LMC'] =
#ng_MV[ngtab['name']=='LMC'] =
#MV -> Mr: assuming "typcial" B-V=1 and Jester for Stars with Rc-Ic < 1.15 and U-B < 0
BmV = 1
ng_Mr = ng_MV - 0.46*(BmV) + 0.11
Mr_MW_sats = ng_Mr[(20 < ngtab['distance'])&(ngtab['distance'] < 300)]
Anddist = ngtab[ngtab['and_number']==0]['center'][0].separation_3d(SkyCoord(ra=[row.ra for row in ngtab['center']],
dec=[row.dec for row in ngtab['center']],
distance=[row.distance for row in ngtab['center']]))
Mr_And_sats = ng_Mr[Anddist < 300*u.kpc][1:] #First one is actually M31
In [65]:
allspec = Table.read(os.environ['HOME']+'/Dropbox/SAGA/data/allspectaken_v4.fits')
allsats = allspec[(allspec['SATS']==1)&(allspec['REMOVE']==-1)]
allsats
Out[65]:
In [66]:
#double-check that there's no very close pairs/repeats
allsatcoords = SkyCoord(allsats['ra'], allsats['dec'], unit=u.deg)
idx, d2d, d3d = allsatcoords.match_to_catalog_sky(allsatcoords, nthneighbor=2)
plt.hist(d2d.arcsec,range=(0,30))
Out[66]:
In [57]:
nametoids = dict(zip(allsats['HOST_SAGA_NAME'], allsats['HOST_NSAID']))
del nametoids['']
nametoids
Out[57]:
In [59]:
#minus sign means low enough not to put on the plot below
completeness = {'Odyssey':.82,
'Gilgamesh':.78,
'AnaK':.76,
'StarTrek':.84,
'MobyDick':.58,
'Narnia':.52,
'Dune':.74,
'OBrother':.69,
'Alice':-.14,
'Sopranos':-.08,
'Aeneid':.78,
'Beowulf':-.14,
'Hamlet':.35}
In [12]:
plt.figure(figsize=(12,10))
lower, upper = -10, -20
plot_styles = []
color_cycle = style.library['ggplot']['axes.color_cycle']
for line_style in ['--', ':']:
for c in color_cycle:
plot_styles.append(dict(color=c, ls=line_style))
for i, (nm, nsaid) in enumerate(nametoids.items()):
msk = allsats['HOST_NSAID'] == nsaid
satsofhost = allsats[msk]
dm = Distance(satsofhost['HOST_DIST'], u.Mpc).distmod.value
Mr = satsofhost['r'] + satsofhost['Ar'] - dm
compl = completeness.get(nm, 1)
if compl<0:
continue
vals, ns = vals_to_steps(Mr, lower, upper)
plt.plot(vals, ns/compl, lw=2, label=nm, **plot_styles[i])
plt.plot(*vals_to_steps(Mr_MW_sats, lower, upper), label='MW', ls='-', lw=3)
plt.plot(*vals_to_steps(Mr_And_sats, lower, upper), label='M31', ls='-', lw=3)
incomplmag = 20.5*u.mag - Distance(42*u.Mpc).distmod
plt.axvspan(lower, incomplmag.value, alpha=.2,color='k')
plt.xlim(upper, lower)
plt.ylim(0, 10.)
plt.legend(loc=0, fontsize=18)
plt.xlabel(r'$M_r$', fontsize=48)
plt.ylabel(r'$N(<M_r)/C$', fontsize=48)
plt.xticks(fontsize=22)
plt.yticks(fontsize=22)
plt.tight_layout()
plt.savefig('SAGA_LF.png')
plt.savefig('SAGA_LF.pdf')
In [30]:
plt.figure(figsize=(12,10))
lower, upper = -10, -20
plot_styles = []
color_cycle = style.library['ggplot']['axes.color_cycle']
for line_style in ['--', ':']:
for c in color_cycle:
plot_styles.append(dict(color=c, ls=line_style))
sorti = np.argsort(np.array(nametoids.values()))
sortednametoids = zip(np.array(nametoids.keys())[sorti], np.array(nametoids.values())[sorti])
i = -1
for nm, nsaid in sortednametoids:
if nm in ('Ulysses', 'Iliad', 'Hamlet'):
continue
else:
i += 1
msk = allsats['HOST_NSAID'] == nsaid
satsofhost = allsats[msk]
dm = Distance(satsofhost['HOST_DIST'], u.Mpc).distmod.value
Mr = satsofhost['r'] + satsofhost['Ar'] - dm
compl = completeness.get(nm, 1)
if compl<0:
continue
vals, ns = vals_to_steps(Mr, lower, upper)
plt.plot(vals, ns/compl, lw=2, label='NSA {}'.format(nsaid), **plot_styles[i])
plt.plot(*vals_to_steps(Mr_MW_sats, lower, upper), label='MW', ls='-', lw=3)
plt.plot(*vals_to_steps(Mr_And_sats, lower, upper), label='M31', ls='-', lw=3)
incomplmag = 20.5*u.mag - Distance(42*u.Mpc).distmod
plt.axvspan(lower, incomplmag.value, alpha=.2,color='k')
plt.xlim(upper, lower)
plt.ylim(0, 10.)
plt.legend(loc=0, fontsize=18)
plt.xlabel(r'$M_r$', fontsize=48)
plt.ylabel(r'$N(<M_r)/C$', fontsize=48)
plt.xticks(fontsize=22)
plt.yticks(fontsize=22)
plt.tight_layout()
plt.savefig('SAGA_LF.png')
plt.savefig('SAGA_LF.pdf')
In [119]:
allspec = Table.read(os.environ['HOME']+'/Dropbox/SAGA/data/allspectaken_v5.fits.gz')
allsats = allspec[(allspec['SATS']==1)&(allspec['REMOVE']==-1)]
In [120]:
#double-check that there's no very close pairs/repeats
allsatcoords = SkyCoord(allsats['ra'], allsats['dec'], unit=u.deg)
idx, d2d, d3d = allsatcoords.match_to_catalog_sky(allsatcoords, nthneighbor=2)
plt.hist(d2d.arcsec,range=(0,30))
Out[120]:
In [121]:
idx1, idx2, d2d, _ = allsatcoords.search_around_sky(allsatcoords, 1*u.arcsec)
uniquepairs = set([tuple(sorted(pair)) for pair in zip(idx1[idx1!=idx2], idx2[idx1!=idx2])])
msk = np.ones(len(allsats), dtype=bool)
msk[np.array(list(uniquepairs))[:,1]] = False
allsats = allsats[msk]
allsatcoords = SkyCoord(allsats['ra'], allsats['dec'], unit=u.deg)
idx, d2d, d3d = allsatcoords.match_to_catalog_sky(allsatcoords, nthneighbor=2)
plt.hist(d2d.arcsec,range=(0,30))
Out[121]:
In [122]:
nsaids = [147100,150887,61945,148734,166313,165536,149781,33446,140594,85746]
p01_compl = [.34,.12,.57,.15,.54,.39,.27,.43,.19,.36]
p1_compl = [1,.66,.66,.5,.92,.73,1,1,.7,.7]
gri_compl = [.21,.4,.47,.8,.34,.27,.21,.36,.8,.2]
In [123]:
plt.figure(figsize=(12,10))
lower, upper = -10, -20
plot_styles = []
color_cycle = style.library['ggplot']['axes.color_cycle']
for line_style in ['--', ':']:
for c in color_cycle:
plot_styles.append(dict(color=c, ls=line_style))
i = - 1
for nsaid, compl in zip(nsaids, p1_compl):
msk = allsats['HOST_NSAID'] == nsaid
satsofhost = allsats[msk]
dm = Distance(satsofhost['HOST_DIST'], u.Mpc).distmod.value
Mr = satsofhost['r'] + satsofhost['Ar'] - dm
if len(Mr) < 1:
print('skipping', nsaid)
continue
else:
print('NSA', nsaid, 'has', len(Mr), 'sats')
i+=1
vals, ns = vals_to_steps(Mr, lower, upper)
plt.plot(vals, ns/compl, lw=2, label='NSA {}'.format(nsaid), **plot_styles[i])
plt.plot(*vals_to_steps(Mr_MW_sats, lower, upper), label='MW', ls='-', lw=3)
plt.plot(*vals_to_steps(Mr_And_sats, lower, upper), label='M31', ls='-', lw=3)
incomplmag = 20.5*u.mag - Distance(42*u.Mpc).distmod
plt.axvspan(lower, incomplmag.value, alpha=.2,color='k')
plt.xlim(upper, lower)
plt.ylim(0, 10.)
plt.legend(loc=0, fontsize=18)
plt.xlabel(r'$M_r$', fontsize=48)
plt.ylabel(r'$N(<M_r)/C$', fontsize=48)
plt.xticks(fontsize=22)
plt.yticks(fontsize=22)
plt.tight_layout()
plt.savefig('SAGA_LF_2.png')
plt.savefig('SAGA_LF_2.pdf')
In [3]:
sattab = fits.getdata('/Users/erik/Dropbox/SAGA/satellite-learning/galaxies_around_SAGAhosts_allspectra_v2.3.fits.gz')
In [21]:
issat = sattab['SATS']==1
inody = sattab['HOSTNAME']=='Odyssey'
ingilg = sattab['HOSTNAME']=='Gilgamesh'
odysats = sattab[issat&inody]
gilgsats = sattab[issat&ingilg]
len(odysats), len(gilgsats)
Out[21]:
In [206]:
odysats[-2][1]
Out[206]:
In [199]:
Mr_ody_sats = odysats['R'] - odysats['AR'] - Distance(odysats['HOST_DIST']*u.Mpc).distmod.value
Mr_gilg_sats = gilgsats['R'] - gilgsats['AR'] - Distance(gilgsats['HOST_DIST']*u.Mpc).distmod.value
In [207]:
rcParams['xtick.labelsize'] = rcParams['ytick.labelsize'] = 16*2
rcParams['axes.labelsize'] = 24*2
rcParams['legend.fontsize'] = 24
def lumfunc(mag, startat=-20, extend_to=-12, **kwargs):
kwargs.setdefault('where', 'pre')
kwargs.setdefault('lw', 2)
mags = np.sort(mag)
Mr, n = np.r_[mags, mags[-1]], np.arange(len(mags)+1)
if extend_to and mags[-1] < extend_to:
Mr = np.r_[Mr, extend_to]
n = np.r_[n, n[-1]]
if startat and mags[0] > startat:
Mr = np.r_[startat, Mr]
n = np.r_[0, n]
return plt.step(Mr, n, **kwargs)
plt.figure(figsize=(10,10))
lumfunc(Mr_gilg_sats, label='NGC 5962', lw=4)
lumfunc(Mr_ody_sats, label='NGC 6181', ls='-', lw=4)
lumfunc(Mr_MW_sats, label='MW', ls='--', lw=2)
lumfunc(Mr_And_sats, label='M31', ls='--', lw=2)
plt.axvline(-12, color='k', ls=':')
plt.xlim(-20,-9.5)
plt.ylim(-.1,9.1)
plt.yticks(np.arange(10))
magstr = 'M_r'
plt.xlabel('${magstr}$'.format(**locals()))
plt.ylabel('$N(<{magstr})$'.format(**locals()))
plt.legend(loc=0)
plt.tight_layout()
plt.savefig('/Users/erik/Desktop/aatprop_lumfunc.pdf')
plt.savefig('/Users/erik/Desktop/aatprop_lumfunc.eps')
plt.savefig('/Users/erik/Desktop/aatprop_lumfunc.png')
In [ ]: