def rc_set_dark_colourscheme(): # make pretty dark colourscheme for pylab global colorscheme global cmap_funk, cmap_bifunk colorscheme = ['#ccff00', '#0082ff', '#ff0037', '#00ff13', '#5e00ff', '#ffa800', '#00fff2', '#ff00c1', '#77ff00', '#002cff'] rc('axes', facecolor='k', edgecolor='0.3', linewidth=1, labelcolor='#ccff00', prop_cycle=pl.cycler(color=colorscheme), titlesize='medium', labelsize='small') rc('grid', color='0.25') rc('text', color='#ccff00') rc('figure', facecolor='k', edgecolor='0.3') rc('savefig', facecolor='k', edgecolor='0.3', format='png') # does not have any effect? rc('xtick', color='0.6') rc('ytick', color='0.6') rc('image', interpolation='nearest') # dash_capstyle: ['butt' | 'round' | 'projecting'] # dash_joinstyle: ['miter' | 'round' | 'bevel'] cmap_funk = pl.mpl.colors.LinearSegmentedColormap.from_list('funk', [ (0.00, (0.0, 0.0, 0.0)), (0.50, (0.8, 1.0, 0.0)), (1.00, (1.0, 1.0, 1.0))]) cmap_bifunk = pl.mpl.colors.LinearSegmentedColormap.from_list('bifunk', [ (0.00, (0.0, 0.3, 0.6)), (0.50, (0.0, 0.0, 0.0)), (0.75, (0.8, 1.0, 0.0)), (1.00, (1.0, 1.0, 1.0))])
def PlotKinematics(traj0, traj1, dt=0.01, vmax=[], amax=[], figstart=0): from pylab import figure, clf, hold, gca, title, xlabel, ylabel, plot, axis, cycler x = ['r', 'g', 'b', 'y', 'k'] colorcycle = cycler('color', x[0:traj0.dimension]) Tmax = max(traj0.duration, traj1.duration) # Joint angles figure(figstart) clf() hold('on') ax = gca() ax.set_prop_cycle(colorcycle) traj0.Plot(dt, '--') ax.set_prop_cycle(colorcycle) traj1.Plot(dt) title('Joint values', fontsize=20) xlabel('Time (s)', fontsize=18) ylabel('Joint values (rad)', fontsize=18) # Velocity figure(figstart + 1) clf() hold('on') ax = gca() ax.set_prop_cycle(colorcycle) traj0.Plotd(dt, '--') ax.set_prop_cycle(colorcycle) traj1.Plotd(dt) for v in vmax: plot([0, Tmax], [v, v], '-.') for v in vmax: plot([0, Tmax], [-v, -v], '-.') if len(vmax) > 0: Vmax = 1.2 * max(vmax) if Vmax < 0.1: Vmax = 10 axis([0, Tmax, -Vmax, Vmax]) title('Joint velocities', fontsize=20) xlabel('Time (s)', fontsize=18) ylabel('Joint velocities (rad/s)', fontsize=18) # Acceleration figure(figstart + 2) clf() ax = gca() ax.set_prop_cycle(colorcycle) hold('on') traj0.Plotdd(dt, '--') ax.set_prop_cycle(colorcycle) traj1.Plotdd(dt) for a in amax: plot([0, Tmax], [a, a], '-.') for a in amax: plot([0, Tmax], [-a, -a], '-.') if len(amax) > 0: Amax = 1.2 * max(amax) axis([0, Tmax, -Amax, Amax]) title('Joint accelerations', fontsize=20) xlabel('Time (s)', fontsize=18) ylabel('Joint accelerations (rad/s^2)', fontsize=18)
def PlotProfiles(profileslist0, switchpointslist=[], max_sdot=20, figstart=None, colorscheme=1): from pylab import figure, clf, hold, plot, gca, axis, title, xlabel, ylabel, cycler profileslist = list(profileslist0) if figstart is not None: figure(figstart) clf() mvcbobrow = profileslist.pop(0) mvcdirect = profileslist.pop(0) if colorscheme == 1: plot(mvcbobrow[2], mvcbobrow[3], 'm', linewidth=1) plot(mvcdirect[2], mvcdirect[3], 'g--', linewidth=1) else: plot(mvcbobrow[2], mvcbobrow[3], 'm', linewidth=1) plot(mvcdirect[2], mvcdirect[3], 'g--', linewidth=1) colorcycle = cycler('color', ['r', 'g', 'b', 'c', 'm']) ax = gca() ax.set_prop_cycle(colorcycle) for p in profileslist: plot(p[2], p[3], 'k', linewidth=2) if len(profileslist) > 0: M = 2 * max([max(p[3]) for p in profileslist]) else: M = max_sdot bobrow = list(filter((lambda x: x < M), mvcbobrow[3])) direct = list(filter((lambda x: x < M), mvcdirect[3])) if len(bobrow) > 0: M = max(M, max(bobrow)) if len(direct) > 0: M = max(M, max(direct)) for sw in switchpointslist: if sw[2] == 0: plot(sw[0], sw[1], 'ro', markersize=8) if sw[2] == 1: plot(sw[0], sw[1], 'go', markersize=8) if sw[2] == 2: plot(sw[0], sw[1], 'bo', markersize=8) if sw[2] == 3: plot(sw[0], sw[1], 'yo', markersize=8) smax, sdmax = mvcbobrow[0], M axis([0, smax, 0, sdmax]) if colorscheme == 1: title('Maximum Velocity Curves and profiles', fontsize=20) xlabel('$s$', fontsize=22) ylabel('$\dot s$', fontsize=22) return smax, sdmax # return this for PlotPhase (yurk!)
def PlotProfiles(profileslist0, switchpointslist=[], figstart=None, colorscheme = 1): from pylab import figure, clf, hold, plot, gca, axis, title, xlabel, ylabel, cycler profileslist = list(profileslist0) if figstart is not None: figure(figstart) clf() hold('on') mvcbobrow = profileslist.pop(0) mvcdirect = profileslist.pop(0) if colorscheme == 1: plot(mvcbobrow[2], mvcbobrow[3], 'c', linewidth=4) plot(mvcdirect[2], mvcdirect[3], 'c--', linewidth=4) else: plot(mvcbobrow[2], mvcbobrow[3], 'm', linewidth=4) plot(mvcdirect[2], mvcdirect[3], 'm--', linewidth=4) colorcycle = cycler('color', ['r', 'g', 'b', 'y', 'k']) ax = gca() ax.set_prop_cycle(colorcycle) for p in profileslist: plot(p[2], p[3], 'k',linewidth=2) if len(profileslist) > 0: M = 2 * max([max(p[3]) for p in profileslist]) else: M = 20 bobrow = list(filter((lambda x: x < M), mvcbobrow[3])) direct = list(filter((lambda x: x < M), mvcdirect[3])) if len(bobrow) > 0: M = max(M, max(bobrow)) if len(direct) > 0: M = max(M, max(direct)) for sw in switchpointslist: if sw[2] == 0: plot(sw[0], sw[1], 'ro', markersize=8) if sw[2] == 1: plot(sw[0], sw[1], 'go', markersize=8) if sw[2] == 2: plot(sw[0], sw[1], 'bo', markersize=8) if sw[2] == 3: plot(sw[0], sw[1], 'yo', markersize=8) smax, sdmax = mvcbobrow[0], M axis([0, smax, 0, sdmax]) if colorscheme == 1: title('Maximum Velocity Curves and profiles', fontsize=20) xlabel('$s$', fontsize=22) ylabel('$\dot s$', fontsize=22) return smax, sdmax # return this for PlotPhase (yurk!)
def PlotMRR(traj, volume_rates, svalues, dt=0.01, mrr_desired=[], figstart=0): from pylab import figure, clf, hold, gca, title, xlabel, ylabel, plot, axis, cycler x = ['r', 'g', 'b', 'c', 'm'] colorcycle = cycler('color', x[0:traj.dimension]) Tmax = traj.duration # Material removal rate figure(figstart) clf() ax = gca() ax.set_prop_cycle(colorcycle) tvect = np.arange(0, traj.duration + dt, dt) # Compute times for tsmap times = [] current_time = 0 for chunk in traj.chunkslist: times.append(current_time) current_time = current_time + chunk.duration # Compute for each time, if it is contained in interval [tcur, tcur+dt] for # tvect[0:-1] time_contained_in_dt = np.asarray([ np.logical_and(times >= tvect[index], times < tvect[index + 1]) for index in np.arange(tvect.size - 1) ]) # For each interval of tvect[0:-1], compute s values that are traversed in # interval. Correspond these s-values to the beginning of the interval s_for_dts = [ svalues[time_contained_in_dt[index, :]] for index in np.arange(time_contained_in_dt.shape[0]) ] # Use the s values to compute the ds values for each interval ds_for_dts_firsts = [0] + [ s_for_dt[0] - s_for_dt_last[-1] for s_for_dt, s_for_dt_last in zip(s_for_dts[1:], s_for_dts[:-1]) ] ds_for_dts_others = [ tuple(s_for_dt[1:] - s_for_dt[:-1]) for s_for_dt in s_for_dts ] ds_for_dts = [ np.asarray((ds_for_dt_first, ) + ds_for_dt_others) for ds_for_dt_first, ds_for_dt_others in zip(ds_for_dts_firsts, ds_for_dts_others) ] volumes_dt = np.zeros_like(tvect) volumes_dt[1:] = [ np.sum( np.asarray([ volume_rates.Eval(s_for_dt[index]) * ds_for_dt[index] for index in np.arange(s_for_dt.size) ])) for s_for_dt, ds_for_dt in zip(s_for_dts, ds_for_dts) ] qdvect = array([traj.Evald(t) for t in tvect]) #plot(tvect, np.linalg.norm(qdvect, axis=1), 'r--', linewidth=2) #plot(tvect, volumes_dt, 'b--', linewidth=2) plot(tvect, (volumes_dt / dt), 'g', linewidth=2) for mrr in mrr_desired: plot([0, Tmax], [mrr, mrr], 'b-.') for mrr in mrr_desired: plot([0, Tmax], [0, 0], 'b-.') #if len(mrr_desired) > 0: # Vmax = 1.2 * max(vmax) # if Vmax < 0.1: # Vmax = 10 # axis([0, Tmax, -Vmax, Vmax]) title('Material removal rate', fontsize=20) xlabel('Time (s)', fontsize=18) ylabel('MRR', fontsize=18)
def plotit(): import astropy.stats import pylab as pl pl.rcParams['axes.prop_cycle'] = pl.cycler('color', [ '#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf' ]) pl.rcParams['figure.figsize'] = (12, 8) pl.rcParams['figure.dpi'] = 75 pl.rcParams['savefig.dpi'] = 150 pl.rcParams['axes.titlesize'] = 40 pl.rcParams['axes.labelsize'] = 24 pl.rcParams['xtick.labelsize'] = 20 pl.rcParams['ytick.labelsize'] = 20 pl.figure(1).clf() pl.figure(2).clf() pl.figure(3).clf() pl.figure(4).clf() pl.figure(5, figsize=(12, 8), dpi=75).clf() fig9 = pl.figure(9) fig9.clf() for ii, imname in enumerate(f for f in files if 'column' in f.lower()): print("Plotting {0}".format(imname)) data = files[imname]['file'].data mask = files[imname]['mask'] brickdata = brick_files[imname]['file'].data # https://github.com/astropy/astropy/pull/5232 for ignore_nan lo = astropy.stats.mad_std(data, ignore_nan=True) hi = np.nanmax(data) bins = np.logspace(np.log10(lo), np.log10(hi), 100) pl.figure(1) pl.subplot(2, 4, ii + 1) brickweights = np.ones(np.isfinite(brickdata).sum(), dtype='float') / np.isfinite( brickdata).sum() * np.isfinite(data).sum() bH, bL, bP = pl.hist( brickdata[np.isfinite(brickdata)], bins=bins, log=True, alpha=0.5, histtype='step', #weights=brickweights, bottom=1.1, color='b', zorder=-1) #weights = np.ones(np.isfinite(data).sum(), dtype='float')/np.isfinite(data).sum() H, L, P = pl.hist( data[np.isfinite(data) & mask], bins=bins, log=True, alpha=0.5, color='k', #normed=True, histtype='step') # Lada threshold, approximately (116 Msun/pc^2) pl.vlines(5e21, 1.1, H.max(), label='Lada+ 2010 Threshold') #pl.hist(tbl[imname], bins=bins, log=True, alpha=0.5) pl.xlim(np.min([bL.min(), L.min()]), L.max()) pl.semilogx() pl.yscale('log', nonposy='clip') ax2 = pl.gca().twinx() ax2.plot(np.sort(tbl[imname]), np.arange(len(tbl), dtype='float') / len(tbl), 'k-', linewidth=3, alpha=0.5, zorder=10) ax2.set_xlim(L.min(), L.max()) ax2.set_ylim(0, 1) pl.title(imname, fontsize=12) pl.figure(2) pl.subplot(2, 4, ii + 1) pl.imshow(data, cmap='gray_r') pl.contour(data, levels=np.percentile(tbl[imname], [5, 10, 25, 50, 75, 90, 95])) pl.contour(mask, levels=[0.5]) pl.title(imname) sorted_col = u.Quantity(np.sort(data[mask & (data > 0)]), u.cm**-2) cumul = np.cumsum(sorted_col)[::-1] pixarea_cm2 = (files[imname]['pixarea'] * distance**2) cum_mass = (cumul * pixarea_cm2 * 2.8 * u.Da).to( u.M_sun, u.dimensionless_angles()) pl.figure(3) pl.plot(sorted_col, cum_mass, label=names[imname]) pl.legend(loc='best') pl.xlim(1e21, 2e25) pl.gca().set_xscale('log') pl.gca().set_yscale('log') pl.figure(4) assert cum_mass.min() > 0.1 * u.M_sun pl.plot(sorted_col - 5e22 * u.cm**-2, cum_mass - (5e22 * u.cm**-2 * pixarea_cm2 * 2.8 * u.Da).to( u.M_sun, u.dimensionless_angles()), label=names[imname]) pl.legend(loc='best') pl.xlim(1e21, 2e25) pl.gca().set_xscale('log') pl.gca().set_yscale('log') pl.figure(1) pl.tight_layout() pl.savefig(paths.fpath("flux_histograms_with_core_location_CDF.pdf"), bbox_inches='tight') pl.figure(3) pl.vlines(5e21, 0.5, 1e6, color='k', linestyle='--', linewidth=1, label='Lada+ 2010 Threshold') pl.tight_layout() pl.legend(loc='best') pl.savefig(paths.fpath("mass_cdf_histograms.pdf"), bbox_inches='tight') pl.figure(4) pl.vlines(5e21, 0.5, 1e6, color='k', linestyle='--', linewidth=1, label='Lada+ 2010 Threshold') pl.legend(loc='best') pl.tight_layout() pl.savefig(paths.fpath("mass_cdf_histograms_bgsubd.pdf"), bbox_inches='tight') pl.figure(5).clf() for imname, color in [('HerschelColumn25', 'k'), ('HerschelColumn36', 'g'), ('SharcHTemColumn', 'b'), ('ScubaHTemColumn', 'r')]: pl.plot( np.sort(tbl[imname]), np.arange(len(tbl), dtype='float') / len(tbl), linestyle='-', linewidth=4, alpha=1, zorder=10, color=color, label=names[imname], ) pl.xscale('log') pl.xlim(1e21, 2e25) pl.ylim(0, 1) fb1 = pl.fill_betweenx( y=np.arange(len(tbl), dtype='float') / len(tbl), x1=np.sort(nan_to_val(tbl['Sharc20Column'], 1e26)), x2=np.sort(nan_to_val(tbl['Sharc50Column'], 1e26)), alpha=0.5, label='SHARC 20-50 K', edgecolor='b', facecolor='none', zorder=-10, hatch='//', linewidth=2, ) fb2 = pl.fill_betweenx( y=np.arange(len(tbl), dtype='float') / len(tbl), x1=np.sort(nan_to_val(tbl['Scuba20Column'], 1e26)), x2=np.sort(nan_to_val(tbl['Scuba50Column'], 1e26)), alpha=0.5, label='SCUBA 20-50 K', edgecolor='r', facecolor='none', zorder=-10, hatch='\\\\', linewidth=2, ) pl.figure(5) pl.vlines(5e21, 0, 1, color='k', linestyle='--', linewidth=1, label='Lada+ 2010 Threshold') pl.vlines(2e23, 0, 1, color='k', linestyle=':', label='Krumholz+ 2008 Threshold') pl.legend(loc='best', fontsize=20) pl.tight_layout() pl.xlabel("Column Density [$N(\mathrm{H}_2)$ cm$^{-2}$]", fontsize=24) pl.ylabel("Cumulative fraction\nof cores at column $<N$", fontsize=24) ax1 = pl.gca() pl.draw() ax2 = ax1.twiny() print("ax1 xlims: {0}".format(ax1.get_xlim())) pl.draw() ax2.set_xlim(np.array(ax1.get_xlim()) * (2.8 * u.Da).to(u.g).value) print("ax2 xlims: {0}".format(ax2.get_xlim())) ax2.set_xscale('log') ax2.set_xlabel("Column Density [g cm$^{-2}$]") pl.draw() pl.savefig(paths.fpath("core_background_column_cdf.pdf"), bbox_inches='tight') pl.figure(6).clf() ax1 = pl.gca() imname = 'ScubaHTemColumn' print("fig6: Plotting {0}".format(imname)) data = files[imname]['file'].data mask = files[imname]['mask'] brickdata = brick_files[imname]['file'].data lo = astropy.stats.mad_std(brickdata, ignore_nan=True) hi = np.nanmax(data) bins = np.logspace(np.log10(lo) - 0.5, np.log10(hi), 100) bH, bL, bP = ax1.hist(brickdata[np.isfinite(brickdata)], bins=bins, log=True, alpha=0.5, histtype='step', bottom=0.1, linewidth=2, color='b', zorder=-1) #weights = np.ones(np.isfinite(data).sum(), dtype='float')/np.isfinite(data).sum() H, L, P = ax1.hist( data[np.isfinite(data) & mask], bins=bins, log=True, alpha=0.5, color='k', linewidth=2, #normed=True, histtype='step') # Lada threshold, approximately (116 Msun/pc^2) ax1.vlines(5e21, 1.1, H.max(), label='Lada+ 2010 Threshold') ax1.vlines(2e23, 0.1, H.max() * 2, color='k', linestyle=':', label='Krumholz+ 2008 Threshold') #ax1.hist(tbl[imname], bins=bins, log=True, alpha=0.5) ax1.set_xlim(np.min([bL.min(), L.min()]), L.max()) ax1.set_ylim(0.5, np.max([bH.max(), H.max()]) * 1.1) ax1.semilogx() ax1.set_yscale('log', nonposy='clip') ax1.set_xlabel("Column Density [N(H$_2$) cm$^{-2}$]") ax1.set_ylabel("Number of pixels") ax3 = ax1.twiny() print("ax1 xlims: {0}".format(ax1.get_xlim())) pl.draw() ax3.set_xlim(np.array(ax1.get_xlim()) * (2.8 * u.Da).to(u.g).value) ax3lims = ax3.get_xlim() print("ax2 xlims: {0}".format(ax2.get_xlim())) ax3.set_xscale('log') ax3.set_xlabel("Column Density [g cm$^{-2}$]") pl.draw() pl.savefig(paths.fpath("compare_brick_sgrb2_colPDF_nofractions.pdf"), bbox_inches='tight') ax2 = ax1.twinx() ax2.plot(np.sort(tbl[imname]), np.arange(len(tbl), dtype='float') / len(tbl), 'k-', linewidth=3, alpha=0.5, zorder=10) ax2.set_xlim(L.min(), L.max()) ax2.set_ylim(0, 1) ax2.set_ylabel("Fraction of point sources below N(H$_2$)") ax3.set_xlim(ax3lims) ax2.set_xlim(L.min(), L.max()) pl.savefig(paths.fpath("compare_brick_sgrb2_colPDF.pdf"), bbox_inches='tight') ax9 = fig9.gca() ax9.loglog(np.sort(tbl[imname]), 1 - np.arange(len(tbl), dtype='float') / len(tbl), 'k-', linewidth=3, alpha=0.5, zorder=10, label='Stars') ax9.set_ylabel("Fraction of point sources above N(H$_2$)") ax9.set_xlabel("Column Density [N(H$_2$) cm$^{-2}$]") fig9.savefig(paths.fpath("cdf_of_point_sources.pdf"), bbox_inches='tight') ax9.set_ylabel("Fraction above N(H$_2$)") dmask = np.isfinite(data) & mask ax9.loglog(np.sort(data[dmask]), 1 - np.arange(dmask.sum(), dtype='float') / dmask.sum(), alpha=0.5, color='b', linewidth=2, label='Gas') fig9.legend(loc='best') fig9.savefig(paths.fpath("cdf_of_point_sources_and_column.pdf"), bbox_inches='tight') nn11_pc = (u.Quantity(tbl['nn11'], u.arcsec) * distance).to( u.pc, u.dimensionless_angles()) nn = 11 nn11_msunpersqpc_starcentered = ((nn - 1) * mass_represented_by_a_source / (np.pi * (nn11_pc)**2)).to(u.M_sun / u.pc**2) herschelsurfdens = (u.Quantity(tbl['HerschelColumn25']).to(u.cm**-2) * 2.8 * u.Da).to(u.M_sun / u.pc**2) tbl.add_column(table.Column(name='HerschelSurfDens', data=herschelsurfdens)) tbl.add_column( table.Column(name='nn11_starcentered_surfdens', data=nn11_msunpersqpc_starcentered)) assert herschelsurfdens.min() < 10**5 * u.M_sun / u.pc**2 assert herschelsurfdens.max() > 10**3 * u.M_sun / u.pc**2 fig7 = pl.figure(7, figsize=(10, 10)) fig7.clf() ax7 = fig7.gca() ax7.loglog(herschelsurfdens, nn11_msunpersqpc_starcentered, 'k.', alpha=0.7, markeredgecolor=(0, 0, 0, 0.5)) lims = ax7.axis() # 5/3 slope #ax7.loglog([1e3,1e6], [3e0, 3e5], 'k--') ax7.set_ylabel( "Source-centered NN11 Surface Density\n$\Sigma_*$ [M$_\odot$ pc$^{-2}$]" ) ax7.set_xlabel("Gas Surface Density $\Sigma_{gas}$ [M$_\odot$ pc$^{-2}$]") ax7.axis(lims) # Arrows showing the shift if you subtract off the "most aggressive plausible" # uniform foreground value bg_5e22 = (5e22 * u.cm**-2 * 2.8 * u.Da).to(u.M_sun / u.pc**2) ax7.arrow(3e3, 1.1, -bg_5e22.value, 0, head_width=0.1, head_length=0.033 * (3e3 - bg_5e22.value), color='k') ax7.arrow(1e4, 1.1, -bg_5e22.value, 0, head_width=0.1, head_length=0.033 * (1e4 - bg_5e22.value), color='k') ax7.arrow(3e4, 1.1, -bg_5e22.value, 0, head_width=0.1, head_length=0.033 * (3e4 - bg_5e22.value), color='k') ax7.axis([1e3, 1e5, 1e0, 1e5]) fig7.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_herschel_nomodels_nolocal.png" ), bbox_inches='tight') fig7.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_herschel_nomodels_nolocal.pdf" ), bbox_inches='tight') monr2_lowerline = np.array([0.1, 1e5])**2.67 / (100**2.67) * 2.5 monr2_fill = ax7.fill_between([0.1, 1e5], monr2_lowerline, monr2_lowerline * 10, alpha=0.5, color='green', label='Mon R2') oph_lowerline = np.array([0.1, 1e5])**1.87 / (100**1.87) * 1.5 oph_fill = ax7.fill_between([0.1, 1e5], oph_lowerline, oph_lowerline * 10, color='blue', alpha=0.5, label='Ophiuchus') local_plotobjs = [monr2_fill, oph_fill] T = ax7.text(2.3e3, 9e3, "Mon R2", color='k', rotation=50, fontsize=18, verticalalignment='bottom', horizontalalignment='center') local_plotobjs.append(T) T = ax7.text(2.5e3, 4.5e2, "Ophiuchus", color='k', rotation=38, fontsize=18, verticalalignment='bottom', horizontalalignment='center') local_plotobjs.append(T) #ax7.plot([0.1, 1e5], np.array([0.1, 1e5])**1.87/(1e4**1.87)*(1e4**(5/3.)/1e5), 'b:', linewidth=3, alpha=0.5) oph_scalefactor = 50. L = ax7.plot([0.1, 1e5], oph_lowerline / oph_scalefactor, 'b:', linewidth=3, alpha=0.5) local_plotobjs += L ax7.axis([1e3, 1e5, 1e0, 1e5]) fig7.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_herschel_nomodels.png"), bbox_inches='tight') fig7.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_herschel_nomodels.pdf"), bbox_inches='tight') sigma_gas = np.logspace(1, 6) * u.M_sun / u.pc**2 mdlplots = {} for time in (0.01, 0.1, 0.74) * u.Myr: mdlplots[(1, time)] = ax7.loglog( sigma_gas_of_t(sigma_gas, time, alpha=1, k=0.1 / u.Myr), gas_depletion_law(sigma_gas, time, alpha=1, k=0.1 / u.Myr), label=time, color='r', linewidth=3, alpha=0.5, zorder=-10, ) mdlplots[(2, time)] = ax7.loglog(sigma_gas_of_t(sigma_gas, time), gas_depletion_law(sigma_gas, time), label=time, color='orange', linewidth=3, zorder=-5, alpha=0.5) ax7.axis([1e3, 1e5, 1e0, 1e5]) #ax7.plot([0.1, 1e5], np.array([0.1, 1e5])*4e-2, 'r-', linewidth=3, alpha=0.5, zorder=-10) fig7.savefig( paths.fpath("stellar_vs_gas_column_density_starcentered_herschel.png"), bbox_inches='tight') fig7.savefig( paths.fpath("stellar_vs_gas_column_density_starcentered_herschel.pdf"), bbox_inches='tight') ax7.loglog(np.logspace(3, 5), lada2017relation.sigma_star_california( np.logspace(3, 5) * u.M_sun / u.pc**2), linewidth=3, color='m', label='Lada2017_cali') ax7.loglog(np.logspace(3, 5), lada2017relation.sigma_star_orionA( np.logspace(3, 5) * u.M_sun / u.pc**2), linewidth=3, linestyle='--', color='m', label='Lada2017_orionA') ax7.loglog(np.logspace(3, 5), lada2017relation.sigma_star_orionB( np.logspace(3, 5) * u.M_sun / u.pc**2), linewidth=3, linestyle=':', color='m', label='Lada2017_orionB') fig7.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_herschel_withLada2017.png" ), bbox_inches='tight') fig7.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_herschel_withLada2017.pdf" ), bbox_inches='tight') for line in mdlplots.values(): try: for ll in line: ll.set_visible(False) except TypeError: line.set_visible(False) for obj in local_plotobjs: obj.set_visible(False) fig7.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_herschel_nomodels_withLada2017.png" ), bbox_inches='tight') fig7.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_herschel_nomodels_withLada2017.pdf" ), bbox_inches='tight') scubasurfdens = (u.Quantity(tbl['ScubaHTemColumn'], u.cm**-2) * 2.8 * u.Da).to(u.M_sun / u.pc**2) fig8 = pl.figure(8) fig8.clf() ax8 = fig8.gca() ax8.loglog(scubasurfdens, nn11_msunpersqpc_starcentered, 'k.', alpha=0.7, markeredgecolor=(0, 0, 0, 0.5)) lims = ax8.axis() # 5/3 slope #ax8.loglog([1e3,1e6], [3e0, 3e5], 'k--') #ax8.plot([0.1, 1e5], np.array([0.1, 1e5])**1.87/(1e4**1.87)*(1e4**(5/3.)/1e5), 'b:', linewidth=3, alpha=0.5) ax8.plot([0.1, 1e5], oph_lowerline / oph_scalefactor, 'b:', linewidth=3, alpha=0.5) ax8.axis(lims) ax8.set_ylabel( "Source-centered NN11 Surface Density\n$\Sigma_*$ [M$_\odot$ pc$^{-2}$]" ) ax8.set_xlabel("SCUBA-derived Surface Density [M$_\odot$ pc$^{-2}$]") # arrows showing the shift if you subtract off the "most aggressive plausible" # uniform foreground value bg_5e22 = (5e22 * u.cm**-2 * 2.8 * u.Da).to(u.M_sun / u.pc**2) ax8.arrow(3e3, 1.1, -bg_5e22.value, 0, head_width=0.1, head_length=0.033 * (3e3 - bg_5e22.value), color='k') ax8.arrow(1e4, 1.1, -bg_5e22.value, 0, head_width=0.1, head_length=0.033 * (1e4 - bg_5e22.value), color='k') ax8.arrow(3e4, 1.1, -bg_5e22.value, 0, head_width=0.1, head_length=0.033 * (3e4 - bg_5e22.value), color='k') fig8.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_scuba_nomodels_nolocal.png" ), bbox_inches='tight') fig8.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_scuba_nomodels_nolocal.pdf" ), bbox_inches='tight') monr2_lowerline = np.array([0.1, 1e5])**2.67 / (100**2.67) * 2.5 monr2_fill = ax8.fill_between([0.1, 1e5], monr2_lowerline, monr2_lowerline * 10, alpha=0.5, color='green', label='Mon R2') oph_lowerline = np.array([0.1, 1e5])**1.87 / (100**1.87) * 1.5 oph_fill = ax8.fill_between([0.1, 1e5], oph_lowerline, oph_lowerline * 10, color='blue', alpha=0.5, label='Ophiuchus') local_plotobjs = [monr2_fill, oph_fill] monr2txt = ax8.text(2.3e3, 9e3, "Mon R2", color='k', rotation=50, fontsize=18, verticalalignment='bottom', horizontalalignment='center') ophtxt = ax8.text(2.5e3, 4.5e2, "Ophiuchus", color='k', rotation=38, fontsize=18, verticalalignment='bottom', horizontalalignment='center') local_plotobjs.append(monr2txt) local_plotobjs.append(ophtxt) ax8.axis([1e3, 1e5, 1e0, 1e5]) fig8.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_scuba_nomodels.png"), bbox_inches='tight') fig8.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_scuba_nomodels.pdf"), bbox_inches='tight') mdlplots = {} for time in (0.01, 0.1, 0.74) * u.Myr: mdlplots[(1, time)] = ax8.loglog( sigma_gas_of_t(sigma_gas, time, alpha=1, k=0.1 / u.Myr), gas_depletion_law(sigma_gas, time, alpha=1, k=0.1 / u.Myr), label=time, color='r', linewidth=3, alpha=0.5, zorder=-10, ) mdlplots[(2, time)] = ax8.loglog(sigma_gas_of_t(sigma_gas, time), gas_depletion_law(sigma_gas, time), label=time, color='orange', linewidth=3, zorder=-5, alpha=0.5) #ax8.axis(lims) ax8.axis([1e3, 1e5, 1e0, 1e5]) fig8.savefig( paths.fpath("stellar_vs_gas_column_density_starcentered_scuba.png"), bbox_inches='tight') fig8.savefig( paths.fpath("stellar_vs_gas_column_density_starcentered_scuba.pdf"), bbox_inches='tight') ax8.loglog(np.logspace(3, 5), lada2017relation.sigma_star( np.logspace(3, 5) * u.M_sun / u.pc**2), linewidth=3, color='m', label='Lada2017') ax8.loglog(np.logspace(3, 5), lada2017relation.sigma_star_orionA( np.logspace(3, 5) * u.M_sun / u.pc**2), linewidth=3, linestyle='--', color='m', label='Lada2017_orionA') ax8.loglog(np.logspace(3, 5), lada2017relation.sigma_star_orionB( np.logspace(3, 5) * u.M_sun / u.pc**2), linewidth=3, linestyle=':', color='m', label='Lada2017_orionB') fig8.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_scuba_withLada2017.png"), bbox_inches='tight') fig8.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_scuba_withLada2017.pdf"), bbox_inches='tight') for line in mdlplots.values(): try: for ll in line: ll.set_visible(False) except TypeError: line.set_visible(False) for obj in local_plotobjs: obj.set_visible(False) fig8.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_scuba_nomodels_withLada2017.png" ), bbox_inches='tight') fig8.savefig(paths.fpath( "stellar_vs_gas_column_density_starcentered_scuba_nomodels_withLada2017.pdf" ), bbox_inches='tight') # TODO: plot the same (?) histograms for The Brick # DONE! tbl.write(paths.tpath("continuum_photometry_plusbackground.ipac"), format='ascii.ipac', overwrite=True)
import os import sys import numpy as np import pandas as pd import copy import csv import warnings import operator import tqdm from pathlib import Path from tqdm.notebook import trange, tqdm from IPython.display import display, HTML import matplotlib.pyplot as plt from pylab import cycler warnings.filterwarnings("ignore") plt.rcParams['font.family'] = 'sans-serif' plt.rcParams['font.sans-serif'] = 'Adobe Clean' plt.rcParams['axes.prop_cycle'] = cycler(color=['r', 'g', 'b', 'y']) pd.set_option('display.max_columns', None) _path = os.getcwd() DIRECTORY = str(Path(_path).parents[2]) PROJECT = str(Path(_path).parents[1]).split('/')[-1]
'axes.titlesize': 14, 'axes.labelsize': 12, 'axes.facecolor': 'none', 'axes.linewidth': 0.8, 'axes.spines.right': False, 'axes.spines.top': False, 'axes.titleweight': 'bold', 'axes.prop_cycle': plt.cycler('color', colors), 'ytick.major.size': 8, 'xtick.major.size': 8, 'xtick.labelsize': 8, 'ytick.labelsize': 8, 'xtick.major.width': 1, 'ytick.major.width': 1, 'figure.edgecolor': 'none', 'figure.facecolor':