def single_frame(num, max_pixel, nframes): snap = "%04d" % num # Define path path = '/cosma/home/dp004/dc-rope1/cosma7/SWIFT/' \ 'hydro_1380_data/ani_hydro_' + snap + ".hdf5" snap = "%05d" % num data = load(path) meta = data.metadata boxsize = meta.boxsize[0] z = meta.redshift print("Boxsize:", boxsize) filters = ('JWST.NIRCAM.F480M', 'JWST.NIRCAM.F150W', 'JWST.NIRCAM.F090W') weights = {'JWST.NIRCAM.F480M': 1, 'JWST.NIRCAM.F150W': 0.99, 'JWST.NIRCAM.F090W': 1} # Define centre cent = np.array([11.76119931, 3.95795609, 1.26561173]) # Define targets targets = [[0, 0, 0]] ang_v = -360 / (1380 - 60) decay = lambda t: (boxsize.value + 5) * np.exp(-0.01637823848547536 * t) anti_decay = lambda t: 1.5 * np.exp(0.005139614587492267 * (t - 901)) id_frames = np.arange(0, 1381, dtype=int) rs = np.zeros(len(id_frames), dtype=float) # rs[0: 151] = decay(id_frames[0:151]) # rs[151:901] = 1.5 # rs[901:] = anti_decay(id_frames[901:]) rs[:] = 1 simtimes = np.zeros(len(id_frames), dtype=int) id_targets = np.zeros(len(id_frames), dtype=int) ts = np.full(len(id_frames), 5) ps = np.zeros(len(id_frames)) # ps[0:60] = 0 # ps[60:] = ang_v * (id_frames[60:] - 60) # ps[-2:] = -360 zoom = np.full(len(id_frames), 1) extent = np.full(len(id_frames), 10) # Define anchors dict for camera parameters anchors = {} anchors['sim_times'] = list(simtimes) anchors['id_frames'] = list(id_frames) anchors['id_targets'] = list(id_targets) anchors['r'] = list(rs) anchors['t'] = list(ts) anchors['p'] = list(ps) anchors['zoom'] = list(zoom) anchors['extent'] = list(extent) print("Processing frame with properties:") for key, val in anchors.items(): print(key, "=", val[num]) # Define the camera trajectory cam_data = camera_tools.get_camera_trajectory(targets, anchors) # Get colormap # cmap = cmaps.sunlight() cmap = ml.cm.magma poss = data.gas.coordinates.value mass = data.gas.masses.value * 10 ** 10 # okinds = np.linalg.norm(poss - cent, axis=1) < 1 # cent = np.average(poss[okinds], weights=rho_gas[okinds], axis=0) print("Centered on:", cent) poss -= cent hsmls = data.gas.smoothing_lengths.value poss[np.where(poss > boxsize.value / 2)] -= boxsize.value poss[np.where(poss < - boxsize.value / 2)] += boxsize.value # Get images rgb_gas, extent = getimage(cam_data, poss, mass, hsmls, num, max_pixel, cmap, Type="gas") # Get colormap cmap = ml.cm.Greys_r try: poss = data.stars.coordinates.value - cent mass = data.stars.masses.value * 10 ** 10 hsmls = data.stars.smoothing_lengths.value if hsmls.max() == 0.0: print("Ill-defined smoothing lengths") last_snap = "%04d" % (num - 1) # Define path path = '/cosma/home/dp004/dc-rope1/cosma7/SWIFT/' \ 'hydro_1380/data/ani_hydro_' + last_snap + ".hdf5" data = load(path) old_hsmls = data.stars.smoothing_lengths.value hsmls[:old_hsmls.size] = old_hsmls hsmls[old_hsmls.size:] = np.median(old_hsmls) Lum = photm.lum(num, data, kappa=0.007895, z=z, BC_fac=1, cent=cent, campos=rs[num], IMF='Chabrier_300', filters=filters, Type='Total', log10t_BC=7., extinction='default') poss[np.where(poss > boxsize.value / 2)] -= boxsize.value poss[np.where(poss < - boxsize.value / 2)] += boxsize.value rgb_stars = np.zeros((5000, 5000, 3)) for i, f in enumerate(filters): print(f) # Get images rgb_stars[:, :, i], extent = getimage(cam_data, poss, Lum[f], hsmls, num, max_pixel, cmap, Type="star") rgb_stars[:, :, i] *= weights[f] rgb_stars = get_normalised_image(rgb_stars, vmin=16.5, vmax=22.5) except AttributeError as e: print(e) rgb_stars = np.zeros_like(rgb_gas) blend = Blend.Blend(rgb_gas, rgb_stars) rgb_output = blend.Screen() extent = [0, 2 * anchors["r"][num] / anchors["zoom"][num], 0, 2 * anchors["r"][num] / anchors["zoom"][num]] fig = plt.figure(figsize=(4, 4)) ax = fig.add_subplot(111) ax.imshow(rgb_stars, extent=extent, origin='lower') ax.tick_params(axis='both', left=False, top=False, right=False, bottom=False, labelleft=False, labeltop=False, labelright=False, labelbottom=False) ax.text(0.975, 0.05, "$t=$%.1f Gyr" % cosmo.age(z).value, transform=ax.transAxes, verticalalignment="top", horizontalalignment='right', fontsize=5, color="w") # ax.plot([0.05, 0.15], [0.025, 0.025], lw=0.75, color='w', clip_on=False, transform=ax.transAxes) ax.plot([0.05, 0.05], [0.022, 0.027], lw=0.75, color='w', clip_on=False, transform=ax.transAxes) ax.plot([0.15, 0.15], [0.022, 0.027], lw=0.75, color='w', clip_on=False, transform=ax.transAxes) axis_to_data = ax.transAxes + ax.transData.inverted() left = axis_to_data.transform((0.05, 0.075)) right = axis_to_data.transform((0.15, 0.075)) dist = right[0] - left[0] if dist > 0.1: ax.text(0.1, 0.06, "%.1f cMpc" % dist, transform=ax.transAxes, verticalalignment="top", horizontalalignment='center', fontsize=5, color="w") elif 100 > dist * 10**3 > 1: ax.text(0.1, 0.06, "%.1f ckpc" % dist * 10**3, transform=ax.transAxes, verticalalignment="top", horizontalalignment='center', fontsize=5, color="w") else: ax.text(0.1, 0.06, "%.1f cpc" % dist * 10**6, transform=ax.transAxes, verticalalignment="top", horizontalalignment='center', fontsize=5, color="w") plt.margins(0, 0) fig.savefig('plots/Ani/GasStars_starcolour_flythrough_' + snap + '.png', bbox_inches='tight', dpi=1200, pad_inches=0) plt.close(fig)
def single_frame(num, max_pixel, nframes): snap = "%04d" % num # Define path path = '/cosma/home/dp004/dc-rope1/cosma7/SWIFT/hydro_1380_ani/data/ani_hydro_' + snap + ".hdf5" snap = "%05d" % num data = load(path) meta = data.metadata boxsize = meta.boxsize[0] z = meta.redshift print(boxsize, z) print("Physical Box Size:", boxsize / (1 + z)) print("Boxes in frame:", (1 + z)) # Define centre cent = np.array([boxsize / 2, boxsize / 2, boxsize / 2]) # Define targets targets = [[0, 0, 0], ] # Define anchors dict for camera parameters anchors = {} anchors['sim_times'] = [0.0, 'same', 'same', 'same', 'same', 'same', 'same', 'same'] anchors['id_frames'] = np.linspace(0, nframes, 8, dtype=int) anchors['id_targets'] = [0, 'same', 'same', 'same', 'same', 'same', 'same', 'same'] anchors['r'] = [10, 'same', 'same', 'same', 'same', 'same', 'same', 'same'] anchors['t'] = [10, 'same', 'same', 'same', 'same', 'same', 'same', 'same'] anchors['p'] = [-20, 'same', 'same', 'same', 'same', 'same', 'same', 'same'] anchors['zoom'] = [1., 'same', 'same', 'same', 'same', 'same', 'same', 'same'] anchors['extent'] = [1, 'same', 'same', 'same', 'same', 'same', 'same', 'same'] # Define the camera trajectory cam_data = camera_tools.get_camera_trajectory(targets, anchors) poss = data.dark_matter.coordinates.value hsmls = data.dark_matter.softenings.value / (1 + z) poss -= cent poss[np.where(poss > boxsize.value / 2)] -= boxsize.value poss[np.where(poss < - boxsize.value / 2)] += boxsize.value poss /= (1 + z) wrapped_boxes = int(np.ceil(1 + z)) if wrapped_boxes < 5: wrapped_boxes = 5 elif wrapped_boxes % 2 == 0: wrapped_boxes += 1 half_wrapped_boxes = int(wrapped_boxes / 2) wrapped_poss = np.zeros((poss.shape[0] * wrapped_boxes ** 3, 3), dtype=np.float64) wrapped_hsmls = np.zeros(poss.shape[0] * wrapped_boxes ** 3, dtype=np.float64) print(wrapped_poss.shape[0]**(1/3)) n = 0 for i in range(-half_wrapped_boxes, half_wrapped_boxes + 1, 1): for j in range(-half_wrapped_boxes, half_wrapped_boxes + 1, 1): for k in range(-half_wrapped_boxes, half_wrapped_boxes + 1, 1): wrapped_poss[poss.shape[0] * n: poss.shape[0] * (n + 1), :] = poss + np.array([i * boxsize / (1 + z), j * boxsize / (1 + z), k * boxsize / (1 + z)]) wrapped_hsmls[poss.shape[0] * n: poss.shape[0] * (n + 1)] = hsmls n += 1 print(np.min(wrapped_poss, axis=0) * (1 + z), np.max(wrapped_poss, axis=0) * (1 + z)) print(np.min(wrapped_poss, axis=0) * (1 + z) / boxsize, np.max(wrapped_poss, axis=0) * (1 + z) / boxsize) # Get images cmap = cmr.apple rgb_DM_box, ang_extent = getimage(cam_data, poss, hsmls, num, z, cmap) cmap = cmr.neutral rgb_DM_wrapped, ang_extent = getimage(cam_data, wrapped_poss, wrapped_hsmls, num, z, cmap) i = cam_data[num] extent = [0, 2 * np.tan(ang_extent[1]) * i['r'], 0, 2 * np.tan(ang_extent[-1]) * i['r']] print(ang_extent, extent) blend = Blend.Blend(rgb_DM_wrapped, rgb_DM_box) rgb_DM = blend.Overlay() dpi = rgb_DM.shape[0] print(dpi, rgb_DM.shape) fig = plt.figure(figsize=(1, 1.77777777778), dpi=dpi) ax = fig.add_subplot(111) ax.imshow(rgb_DM, extent=ang_extent, origin='lower') ax.tick_params(axis='both', left=False, top=False, right=False, bottom=False, labelleft=False, labeltop=False, labelright=False, labelbottom=False) ax.text(0.975, 0.05, "$t=$%.1f Gyr" % cosmo.age(z).value, transform=ax.transAxes, verticalalignment="top", horizontalalignment='right', fontsize=1, color="w") ax.plot([0.05, 0.15], [0.025, 0.025], lw=0.1, color='w', clip_on=False, transform=ax.transAxes) ax.plot([0.05, 0.05], [0.022, 0.027], lw=0.15, color='w', clip_on=False, transform=ax.transAxes) ax.plot([0.15, 0.15], [0.022, 0.027], lw=0.15, color='w', clip_on=False, transform=ax.transAxes) ax.plot([0.05, 0.15], [0.105, 0.105], lw=0.1, color='w', clip_on=False, transform=ax.transAxes) ax.plot([0.05, 0.05], [0.102, 0.107], lw=0.15, color='w', clip_on=False, transform=ax.transAxes) ax.plot([0.15, 0.15], [0.102, 0.107], lw=0.15, color='w', clip_on=False, transform=ax.transAxes) axis_to_data = ax.transAxes + ax.transData.inverted() left = axis_to_data.transform((0.05, 0.075)) right = axis_to_data.transform((0.15, 0.075)) dist = extent[1] * (right[0] - left[0]) / (ang_extent[1] - ang_extent[0]) print(left, right, (right[0] - left[0]) / (ang_extent[1] - ang_extent[0]), dist) if dist > 0.1: ax.text(0.1, 0.145, "%.1f cMpc" % (dist * (1 + z)), transform=ax.transAxes, verticalalignment="top", horizontalalignment='center', fontsize=1, color="w") ax.text(0.1, 0.065, "%.1f pMpc" % dist, transform=ax.transAxes, verticalalignment="top", horizontalalignment='center', fontsize=1, color="w") elif 100 > dist * 10**3 > 1: ax.text(0.1, 0.065, "%.1f pkpc" % dist * 10**3, transform=ax.transAxes, verticalalignment="top", horizontalalignment='center', fontsize=1, color="w") else: ax.text(0.1, 0.065, "%.1f pkpc" % dist * 10**6, transform=ax.transAxes, verticalalignment="top", horizontalalignment='center', fontsize=1, color="w") plt.margins(0, 0) fig.savefig('plots/Ani/Physical/DMphysical_animation_wrapped_' + snap + '.png', bbox_inches='tight', pad_inches=0) plt.close(fig)
def single_frame(num, max_pixel, nframes): snap = "%04d" % num # Define path path = '/cosma/home/dp004/dc-rope1/cosma7/SWIFT/hydro_1380/data/ani_hydro_' + snap + ".hdf5" snap = "%05d" % num data = load(path) meta = data.metadata boxsize = meta.boxsize[0] z = meta.redshift print(boxsize) # Define targets targets = [[boxsize / 2, boxsize / 2, boxsize / 2]] # Define anchors dict for camera parameters anchors = {} anchors['sim_times'] = [ 0.0, 'same', 'same', 'same', 'same', 'same', 'same', 'same' ] anchors['id_frames'] = np.linspace(0, nframes, 8, dtype=int) anchors['id_targets'] = [ 0, 'same', 'same', 'same', 'same', 'same', 'same', 'same' ] anchors['r'] = [ boxsize.value + 5, 'same', 'same', 'same', 'same', 'same', 'same', 'same' ] anchors['t'] = [5, 'same', 'same', 'same', 'same', 'same', 'same', 'same'] anchors['p'] = [0, 'pass', 'pass', 'pass', 'pass', 'pass', 'pass', -360] anchors['zoom'] = [ 1., 'same', 'same', 'same', 'same', 'same', 'same', 'same' ] anchors['extent'] = [ 10, 'same', 'same', 'same', 'same', 'same', 'same', 'same' ] # Define the camera trajectory cam_data = camera_tools.get_camera_trajectory(targets, anchors) # Get colormap # cmap = cmaps.sunlight() cmap = ml.cm.magma poss = data.gas.coordinates.value hsmls = data.gas.smoothing_lengths.value # Get images rgb_gas, extent = getimage(cam_data, poss, hsmls, num, max_pixel, cmap, Type="gas") # Get colormap cmap = ml.cm.Greys_r poss = data.dark_matter.coordinates.value hsmls = data.dark_matter.softenings.value # Get images rgb_dm, extent = getimage(cam_data, poss, hsmls, num, max_pixel, cmap, Type="dm") blend = Blend.Blend(rgb_dm, rgb_gas) rgb_output = blend.Overlay() fig = plt.figure(figsize=(4, 4)) ax = fig.add_subplot(111) ax.imshow(rgb_output, extent=extent, origin='lower') ax.tick_params(axis='both', left=False, top=False, right=False, bottom=False, labelleft=False, labeltop=False, labelright=False, labelbottom=False) ax.text(0.9, 0.9, "%.3f Gyrs" % cosmo.age(z).value, bbox=dict(boxstyle="round,pad=0.3", fc='w', ec="k", lw=1, alpha=0.8), transform=ax.transAxes, horizontalalignment='right', fontsize=8) fig.savefig('plots/Ani/DMGas_animation_' + snap + '.png', bbox_inches='tight', dpi=300) plt.close(fig)
def single_frame(num, max_pixel, nframes): snap = "%04d" % num # Define path path = '/cosma/home/dp004/dc-rope1/cosma7/SWIFT/hydro_1380_ani/data/ani_hydro_' + snap + ".hdf5" snap = "%05d" % num data = load(path) meta = data.metadata boxsize = meta.boxsize[0] z = meta.redshift print("Boxsize:", boxsize) # Define centre cent = np.array([11.76119931, 3.95795609, 1.26561173]) # Define targets targets = [[0, 0, 0]] ang_v = -360 / (1380 - 60) decay = lambda t: (boxsize.value + 5) * np.exp(-0.01637823848547536 * t) anti_decay = lambda t: 1.5 * np.exp(0.005139614587492267 * (t - 901)) id_frames = np.arange(0, 1381, dtype=int) rs = np.zeros(len(id_frames), dtype=float) rs[0:151] = decay(id_frames[0:151]) rs[151:901] = 1.5 rs[901:] = anti_decay(id_frames[901:]) simtimes = np.zeros(len(id_frames), dtype=int) id_targets = np.zeros(len(id_frames), dtype=int) ts = np.full(len(id_frames), 5) ps = np.zeros(len(id_frames)) ps[0:60] = 0 ps[60:] = ang_v * (id_frames[60:] - 60) ps[-2:] = -360 zoom = np.full(len(id_frames), 1) extent = np.full(len(id_frames), 10) # Define anchors dict for camera parameters anchors = {} anchors['sim_times'] = list(simtimes) anchors['id_frames'] = list(id_frames) anchors['id_targets'] = list(id_targets) anchors['r'] = list(rs) anchors['t'] = list(ts) anchors['p'] = list(ps) anchors['zoom'] = list(zoom) anchors['extent'] = list(extent) print("Processing frame with properties:") for key, val in anchors.items(): print(key, "=", val[num]) # Define the camera trajectory cam_data = camera_tools.get_camera_trajectory(targets, anchors) # Get colormap # cmap = cmaps.sunlight() hex_list = [ "#590925", "#6c1c55", "#7e2e84", "#ba4051", "#f6511d", "#ffb400", "#f7ec59", "#fbf6ac", "#ffffff" ] float_list = [0, 0.2, 0.3, 0.4, 0.45, 0.5, 0.6, 0.8, 1] cmap = get_continuous_cmap(hex_list, float_list=float_list) norm = plt.Normalize(vmin=3.5, vmax=7.5, clip=True) poss = data.gas.coordinates.value temp = data.gas.temperatures.value mass = data.gas.masses.value * 10**10 print(np.log10(temp.max()), np.log10(np.percentile(temp, 99)), np.log10(np.percentile(temp, 95)), np.log10(np.percentile(temp, 90)), np.log10(np.percentile(temp, 67.5)), np.log10(np.percentile(temp, 50))) # okinds = np.linalg.norm(poss - cent, axis=1) < 1 # cent = np.average(poss[okinds], weights=rho_gas[okinds], axis=0) print("Centered on:", cent) poss -= cent hsmls = data.gas.smoothing_lengths.value poss[np.where(poss > boxsize.value / 2)] -= boxsize.value poss[np.where(poss < -boxsize.value / 2)] += boxsize.value # Get images rgb_gas, ang_extent = getimage(cam_data, poss, temp, mass, hsmls, num, norm, cmap) # Get colormap cmap = ml.cm.Greys_r try: poss = data.stars.coordinates.value - cent mass = data.stars.masses.value * 10**10 hsmls = data.stars.smoothing_lengths.value if hsmls.max() == 0.0: print("Ill-defined smoothing lengths") last_snap = "%04d" % (num - 1) # Define path path = '/cosma/home/dp004/dc-rope1/cosma7/SWIFT/hydro_1380_ani/data/ani_hydro_' + last_snap + ".hdf5" data = load(path) old_hsmls = data.stars.smoothing_lengths.value hsmls[:old_hsmls.size] = old_hsmls hsmls[old_hsmls.size:] = np.median(old_hsmls) print(np.min(hsmls), np.max(hsmls)) poss[np.where(poss > boxsize.value / 2)] -= boxsize.value poss[np.where(poss < -boxsize.value / 2)] += boxsize.value # Get images rgb_stars, ang_extent = getimage_stars(cam_data, poss, mass, hsmls, num, max_pixel, cmap, Type="star") except AttributeError: rgb_stars = np.zeros_like(rgb_gas) blend = Blend.Blend(rgb_gas, rgb_stars) rgb_output = blend.Screen() i = cam_data[num] extent = [ 0, 2 * np.tan(ang_extent[1]) * i['r'], 0, 2 * np.tan(ang_extent[-1]) * i['r'] ] print(ang_extent, extent) dpi = rgb_output.shape[0] / 2 print(dpi, rgb_output.shape) fig = plt.figure(figsize=(2, 2 * 1.77777777778), dpi=dpi) ax = fig.add_subplot(111) ax.imshow(rgb_output, extent=ang_extent, origin='lower') ax.tick_params(axis='both', left=False, top=False, right=False, bottom=False, labelleft=False, labeltop=False, labelright=False, labelbottom=False) ax.text(0.975, 0.05, "$t=$%.1f Gyr" % cosmo.age(z).value, transform=ax.transAxes, verticalalignment="top", horizontalalignment='right', fontsize=1, color="w") ax.plot([0.05, 0.15], [0.025, 0.025], lw=0.1, color='w', clip_on=False, transform=ax.transAxes) ax.plot([0.05, 0.05], [0.022, 0.027], lw=0.15, color='w', clip_on=False, transform=ax.transAxes) ax.plot([0.15, 0.15], [0.022, 0.027], lw=0.15, color='w', clip_on=False, transform=ax.transAxes) axis_to_data = ax.transAxes + ax.transData.inverted() left = axis_to_data.transform((0.05, 0.075)) right = axis_to_data.transform((0.15, 0.075)) dist = extent[1] * (right[0] - left[0]) / (ang_extent[1] - ang_extent[0]) print(left, right, (right[0] - left[0]) / (ang_extent[1] - ang_extent[0]), dist) ax.text(0.1, 0.055, "%.2f cMpc" % dist, transform=ax.transAxes, verticalalignment="top", horizontalalignment='center', fontsize=1, color="w") sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm) sm._A = [] # # fake up the array of the scalar mappable cbaxes = ax.inset_axes([0.05, 0.95, 0.25, 0.015]) cbar = plt.colorbar(sm, cax=cbaxes, orientation="horizontal") cbar.set_ticks([3.5, 5, 6, 7.5]) labels = ["$\leq3.5$", "5", "6", "$7.5\leq$"] cbar.ax.set_xticklabels(labels) for tick in cbar.ax.xaxis.get_major_ticks(): tick.label.set_fontsize("xx-small") tick.label.set_color("w") tick.label.set_y(3) cbar.ax.tick_params(axis='x', color='w', size=0.3, width=0.1) cbar.ax.set_xlabel(r"$\log_{10}\left(T / [\mathrm{K}]\right)$", color='w', fontsize=0.2, labelpad=-0.1) cbar.outline.set_edgecolor('white') cbar.outline.set_linewidth(0.05) plt.margins(0, 0) fig.savefig('plots/Ani/GasTempStars_flythrough_' + snap + '.png', bbox_inches='tight', pad_inches=0) plt.close(fig)
def single_frame(num, max_pixel, nframes): snap = "%04d" % num # Define path path = '/cosma/home/dp004/dc-rope1/cosma7/SWIFT/hydro_1380_ani/data/ani_hydro_' + snap + ".hdf5" snap = "%05d" % num img_dimens = 4096 data = load(path) meta = data.metadata boxsize = meta.boxsize[0] z = meta.redshift print("Boxsize:", boxsize) # Define centre cent = np.array([11.76119931, 3.95795609, 1.26561173]) # Define targets targets = [[0, 0, 0]] id_frames = np.arange(0, 1381, dtype=int) rs = np.full(len(id_frames), 0., dtype=float) simtimes = np.zeros(len(id_frames), dtype=int) id_targets = np.zeros(len(id_frames), dtype=int) zoom = np.full(len(id_frames), 1) extent = np.full(len(id_frames), 10) t_projs = [0, 0, 0, 0, 90, -90] p_projs = [0, 180, 90, 270, 90, 90] projs = [(1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, -1), (0, 0, 1)] hex_list = [ "#000000", "#590925", "#6c1c55", "#7e2e84", "#ba4051", "#f6511d", "#ffb400", "#f7ec59", "#fbf6ac", "#ffffff" ] float_list = [0, 0.2, 0.3, 0.4, 0.45, 0.5, 0.7, 0.8, 0.9, 1] cmap = get_continuous_cmap(hex_list, float_list=float_list) poss = data.gas.coordinates.value mass = data.gas.masses.value * 10**10 rho_gas = data.gas.densities.value # okinds = np.linalg.norm(poss - cent, axis=1) < 1 # cent = np.average(poss[okinds], weights=rho_gas[okinds], axis=0) print("Centered on:", cent) poss -= cent hsmls = data.gas.smoothing_lengths.value poss[np.where(poss > boxsize.value / 2)] -= boxsize.value poss[np.where(poss < -boxsize.value / 2)] += boxsize.value gas_imgs = {} star_imgs = {} for proj_ind in range(6): ts = np.full(len(id_frames), t_projs[proj_ind]) ps = np.full(len(id_frames), p_projs[proj_ind]) proj = projs[proj_ind] # Define anchors dict for camera parameters anchors = {} anchors['sim_times'] = list(simtimes) anchors['id_frames'] = list(id_frames) anchors['id_targets'] = list(id_targets) anchors['r'] = list(rs) anchors['t'] = list(ts) anchors['p'] = list(ps) anchors['zoom'] = list(zoom) anchors['extent'] = list(extent) print(f"Processing projection {proj} with properties:") for key, val in anchors.items(): print(key, "=", val[num]) # Define the camera trajectory cam_data = camera_tools.get_camera_trajectory(targets, anchors) # Get images gas_imgs[proj], ang_extent = getimage(cam_data, poss, mass, hsmls, num, img_dimens, cmap, Type="gas") # Get colormap cmap = ml.cm.Greys_r try: poss = data.stars.coordinates.value - cent mass = data.stars.masses.value * 10**10 hsmls = data.stars.smoothing_lengths.value if hsmls.max() == 0.0: print("Ill-defined smoothing lengths") last_snap = "%04d" % (num - 1) # Define path path = '/cosma/home/dp004/dc-rope1/cosma7/SWIFT/hydro_1380_ani/data/ani_hydro_' + last_snap + ".hdf5" data = load(path) old_hsmls = data.stars.smoothing_lengths.value hsmls[:old_hsmls.size] = old_hsmls hsmls[old_hsmls.size:] = np.median(old_hsmls) print(np.min(hsmls), np.max(hsmls)) poss[np.where(poss > boxsize.value / 2)] -= boxsize.value poss[np.where(poss < -boxsize.value / 2)] += boxsize.value for proj_ind in range(6): ts = np.full(len(id_frames), t_projs[proj_ind]) ps = np.full(len(id_frames), p_projs[proj_ind]) proj = projs[proj_ind] # Define anchors dict for camera parameters anchors = {} anchors['sim_times'] = list(simtimes) anchors['id_frames'] = list(id_frames) anchors['id_targets'] = list(id_targets) anchors['r'] = list(rs) anchors['t'] = list(ts) anchors['p'] = list(ps) anchors['zoom'] = list(zoom) anchors['extent'] = list(extent) print(f"Processing projection {proj} with properties:") for key, val in anchors.items(): print(key, "=", val[num]) # Define the camera trajectory cam_data = camera_tools.get_camera_trajectory(targets, anchors) # Get images star_imgs[proj], ang_extent = getimage(cam_data, poss, mass, hsmls, num, img_dimens, cmap, Type="star") except AttributeError: for proj_ind in range(6): proj = projs[proj_ind] star_imgs[proj] = np.zeros_like(gas_imgs[proj]) imgs = {} for proj_ind in range(6): proj = projs[proj_ind] blend = Blend.Blend(gas_imgs[proj], star_imgs[proj]) imgs[proj] = blend.Screen() cube = np.zeros((img_dimens * 3, img_dimens * 4, 4), dtype=np.float32) cube[img_dimens:img_dimens * 2, 0:img_dimens] = imgs[(1, 0, 0)] cube[img_dimens:img_dimens * 2, img_dimens:img_dimens * 2] = imgs[(0, 1, 0)] cube[img_dimens:img_dimens * 2, img_dimens * 2:img_dimens * 3] = imgs[(-1, 0, 0)] cube[img_dimens:img_dimens * 2, img_dimens * 3:img_dimens * 4] = imgs[(0, -1, 0)] cube[img_dimens * 2:img_dimens * 3, img_dimens:img_dimens * 2] = imgs[(0, 0, -1)] cube[0:img_dimens, img_dimens:img_dimens * 2] = imgs[(0, 0, 1)] posx = imgs[(1, 0, 0)] negx = imgs[(-1, 0, 0)] posy = imgs[(0, 1, 0)] negy = imgs[(0, -1, 0)] posz = imgs[(0, 0, 1)] negz = imgs[(0, 0, -1)] squareLength = posx.shape[0] halfSquareLength = squareLength / 2 outputWidth = squareLength * 2 outputHeight = squareLength * 1 output = np.zeros((outputHeight, outputWidth, 4)) for loopY in range(0, int(outputHeight)): # 0..height-1 inclusive print(loopY) for loopX in range(0, int(outputWidth)): # 2. get the normalised u,v coordinates for the current pixel U = float(loopX) / (outputWidth - 1) # 0..1 V = float(loopY) / ( outputHeight - 1 ) # no need for 1-... as the image output needs to start from the top anyway. # 3. taking the normalised cartesian coordinates calculate the polar coordinate for the current pixel theta = U * 2 * np.pi phi = V * np.pi # 4. calculate the 3D cartesian coordinate which has been projected to a cubes face cart = convertEquirectUVtoUnit2D(theta, phi, squareLength) # 5. use this pixel to extract the colour index = cart["index"] if (index == "X+"): output[loopY, loopX] = posx[cart["y"], cart["x"]] elif (index == "X-"): output[loopY, loopX] = negx[cart["y"], cart["x"]] elif (index == "Y+"): output[loopY, loopX] = posy[cart["y"], cart["x"]] elif (index == "Y-"): output[loopY, loopX] = negy[cart["y"], cart["x"]] elif (index == "Z+"): output[loopY, loopX] = posz[cart["y"], cart["x"]] elif (index == "Z-"): output[loopY, loopX] = negz[cart["y"], cart["x"]] dpi = output.shape[0] print(dpi, cube.shape) fig = plt.figure(figsize=(1, 2), dpi=dpi) ax = fig.add_subplot(111) ax.imshow(output, origin='lower') ax.tick_params(axis='both', left=False, top=False, right=False, bottom=False, labelleft=False, labeltop=False, labelright=False, labelbottom=False) # ax.text(0.975, 0.05, "$t=$%.1f Gyr" % cosmo.age(z).value, # transform=ax.transAxes, verticalalignment="top", # horizontalalignment='right', fontsize=1, color="w") plt.margins(0, 0) ax.set_frame_on(False) fig.savefig('plots/Ani/360/Equirectangular_flythrough_' + snap + '.png', bbox_inches='tight', pad_inches=0) plt.close(fig)
def single_sphere(reg, snap, soft, num, runall=True): if not runall: if 'gas_animationdata_reg' + reg + '_snap' + snap + '_angle%05d.npy'%num in os.listdir('animationdata/') and \ 'dm_animationdata_reg' + reg + '_snap' + snap + '_angle%05d.npy'%num in os.listdir('animationdata/'): return # Define path path = '/cosma/home/dp004/dc-rope1/FLARES/FLARES-1/G-EAGLE_' + reg + '/data' # Get centres of groups grp_cops = E.read_array('SUBFIND', path, snap, 'FOF/GroupCentreOfPotential', noH=True, numThreads=8) grp_ms = E.read_array('SUBFIND', path, snap, 'FOF/GroupMass', noH=True, numThreads=8) # Get the spheres centre centre, radius, mindist = spherical_region(path, snap) # Define targets sinds = np.argsort(grp_ms) grp_cops = grp_cops[sinds] targets = [[0, 0, 0]] targets.append(grp_cops[0, :] - centre) targets.append(grp_cops[1, :] - centre) # Define the box size lbox = (15 / 0.677) * 2 # Define anchors dict for camera parameters anchors = {} anchors['sim_times'] = [ 0.0, 'same', 'same', 'same', 'same', 'same', 'same', 'same' ] anchors['id_frames'] = [0, 45, 188, 210, 232, 375, 420, 500] anchors['id_targets'] = [0, 'pass', 2, 'pass', 'pass', 'pass', 'pass', 0] anchors['r'] = [ lbox * 3 / 4, 'pass', lbox / 100, 'same', 'pass', 'pass', 'pass', lbox * 3 / 4 ] anchors['t'] = [0, 'pass', 'pass', -180, 'pass', -270, 'pass', -360] anchors['p'] = [0, 'pass', 'pass', 'pass', 'pass', 'pass', 'pass', 360 * 3] anchors['zoom'] = [ 1., 'same', 'same', 'same', 'same', 'same', 'same', 'same' ] anchors['extent'] = [ 10, 'same', 'same', 'same', 'same', 'same', 'same', 'same' ] # Define the camera trajectory data = camera_tools.get_camera_trajectory(targets, anchors) # Get images rgb_DM, extent = getimage(path, snap, soft, num, centre, data, part_type=1) rgb_gas, _ = getimage(path, snap, soft, num, centre, data, part_type=0) blend = Blend.Blend(rgb_DM, rgb_gas) rgb_output = blend.Overlay() fig = plt.figure(figsize=(4, 4)) ax = fig.add_subplot(111) ax.imshow(rgb_output, extent=extent, origin='lower') ax.tick_params(axis='both', left=False, top=False, right=False, bottom=False, labelleft=False, labeltop=False, labelright=False, labelbottom=False) fig.savefig('plots/spheres/All/all_parts_animation_reg' + reg + '_snap' + snap + '_angle%05d.png' % num, bbox_inches='tight') plt.close(fig)