Creating populations from snapshots#
Time for part two of learning about using hydrodynamical zoom-in simulations in cogsworth. Now we’re going to put what we learnt into action in creating a HydroPopulation.
Learning Goals#
By the end of this tutorial you should know:
How to initialise a
HydroPopulationThe differences between a
HydroPopulationand a regularPopulation
Beware - extra dependencies required here!
You’ll need to have installed the extra dependencies of cogsworth to postprocess hydrodynamical simulations. Check out the installation page for more details on how to do this! (You’ll probably just need to run pip install cogsworth[extras])
[1]:
import cogsworth
import gala.potential as gp
import astropy.units as u
import matplotlib.pyplot as plt
import pandas as pd
[2]:
# this all just makes plots look nice
%config InlineBackend.figure_format = 'retina'
plt.rc('font', family='serif')
plt.rcParams['text.usetex'] = False
fs = 24
# update various fontsizes to match
params = {'figure.figsize': (12, 8),
'legend.fontsize': fs,
'axes.labelsize': fs,
'xtick.labelsize': 0.9 * fs,
'ytick.labelsize': 0.9 * fs,
'axes.linewidth': 1.1,
'xtick.major.size': 7,
'xtick.minor.size': 4,
'ytick.major.size': 7,
'ytick.minor.size': 4}
plt.rcParams.update(params)
Here’s one I made earlier…
In this tutorial I’m going to cheat and use a collection of star particles/a potential that I created from the FIRE m11h snapshot. Check out the previous tutorial (press your left arrow key) to find out where to download this snapshot and how to rewind star particles/calculate a galactic potential from a snapshot
HydroPopulation creation#
As we talked about in the last tutorial, a HydroPopulation can be very useful for properly accounting for a more complex star formation history (e.g. including initial spatial stellar clustering) and galactic potentials.
A HydroPopulation samples a subpopulation of systems from each of the star particles that are supplied. The positions and velocities of these systems are determined by their parent star particle and are given small offsets in position to account for the nonzero cluster radii and a velocity dispersion based on the cluster mass, radius and virial parameter.
Let’s start by creating a (very simple) HydroPopulation based on FIRE m11h.
[3]:
# load in some star particles and the potential we've made in a previous tutorial
star_particles = pd.read_hdf("../../../data/init_star_particles_m11h.h5")
pot = gp.load("../../../data/m11h.yml")
[4]:
# take out a single particle and reduce the mass to speed up the runtime
particle = star_particles.iloc[[0]].copy()
particle["mass"] = 200
Creating a new population requires a couple of extra parameters from a regular one. In this case we can now specify the star particles from which to sample as well as details for how the cluster radius, mass and virial parameter are determined (which sets the position/velocity sampling as we mentioned above).
[5]:
# create a new HydroPopulation
p = cogsworth.hydro.pop.HydroPopulation(star_particles=particle,
galactic_potential=pot,
cluster_radius=3 * u.pc,
cluster_mass=10000 * u.Msun,
virial_parameter=1.0,
max_ev_time=13.736 * u.Gyr,
processes=1,
use_default_BSE_settings=True)
p
[5]:
<HydroPopulation - 1 star particles - galactic_potential=CompositePotential, SFH=Wagg2022>
The population will now keep track of how many star particles are being used (and once we evolve the population it’ll tell you how many systems as well).
[6]:
p.create_population()
p
Run for None binaries
Ended up with 95 binaries with m1 > 0 solar masses
[8e-03s] Sample initial binaries
[0.1s] Evolve binaries (run COSMIC)
[0.2s] Get orbits (run gala)
Overall: 0.3s
[6]:
<HydroPopulation - 1 star particles - 95 evolved systems - galactic_potential=CompositePotential, SFH=Wagg2022>
Excellent! And now we can do all of the regular Population things that we know and love on our shiny new HydroPopulation!
Differences from Population#
Lastly, let’s just explore some of the differences from a regular Population. There’s of course the new parameters which we can access and track:
[13]:
p.star_particles
[13]:
| id | mass | Z | t_form | x | y | z | v_x | v_y | v_z | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 5726876 | 200 | 0.014378 | 13.735638 | -3.984967 | -6.560426 | 0.89052 | 77.782451 | -49.182975 | 39.996301 |
[17]:
p.cluster_mass, p.cluster_radius, p.virial_parameter
[17]:
(<Quantity 10000. solMass>, <Quantity 3. pc>, 1.0)
We could update any of these and re-run the population to get new results, feel free to try it for yourself!
Additionally, the initial conditions now track not only the system information, but also which particle it came from so that you can reconnect systems to their parent star particles.
[19]:
p.initC["particle_id"]
[19]:
0 0
1 0
2 0
3 0
4 0
..
90 0
91 0
92 0
93 0
94 0
Name: particle_id, Length: 95, dtype: int64
Wrap-up#
And that’s all for learning about using hydrodynamical zoom-in simulations in cogsworth, hope you had fun! Head over to the main tutorials page for more options of learning about all things cogsworth, see you there!
Note
This tutorial was generated from a Jupyter notebook that can be found here.