The main goal this week is to get familiar with importing (and using) three really useful packages: numpy
, astropy
and matplotlib
. Throughout the assignment we will also write some for-loops and practice logic statements
This assignment is meant to be done in groups of 2-3 people.
Part 1: Loading in the SubHalo Merger Tree Data (10 - 15 minutes)¶
All galaxies live inside large accumulations of dark matter. These accumulations can be thought of as clouds or “halos”. A “merger tree” is a way of understanding the accretion history of a dark matter host halo. The trunk represents the present day host halo, and every branch is a merger event (a smaller halo being eaten up). The higher up the tree you go, the further back in time you look! I work with a code named SatGen that can create these merger trees and today you will be handling the output of the SatGen code.
The code outputs several numpy arrays that are compressed together into a single .npz
file.
(See this link https://
Part 2: Playing around with halo mass (10 - 15 minutes)¶
Now that you have opened up the data, I can tell you that the host halo is saved in the first index of the mass array. The rest of the indices correspond to the subhalos that were accreted by the host during the “simulation”.
Now, we are going to make our very first plot! We will be using a python package called matplotlib
. The matplotlib
documentation has a nice page to walk you through the basics of how we can use this package to make plots. This will be a helpful reference: Matplotlib Tutorial
Plot a histogram of the maximum masses you computed using the matplotlib.pytplot.hist
method (See this link).
Make sure to label the axes and change the binsize so that we have 15 evenly spaced (in log space) bins and put the y axis in log scale!
You could have also accomplished something similar with numpy.histogram
but since we wanted to visualize the data, in this case its easier to use matplotlib
WOW! There are so many more low mass subhalos than there are high mass subhalos!! LCDM predicts a steep mass function!
Part 3: Plotting the merger tree! (20-25 minutes)¶
First, let’s plot just the host halo’s mass vs. time. Start by selecting the host halo (e.g. the first element of in the mass array), and plot mass vs. time using matplotlib
.
Hint: Plotting 2-D Data
You can use matplotlib.pyplot.plot
to plot a line by giving the arguments (x-data, y-data).
Okay so as we know, there are a bunch of subhalos in this merger tree. If we wanted plot all of them with respect to time, the figure would be a bit crowded. Instead lets only pick the ones that are above a given mass at present day.
In your mass array, select only the present day time index. Create a mask on this selection that excludes an subhalos that are less massive than 10^9.5 solar masses. How many are there?
Make a mass vs. time plot for the subhalos that meet the present day mass criteria in the previous step. Make sure you plot the host mass in a different color. Don’t forget to label your axes!
Can you see the little dips in the accretion histories? That is when the subhalo is accreted onto the host! Notice there is no such dip for the red line!