.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/u_particles/plot_galaxy_cluster_particles.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_u_particles_plot_galaxy_cluster_particles.py: ================================== Particle Datasets: Galaxy Clusters ================================== This example demonstrates how to generate particle datasets for a galaxy cluster model using Pisces. To do so, we'll use the built-in hook for generating particles, which gives us access to the :meth:`~models.galaxy_clusters.spherical.SphericalGalaxyClusterModel.generate_particles` method. .. GENERATED FROM PYTHON SOURCE LINES 14-22 Setup & Imports ---------------- The first thing that needs to happen is importing the relevant building blocks. For this, we'll need the :class:`~models.galaxy_clusters.spherical.SphericalGalaxyClusterModel` class which will be our model and the :class:`~profiles.density.HernquistDensityProfile`, which we'll use to represent the total and gas density profiles of the cluster. .. GENERATED FROM PYTHON SOURCE LINES 22-31 .. code-block:: Python import tempfile import matplotlib.pyplot as plt import numpy as np import unyt from pisces.models.galaxy_clusters import SphericalGalaxyClusterModel from pisces.profiles.density import HernquistDensityProfile .. GENERATED FROM PYTHON SOURCE LINES 32-39 Building the Model ------------------ First things first, we need to build the model. In this case, we'll be using basic Hernquist profiles :footcite:p:`HernquistProfile` for both the gas and total density. This is nice for simple models because we can fix the total mass easily. We'll create a galaxy cluster with 85\% of the total mass in dark matter and 15\% in gas. The total mass of the cluster will be :math:`10^{15} \;{\rm M_\odot}`. .. GENERATED FROM PYTHON SOURCE LINES 39-80 .. code-block:: Python # Define some parameters for the total density profile. total_mass = unyt.unyt_quantity(1e15, "Msun") gas_mass, dm_mass = total_mass * 0.15, total_mass * 0.85 gas_scale_radius = unyt.unyt_quantity(220, "kpc") dm_scale_radius = unyt.unyt_quantity(200, "kpc") gas_rho_0 = gas_mass / (2 * np.pi * gas_scale_radius**3) dm_rho_0 = dm_mass / (2 * np.pi * dm_scale_radius**3) # Create the density profiles. gas_density_profile = HernquistDensityProfile( rho_0=gas_rho_0, r_s=gas_scale_radius, ) total_density_profile = HernquistDensityProfile( rho_0=dm_rho_0, r_s=dm_scale_radius, ) # Radial range and resolution rmin = unyt.unyt_quantity(1.0, "kpc") rmax = unyt.unyt_quantity(3.0, "Mpc") # Create a temporary directory to store the model file and # give the model a filename. tmpdir = tempfile.TemporaryDirectory() filename = f"{tmpdir.name}/cluster_temp_dens_model.h5" # Now we can move forward with making the model! model = SphericalGalaxyClusterModel.from_density_and_total_density( gas_density_profile, total_density_profile, filename, min_radius=rmin, max_radius=rmax, num_points=1000, overwrite=True, ) .. rst-class:: sphx-glr-script-out .. code-block:: none Preparing metadata...: 0%| | 0/7 [00:00 0] = hist_temp_dens[hist_dens > 0] / hist_dens[hist_dens > 0] # Create the plot. fig, ax = plt.subplots(figsize=(8, 6)) c = ax.pcolormesh(bins, bins, mass_weighted_temp.T, shading="auto", cmap="inferno") ax.set_xlabel("X Position (kpc)") ax.set_ylabel("Y Position (kpc)") ax.set_title("Mass-Weighted Gas Temperature Distribution") fig.colorbar(c, ax=ax, label="Temperature (keV)") plt.tight_layout() plt.show() .. image-sg:: /auto_examples/u_particles/images/sphx_glr_plot_galaxy_cluster_particles_001.png :alt: Mass-Weighted Gas Temperature Distribution :srcset: /auto_examples/u_particles/images/sphx_glr_plot_galaxy_cluster_particles_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 21.165 seconds) .. _sphx_glr_download_auto_examples_u_particles_plot_galaxy_cluster_particles.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_galaxy_cluster_particles.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_galaxy_cluster_particles.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_galaxy_cluster_particles.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_