Astrophysicist

Author: Rainer Weinberger (Page 1 of 4)

Python programming for scientists

A minimalist guide to learning Python for scientific use

Why another guide to Python programming? The main reason is that scientific programming is different from commercial software development, in particular for those who need results quickly and might not have the desire or the time to become a Python expert. The following guide is an ordered list of things I consider the most useful things to know for scientific code development in Python. It assumes the ability to write and run a single-file python script (or a Jupyter Notebook), and ends with writing and publishing your own package.

Mastering all of these topics takes years of practice (and I don’t claim I do), so start with the basics, and once you are familiar with one topic, move on to the next.

  • The most important libraries: numpy and matplotlib.pyplot. Get familiar with their functionality and how to use them.
  • Algorithms and data structures:
    • Learn a few of the basic algorithms and check if there is a library implementation.
    • Difference between arrays and dictionaries, and how to use both is very important.
  • Use functions: once a block of code exceeds the space on your screen, refactor parts to a function (recursively, if needed).
    • Make use of the flexibility in return type.
    • Use keyword arguments and default values wherever appropriate.
  • Use the time module to determine slowest part of code.
  • Learn simple optimization techniques:
    • Avoid loops.
    • Save intermediate results of calculation in files (numpy or pickle) or in memory.
    • Use of library functions whenever possible.
  • Create modules
    • In particular, packages (section 6.4 in ‘create modules’ link)
  • Documentation of functions and classes.
  • If you don’t to this already: use version control, e.g. git for your project
  • Get familiar with classes and object-oriented programming in Python. But:
    • Learn about design patterns and design principles. Using classes without having heard about these can be counterproductive.
    • Stick to the PEP8 style guide naming conventions
  • Unit tests via pytest
  • More advanced optimization:
    • Cython/using compiled code
    • Parallelism in python e.g. mpi4py
  • Create your own package
    • setuptools to install packages as a library
    • Continuous integration/ automated test and style check
    • Versioning (maybe a bit over-the-top for most purposes, but one suggestion here)
    • Creating a python package (e.g. for pip)

The question now is how to learn all of this. First and foremost, you learn to code by coding. There is no way around this. However, sometimes it is easy to fall back to somewhat complicated but known ways to implement things. Therefore spending some time trying new things is a good investment in your programming skills. Search engines are essential for concrete problems. For improving code structure, reading more experienced programmers’ code can be helpful. Once you are more advanced, I would therefore recommend looking at implementations of some of the major libraries and trying to understand them.

Weinberger, Springel, Pakmor (2020)

The Arepo public code release

by
Weinberger, Rainer; Springel, Volker and Pakmor, Rüdiger

abstract
We introduce the public version of the cosmological magnetohydrodynamical moving-mesh simulation code Arepo. This version contains a finite-volume magnetohydrodynamics algorithm on an unstructured, dynamic Voronoi tessellation coupled to a tree-particle-mesh algorithm for the Poisson equation either on a Newtonian or cosmologically expanding spacetime. Time-integration is performed adopting local timestep constraints for each cell individually, solving the fluxes only across active interfaces, and calculating gravitational forces only between active particles, using an operator-splitting approach. This allows simulations with high dynamic range to be performed efficiently. Arepo is a massively distributed-memory parallel code, using the Message Passing Interface (MPI) communication standard and employing a dynamical work-load and memory balancing scheme to allow optimal use of multi-node parallel computers. The employed parallelization algorithms of Arepo are deterministic and produce binary-identical results when re-run on the same machine and with the same number of MPI ranks. A simple primordial cooling and star formation model is included as an example of sub-resolution models commonly used in simulations of galaxy formation. Arepo also contains a suite of computationally inexpensive test problems, ranging from idealized tests for automated code verification to scaled-down versions of cosmological galaxy formation simulations, and is extensively documented in order to assist adoption of the code by new scientific users.

published in
 The Astrophysical Journal Supplement Series, Volume 248, Issue 2, id.32, June 2020

links to paper
[ADS][arXiv][website][repository]

Li et al. (2020)

Correlations between Black Holes and Host Galaxies in the Illustris and IllustrisTNG Simulations

