Skip to content

Commit 7830de1

Browse files
committed
Seeds tutorial notebook
Addressing #6
1 parent af1cede commit 7830de1

File tree

3 files changed

+226
-2
lines changed

3 files changed

+226
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
*.log
88
*.blg
99
*.out
10-
*.exe
10+
*.exe
11+
.ipynb_checkpoints

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ help:
1818
@echo ' make prod -> Builds main program for a production run.'
1919
@echo ' make test -> Builds main program for a test run (debugging and backtracing enabled).'
2020
@echo ' make Observables -> Builds the Observables.exe excecutable, which computes polarized and total synchrotron intensity, as well as rotation measures, and includes them in the output.'
21-
@echo ' make Observables -> Builds the Observables_single.exe excecutable, which computes line-of-sight quantities for individual galaxies in the output.'
21+
@echo ' make Observables_single -> Builds the Observables_single.exe excecutable, which computes line-of-sight quantities for individual galaxies in the output.'
2222
@echo ' make clean -> Removes all object files.'
2323
@echo ' make cleanall -> Removes all object files, executables files and python bytecode.'
2424
@echo ' make all -> Builds all test programs and main program (test settings).'

doc/magnetizer_tutorial.ipynb

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import os"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 2,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"os.chdir('..')"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"## Compiling\n",
26+
"\n",
27+
"If all the required libraries are installed and the paths had been adjusted in the Makefile, one should be able to build the code.\n",
28+
"\n",
29+
"If one simple executes `make` or `make help`, there is a brief summary of which components can be built."
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 16,
35+
"metadata": {},
36+
"outputs": [
37+
{
38+
"name": "stdout",
39+
"output_type": "stream",
40+
"text": [
41+
"---------------------\n",
42+
" Magnetizer Makefile\n",
43+
"---------------------\n",
44+
" make prod -> Builds main program for a production run.\n",
45+
" make test -> Builds main program for a test run (debugging and backtracing enabled).\n",
46+
" make Observables -> Builds the Observables.exe excecutable, which computes polarized and total synchrotron intensity, as well as rotation measures, and includes them in the output.\n",
47+
" make Observables_single -> Builds the Observables_single.exe excecutable, which computes line-of-sight quantities for individual galaxies in the output.\n",
48+
" make clean -> Removes all object files.\n",
49+
" make cleanall -> Removes all object files, executables files and python bytecode.\n",
50+
" make all -> Builds all test programs and main program (test settings).\n",
51+
" make help -> Displays this help\n"
52+
]
53+
}
54+
],
55+
"source": [
56+
"%%bash\n",
57+
"\n",
58+
"make "
59+
]
60+
},
61+
{
62+
"cell_type": "markdown",
63+
"metadata": {},
64+
"source": [
65+
"We strongly recommend initially using `make test` for compiling the `Magnetizer`. The `make prod` option enables the compiler optimizations and *disables* debugging and backtracing features. Also, when major changes are made to the source, it often a good idea to use the `make cleanall` command to avoid problems."
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": 17,
71+
"metadata": {},
72+
"outputs": [
73+
{
74+
"name": "stdout",
75+
"output_type": "stream",
76+
"text": [
77+
"\n",
78+
"Building Magnetizer test/debug run\n",
79+
"\n",
80+
"h5pfc build/tsDataObj.o build/bessel_functions.o build/root_finder.o build/constants.o build/grid.o build/floor_field.o build/global_input_parameters.o build/surface_density.o build/pressureEquilibrium.o build/outflow.o build/random.o build/input_parameters.o build/IO_hdf5.o build/profiles.o build/gutsdynamo.o build/ts_arrays.o build/data_transfer.o build/output.o build/dynamo.o build/rotationCurves.o build/deriv.o build/messages.o build/interpolation.o build/integration.o build/seed_field.o build/distributor.o build/Magnetizer.o -I /usr/local/include/fgsl/ -lfgsl -I. -I./source/ -J./build/ -fintrinsic-modules-path ./build -I./build/ -I/usr/include/ -fbacktrace -ffpe-trap=zero,invalid,overflow -fbounds-check -lgsl -lgslcblas -lm -g -Wall -o Magnetizer.exe\n"
81+
]
82+
}
83+
],
84+
"source": [
85+
"%%bash \n",
86+
"\n",
87+
"make test"
88+
]
89+
},
90+
{
91+
"cell_type": "markdown",
92+
"metadata": {},
93+
"source": [
94+
"This should have generated the `Magnetizer.exe` executable file in the current working directory."
95+
]
96+
},
97+
{
98+
"cell_type": "markdown",
99+
"metadata": {},
100+
"source": [
101+
"## Preparing an input file\n",
102+
"\n",
103+
"The Magnetizer code relies on two things in order to run: a **parameters file** and an **input file**. The *parameters file* contains all the setup associated with a run particular run. For example, it contains the path to the input and output files, the number of grid points to be used for the profiles, which assumptions should be used for solving the dynamo equations, etc. We will discuss this in another section.\n",
104+
"\n",
105+
"The *input file* contains the properties of the galaxies for which the Magentizer will compute the ISM and magnetic properties. This file can be generated from a Galform `galaxies.hdf5` output file using the python script `python/prepare_input.py`, which contains some usage information:"
106+
]
107+
},
108+
{
109+
"cell_type": "code",
110+
"execution_count": 20,
111+
"metadata": {},
112+
"outputs": [
113+
{
114+
"name": "stdout",
115+
"output_type": "stream",
116+
"text": [
117+
"usage: prepare_input.py [-h] [-n NUMBER_OF_GALAXIES]\n",
118+
" [-nz NUMBER_OF_EXTRA_GALAXIES_PER_Z]\n",
119+
" [-BoT MAXIMUM_B_OVER_T] [-ms MINIMUM_STELLAR_MASS]\n",
120+
" [-mg MINIMUM_GAS_MASS] [-Ms MAXIMUM_STELLAR_MASS]\n",
121+
" [-r MINIMUM_DISK_SIZE] [-z MAX_REDSHIFT] [-naz]\n",
122+
" SAM_OUTPUT MAGNETIZER_INPUT\n",
123+
"\n",
124+
"Prepares an input file for the Magnetizer.\n",
125+
"\n",
126+
"positional arguments:\n",
127+
" SAM_OUTPUT HDF5 output file of a Galform run.\n",
128+
" MAGNETIZER_INPUT Name of the Magnetizer input file to be prepared.\n",
129+
"\n",
130+
"optional arguments:\n",
131+
" -h, --help show this help message and exit\n",
132+
" -n NUMBER_OF_GALAXIES, --number_of_galaxies NUMBER_OF_GALAXIES\n",
133+
" Approximate *maximum* number of galaxies to extract\n",
134+
" from the SAM_OUTPUT file at z=0. The evolution of\n",
135+
" these galaxies will then be followed.Default: 1e10.\n",
136+
" -nz NUMBER_OF_EXTRA_GALAXIES_PER_Z, --number_of_extra_galaxies_per_z NUMBER_OF_EXTRA_GALAXIES_PER_Z\n",
137+
" Approximate *maximum* number of galaxies to extract\n",
138+
" from the SAM_OUTPUT file for each redshift(except\n",
139+
" z=0). Default: same as number_of_galaxies.\n",
140+
" -BoT MAXIMUM_B_OVER_T, --maximum_B_over_T MAXIMUM_B_OVER_T\n",
141+
" Maximum bulge to total mass ratio. Default: 1.0\n",
142+
" -ms MINIMUM_STELLAR_MASS, --minimum_stellar_mass MINIMUM_STELLAR_MASS\n",
143+
" Minimum disk stellar mass at z=0 (in Msun). Default:\n",
144+
" 1e7.\n",
145+
" -mg MINIMUM_GAS_MASS, --minimum_gas_mass MINIMUM_GAS_MASS\n",
146+
" Minimum disk gas mass at z=0 (in Msun). Default: 1e6.\n",
147+
" -Ms MAXIMUM_STELLAR_MASS, --maximum_stellar_mass MAXIMUM_STELLAR_MASS\n",
148+
" Maximum disk stellar mass at z=0 (in Msun). Default:\n",
149+
" 1e14.\n",
150+
" -r MINIMUM_DISK_SIZE, --minimum_disk_size MINIMUM_DISK_SIZE\n",
151+
" Minimum disk half mass radius at z=0 (in kpc).\n",
152+
" Default: 0.5.\n",
153+
" -z MAX_REDSHIFT, --max_redshift MAX_REDSHIFT\n",
154+
" Maximum redshift to use. Default: 6.\n",
155+
" -naz, --do_not_sample_all_z\n",
156+
" If present, galaxies will be sampled only at z=0 and\n",
157+
" their ancestors will be followed to high z (this is\n",
158+
" equivalent to -nz 0). If absent, extra galaxies will\n",
159+
" me sampled for each redshift following -nz.\n"
160+
]
161+
}
162+
],
163+
"source": [
164+
"%%bash\n",
165+
"\n",
166+
"./python/prepare_input.py -h"
167+
]
168+
},
169+
{
170+
"cell_type": "markdown",
171+
"metadata": {},
172+
"source": [
173+
"Here I provide a brief description of what is been done by this script.\n",
174+
"\n",
175+
"The script will start looking at the output at $z=0$, select the specified number of galaxies. For each galaxy, it step on the merger tree towards higher redshift, always choosing the most massive progenitor brach. Thus, this procedures *converts the original merger tree to a simple time series*, i.e. each galaxy is represented by a time series of properties (instead of a graph).\n",
176+
"\n",
177+
"The sample obtained until now is biased: for $z>0$, only the most massive galaxies of each merger tree is being selected. To avoid this, the script moves to the next available redshift and repeats the procedure (skipping galaxies which had been previously stored). Suppose, for definitness that this next redshift is $z=0.01$, the script will look at a number NUMBER_OF_EXTRA_GALAXIES_PER_Z galaxies at $z=0.01$ that were not picked before. For each of these, it will store their properties of the galaxies and move to the most massive branch. Again, a time series will be generated, but it will end at $z=0.01$ instead of $z=0$, because this galaxies merge (or cease to satisfy the selecton criteria) after this redshit. The absent $z=0$ data is signalled in the input file as -999999 marker (which is ignored both by the Magnetizer programs and the python library).\n",
178+
"The procedure then continues analogously for other redshits.\n",
179+
"\n",
180+
"The seclection criteria (e.g. MINIMUM_DISK_SIZE) are applied on the redshift where the galaxies are first sampled *but not on the progenitors of the galaxies* (but note that the progenitors *do appear in the sample*). To make things concrete, suppose we choose to sample 10 galaxies with disk size greater than 10 kpc. The script will look at $z=0$, try to find 10 galaxies with $r_{\\rm disk}>10\\,\\rm kpc$, and include those galaxies and all their (most massive) progenitors at $z>0$, even if the progenitors have $r_{\\rm disk}<10\\,\\rm kpc$. The reason for this is that, for any sampled galaxy, we want to have access the full history of the galaxy in its time series, so that the Magnetizer can solve the dynamo equations. To avoid mixing galaxies which are actually sampled with galaxies which are in the sample simply because they are progenitors of sampled galaxies, one can use the \"sample_z\" property. A very brute-force and computationally intensive (but often useful) alternative, is to use all the galaxies in a given Galform's output, and leave any selection for the analysis step."
181+
]
182+
},
183+
{
184+
"cell_type": "code",
185+
"execution_count": null,
186+
"metadata": {},
187+
"outputs": [],
188+
"source": []
189+
},
190+
{
191+
"cell_type": "code",
192+
"execution_count": 18,
193+
"metadata": {},
194+
"outputs": [],
195+
"source": [
196+
"import sys\n",
197+
"sys.path.append('python')\n",
198+
"import magnetizer"
199+
]
200+
}
201+
],
202+
"metadata": {
203+
"kernelspec": {
204+
"display_name": "Python 3",
205+
"language": "python",
206+
"name": "python3"
207+
},
208+
"language_info": {
209+
"codemirror_mode": {
210+
"name": "ipython",
211+
"version": 3
212+
},
213+
"file_extension": ".py",
214+
"mimetype": "text/x-python",
215+
"name": "python",
216+
"nbconvert_exporter": "python",
217+
"pygments_lexer": "ipython3",
218+
"version": "3.7.8"
219+
}
220+
},
221+
"nbformat": 4,
222+
"nbformat_minor": 4
223+
}

0 commit comments

Comments
 (0)