# Computational Astrophysics in Python (WP1.1)

## Table of Contents

Questions/Comments about the Python lab should go to Kerstin Paech (email is paech and then the usual @usm.lmu.de).

The lab ipython notebooks are continously updated over the course of the lab. So please make sure you download the notebooks before starting to work on a lab.

## 1 About this lab

This is the webpage for the **Computational Astrophysics in Python Lab**. For
informations about the FORTRAN lab and general terms of this numerics lab,
please refer to the FORTRAN numerics lab website.
The labs will be very similar to the FORTRAN labs, but with a stronger emphasis
on writing your own programs.

For general information about how this lab course is organized go to the course main page. There you will find information how everything works, including evaluation criteria. These criteria are not self-serving and you should very much see them as a guideline on what important skills as a scientist are. You will need these and other skills to successfully complete your master thesis eventually.

For information about the introduction that takes place in the first two weeks, see here.

The Python numerics lab exercises are mostly provided as jupyter ipython notebook (exceptions are mentioned in the lab descriptions you can find below). Check out the respective sections for each lab.

How to use ipython notebooks will be discussed in the tutorial. If you'd like to install python and jupyter on your personal computer, a convenient choice is described on the jupyter website here.

The following labs are offered in Python:

## 2 Introduction to programming and plotting in Python

### 2.1 First week: Tutorial about finding your way in Linux

### 2.2 Second week: Python tutorial

In the second week you'll have a basic tutorial about programming and visualizing results. For the numerics lab in python, we'll have a separate tutorial to the traditional one (which focuses on FORTRAN and IDL), which focuses on Python2 as a programming language and will be the main tool for visualization (April 26, 2016). We'll meet in the lobby.

Please download the ipython notebook that you'll be using in the tutorial. We recommend that you look at it before the tutorial. If you don't have access to ipython (yet), you can download the html version and copy/paste the content from there.

After the tutrial, work through the exercises in the following notebook. You have to and this in one week after the Python2 tutorial.

## 3 Matrix inversion

Algorithmic Advisor: Keith Butler / Python contact person: Markus Michael Rau

In this lab, basic methods for solving linear equations are implemented and applied.

Please prepare for this lab by reading chapters 1-6 of the lab manual. For exercises 1-6 and advanced task 1, please refer to the ipython notebook, all other exercises are found the in the FORTRAN lab manual. You can find the codes and data exercise 7 here.

## 4 Integration methods

Algorithmic Advisor: Adi Pauldrach / Python contact person: Kerstin Paech

You'll numerically calculate integrals and apply those methods to calculate the radius a pure ionized hydrogen Strömgren sphere.

Please use the manual (the password is the same as for the general astro physics lab webpages) to prepare for the lab and refer to the ipython notebook for carying out hthe exercises.

## 5 Ordinary differential equations

Algorithmic Advisor: Tadziu Hoffmann / Python contact person: Ben Hoyle

This lab provides an introduction to some numerical methods to evaluate differential equations, and coupled differential equation.

Please prepare for the lab by working through the first three chapters of FORTRAN lab manual and answering the inline questions.

You find additional instructions in the following ipython notebooks: notebook1 and notebook1a for the first afternoon and notebook2 for the second afternoon.

## 6 N-body simulations

This version of the lab is under development. Please contact Oliver Friedrich for the relevant materials and instructions.

## 7 Random numbers and Monte Carlo simulations

Algorithmic Advisor: Jo Puls / Python contact person: Kerstin Paech

In this lab you will learn how to create simple pseudo random numbers and use random numbers to calculate an integral as well as simulate pure radiative transfer in stellar atmospheres.

Please prepare for the lab by working through chapter 1 of FORTRAN lab manual. You can find the actual lab exercises in the ipython notebooks for the following three tasks:

- Notebook 1 In a first step you'll program a simple random number generator
- Notebook 2 The first application an integral is calculated using Monte Carlo Integration
- Notebook 3 The second application is the simulation of pure radiative transfer in stellar atmospheres and you'll simulate why the sun is darker at it's edges than at the center.

## 8 Monte Carlo Markov Chains and Lensing Profile of Galaxy Clusters

Algorithmic Advisor: Matteo Costanzi/Ben Hoyle / Python contact person: Steffen Hagstotz

- You'll learn how to use Monte Carlo Markov Chains (MCMC) to estimate the parameters of a model, including confidence regions (i.e. uncertainties).
- As an application you'll estimate the mass of a galaxy cluster with weak lensing

Please use the manual to prepare for the lab. Further instructions can be found in this ipython notebook.

You will use the data in halo5.tab (download) - make sure you either save it to the current working directory of your notebook or specify the right path inside your notebook when opening the file.