by
Li, Yuan; Habouzit, Melanie; Genel, Shy; Somerville, Rachel; Terrazas, Bryan A.; Bell, Eric F.; Pillepich, Annalisa; Nelson, Dylan; Weinberger, Rainer; Rodriguez-Gomez, Vicente; Ma, Chung-Pei; Pakmor, Rüdiger; Hernquist, Lars; Vogelsberger, Mark

abstract
We study black hole-host galaxy correlations, and the relation between the overmassiveness (the distance from the average MBH-σ relation) of supermassive black holes (SMBHs) and the star formation histories of their host galaxies in the Illustris and TNG100 simulations. We find that both simulations are able to produce black hole scaling relations in general agreement with observations at z = 0, but with noticeable discrepancies. Both simulations show an offset from the observations for the MBH-σ relation, and the relation between MBH and the Sérsic index. The relation between MBH and stellar mass M* is tighter than the observations, especially for TNG100. For massive galaxies in both simulations, the hosts of overmassive SMBHs (those above the mean MBH-σ relation) tend to have larger Sérsic indices and lower baryon conversion efficiency, suggesting a multidimensional link between SMBHs and the properties of their hosts. In Illustris, the hosts of overmassive SMBHs have formed earlier and have lower present-day star formation rates, in qualitative agreement with the observations for massive galaxies with σ > 100 km s-1. For low-mass galaxies, such a correlation still holds in Illustris but does not exist in the observed data. For TNG100, the correlation between SMBH overmassiveness and star formation history is much weaker. The hosts of overmassive SMBHs generally have consistently larger star formation rates throughout history. These galaxies have higher stellar mass as well, due to the strong MBH-M*correlation. Our findings show that simulated SMBH scaling relations and correlations are sensitive to features in the modeling of SMBHs.

published in
The Astrophysical Journal, Volume 895, Issue 2, id.102, June 2020

link to paper
[ADS][arXiv]

Terrazas et al. (2020)

The relationship between black hole mass and galaxy properties: examining the black hole feedback model in IllustrisTNG

by
Terrazas, Bryan A.; Bell, Eric F.; Pillepich, Annalisa; Nelson, Dylan; Somerville, Rachel S.; Genel, Shy; Weinberger, Rainer; Habouzit, Mélanie; Li, Yuan; Hernquist, Lars; Vogelsberger, Mark

abstract
Supermassive black hole feedback is thought to be responsible for the lack of star formation, or quiescence, in a significant fraction of galaxies. We explore how observable correlations between the specific star formation rate (sSFR), stellar mass (Mstar), and black hole mass (MBH) are sensitive to the physics of black hole feedback in a galaxy formation model. We use the IllustrisTNG simulation suite, specifically the TNG100 simulation and 10 model variations that alter the parameters of the black hole model. Focusing on central galaxies at z = 0 with Mstar > 1010 M, we find that the sSFR of galaxies in IllustrisTNG decreases once the energy from black hole kinetic winds at low accretion rates becomes larger than the gravitational binding energy of gas within the galaxy stellar radius. This occurs at a particular MBH threshold above which galaxies are found to sharply transition from being mostly star forming to mostly quiescent. As a result of this behaviour, the fraction of quiescent galaxies as a function of Mstar is sensitive to both the normalization of the MBH-Mstar relation and the MBH threshold for quiescence in IllustrisTNG. Finally, we compare these model results to observations of 91 central galaxies with dynamical MBH measurements with the caveat that this sample is not representative of the whole galaxy population. While IllustrisTNG reproduces the observed trend that quiescent galaxies host more massive black holes, the observations exhibit a broader scatter in MBH at a given Mstar and show a smoother decline in sSFR with MBH.

published in
Monthly Notices of the Royal Astronomical Society, Volume 493, Issue 2, p.1888-1906, April 2020

links to paper
[ADS][arXiv]

Truong et al. (2020)

X-ray signatures of black hole feedback: hot galactic atmospheres in IllustrisTNG and X-ray observations

by
Truong, Nhut; Pillepich, Annalisa; Werner, Norbert; Nelson, Dylan; Lakhchaura, Kiran; Weinberger, Rainer; Springel, Volker; Vogelsberger, Mark; Hernquist, Lars

