Skip to content

Instantly share code, notes, and snippets.

@smutch
Created September 2, 2014 04:19
Show Gist options
  • Save smutch/8e73feb58e2ef4b4c3e1 to your computer and use it in GitHub Desktop.
Save smutch/8e73feb58e2ef4b4c3e1 to your computer and use it in GitHub Desktop.
py: basic SMF plot with ssimpl & Meraxes
#!/usr/bin/env python
"""Plot the stellar mass function."""
import numpy as np
import matplotlib.pyplot as plt
from ssimpl import meraxes, munge
# if you want to use the plot style that I often use then uncomment these lines
# from ssimpl import plotutils
# plotutils.init_style()
# read in the galaxies
fname = "meraxes.hdf5"
props = ["StellarMass",]
snapshot = -1
redshift = meraxes.grab_redshift(fname, snapshot)
gals, simprops = meraxes.read_gals(fname, snapshot=snapshot, props=props,
sim_props=True)
gals = gals.view(np.recarray)
# get rid of galaxies with zero stellar mass (these shouldn't exist in the most
# recent version of Meraxes)
gals = np.compress(gals.StellarMass > 0, gals)
# generate the SMF
smf = munge.mass_function(np.log10(gals.StellarMass*1.e10), simprops["Volume"], bins="knuth")
# plot the result
fig, ax = plt.subplots(1,1)
ax.plot(smf[:,0], np.log10(smf[:,1]), label="z={:.1f}".format(redshift))
ax.legend(loc="upper right")
ax.set_xlabel(r"$\log_{10}(M_*/{\rm M_{\odot}})$")
ax.set_ylabel(r"$\log_{10}(\phi / ({\rm dex^{-1} Mpc^{-3}}))$")
ax.set_xlim(left=6)
# save the figure
plt.tight_layout()
plt.savefig("smf.pdf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment