Skip to content

Commit

Permalink
Fix notebook layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
FredDeCeuster committed Aug 8, 2024
1 parent cde5e10 commit 8f8946a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"\n",
"## Model setup\n",
"\n",
"---\n",
"\n",
"### Geometry\n",
"\n",
"---\n",
"The model box is given by the radial coordinate $r \\in [r_{\\star}, r_{\\text{out}}] = [1, 10^{4}] \\ \\text{au}$. The model is discretised on a logarithmically-spaced grid consisting of 1024 elements with $r \\in [r_{\\text{in}}, r_{\\text{out}}] = [10^{-1}, 10^{4}] \\ \\text{au}$.\n",
"Note that $r_{\\text{in}} < r_{\\star}$, such that several rays hit the stellar surface, since, for concenience, we use the same discretisation for the impact parameters of the rays. We impose a boundary condition at $r=r_{\\star}$, such that the part of the model inside the star ($r<r_{\\star}$) does not contribute to the resulting observation, and thus cannot be reconstructed."
]
Expand All @@ -62,9 +62,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Velocity\n",
"\n",
"---\n",
"\n",
"### Velocity\n",
"For the velocity field, we assume a typical radially outward directed $\\beta$-law,\n",
"\\begin{equation*}\n",
"v(r) \\ = \\ v_{\\star} \\ + \\ \\left( v_{\\infty} - v_{\\star} \\right) \\left(1 - \\frac{r_{\\star}}{r}\\right)^{\\beta} ,\n",
Expand All @@ -91,10 +91,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Density\n",
"\n",
"---\n",
"\n",
"### Density\n",
"We assume the density and velocity to be related through the conservation of mass, such that,\n",
"\\begin{equation*}\n",
"\\rho \\left( r \\right) \\ = \\ \\frac{\\dot{M}}{4 \\pi r^{2} \\, v(r)},\n",
Expand All @@ -117,10 +116,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### CO abundance\n",
"\n",
"---\n",
"\n",
"### CO abundance\n",
"The CO abundance is assumed to be proportional to the density, such that, $n^{\\text{CO}}(r) = 3.0 \\times 10^{-4} \\, N_{A} \\, \\rho(r) / m^{\\text{H}_2}$, with $N_{A}$ Avogadro's number, and $m^{\\text{H}_2} = 2.02 \\ \\text{g}/\\text{mol}$, the molar mass of $\\text{H}_{2}$."
]
},
Expand All @@ -138,10 +136,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Temperature\n",
"\n",
"---\n",
"\n",
"### Temperature\n",
"For the gas temperature, we assume a power law,\n",
"\\begin{equation*}\n",
"T(r) \\ = \\ T_{\\star} \\left(\\frac{r_{\\star}}{r}\\right)^{\\epsilon} ,\n",
Expand All @@ -167,10 +164,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Micro-turbulence\n",
"\n",
"---\n",
"\n",
"### Micro-turbulence\n",
"Finally, we assume a constant turbulent velocity $v_{\\text{turb}}(r) = 1 \\ \\text{km}/\\text{s}$."
]
},
Expand All @@ -187,10 +183,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### TensorModel\n",
"\n",
"---\n",
"\n",
"### TensorModel\n",
"With all the data in place, we can start building a pomme model.\n",
"First, we store all model parameters as a TensorModel object and store this in an HDF5 file.\n",
"We will use this later as the ground truth to verify our reconstructions against."
Expand Down Expand Up @@ -221,10 +216,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### SphericalModel\n",
"\n",
"---\n",
"\n",
"### SphericalModel\n",
"First, we define the functions that can generate the model distributions from the model parameters."
]
},
Expand Down Expand Up @@ -324,10 +318,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Spectral lines\n",
"\n",
"---\n",
"\n",
"### Spectral lines\n",
"We base our reconstructions on synthetic observations of two commonly observed rotational CO lines $J = \\{(3-2), \\, (7-6)\\}$, which we observe, each in 50 frequency bins, centred around the lines, with a spacing of 1.02 km/s."
]
},
Expand Down Expand Up @@ -373,10 +366,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Frequencies\n",
"\n",
"---\n",
"\n",
"### Frequencies\n",
"Next, we define the velocity/frequency range of interest around the lines."
]
},
Expand All @@ -397,10 +389,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Synthetic observations\n",
"\n",
"---\n",
"\n",
"## Synthetic observations\n",
"We can now generate synthetic observations, directly from the SphericalModel object.\n",
"We will use these later to derive our reconstructions."
]
Expand Down Expand Up @@ -452,10 +443,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reconstruction setup\n",
"\n",
"---\n",
"\n",
"## Reconstruction setup\n",
"In this example, we will try to reconstruct the CO abundance, velocity, and temperature distribution.\n",
"First, we define the model object for the reconstruction. Note that in the smodel defined above, all the right parameters are already stored, so we need a new one for the reconstruction.\n",
"We take, $n_{\\text{CO}}^{\\text{init}}(r) = 5.0 \\times 10^{14} \\, \\text{m}^{-3} \\, (r_{\\text{in}}/r)^{2} $, as initial guess for the CO abundance distribution, and initialise both the velocity and the temperature with the correct values."
Expand Down Expand Up @@ -495,11 +485,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"### Loss functions\n",
"\n",
"---\n",
"\n",
"### Loss functions\n",
"We first create Loss object that can conveniently store the different losses.\n",
"We will use a reproduction loss (split into an averaged and relative component), a smoothness, and a continuity loss."
]
Expand All @@ -519,9 +507,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Reproduction loss\n",
"\n",
"---\n",
"\n",
"#### Reproduction loss\n",
"We split the reproduction loss into an averaged and a relative component,\n",
"\\begin{equation*}\n",
"\\mathcal{L}_{\\text{rep}}\\big(f(\\boldsymbol{m}), \\boldsymbol{o} \\big)\n",
Expand Down Expand Up @@ -559,9 +547,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Smoothness loss\n",
"\n",
"---\n",
"\n",
"#### Smoothness loss\n",
"The smoothnes loss in spherical symmetry is defined as, "
]
},
Expand All @@ -587,9 +575,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Continuity loss\n",
"\n",
"---\n",
"\n",
"#### Continuity loss\n",
"In spherical symmetry, the regularisation loss that assumes a steady state and enforces the continuity equation, reads,\n",
"\\begin{equation*}\n",
"\\mathcal{L}[\\rho, v]\n",
Expand Down Expand Up @@ -626,15 +614,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Fit function\n",
"\n",
"---\n",
"\n",
"### Fit function\n",
"With everything in place, we can finally define the fit function."
]
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -666,14 +654,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Experiments\n",
"---\n",
"\n",
"---"
"## Experiments"
]
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 21,
"metadata": {},
"outputs": [
{
Expand All @@ -682,7 +670,7 @@
"text": [
" 0%| | 0/3 [00:00<?, ?it/s]/home/frederikd/.local/lib/python3.9/site-packages/torch/autograd/__init__.py:200: UserWarning: CUDA initialization: The NVIDIA driver on your system is too old (found version 9010). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver. (Triggered internally at ../c10/cuda/CUDAFunctions.cpp:109.)\n",
" Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass\n",
"100%|██████████| 3/3 [00:25<00:00, 8.64s/it]\n"
" 33%|███▎ | 1/3 [00:08<00:17, 8.99s/it]"
]
}
],
Expand All @@ -701,14 +689,14 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" 8%|▊ | 8/100 [01:17<15:12, 9.92s/it]"
" 36%|███▌ | 36/100 [06:08<11:29, 10.77s/it]"
]
}
],
Expand All @@ -724,6 +712,27 @@
"losses.plot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'losses' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Input \u001b[0;32mIn [1]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mlosses\u001b[49m\u001b[38;5;241m.\u001b[39mplot()\n",
"\u001b[0;31mNameError\u001b[0m: name 'losses' is not defined"
]
}
],
"source": [
"losses.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -739,6 +748,13 @@
"source": [
"smodel_recon.model_1D.save('model_recon.h5')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Empty file.
3 changes: 2 additions & 1 deletion docs/src/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Some examples showcasing the use of pomme.
:maxdepth: 1
:caption: Contents:

spherically_symmetric
1D_stellar_wind
3D_stellar_wind

0 comments on commit 8f8946a

Please sign in to comment.