def velocity_plot(s, width='15 kpc', cmap1='hot', cmap2='viridis', stream=False): import pynbody import pynbody.plot.sph as sph import matplotlib.pylab as plt f, axs = plt.subplots(1, 2, figsize=(14, 6)) pynbody.analysis.angmom.faceon(s.g) sph.velocity_image(s.g, qty='temp', width=width, cmap=cmap1, vector_color='cyan', denoise=True, vector_resolution=20, subplot=axs[0], show_cbar=False) mode = 'stream' if stream else 'quiver' pynbody.analysis.angmom.faceon(s.g) sph.velocity_image(s.g, width=width, cmap=cmap2, vector_color='black', denoise=True, units='Msol kpc^-2', mode=mode, vector_resolution=20, subplot=axs[1], show_cbar=False)
def tmp2(h1, av_z=False, vc='k', rotate=False, out_units="Msol yr**-1 pc**-2", **kwargs): import matplotlib.pylab as plt from matplotlib.ticker import IndexLocator, FormatStrFormatter from matplotlib.colors import Colormap, LinearSegmentedColormap from matplotlib.patches import Circle import pynbody import numpy as np from pynbody.plot import sph from seren3.utils import plot_utils def anno(ax, xy, rvir, color="lightsteelblue", facecolor="none", alpha=1): e = Circle(xy=xy, radius=rvir) ax.add_artist(e) e.set_clip_box(ax.bbox) e.set_edgecolor(color) e.set_facecolor(facecolor) # "none" not None e.set_alpha(alpha) xy = (0, 0) nrows = 3 # fig, axs = plt.subplots(nrows=nrows, ncols=1, figsize=(8,12)) # fig, axs = plt.subplots(nrows=1, ncols=nrows, figsize=(10,4)) import matplotlib.gridspec as gridspec gs = gridspec.GridSpec(2, 6) ax1 = plt.subplot(gs[0, 1:3]) ax2 = plt.subplot(gs[0, 3:5]) ax3 = plt.subplot(gs[1, 2:4]) axs = np.array([ax1, ax2, ax3]) # fig.subplots_adjust(hspace=0.001) # fig.subplots_adjust(wspace=0.9) def _load_s(h): s = h.pynbody_snapshot(filt=False) return s if "s" in kwargs: s = kwargs.pop("s") else: s = _load_s(h1) if rotate: # tx = pynbody.analysis.angmom.sideon(s[1].s[pynbody.filt.Sphere(radius='2 kpc')]) # tx.apply_to(s[0]) pynbody.analysis.angmom.sideon(s.s[pynbody.filt.Sphere( radius='%f kpc' % (h1.rvir.in_units("kpc") / 4.))]) s.physical_units() rvir = h1.rvir.in_units(s.g['pos'].units) width = '%1.2f kpc' % (2.1 * rvir) s.g['rad_flux_radial'].convert_units("s**-1 m**-2") # s.g['rad_0_rho'].convert_units("s**-1 m**-2") print s.g['rad_flux_radial'].units for ax, field in zip(axs.flatten(), ["rho", "mass_flux_radial", "rad_flux_radial"]): print "Rvir = %1.2f kpc" % rvir.in_units("kpc") if field == "mass_flux_radial": sph.velocity_image(s.g, qty="outflow_rate", units=out_units,\ width=width, av_z=av_z, cmap="RdBu_r", qtytitle=r"$\vec{F}_{\mathrm{M}_{\mathrm{gas}}}$",\ subplot=ax, quiverkey=False, vector_color=vc, edgecolor="k", vector_resolution=20, key_length="250 km s**-1", scale="2500 km s**-1", **kwargs) # sph.velocity_image(s.g, qty="mass_flux_radial", units=out_units,\ # width=width, av_z=av_z, cmap="RdBu_r", qtytitle=r"$\vec{F}_{\mathrm{M}_{\mathrm{gas}}}$",\ # subplot=ax, quiverkey=False, vector_color=vc, vector_resolution=20, key_length="1000 km s**-1", **kwargs) elif field == "rad_flux_radial": cmap2 = plot_utils.load_custom_cmaps("blues_black_test") sph.velocity_image(s.g, qty="rad_flux_radial", units="s**-1 m**-2",\ width=width, cmap=cmap2, qtytitle=r"$\vec{F}_{\mathrm{ion}}$",\ subplot=ax, quiverkey=False, vector_color=vc, edgecolor="k", vector_resolution=20, key_length="250 km s**-1", scale="2500 km s**-1", vmin=1e9, vmax=1e14, **kwargs) # sph.velocity_image(s.g, qty="rad_0_rho", units="s**-1 m**-2",\ # width=width, cmap="RdBu_r", qtytitle=r"$\vec{F}_{\mathrm{ion}}$",\ # subplot=ax, quiverkey=False, vector_color=vc, vector_resolution=20, key_length="1000 km s**-1", vmin=1e8, vmax=1e12) # sph.velocity_image(s.g, qty="temp", units="K",\ # width=width, av_z=av_z, cmap="jet", qtytitle=r"T",\ # subplot=ax, quiverkey=False, vector_color="k", vector_resolution=20, key_length="1000 km s**-1") else: sph.velocity_image(s.g, qty=field, width=width, cmap="RdBu_r", qtytitle=r"$\rho$$_{\mathrm{gas}}$",\ vector_resolution=20, vector_color=vc, key_x=0.38, key_y=0.815, key_color='yellow', key_length="250 km s**-1", scale="2500 km s**-1", units="Msol kpc**-2", subplot=ax, **kwargs) anno(ax, xy, rvir) anno(ax, xy, rvir / 4., color="r") return s
def tmp(h1, h2, av_z=False, vc='k', rotate=False, out_units="Msol yr**-1 pc**-2", **kwargs): import matplotlib.pylab as plt from matplotlib.ticker import IndexLocator, FormatStrFormatter from matplotlib.colors import Colormap, LinearSegmentedColormap from matplotlib.patches import Circle import pynbody from pynbody.plot import sph def anno(ax, xy, rvir, color="lightsteelblue", facecolor="none", alpha=1): e = Circle(xy=xy, radius=rvir) ax.add_artist(e) e.set_clip_box(ax.bbox) e.set_edgecolor(color) e.set_facecolor(facecolor) # "none" not None e.set_alpha(alpha) xy = (0, 0) nrows = 3 fig, axes = plt.subplots(nrows=nrows, ncols=2, figsize=(12, 16)) # fig.subplots_adjust(hspace=0.001) # fig.subplots_adjust(wspace=0.9) def _load_s(h): s = h.pynbody_snapshot(filt=False) return s if "s" in kwargs: s = kwargs.pop("s") else: s = [_load_s(hi) for hi in [h1, h2]] if rotate: # tx = pynbody.analysis.angmom.sideon(s[1].s[pynbody.filt.Sphere(radius='2 kpc')]) # tx.apply_to(s[0]) for s_h in s: pynbody.analysis.angmom.sideon( s_h.s[pynbody.filt.Sphere(radius='2 kpc')]) for row, field in zip(range(nrows), ["rho", "mass_flux_radial", "rad_flux_radial"]): axs = axes[row, :] print len(axs.flatten()), field for h, s_h, ax in zip([h1, h2], s, axs.flatten()): s_h.physical_units() rvir = h.rvir.in_units(s_h.g['pos'].units) width = '%1.2f kpc' % (2.1 * rvir) s_h.g['rad_flux_radial'].convert_units("s**-1 m**-2") s_h.g['rad_0_rho'].convert_units("s**-1 m**-2") print "Rvir = %1.2f kpc" % rvir.in_units("kpc") if field == "mass_flux_radial": sph.velocity_image(s_h.g, qty="outflow_rate", units=out_units,\ width=width, av_z=av_z, cmap="RdBu_r", qtytitle=r"$\mathbf{F}_{\mathrm{M}_{\mathrm{gas}}}$",\ subplot=ax, quiverkey=False, vector_color=vc, vector_resolution=20, key_length="1000 km s**-1", **kwargs) elif field == "rad_flux_radial": # sph.velocity_image(s_h.g, qty="rad_flux_radial", units="s**-1 m**-2",\ # width=width, cmap="RdBu_r", qtytitle=r"$\vec{F}_{\mathrm{ion}}$",\ # subplot=ax, quiverkey=False, vector_color=vc, vector_resolution=20, key_length="1000 km s**-1") sph.velocity_image(s_h.g, qty="rad_0_rho", units="s**-1 m**-2",\ width=width, cmap="RdBu_r", qtytitle=r"$\mathbf{F}_{\mathrm{ion}}$",\ subplot=ax, quiverkey=False, vector_color=vc, vector_resolution=20, key_length="1000 km s**-1", vmin=1e8, vmax=1e12) # sph.velocity_image(s_h.g, qty="temp", units="K",\ # width=width, av_z=av_z, cmap="jet", qtytitle=r"T",\ # subplot=ax, quiverkey=False, vector_color="k", vector_resolution=20, key_length="1000 km s**-1") else: sph.velocity_image(s_h.g, qty=field, width=width, cmap="RdBu_r", qtytitle=r"$\rho$$_{\mathrm{gas}}$",\ vector_resolution=20, vector_color=vc, key_x=0.35, key_y=0.815, key_color='yellow', key_length="250 km s**-1", units="Msol kpc**-2", subplot=ax) anno(ax, xy, rvir) anno(ax, xy, rvir / 4., color="r") return s
## fig = plt.figure() ## ax = fig.add_subplot(111) ## ax.xaxis.set_visible(False) ## ax.yaxis.set_visible(False) ## fileOut="img_log_ax_v-z=%.1lf-%i.pdf"% (z,i) ## titleStr = "v - z = %.1lf" % z# + "\n[%.2lf %.2lf %.2lf]"%(rx,ry,rz) ## print (titleStr) ## sph.image(impData.g,qty="v",width=smallbox,cmap="RdYlBu_r", denoise=True ,av_z=False, units="km s^-1", ## log=True, approximate_fast=False,subplot=ax,qtytitle=r"${\rm log}\, v\, {\rm km/s}$" ## ); #vmin=0.006, vmax=1.0, ## plt.savefig(fileOut,dpi=fig.dpi,bbox_inches='tight') ## plt.close(fig) fig = plt.figure() ax = fig.add_subplot(111) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) fileOut="img_log_ax_vt-z=%.1lf-%i.pdf"% (z,i) titleStr = "$v_{t}$ @ z = %.1f" % z + "\nThin slice @ %s" % str(coords) print(titleStr) sph.velocity_image(impData.g, qty="tv", width=smallbox, cmap = "gist_ncar", units="km s^-1", mode='quiver', quiverkey=False,qtytitle=r"${\rm log}\, v_{t}\, {\rm km/s}$", density = 1.0, vector_resolution=40, vmax=1e3, subplot=ax, show_cbar=True, vector_color='black') plt.savefig(fileOut,dpi=fig.dpi,bbox_inches='tight') plt.close(fig) gc.collect() del(s) gc.collect()
# load the halos h = s.halos() # center on the largest halo and align the disk pynbody.analysis.angmom.sideon(h[1]) # create the subplots f, axs = plt.subplots(1, 2, figsize=(14, 6)) #create a simple slice showing the gas temperature, with velocity vectors overlaid sph.velocity_image(h[1].g, vector_color="cyan", qty="temp", width=50, cmap="YlOrRd", denoise=True, approximate_fast=False, subplot=axs[0], show_cbar=False) #you can also make a stream visualization instead of a quiver plot pynbody.analysis.angmom.faceon(h[1]) s['pos'].convert_units('Mpc') sph.velocity_image(s.g, width='3 Mpc', cmap="Greys_r", mode='stream', units='Msol kpc^-2', density=2.0, vector_resolution=100,
import pynbody import pynbody.plot.sph as sph import matplotlib.pylab as plt # load the snapshot and set to physical units s = pynbody.load('testdata/g15784.lr.01024.gz') s.physical_units() # load the halos h = s.halos() # center on the largest halo and align the disk pynbody.analysis.angmom.sideon(h[1]) # create the subplots f, axs = plt.subplots(1,2,figsize=(14,6)) #create a simple slice showing the gas temperature, with velocity vectors overlaid sph.velocity_image(h[1].g, vector_color="cyan", qty="temp",width=50,cmap="YlOrRd", denoise=True,approximate_fast=False, subplot=axs[0], show_cbar = False) #you can also make a stream visualization instead of a quiver plot pynbody.analysis.angmom.faceon(h[1]) s['pos'].convert_units('Mpc') sph.velocity_image(s.g, width='3 Mpc', cmap = "Greys_r", mode='stream', units='Msol kpc^-2', density = 2.0, vector_resolution=100, vmin=1e-1,subplot=axs[1], show_cbar=False, vector_color='black')
subplot=sps[1],vmin=1e16,vmax=1e22,cmap='Greys'); sph.contour(outflow3_part.gas,units='m_p cm^-2', width=width, levels=levels,subplot=sps[2]) setp(ax3.get_yticklabels(), visible=False) setp(ax3.set_ylabel('')) for label in ax3.xaxis.get_ticklabels(): label.set_fontsize(8) sps[3].axis('off') ax3.set_title(ax3.get_title(),fontsize = 12) ax3.add_artist(circle) show() #--------------------------------------------------------- sph.velocity_image(outflow1_part.gas,vector_color="cyan",qty="temp", width=xymax,cmap="YlOrRd", approximate_fast=False,fill_nan=True,fill_val = 0.0) sph.image(s.gas,width=500) #HI map hiif = pynbody.analysis.ionfrac.calculate(s.gas,ion='hi') s.gas['hiden'] = s.gas['rho']*s.gas['hydrogen']*hiif s.gas['hiden'].units = s.gas['rho'].units #shiim = sph.image(s.gas,qty='hiden', # units='m_p cm^-2', width=5*xymax, clear=False, # title='N$_{HI}$ cm$^{-2}$', # vmin=1e12,vmax=1e20); sim = sph.image(s.gas, units='m_p cm^-2', width=5*xymax, clear=False, title='N$_{gas}$ cm$^{-2}$',