abstract
Hot gaseous atmospheres that permeate galaxies and extend far beyond their stellar distribution, where they are commonly referred to as the circumgalactic medium, imprint important information about feedback processes powered by the stellar populations of galaxies and their central supermassive black holes (SMBHs). In this work, we study the properties of this hot X-ray emitting medium using the IllustrisTNG cosmological simulations. We analyse their mock X-ray spectra, obtained from the diffuse and metal-enriched gas in TNG100 and TNG50, and compare the results with X-ray observations of nearby early-type galaxies. The simulations reproduce the observed X-ray luminosities (LX) and temperature (TX) at small (<Re) and intermediate (<5Re) radii reasonably well. We find that the X-ray properties of lower mass galaxies depend on their star formation rates. In particular, in the magnitude range where the star-forming and quenched populations overlap, we find that the X-ray luminosities of star-forming galaxies are on average about an order of magnitude higher than those of their quenched counterparts. We show that this diversity in LX is a direct manifestation of the quenching mechanism in the simulations, where the galaxies are quenched due to gas expulsion driven by SMBH kinetic feedback. The observed dichotomy in LX is thus an important observable prediction for the SMBH feedback-based quenching mechanisms implemented in state-of-the-art cosmological simulations. While the current X-ray observations of star-forming galaxies are broadly consistent with the predictions of the simulations, the observed samples are small and more decisive tests are expected from the sensitive all-sky X-ray survey with eROSITA.

published in
Monthly Notices of the Royal Astronomical Society, Volume 494, Issue 1, pp.549-570, March 2020

links to paper
[ADS][arXiv]

Vogelsberger et al. (2020)

High-redshift JWST predictions from IllustrisTNG: dust modelling and galaxy luminosity functions

by
Vogelsberger, Mark; Nelson, Dylan; Pillepich, Annalisa; Shen, Xuejian; Marinacci, Federico; Springel, Volker; Pakmor, Rüdiger; Tacchella, Sandro; Weinberger, Rainer; Torrey, Paul; Hernquist, Lars

abstract
The James Webb Space Telescope (JWST) promises to revolutionize our understanding of the early Universe, and contrasting its upcoming observations with predictions of the Λ cold dark matter model requires detailed theoretical forecasts. Here, we exploit the large dynamic range of the IllustrisTNG simulation suite, TNG50, TNG100, and TNG300, to derive multiband galaxy luminosity functions from z = 2 to z = 10. We put particular emphasis on the exploration of different dust attenuation models to determine galaxy luminosity functions for the rest-frame ultraviolet (UV), and apparent wide NIRCam bands. Our most detailed dust model is based on continuum Monte Carlo radiative transfer calculations employing observationally calibrated dust properties. This calibration results in constraints on the redshift evolution of the dust attenuation normalization and dust-to-metal ratios yielding a stronger redshift evolution of the attenuation normalization compared to most previous theoretical studies. Overall we find good agreement between the rest-frame UV luminosity functions and observational data for all redshifts, also beyond the regimes used for the dust model calibrations. Furthermore, we also recover the observed high-redshift (z = 4-6) UV luminosity versus stellar mass relation, the H α versus star formation rate relation, and the H α luminosity function at z = 2. The bright end (MUV > -19.5) cumulative galaxy number densities are consistent with observational data. For the F200W NIRCam band, we predict that JWST will detect ∼80 (∼200) galaxies with a signal-to-noise ratio of 10 (5) within the NIRCam field of view, 2.2× 2.2 arcmin2, for a total exposure time of 10^5 s in the redshift range z = 8 ± 0.5. These numbers drop to ∼10 (∼40) for an exposure time of 10^4 s.

published in
Monthly Notices of the Royal Astronomical Society, Volume 492, Issue 4, p.5167-5201, March 2020

links to paper
[ADS][arXiv]

Wang et al. (2020)

Early-type galaxy density profiles from IllustrisTNG – I. Galaxy correlations and the impact of baryons

by
Wang, Yunchong; Vogelsberger, Mark; Xu, Dandan; Mao, Shude; Springel, Volker; Li, Hui; Barnes, David; Hernquist, Lars; Pillepich, Annalisa; Marinacci, Federico; Pakmor, Rüediger; Weinberger, Rainer; Torrey, Paul

