def main(): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') mass = (10**12.5) * u.M_sun z = 0 makino_env_12p5 = MakinoProfile( mass, z, delta_vir=200, cosmo=cosmology.Planck15, concentration_method='klypin-planck-relaxed') theta_deg = 15 M_x = 25 Q = 1e37 * u.W jet_12p5 = jet.AstroJet(theta_deg, M_x, makino_env_12p5.sound_speed, makino_env_12p5.central_density, Q, makino_env_12p5.gamma) data = pk.simulations.load_timestep_data(452, '../tests/data/pluto/') z = 0.1 beam_width = 5 * u.arcsec uv = jet.get_unit_values(makino_env_12p5, jet_12p5) l = radio.get_luminosity(data, uv, z, beam_width, ) f = radio.get_flux_density(l, z) fc = radio.get_convolved_flux_density(f, z, beam_width) sb = radio.get_surface_brightness(f, data, uv, z, beam_width) cmap = plt.cm.plasma norm = mpl.colors.Normalize(vmin=-3, vmax=0) colors = cmap(norm(np.log10(sb.to(u.mJy).T.value))) k = 0 for i in range(0, 360, 90): #r = np.arange(1, 11) #θ = np.arange(0, 100, 10) r = data.x1[:600] θ = data.x2 φ = np.deg2rad(np.full_like(r, i)) rr, θθ, φφ = np.meshgrid(r, θ, φ) xx = rr * np.sin(θθ) * np.cos(φφ) yy = rr * np.sin(θθ) * np.sin(φφ) zz = rr * np.cos(θθ) #ax.plot(xx[:,:,1], yy[:,:,1], zs=φφ[:,1,1], zdir='z') #ax.plot(xx[:,:,1], yy[:,:,1], zs=zz[:,1,1], color=f'C{k}') #ax.plot(xx[:,:,1].T, yy[:,:,1].T, zs=zz[1,:,1], color=f'C{k}') ax.plot_surface(xx[:,:,1], yy[:,:,1], zz[:,:,1], linewidth=0, antialiased=True, alpha=1, facecolors=colors) ax.set_aspect('equal') k += 1 sc = mpl.cm.ScalarMappable(cmap=cmap, norm=norm) sc.set_array([]) plt.colorbar(sc) plt.show()
def test_get_surface_brightness(datafiles, makino_env_12p5, jet_12p5): from plutokore import jet from plutokore import io from astropy import units as u assert len(datafiles.listdir()) == 1 path = str(datafiles.listdir()[0]) data = io.pload(0, w_dir=path) z = 0.1 beam_width = 5 * u.arcsec ntracers = 4 uv = jet.get_unit_values(makino_env_12p5, jet_12p5) l = radio.get_luminosity(data, uv, z, beam_width) f = radio.get_flux_density(l, z) fc = radio.get_convolved_flux_density(f, z, beam_width) sb = radio.get_surface_brightness(f, data, uv, z, beam_width)
def main(): fig = plt.figure() ax = fig.add_subplot(111) mass = (10**12.5) * u.M_sun redshift = 0 makino_env_12p5 = MakinoProfile( mass, redshift, delta_vir=200, cosmo=cosmology.Planck15, concentration_method='klypin-planck-relaxed') theta_deg = 15 M_x = 25 Q = 1e37 * u.W jet_12p5 = jet.AstroJet(theta_deg, M_x, makino_env_12p5.sound_speed, makino_env_12p5.central_density, Q, makino_env_12p5.gamma) data = pk.simulations.load_timestep_data(452, '../tests/data/pluto/') redshift = 0.1 beam_width = 5 * u.arcsec uv = jet.get_unit_values(makino_env_12p5, jet_12p5) l = radio.get_luminosity(data, uv, redshift, beam_width, ) f = radio.get_flux_density(l, redshift) #sb = radio.get_surface_brightness(f, data, uv, redshift, beam_width).to(u.Jy).value #sb = radio.convolve_surface_brightness(sb, uv, redshift, beam_width).to(u.Jy) sb = f.to(u.Jy).value xmax=30 xstep=1 zmax=60 zstep=1 ymax = max(xmax, zmax) ystep = min(xstep, zstep) x = np.arange(0, xmax, xstep) z = np.arange(0, zmax, zstep) y = np.arange(-ymax, ymax, ystep) final = np.zeros((x.shape[0], z.shape[0])) raytrace_surface_brightness( r=data.x1, θ=data.x2, x=x, y=y, z=z, final=final, sb=sb ) final = final * u.Jy kpc_per_arcsec = cosmology.Planck15.kpc_proper_per_arcmin(redshift).to(u.kpc / u.arcsec) # beam information sigma_beam_arcsec = beam_width / 2.355 area_beam_kpc2 = (np.pi * (sigma_beam_arcsec * kpc_per_arcsec) **2).to(u.kpc**2) radio_cell_areas = np.full(final.shape, xstep * zstep) # in physical units radio_cell_areas_physical = radio_cell_areas * uv.length**2 # n beams per cell n_beams_per_cell = (radio_cell_areas_physical / area_beam_kpc2).si final = final / n_beams_per_cell final_convolved = radio.convolve_surface_brightness(final, uv, redshift, beam_width) # rr, θθ = np.meshgrid(r, θ) # x = r * np.sin(θθ) * np.cos(φ) # y = r * np.sin(θθ) * np.sin(φ) # z = r * np.cos(θθ) #im = ax.pcolormesh(x, z, np.log10(sb.to(u.mJy).T.value), vmin=-3, vmax=0, cmap='viridis') im = ax.pcolormesh(x, z, np.log10(final_convolved.to(u.mJy).T.value), vmin=-3, vmax=3, cmap='viridis') fig.colorbar(im) ax.set_xlim(0, 30) ax.set_ylim(0, 60) ax.set_aspect('equal') plt.show()
def plot_surface_brightness(timestep, unit_values, run_dirs, filename, redshift=0.1, beamsize=5 * u.arcsec, showbeam=True, xlim=(-200, 200), ylim=(-750, 750), #actually z in arcsec xticks=None, pixel_size=1.8 * u.arcsec, beam_x=0.8, beam_y=0.8, png=True, contours=True, convolve=True, half_plane=True, vmin=-3.0, vmax=2.0, no_labels=False, with_hist=False, #set to false ): from plutokore import radio from numba import jit from astropy.convolution import convolve, Gaussian2DKernel @jit(nopython=True) def raytrace_surface_brightness(r, theta, x, y, z, raytraced_values, original_values): phi = 0 rmax = np.max(r) thetamax = np.max(theta) x_half_step = (x[1] - x[0]) * 0.5 pi2_recip = (1 / (2 * np.pi)) visited = np.zeros(original_values.shape) for x_index in range(len(x)): for z_index in range(len(z)): visited[:,:] = 0 for y_index in range(len(y)): # Calculate the coordinates of this point ri = np.sqrt(x[x_index] **2 + y[y_index] ** 2 + z[z_index] ** 2) if ri == 0: continue if ri > rmax: continue thetai = np.arccos(z[z_index] / ri) if thetai > thetamax: continue phii = 0 # Don't care about φi!! chord_length = np.abs(np.arctan2(y[y_index], x[x_index] + x_half_step) - np.arctan2(y[y_index], x[x_index] - x_half_step)) # Now find index in r and θ arrays corresponding to this point r_index = np.argmax(r>ri) theta_index = np.argmax(theta>thetai) # Only add this if we have not already visited this cell (twice) if visited[r_index, theta_index] <= 1: raytraced_values[x_index, z_index] += original_values[r_index, theta_index] * chord_length * pi2_recip visited[r_index, theta_index] += 1 #return raytraced_values return fig, ax = newfig(1, 1.8) #fig, ax = figsize(10,50) # calculate beam radius sigma_beam = (beamsize / 2.355) # calculate kpc per arcsec kpc_per_arcsec = cosmo.kpc_proper_per_arcmin(redshift).to(u.kpc / u.arcsec) # load timestep data file d = pp.pload(timestep,w_dir = run_dir) X1, X2 = pk.simulations.sphericaltocartesian(d) X1 = X1 * (unit_values.length / kpc_per_arcsec).to(u.arcsec).value X2 = X2 * (unit_values.length / kpc_per_arcsec).to(u.arcsec).value l = radio.get_luminosity(d, unit_values, redshift, beamsize) f = radio.get_flux_density(l, redshift).to(u.Jy).value #sb = radio.get_surface_brightness(f, d, unit_values, redshift, beamsize).to(u.Jy) xmax = (((xlim[1] * u.arcsec + pixel_size) * kpc_per_arcsec) / unit_values.length).si xstep = (pixel_size * kpc_per_arcsec / unit_values.length).si zmax = (((ylim[1] * u.arcsec + pixel_size) * kpc_per_arcsec) / unit_values.length).si zstep = (pixel_size * kpc_per_arcsec / unit_values.length).si ymax = max(xmax, zmax) ystep = min(xstep, zstep) ystep = 0.5 if half_plane: x = np.arange(-xmax, xmax, xstep) z = np.arange(-zmax, zmax, zstep) else: x = np.arange(0, xmax, xstep) z = np.arange(0, zmax, zstep) y = np.arange(-ymax, ymax, ystep) raytraced_flux = np.zeros((x.shape[0], z.shape[0])) # print(f'xlim in arcsec is {xlim[1]}, xlim in code units is {xlim[1] * u.arcsec * kpc_per_arcsec / unit_values.length}') # print(f'zlim in arcsec is {ylim[1]}, zlim in code units is {ylim[1] * u.arcsec * kpc_per_arcsec / unit_values.length}') # print(f'xmax is {xmax}, ymax is {ymax}, zmax is {zmax}') # print(f'x shape is {x.shape}; y shape is {y.shape}; z shape is {z.shape}') raytrace_surface_brightness( r=d.x1, theta=d.x2, x=x, y=y, z=z, original_values=f, raytraced_values=raytraced_flux ) raytraced_flux = raytraced_flux * u.Jy # beam information sigma_beam_arcsec = beamsize / 2.355 area_beam_kpc2 = (np.pi * (sigma_beam_arcsec * kpc_per_arcsec) **2).to(u.kpc**2) beams_per_cell = (((pixel_size * kpc_per_arcsec) ** 2) / area_beam_kpc2).si #beams_per_cell = (area_beam_kpc2 / ((pixel_size * kpc_per_arcsec) ** 2)).si # radio_cell_areas = np.full(raytraced_flux.shape, xstep * zstep) * (unit_values.length ** 2) # n beams per cell #n_beams_per_cell = (radio_cell_areas / area_beam_kpc2).si raytraced_flux /= beams_per_cell stddev = sigma_beam_arcsec / beamsize beam_kernel = Gaussian2DKernel(stddev) if convolve: flux = convolve(raytraced_flux.to(u.Jy), beam_kernel, boundary='extend') * u.Jy else: flux = raytraced_flux.to(u.Jy) #flux = radio.convolve_surface_brightness(raytraced_flux, unit_values, redshift, beamsize) #flux = raytraced_flux #return (x, z, flux) # x_coords, z_coords, surfb = plot_surface_brightness(...) X1 = x * (unit_values.length / kpc_per_arcsec).to(u.arcsec).value X2 = z * (unit_values.length / kpc_per_arcsec).to(u.arcsec).value return (X1, X2, flux) # x_coords, z_coords, surfb = plot_surface_brightness(...) # plot data keep ax.set_xlim(xlim) ax.set_ylim(ylim) contour_color = 'k' contour_linewidth = 0.33 #contour_levels = [-3, -1, 1, 2] contour_levels = [-2, -1, 0, 1, 2] # Contours start at 10 μJy #with plt.style.context('flux-plot.mplstyle'): keep im = ax.pcolormesh( X1, X2, np.log10(flux.to(u.mJy).value).T, shading='flat', vmin=vmin, vmax=vmax) im.set_rasterized(True) if contours: ax.contour(X1, X2, np.log10(flux.to(u.mJy).value).T, contour_levels, linewidths=contour_linewidth, colors=contour_color) im = ax.pcolormesh( -X1, X2, np.log10(flux.to(u.mJy).value).T, shading='flat', vmin=vmin, vmax=vmax) im.set_rasterized(True) if contours: ax.contour(-X1, X2, np.log10(flux.to(u.mJy).value).T, contour_levels, linewidths=contour_linewidth, colors=contour_color) if not half_plane: im = ax.pcolormesh( X1, -X2, np.log10(flux.to(u.mJy).value).T, shading='flat', vmin=vmin, vmax=vmax) im.set_rasterized(True) if contours: ax.contour(X1, -X2, np.log10(flux.to(u.mJy).value).T, contour_levels, linewidths=contour_linewidth, colors=contour_color) im = ax.pcolormesh( -X1, -X2, np.log10(flux.to(u.mJy).value).T, shading='flat', vmin=vmin, vmax=vmax) im.set_rasterized(True) if contours: ax.contour(-X1, -X2, np.log10(flux.to(u.mJy).value).T, contour_levels, linewidths=contour_linewidth, colors=contour_color) if with_hist: div = make_axes_locatable(ax) #from mpl_toolkits.axes_grid1 import make_axes_locatable ax_hist = div.append_axes('right', '30%', pad=0.0) s = np.sum(flux.to(u.mJy).value, axis=0) ax_hist.plot(np.concatenate([s, s]), np.concatenate([X2, -X2])) ax_hist.set_yticklabels([]) if not no_labels: (ca, div, cax) = create_colorbar( im, ax, fig, position='right', padding=0.5) ca.set_label(r'$\log_{10}\mathrm{mJy / beam}$') circ = plt.Circle( (xlim[1] * beam_x, ylim[0] * beam_y), color='w', fill=True, radius=sigma_beam.to(u.arcsec).value, alpha=0.7) #circ.set_rasterized(True) if showbeam: ax.add_artist(circ) # reset limits if not no_labels: ax.set_xlabel('X ($\'\'$)') ax.set_ylabel('Y ($\'\'$)') ax.set_aspect('equal') if xticks is not None: ax.set_xticks(xticks) if no_labels: ax.set_position([0, 0, 1, 1]) ax.set_xticks([]) ax.set_yticks([]) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.axis('off') ax.set_aspect('equal') if no_labels: savefig(filename, fig, png=png, kwargs={ 'bbox_inches': 'tight', 'pad_inches': 0} ) else: savefig(filename, fig, png=png, dpi = 300) plt.show()
def internal(fig, a, sim, times, unit_values): from plutokore import radio from plutokore.plot import create_colorbar from numba import jit from astropy.convolution import convolve, Gaussian2DKernel from astropy.cosmology import Planck15 as cosmo @jit(nopython=True) def raytrace_surface_brightness(r, θ, x, y, z, raytraced_values, original_values): φ = 0 rmax = np.max(r) θmax = np.max(θ) x_half_step = (x[1] - x[0]) * 0.5 pi2_recip = (1 / (2 * np.pi)) visited = np.zeros(original_values.shape) for x_index in range(len(x)): for z_index in range(len(z)): visited[:,:] = 0 for y_index in range(len(y)): # Calculate the coordinates of this point ri = np.sqrt(x[x_index] **2 + y[y_index] ** 2 + z[z_index] ** 2) if ri == 0: continue if ri > rmax: continue θi = np.arccos(z[z_index] / ri) if θi > θmax: continue φi = 0 # Don't care about φi!! chord_length = np.abs(np.arctan2(y[y_index], x[x_index] + x_half_step) - np.arctan2(y[y_index], x[x_index] - x_half_step)) # Now find index in r and θ arrays corresponding to this point r_index = np.argmax(r>ri) θ_index = np.argmax(θ>θi) # Only add this if we have not already visited this cell (twice) if visited[r_index, θ_index] <= 1: raytraced_values[x_index, z_index] += original_values[r_index, θ_index] * chord_length * pi2_recip visited[r_index, θ_index] += 1 #return raytraced_values return redshift=0.1 beamsize=5 * u.arcsec showbeam=True xlim=(-15, 15) ylim=(-30, 30) xticks=None pixel_size=1.8 * u.arcsec beam_x=0.8 beam_y=0.8 png=False contours=True should_convolve=True half_plane=False vmin=-3.0 vmax=2.0 style='flux-plot.mplstyle' no_labels=False with_hist=True trc_cutoff = 0.001 output = np.where(times >= comp_time)[0][0] # calculate beam radius sigma_beam = (beamsize / 2.355) # calculate kpc per arcsec kpc_per_arcsec = cosmo.kpc_proper_per_arcmin(redshift).to(u.kpc / u.arcsec) # load timestep data file d = pk.simulations.load_timestep_data(output, sim) X1, X2 = pk.simulations.sphericaltocartesian(d) X1 = X1 * (unit_values.length / kpc_per_arcsec).to(u.arcsec).value X2 = X2 * (unit_values.length / kpc_per_arcsec).to(u.arcsec).value l = radio.get_luminosity(d, unit_values, redshift, beamsize) f = radio.get_flux_density(l, redshift).to(u.Jy).value #sb = radio.get_surface_brightness(f, d, unit_values, redshift, beamsize).to(u.Jy) xmax = (((xlim[1] * u.arcsec + pixel_size) * kpc_per_arcsec) / unit_values.length).si xstep = (pixel_size * kpc_per_arcsec / unit_values.length).si zmax = (((ylim[1] * u.arcsec + pixel_size) * kpc_per_arcsec) / unit_values.length).si zstep = (pixel_size * kpc_per_arcsec / unit_values.length).si ymax = max(xmax, zmax) ystep = min(xstep, zstep) ystep = 0.5 if half_plane: x = np.arange(-xmax, xmax, xstep) z = np.arange(-zmax, zmax, zstep) else: x = np.arange(0, xmax, xstep) z = np.arange(0, zmax, zstep) y = np.arange(-ymax, ymax, ystep) raytraced_flux = np.zeros((x.shape[0], z.shape[0])) # print(f'xlim in arcsec is {xlim[1]}, xlim in code units is {xlim[1] * u.arcsec * kpc_per_arcsec / unit_values.length}') # print(f'zlim in arcsec is {ylim[1]}, zlim in code units is {ylim[1] * u.arcsec * kpc_per_arcsec / unit_values.length}') # print(f'xmax is {xmax}, ymax is {ymax}, zmax is {zmax}') # print(f'x shape is {x.shape}; y shape is {y.shape}; z shape is {z.shape}') raytrace_surface_brightness( r=d.x1, θ=d.x2, x=x, y=y, z=z, original_values=f, raytraced_values=raytraced_flux ) raytraced_flux = raytraced_flux * u.Jy # beam information sigma_beam_arcsec = beamsize / 2.355 area_beam_kpc2 = (np.pi * (sigma_beam_arcsec * kpc_per_arcsec) **2).to(u.kpc**2) beams_per_cell = (((pixel_size * kpc_per_arcsec) ** 2) / area_beam_kpc2).si #beams_per_cell = (area_beam_kpc2 / ((pixel_size * kpc_per_arcsec) ** 2)).si # radio_cell_areas = np.full(raytraced_flux.shape, xstep * zstep) * (unit_values.length ** 2) # n beams per cell #n_beams_per_cell = (radio_cell_areas / area_beam_kpc2).si raytraced_flux /= beams_per_cell stddev = sigma_beam_arcsec / beamsize beam_kernel = Gaussian2DKernel(stddev) if should_convolve: flux = convolve(raytraced_flux.to(u.Jy), beam_kernel, boundary='extend') * u.Jy else: flux = raytraced_flux.to(u.Jy) #flux = radio.convolve_surface_brightness(raytraced_flux, unit_values, redshift, beamsize) #flux = raytraced_flux X1 = x * (unit_values.length / kpc_per_arcsec).to(u.arcsec).value X2 = z * (unit_values.length / kpc_per_arcsec).to(u.arcsec).value # plot data a.set_xlim(xlim) a.set_ylim(ylim) contour_color = 'k' contour_linewidth = 0.33 # contour_levels = [-3, -1, 1, 2] contour_levels = [-2, -1, 0, 1, 2] # Contours start at 10 μJy im = a.pcolormesh( X1, X2, np.log10(flux.to(u.mJy).value).T, shading='flat', edgecolors = 'face', rasterized = True, vmin=vmin, vmax=vmax) if contours: a.contour(X1, X2, np.log10(flux.to(u.mJy).value).T, contour_levels, linewidths=contour_linewidth, colors=contour_color) im = a.pcolormesh( -X1, X2, np.log10(flux.to(u.mJy).value).T, shading='flat', vmin=vmin, vmax=vmax) im.set_rasterized(True) if contours: a.contour(-X1, X2, np.log10(flux.to(u.mJy).value).T, contour_levels, linewidths=contour_linewidth, colors=contour_color) if not half_plane: im = a.pcolormesh( X1, -X2, np.log10(flux.to(u.mJy).value).T, shading='flat', vmin=vmin, vmax=vmax) im.set_rasterized(True) if contours: a.contour(X1, -X2, np.log10(flux.to(u.mJy).value).T, contour_levels, linewidths=contour_linewidth, colors=contour_color) im = a.pcolormesh( -X1, -X2, np.log10(flux.to(u.mJy).value).T, shading='flat', vmin=vmin, vmax=vmax) im.set_rasterized(True) if contours: a.contour(-X1, -X2, np.log10(flux.to(u.mJy).value).T, contour_levels, linewidths=contour_linewidth, colors=contour_color) (ca, div, cax) = create_colorbar( im, a, fig, position='right', padding=0.5) ca.set_label(r'$\log_{10}\mathrm{mJy / beam}$') circ = plot.Circle( (xlim[1] * beam_x, ylim[0] * beam_y), color='w', fill=True, radius=sigma_beam.to(u.arcsec).value, alpha=0.7) a.add_artist(circ)
def calculate_surface_brightness(*, sim_dir, output_number, xmax, ymax, redshift, beamsize, pixel_size): xlim = [-xmax, xmax] ylim = [-ymax, ymax] # load sim config uv, env, jet = pk.configuration.load_simulation_info( os.path.join(sim_dir, 'config.yaml')) # create our figure fig, ax = plot.subplots(figsize=(2, 2)) # calculate beam radius sigma_beam = (beamsize / 2.355) # calculate kpc per arcsec kpc_per_arcsec = cosmo.kpc_proper_per_arcmin(redshift).to(u.kpc / u.arcsec) # load timestep data file d = pk.simulations.load_timestep_data(output_number, sim_dir) # calculate luminosity and unraytraced flux l = radio.get_luminosity(d, uv, redshift, beamsize) f = radio.get_flux_density(l, redshift).to(u.Jy).value # calculate raytracing grid xmax = (((xlim[1] * u.arcsec + pixel_size) * kpc_per_arcsec) / uv.length).si xstep = (pixel_size * kpc_per_arcsec / uv.length).si zmax = (((ylim[1] * u.arcsec + pixel_size) * kpc_per_arcsec) / uv.length).si zstep = (pixel_size * kpc_per_arcsec / uv.length).si ymax = max(xmax, zmax) ystep = min(xstep, zstep) ystep = 0.5 x = np.arange(0, xmax, xstep) z = np.arange(0, zmax, zstep) y = np.arange(-ymax, ymax, ystep) raytraced_flux = np.zeros((x.shape[0], z.shape[0])) # raytrace surface brightness raytrace_surface_brightness(r=d.x1, theta=d.x2, x=x, y=y, z=z, original_values=f, raytraced_values=raytraced_flux) raytraced_flux = raytraced_flux * u.Jy # beam information area_beam_kpc2 = (np.pi * (sigma_beam * kpc_per_arcsec)**2).to(u.kpc**2) beams_per_cell = (((pixel_size * kpc_per_arcsec)**2) / area_beam_kpc2).si raytraced_flux /= beams_per_cell beam_kernel = Gaussian2DKernel(sigma_beam.value) flux = convolve(raytraced_flux.to(u.Jy), beam_kernel, boundary='extend') * u.Jy X1 = x * (uv.length / kpc_per_arcsec).to(u.arcsec).value X2 = z * (uv.length / kpc_per_arcsec).to(u.arcsec).value return (X1, X2, flux.to(u.mJy), l.sum())
def calculate_surface_brightness(*, sim_data, uv, observing_properties, do_convolve, is_quarter_plane): xlim = observing_properties['ylim'] ylim = observing_properties['xlim'] # calculate beam radius sigma_beam = (observing_properties['beamwidth'] / 2.355) # calculate kpc per arcsec kpc_per_arcsec = cosmo.kpc_proper_per_arcmin( observing_properties['redshift']).to(u.kpc / u.arcsec) # load timestep data file d = sim_data # calculate luminosity and unraytraced flux l = radio.get_luminosity(d, uv, observing_properties['redshift'], observing_properties['beamwidth']) f = radio.get_flux_density(l, observing_properties['redshift']).to(u.Jy).value # calculate raytracing grid xmax = ((xlim[1] + observing_properties['pixelsize'] * kpc_per_arcsec) / uv.length).si zmax = ((ylim[1] + observing_properties['pixelsize'] * kpc_per_arcsec) / uv.length).si if not is_quarter_plane: xmin = ( (xlim[0] - observing_properties['pixelsize'] * kpc_per_arcsec) / uv.length).si zmin = ( (ylim[0] - observing_properties['pixelsize'] * kpc_per_arcsec) / uv.length).si xstep = (observing_properties['pixelsize'] * kpc_per_arcsec / uv.length).si zstep = (observing_properties['pixelsize'] * kpc_per_arcsec / uv.length).si ymax = max(xmax, zmax) ystep = min(xstep, zstep) # ystep = ((0.25 * u.kpc) / uv.length).si if is_quarter_plane: x = np.arange(0, xmax, xstep) z = np.arange(0, zmax, zstep) else: x = np.arange(0, xmax, xstep) z = np.arange(zmin, zmax, zstep) y = np.arange(-ymax, ymax, ystep) raytraced_flux = np.zeros((x.shape[0], z.shape[0])) # raytrace surface brightness raytrace_surface_brightness(r=d.x1, theta=d.x2, x=x, y=y, z=z, original_values=f, raytraced_values=raytraced_flux) raytraced_flux = raytraced_flux * u.Jy # beam information area_beam_kpc2 = (np.pi * (sigma_beam * kpc_per_arcsec)**2).to(u.kpc**2) beams_per_cell = (( (observing_properties['pixelsize'] * kpc_per_arcsec)**2) / area_beam_kpc2).si raytraced_flux /= beams_per_cell beam_kernel = Gaussian2DKernel(sigma_beam.value) if do_convolve: flux = convolve( raytraced_flux.to(u.Jy), beam_kernel, boundary='extend') * u.Jy else: flux = raytraced_flux X1 = x * (uv.length / kpc_per_arcsec).to(u.arcsec).value X2 = z * (uv.length / kpc_per_arcsec).to(u.arcsec).value return (X1, X2, flux.to(u.mJy))
def plot_sb(*, sim_dir, out_dir, output_number, xmax, ymax): xlim = [-xmax, xmax] ylim = [-ymax, ymax] redshift=0.05 beamsize=5 * u.arcsec pixel_size = 1.8 * u.arcsec vmin = -3.0 vmax = 2.0 # load sim config uv, env, jet = pk.configuration.load_simulation_info(sim_dir + 'config.yaml') # create our figure fig, ax = plot.subplots(figsize=(2, 2)) # calculate beam radius sigma_beam = (beamsize / 2.355) # calculate kpc per arcsec kpc_per_arcsec = cosmo.kpc_proper_per_arcmin(redshift).to(u.kpc / u.arcsec) # load timestep data file d = pk.simulations.load_timestep_data(output_number, sim_dir) # calculate luminosity and unraytraced flux l = radio.get_luminosity(d, uv, redshift, beamsize) f = radio.get_flux_density(l, redshift).to(u.Jy).value # calculate raytracing grid xmax = (((xlim[1] * u.arcsec + pixel_size) * kpc_per_arcsec) / uv.length).si xstep = (pixel_size * kpc_per_arcsec / uv.length).si zmax = (((ylim[1] * u.arcsec + pixel_size) * kpc_per_arcsec) / uv.length).si zstep = (pixel_size * kpc_per_arcsec / uv.length).si ymax = max(xmax, zmax) ystep = min(xstep, zstep) ystep = 0.5 x = np.arange(0, xmax, xstep) z = np.arange(0, zmax, zstep) y = np.arange(-ymax, ymax, ystep) raytraced_flux = np.zeros((x.shape[0], z.shape[0])) # raytrace surface brightness raytrace_surface_brightness( r=d.x1, θ=d.x2, x=x, y=y, z=z, original_values=f, raytraced_values=raytraced_flux ) raytraced_flux = raytraced_flux * u.Jy # beam information area_beam_kpc2 = (np.pi * (sigma_beam * kpc_per_arcsec) **2).to(u.kpc**2) beams_per_cell = (((pixel_size * kpc_per_arcsec) ** 2) / area_beam_kpc2).si raytraced_flux /= beams_per_cell beam_kernel = Gaussian2DKernel(sigma_beam.value) flux = convolve(raytraced_flux.to(u.Jy), beam_kernel, boundary='extend') * u.Jy X1 = x * (uv.length / kpc_per_arcsec).to(u.arcsec).value X2 = z * (uv.length / kpc_per_arcsec).to(u.arcsec).value ax.set_xlim(xlim) ax.set_ylim(ylim) contour_color = 'cyan' contour_linewidth = 0.33 contour_levels = [-2, -1, 0, 1, 2] # Contours start at 10 μJy contour_linestyles = ['dashed', 'dashed', 'solid', 'solid', 'solid'] im = ax.pcolormesh( X1, X2, np.log10(flux.to(u.mJy).value).T, shading='flat', vmin=vmin, vmax=vmax, cmap='afmhot') im.set_rasterized(True) ax.contour(X1, X2, np.log10(flux.to(u.mJy).value).T, contour_levels, linewidths=contour_linewidth, colors=contour_color, linestyles=contour_linestyles) im = ax.pcolormesh( -X1, X2, np.log10(flux.to(u.mJy).value).T, shading='flat', vmin=vmin, vmax=vmax, cmap='afmhot') im.set_rasterized(True) ax.contour(-X1, X2, np.log10(flux.to(u.mJy).value).T, contour_levels, linewidths=contour_linewidth, colors=contour_color, linestyles=contour_linestyles) im = ax.pcolormesh( X1, -X2, np.log10(flux.to(u.mJy).value).T, shading='flat', vmin=vmin, vmax=vmax, cmap='afmhot') im.set_rasterized(True) ax.contour(X1, -X2, np.log10(flux.to(u.mJy).value).T, contour_levels, linewidths=contour_linewidth, colors=contour_color, linestyles=contour_linestyles) im = ax.pcolormesh( -X1, -X2, np.log10(flux.to(u.mJy).value).T, shading='flat', vmin=vmin, vmax=vmax, cmap='afmhot') im.set_rasterized(True) ax.contour(-X1, -X2, np.log10(flux.to(u.mJy).value).T, contour_levels, linewidths=contour_linewidth, colors=contour_color, linestyles=contour_linestyles) ax.set_aspect('equal') ax.set_position([0, 0, 1, 1]) ax.set_xticks([]) ax.set_yticks([]) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.axis('off') pk.plot.savefig(f'{out_dir}/{output_number:04}', fig, png=True, dpi=500, kwargs={ 'bbox_inches': 'tight', 'pad_inches': 0}) plot.close();