def des_stream_min_depths(survey='LSST10', maglim=None): if maglim is None: maglim_g = mock_sim.getMagLimit('g', survey) maglim_r = mock_sim.getMagLimit('r', survey) else: maglim_g, maglim_r = [maglim] * 2 depths = [] for stream in STREAMS.keys(): min_detectable_depth = min_gap_depth( STREAMS[stream]['distance'], STREAMS[stream]['surface_brightness'], STREAMS[stream]['width'], maglim_g, maglim_r, survey) depths.append(min_detectable_depth) print stream, min_detectable_depth output = np.vstack([STREAMS.keys(), depths]).T try: np.savetxt('min_depths_%s.txt' % survey, output, delimiter=', ', fmt='%s') except: print 'saving error' return depths
def plot_output_distance(filename, mus=[30.], distances=[20.], velocities=[150.], impact_parameters=[1.], maglims=[None], latitudes=[60.], surveys=['LSST'], gap_fill=True): output = np.genfromtxt('output.txt', unpack=True, delimiter=', ', dtype=None, names=['dist', 'w', 'b', 'maglim', 'lat', 'gap_fill', 'survey', 'mu', 'mass'], encoding='bytes') plt.figure() for survey in surveys: for lat in latitudes: for maglim in maglims: for b in impact_parameters: for w in velocities: for mu in mus: ret = [] if maglim == None: maglim = mock_sim.getMagLimit('g', survey) for distance in distances: idx = (output['dist'] == distance) & (output['w'] == w) & (output['b'] == b) & (output['maglim'] == np.around( maglim, 2)) & (output['survey'] == survey) & (output['gap_fill'] == gap_fill) & (output['mu'] == mu) # print idx mass = output['mass'][idx][0] ret.append(mass) try: label = '' if len(mus) > 1: label += r'$ \mu = %d$' % mu # \ \mathrm{mag/arcsec^2} if len(velocities) > 1: label += r'$ w = %d \mathrm{km/s}$' % w if len(impact_parameters) > 1: label += r'$ b = %d \mathrm{r_s}$' % b if len(maglims) > 1: label += r'$\mathrm{ maglim =} %d$' % maglim if len(latitudes) > 1: label += r'$\mathrm{ lat = %d}$' % lat if len(surveys) > 1: label += r'$\mathrm{ %s}$' % survey if label == '': label = r'$\mathrm{mu=%d, w=%d, b=%d, mag=%d, lat=%d, %s}$' % (mu, w, b, maglim, lat, survey) except: label = r'$\mathrm{d=%d, w=%d, b=%d, mag=%d, lat=%d, %s}$' % (mu, w, b, maglim, lat, survey) plt.semilogy(distances, ret, 'o-', label=label) # label='d = %d, w = %d, b = %d' % (distance, w, b) plt.legend(loc='upper left', fontsize=10) plt.title(r'$\mathrm{Minimum\ Detectable\ Halo\ Mass}$') plt.xlabel(r'$\mathrm{Distance}\ \mathrm{(kpc)}$',) plt.ylabel(r'$M_{\mathrm{halo}}\ \mathrm{(M_{\odot})}$',) plt.tight_layout() plt.savefig('%s.png' % filename)
def final_plot(filename=None, mus=[30., 31., 32., 33.], surveys=['SDSS', 'LSST10'], w=150., b=1., maglim=None, lat=60., gap_fill=True): output = np.genfromtxt('output.txt', unpack=True, delimiter=', ', dtype=None, names=[ 'dist', 'w', 'b', 'maglim', 'lat', 'gap_fill', 'survey', 'mu', 'mass' ], encoding='bytes') colors = ['cornflowerblue', 'seagreen', 'darkslateblue'] markers = ['s', 'o', 'd'] plt.figure() for i, survey in enumerate(surveys): maglim = mock_sim.getMagLimit('g', survey) ret10 = [] ret20 = [] ret40 = [] for mu in mus: idx = (output['w'] == w) & (output['b'] == b) & ( output['maglim'] == np.around( maglim, 2)) & (output['survey'] == survey) & ( output['gap_fill'] == gap_fill) & (output['mu'] == mu) idx10 = idx & (output['dist'] == 10) idx20 = idx & (output['dist'] == 20) idx40 = idx & (output['dist'] == 40) mass10 = output['mass'][idx10][0] mass20 = output['mass'][idx20][0] mass40 = output['mass'][idx40][0] ret10.append(mass10) ret20.append(mass20) ret40.append(mass40) label = r'$\mathrm{%s}$' % survey plt.semilogy( mus, ret20, 'o-', label=label, c=colors[i], marker=markers[i], zorder=1) # label='d = %d, w = %d, b = %d' % (distance, w, b) plt.fill_between(mus, ret10, ret40, alpha=0.2, color=colors[i], zorder=0) plt.legend(loc='upper left', fontsize=12) plt.ylabel(r'$M_{\mathrm{vir}}(z=0)\ \mathrm{(M_{\odot})}$', ) plt.xlabel(r'$\mu\ \mathrm{(mag/arcsec^2)}$', ) ax1 = plt.gca() ax2 = ax1.twinx() ax1.set_ylim(2e4, 2e11) mn, mx = ax1.get_ylim() ax2.set_ylim(mn, mx) ax2.set_yscale('log') ax2.minorticks_off() ticks = ax1.get_yticks() wdm = wdm_mass(np.asarray(ticks)) labels = [r'$%.1f$' % t for t in wdm] ax2.set_yticklabels(labels) ax2.set_ylabel(r'$m_{\mathrm{WDM}\ \mathrm{(keV)}}$') mn2, mx2 = ax2.get_ylim() ax2.fill_between([29.5, 33.5], [halo_mass(2.95), halo_mass(2.95)], [3e8, 3e8], facecolor='none', edgecolor='k', alpha=0.3, hatch='/', lw=2, zorder=4) # MW satellite constraint #plt.plot([29.5, 33.5], [halo_mass(2.95), halo_mass(2.95)], c='0.5', lw=2, linestyle='-')#, label=r'$\mathrm{MW\ satellites}$') plt.text(30.45, 6e8, r'$\mathrm{MW\ satellites}$', horizontalalignment='center', verticalalignment='center', size=10, bbox=dict(facecolor='white', alpha=1, edgecolor='none'), zorder=-1) plt.plot([29.5, 33.5], [halo_mass(5.30), halo_mass(5.30)], c='0.5', lw=2, linestyle='-', zorder=1) #, label=r'$\mathrm{Lyman}\ \alpha$') plt.text(30.45, halo_mass(5.30), r'$\mathrm{Lyman}\ \alpha$', horizontalalignment='center', verticalalignment='center', size=10, bbox=dict(facecolor='white', alpha=1, ec='none'), zorder=2) #plt.plot([31.9,31.9], [mn2,mx2], c='0.5', lw=2, linestyle='--')#, label=r'$\mathrm{MW\ satellites}$') #plt.plot([33.0,33.0], [mn2,mx2], c='0.5', lw=2, linestyle='--')#, label=r'$\mathrm{Lyman}\ \alpha$') #plt.text(31,3e4,r'$\mathrm{GD-1}$',rotation=90., horizontalalignment='center', verticalalignment='bottom', size=10,bbox=dict(facecolor='white', alpha=0, ec='none'),zorder=-10) plt.text(32, 3e4, r'$\mathrm{Indus}$', rotation=90., horizontalalignment='center', verticalalignment='bottom', size=10, bbox=dict(facecolor='white', alpha=1, ec='none'), zorder=-1) plt.text(33, 3e4, r'$\mathrm{ATLAS}$', rotation=90., horizontalalignment='center', verticalalignment='bottom', size=10, bbox=dict(facecolor='white', alpha=1, ec='none'), zorder=-1) plt.xlim(29.9, 33.1) plt.title(r'$\mathrm{Minimum\ Detectable\ Halo\ Mass}$') plt.tight_layout() if filename is not None: plt.savefig('%s.png' % filename) plt.show()
def save_output(filename='output.txt', mus=[30.], distances=[20.], velocities=[150.], impact_parameters=[1.], maglims=[None], latitudes=[60.], surveys=['LSST'], gap_fill=True, **kwargs): if os.path.exists(filename): pass else: output_file = open(filename, 'w') output_file.write( '# distance (kpc), flyby_velocity (km/s), impact_parameter (r_s), magnitude_limit (mag), latitude (deg), gap_fill (True/False), survey, surface_brightness (mag/arcsec^2), minimum_mass (M_sun)\n' ) output_file.close() output = np.genfromtxt(filename, unpack=True, delimiter=', ', dtype=None, names=[ 'dist', 'w', 'b', 'maglim', 'lat', 'gap_fill', 'survey', 'mu', 'mass' ], encoding='bytes') for survey in surveys: for lat in latitudes: for maglim in maglims: for b in impact_parameters: for w in velocities: for distance in distances: ret = [] if maglim == None: maglim_label = mock_sim.getMagLimit( 'g', survey) else: maglim_label = maglim for mu in mus: # print mu, distance, w, b, maglim, lat, survey # check if output already saved for these params try: idx = (output['dist'] == distance) & ( output['w'] == w) & (output['b'] == b) & ( output['maglim'] == np.around( maglim_label, 2) ) & (output['survey'] == survey) & ( output['gap_fill'] == gap_fill) & (output['mu'] == mu) if np.sum(idx) > 0: print 'Output exists' continue except: pass mockfile = '%d_deg_mock.fits' % lat mass, gapt, gapo = mock_sim.predict_gap_depths( mu, distance, survey, width_pc=20, maglim=maglim, timpact=0.5, gap_fill=gap_fill, w=w, X=b, mockfile=mockfile, **kwargs) xind = np.isfinite(gapo / gapt) try: II1 = scipy.interpolate.UnivariateSpline( np.log10(mass)[xind], (gapo / gapt - 1)[xind], s=0) except: print 'Spline error' ret.append(np.nan) continue R = scipy.optimize.root(II1, 6) ret.append(10**R['x']) with open(filename, 'a') as output_file: output_file.write( '%.2f, %.2f, %.2f, %.2f, %.2f, %d, %s, %.2f, %.2f\n' % (distance, w, b, maglim_label, lat, gap_fill, survey, mu, ret[-1]))