abstract
We explore the isothermal total density profiles of early-type galaxies (ETGs) in the IllustrisTNG simulation. For the selected 559 ETGs at z = 0 with stellar masses 10^{10.7} M_{☉ } ≤ M_{\ast } ≤ 10^{11.9} M_{☉ }, the total power-law slope has a mean of <γ′> = 2.011 ± 0.007 and a scatter of σ _{γ ^’ }} = 0.171 over the radial range 0.4-4 times the stellar half-mass radius. Several correlations between γ′ and galactic properties including stellar mass, effective radius, stellar surface density, central velocity dispersion, central dark matter fraction, and in situ-formed stellar mass ratio are compared to observations and other simulations, revealing that IllustrisTNG reproduces many correlation trends, and in particular, γ′ is almost constant with redshift below z = 2. Through analysing IllustrisTNG model variations, we show that black hole kinetic winds are crucial to lowering γ′ and matching observed galaxy correlations. The effects of stellar winds on γ′ are subdominant compared to active galactic nucleus (AGN) feedback, and differ due to the presence of AGN feedback from previous works. The density profiles of the ETG dark matter haloes are well described by steeper than NFW profiles, and they are steeper in the full physics (FP) run than their counterparts in the dark matter-only (DMO) run. Their inner density slopes anticorrelate (remain constant) with the halo mass in the FP (DMO) run, and anticorrelate with the halo concentration parameter c200 in both the types of runs. The dark matter haloes of low-mass ETGs are contracted whereas high-mass ETGs are expanded, suggesting that variations in the total density profile occur through the different halo responses to baryons.

published in
Monthly Notices of the Royal Astronomical Society, Volume 491, Issue 4, p.5188-5215, February 2020

links to paper
[ADS][arXiv]

Nelson et al. (2019)

First results from the TNG50 simulation: galactic outflows driven by supernovae and black hole feedback

by
Nelson, Dylan; Pillepich, Annalisa; Springel, Volker; Pakmor, Rüdiger; Weinberger, Rainer; Genel, Shy; Torrey, Paul; Vogelsberger, Mark; Marinacci, Federico; Hernquist, Lars

