def load_and_make_image(number, res, property): filename = "square_{:04d}.hdf5".format(number) data = load(filename) image = project_gas_pixel_grid(data, res, property) image_none = project_gas_pixel_grid(data, res, None) return image / image_none
def create_t_map(number): this_data = data[number] # We need to construct sum(T_j W_ij) / sum(W_ij) norm_grid = project_gas_pixel_grid(this_data, resolution, None) temp_grid = project_gas_pixel_grid(this_data, resolution, "temperatures") return temp_grid / norm_grid
def make_plot(filename, array, nx, ny, dx, dy): """ Load the data and plop it on the grid using nearest neighbour searching for finding the 'correct' value of the density. """ data = load_and_extract(filename) mesh = project_gas_pixel_grid(data, nx) array.set_array(mesh) return array,
""" from swiftsimio import load from swiftsimio.visualisation import project_gas_pixel_grid, scatter import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import Normalize data = load("kelvinHelmholtz_0175.hdf5") resolution = 1024 n_streamline = 512 grid = project_gas_pixel_grid(data, resolution) sub_mask_velocity = 1024 * 2 x, y, _ = data.gas.coordinates[:].value.T u, v, _ = data.gas.velocities[:].value.T h = data.gas.smoothing_lengths.value u_grid = scatter(x, y, u, h, resolution * 2).T v_grid = scatter(x, y, v, h, resolution * 2).T x = np.linspace(0, 1, resolution * 2) y = np.linspace(0, 1, resolution * 2) speed = np.sqrt(u_grid * u_grid + v_grid * v_grid) fig, ax = plt.subplots(figsize=(8, 8), dpi=300) fig.subplots_adjust(0, 0, 1, 1)
""" Makes an image of snapshot 175. """ from swiftsimio import load from swiftsimio.visualisation import project_gas_pixel_grid import matplotlib.pyplot as plt data = load("kelvinHelmholtz_0164.hdf5") grid = project_gas_pixel_grid(data, 7 * 300) fig, a = plt.subplots(figsize=(7, 7)) fig.subplots_adjust(0, 0, 1, 1, 0, 0) a.imshow(grid, cmap="Spectral", origin="lower", vmin=2.29, vmax=20.92) a.set_xticks([]) a.set_yticks([]) fig.savefig("kelvin_helmholtz_highres.pdf")
matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np from scipy import stats from swiftsimio import load from swiftsimio.visualisation import project_gas_pixel_grid snap = int(sys.argv[1]) sim = load(f"square_{snap:04d}.hdf5") resolution = 512 # First create a grid that gets the particle density so we can divide it out later unweighted_grid = project_gas_pixel_grid(sim, 512, None) # Set up plotting stuff try: plt.style.use("mnras_durham") except: rcParams = { "font.serif": ["STIX", "Times New Roman", "Times"], "font.family": ["serif"], "mathtext.fontset": "stix", "font.size": 8, } plt.rcParams.update(rcParams) def get_data_dump(metadata):
""" Makes an image of snapshot 175. """ from swiftsimio import load from swiftsimio.visualisation import project_gas_pixel_grid import matplotlib.pyplot as plt data = load("kelvinHelmholtz_0320.hdf5") empty_grid = project_gas_pixel_grid(data, 7 * 300, None) grid = project_gas_pixel_grid(data, 7 * 300, "internal_energy") / empty_grid fig, a = plt.subplots(figsize=(7, 7)) fig.subplots_adjust(0, 0, 1, 1, 0, 0) a.imshow(grid, cmap="Spectral", origin="lower") a.set_xticks([]) a.set_yticks([]) fig.savefig("kelvin_helmholtz_highres_energy.png", dpi=300)
if os.path.isfile("{}_{:04d}.hdf5".format(filename, i)): i += 1 else: break if i > 10000: raise FileNotFoundError( "Could not find the snapshots in the directory") frames = tqdm(np.arange(0, i)) # Creation of first frame fig, ax = plt.subplots(1, 1, figsize=(1, 1), frameon=False) ax.axis("off") # Remove annoying black frame. data = load_and_extract("kelvinHelmholtz_0000.hdf5") mesh = project_gas_pixel_grid(data, dpi) # Global variable for set_array plot = ax.imshow(mesh, extent=[0, 1, 0, 1], animated=True, interpolation="none") anim = FuncAnimation(fig, frame, frames, interval=40, blit=False) # Remove all whitespace fig.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=None, hspace=None) # Actually make the movie anim.save("khmovie.mp4", dpi=dpi, bitrate=4096)
Creates a temperature map of the snapshot that is provided and saves it as temperature_map.png. """ import sys from swiftsimio import load from swiftsimio.visualisation import project_gas_pixel_grid from matplotlib.pyplot import imsave from matplotlib.colors import LogNorm resolution = 2048 snapshot = sys.argv[1] try: output_filename = sys.argv[2] except IndexError: output_filename = "temperature_map.png" data = load(snapshot) # We need to construct sum(T_j W_ij) / sum(W_ij) norm_grid = project_gas_pixel_grid(data, resolution, None) temp_grid = project_gas_pixel_grid(data, resolution, "temperatures") # Imsave does not take a norm normalized_grid = LogNorm(vmin=1e2, vmax=1e8)(temp_grid / norm_grid) imsave(output_filename, normalized_grid, cmap="twilight")
def baked(snap): grid = project_gas_pixel_grid(data[snap], 1024) return grid
snap = 40 simulations = { "anarchy-du-lr": "$64^2$", "anarchy-du": "$128^2$", "anarchy-du-hr": "$256^2$", "anarchy-du-hrhr": "$512^2$", } sims = [load(f"{s}/square_{snap:04d}.hdf5") for s in simulations.keys()] resolution = 512 # First create a grid that gets the particle density so we can divide it out later density = [ project_gas_pixel_grid(sim, 512, "densities") / project_gas_pixel_grid(sim, 512, None) for sim in sims ] # Set up plotting stuff try: plt.style.use("mnras_durham") except: rcParams = { "font.serif": ["STIX", "Times New Roman", "Times"], "font.family": ["serif"], "mathtext.fontset": "stix", "font.size": 8, } plt.rcParams.update(rcParams)
0 * units, data.metadata.boxsize[0].to(units), 0 * units, data.metadata.boxsize[0].to(units), ], origin="lower", ) fig.savefig(f"{output_path}/{filename}.png") plt.close(fig) return common_parameters = dict(data=data, resolution=res, parallel=True) norm = project_gas_pixel_grid(**common_parameters, project=None).T mass = project_gas_pixel_grid(**common_parameters).T normed = (lambda project: project_gas_pixel_grid(**common_parameters, project=project).T / norm) diff = normed("diffusion_parameters") visc = normed("viscosity_parameters") temp = normed("temperatures") mmf = normed("metal_mass_fractions") make_image(mass, "inferno", "projected_gas_density") make_image(diff, cm.ice, "diffusion_parameters", 0.01, 1.0) make_image(visc, cm.curl, "viscosity_parameters", 0.2, 2.0) make_image(temp, "twilight", "temperatures", 1e2, 1e8) make_image(mmf, "cubehelix", "metal_mass_fractions", 0.0012, 1.2)
import cmocean.cm as cm snap = 40 simulations = { "minimal": "Density-Energy", "anarchy-du": "ANARCHY-DU", "pressure-energy": "Pressure-Energy", "anarchy-pu": "ANARCHY-PU", } sims = [load(f"{s}/square_{snap:04d}.hdf5") for s in simulations.keys()] resolution = 512 # First create a grid that gets the particle density so we can divide it out later unweighted_grids = [project_gas_pixel_grid(sim, 512, None) for sim in sims] # Set up plotting stuff try: plt.style.use("mnras_durham") except: rcParams = { "font.serif": ["STIX", "Times New Roman", "Times"], "font.family": ["serif"], "mathtext.fontset": "stix", "font.size": 8, } plt.rcParams.update(rcParams) # Now we can do the plotting. fig, ax = plt.subplots(4, 3, figsize=(6.974, 6.974 * 4 / 3))