abstract
We present the new TNG50 cosmological, magnetohydrodynamical simulation – the third and final volume of the IllustrisTNG project. This simulation occupies a unique combination of large volume and high resolution, with a 50 Mpc box sampled by 21603 gas cells (baryon mass of 8 × 104 M). The median spatial resolution of star-forming interstellar medium gas is ∼100-140 pc. This resolution approaches or exceeds that of modern `zoom’ simulations of individual massive galaxies, while the volume contains ∼20 000 resolved galaxies with M_\star ≳ 10^7 M. Herein we show first results from TNG50, focusing on galactic outflows driven by supernovae as well as supermassive black hole feedback. We find that the outflow mass loading is a non-monotonic function of galaxy stellar mass, turning over and rising rapidly above 1010.5 M due to the action of the central black hole (BH). The outflow velocity increases with stellar mass, and at fixed mass it is faster at higher redshift. The TNG model can produce high-velocity, multiphase outflows that include cool, dense components. These outflows reach speeds in excess of 3000 km s-1 out to 20 kpc with an ejective, BH-driven origin. Critically, we show how the relative simplicity of model inputs (and scalings) at the injection scale produces complex behaviour at galactic and halo scales. For example, despite isotropic wind launching, outflows exhibit natural collimation and an emergent bipolarity. Furthermore, galaxies above the star-forming main sequence drive faster outflows, although this correlation inverts at high mass with the onset of quenching, whereby low-luminosity, slowly accreting, massive BHs drive the strongest outflows.

published in

Monthly Notices of the Royal Astronomical Society, Volume 490, Issue 3, p.3234-3261, December 2019

links to paper
[ADS][arXiv]

Pillepich et al. (2019)

First results from the TNG50 simulation: the evolution of stellar and gaseous discs across cosmic time

by
Pillepich, Annalisa; Nelson, Dylan; Springel, Volker; Pakmor, Rüdiger; Torrey, Paul; Weinberger, Rainer; Vogelsberger, Mark; Marinacci, Federico; Genel, Shy; van der Wel, Arjen; Hernquist, Lars

abstract
We present a new cosmological, magnetohydrodynamical simulation for galaxy formation: TNG50, the third and final instalment of the IllustrisTNG project. TNG50 evolves 2 × 21603 dark matter particles and gas cells in a volume 50 comoving Mpc across. It hence reaches a numerical resolution typical of zoom-in simulations, with a baryonic element mass of 8.5× 10^4 M_{\odot } and an average cell size of 70-140 pc in the star-forming regions of galaxies. Simultaneously, TNG50 samples ∼700 (6500) galaxies with stellar masses above 10^{10} (10^8) M_{\odot } at z = 1. Here we investigate the structural and kinematical evolution of star-forming galaxies across cosmic time (0 ≲ z ≲ 6). We quantify their sizes, disc heights, 3D shapes, and degree of rotational versus dispersion-supported motions as traced by rest-frame V-band light (i.e. roughly stellar mass) and by H α light (i.e. star-forming and dense gas). The unprecedented resolution of TNG50 enables us to model galaxies with sub-kpc half-light radii and with ≲300-pc disc heights. Coupled with the large-volume statistics, we characterize a diverse, redshift- and mass-dependent structural and kinematical morphological mix of galaxies all the way to early epochs. Our model predicts that for star-forming galaxies the fraction of disc-like morphologies, based on 3D stellar shapes, increases with both cosmic time and galaxy stellar mass. Gas kinematics reveal that the vast majority of 10^{9-11.5} M_{\odot } star-forming galaxies are rotationally supported discs for most cosmic epochs (Vrot/σ > 2-3, z ≲ 5), being dynamically hotter at earlier epochs (z ≳ 1.5). Despite large velocity dispersion at high redshift, cold and dense gas in galaxies predominantly arranges in disky or elongated shapes at all times and masses; these gaseous components exhibit rotationally dominated motions far exceeding the collisionless stellar bodies.

published in
Monthly Notices of the Royal Astronomical Society, Volume 490, Issue 3, p.3196-3233, December 2019

links to paper
[ADS][arXiv]

Xu et al. (2019)

A study of stellar orbit fractions: simulated IllustrisTNG galaxies compared to CALIFA observations

by
Xu, Dandan; Zhu, Ling; Grand, Robert; Springel, Volker; Mao, Shude; van de Ven, Glenn; Lu, Shengdong; Wang, Yougang; Pillepich, Annalisa; Genel, Shy; Nelson, Dylan; Rodriguez-Gomez, Vicente; Pakmor, Rüdiger; Weinberger, Rainer; Marinacci, Federico; Vogelsberger, Mark; Torrey, Paul; Naiman, Jill; Hernquist, Lars

abstract
Motivated by the recently discovered kinematic `Hubble sequence’ shown by the stellar orbit-circularity distribution of 260 CALIFA galaxies, we make use of a comparable galaxy sample at z = 0 with a stellar mass range of M_{*}/M_{\odot }\in [10^{9.7}, 10^{11.4}] selected from the IllustrisTNG simulation and study their stellar orbit compositions in relation to a number of other fundamental galaxy properties. We find that the TNG100 simulation broadly reproduces the observed fractions of different orbital components and their stellar mass dependences. In particular, the mean mass dependences of the luminosity fractions for the kinematically warm and hot orbits are well reproduced within model uncertainties of the observed galaxies. The simulation also largely reproduces the observed peak and trough features at M_{*}≈ 1{-}2× 10^{10} M_{\odot } in the mean distributions of the cold- and hot-orbit fractions, respectively, indicating fewer cooler orbits and more hotter orbits in both more- and less-massive galaxies beyond such a mass range. Several marginal disagreements are seen between the simulation and observations: the average cold-orbit (counter-rotating) fractions of the simulated galaxies below (above) M_{*}≈ 6× 10^{10} M_{\odot } are systematically higher than the observational data by ≲ 10{{ per cent}} (absolute orbital fraction); the simulation also seems to produce more scatter for the cold-orbit fraction and less so for the non-cold orbits at any given galaxy mass. Possible causes that stem from the adopted heating mechanisms are discussed.

published in
Monthly Notices of the Royal Astronomical Society, Volume 489, Issue 1, p.842-854, October 2019

links
[ADS][arXiv]

« Older posts

© 2020 Rainer Weinberger

Theme by Anders NorenUp ↑