Skip to content

Commit

Permalink
added beam
Browse files Browse the repository at this point in the history
  • Loading branch information
FredDeCeuster committed Aug 2, 2023
1 parent d3ac18f commit a35c69a
Show file tree
Hide file tree
Showing 18 changed files with 3,217 additions and 913 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ We are open to contributions to p3droslo. More information can be found [here](h

## Collaborating

We are always interested in collaborating! If you have a project or data that might benefit from probabilistic 3D reconstruction or any other method you can find in this repository, feel free to contact [me](https://freddeceuster.github.io).
We are always interested in collaborating!
If you like our work but it needs some tailoring for your specific use case feel free to contact [me](https://freddeceuster.github.io).


## Acknowledgements
Expand Down
1 change: 1 addition & 0 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ requirements:
- python={{ python_version }}
- matplotlib
- astroquery
- radio-beam
- ipywidgets
- pytorch>=2.0.0
- astropy
Expand Down
19 changes: 7 additions & 12 deletions docs/src/background/spectral_line_formation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Therefore, for $\\left|b_{1}-b_{0}\\right| < 10^{-3}$, we use the first four terms of the Taylor expansion of $b_1$ around $b_0$,\n",
"Therefore, for $\\left|b_{1}-b_{0}\\right| < 10^{-3}$, we use the first two terms of the Taylor expansion of $b_1$ around $b_0$,\n",
"\\begin{equation*}\n",
"\\begin{split}\n",
"\\Delta \\tau \\ \\approx \\ \\Delta x \\, e^{-b_{0}^{2}} & \\left(\\frac{1}{2}\\left(a_{0} + a_{1}\\right) \\right. \\\\\n",
"& \\ \\ \\ \\ - \\ \\frac{1}{3} \\, \\left( a_{0} + 2 a_{1} \\right) b_{0} \\left(b_{1}-b_{0}\\right) \\\\\n",
"& \\ \\ \\ \\ + \\ \\frac{1}{12} \\, \\left( a_{0} + 3 a_{1} \\right) \\left(2 b_{0}^{2} - 1\\right) \\left(b_{1}-b_{0}\\right)^{2} \\\\\n",
"& \\left. \\ \\ \\ \\ - \\ \\frac{1}{30} \\, \\left( a_{0} + 4 a_{1} \\right) \\left(2 b_{0}^{2} - 3\\right) b_{0} \\left(b_{1}-b_{0}\\right)^{2} \\right) .\n",
"\\end{split}\n",
"\\Delta \\tau \\ \\approx \\ \\Delta x \\, e^{-b_{0}^{2}} \\left(\\frac{1}{2}\\left(a_{0} + a_{1}\\right) \\ - \\ \\frac{1}{3} \\, \\left( a_{0} + 2 a_{1} \\right) b_{0} \\left(b_{1}-b_{0} \\right) \\right) \\\\\n",
"\\end{equation*}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The implementation on this line optical depth can be found in [src/p3droslo/lines.py](https://github.com/Magritte-code/p3droslo/blob/main/src/p3droslo/lines.py)."
"The implementation on this line optical depth can be found in [src/p3droslo/lines.py](https://github.com/Magritte-code/p3droslo/blob/main/src/p3droslo/lines.py). It turned out that the implementation with two masks (one for case $\\left|b_{1}-b_{0}\\right| < 10^{-3}$ and one for its complement) is more expensive than doing both calculations for both cases, and only in the end mergingg the result. This, however, will mean that at seem point some $\\Delta \\tau$ will be NaN due to division by zero (coming from $b_{1}-b_{0}$), which causes no problem for the forward model (since these values will eventually be overwritten), but which causes gradients to diverge (see [this issue](https://github.com/Magritte-code/p3droslo/issues/2)). Therefore we add a small number $10^{-30}$ to the denominator."
]
},
{
Expand Down Expand Up @@ -110,13 +105,13 @@
"\\end{equation*}\n",
"where $\\Delta\\tau \\equiv \\tau_{1} - \\tau_{0}$. This expression is numerically stable as long as $\\Delta \\tau$ is not too small, but will suffer from cancellation errors otherwise.\n",
"\n",
"Therefore, for $\\Delta \\tau < 10^{-2}$ we use the first four terms in the Taylor expansion,\n",
"Therefore, for $\\Delta \\tau < 10^{-2}$ we use the first three terms in the Taylor expansion,\n",
"\\begin{equation*}\n",
"\\frac{1}{2\\Delta\\tau} \\left(e^{-\\Delta\\tau} - (1 - \\Delta\\tau) \\right) \\ \\approx \\ \\frac{1}{2}\\Delta\\tau \\ - \\ \\frac{1}{6}\\Delta\\tau^{2} \\ + \\ \\frac{1}{120}\\Delta\\tau^{3} \\ - \\ \\frac{1}{24}\\Delta\\tau^{4},\n",
"\\frac{1}{2\\Delta\\tau} \\left(e^{-\\Delta\\tau} - (1 - \\Delta\\tau) \\right) \\ \\approx \\ \\frac{1}{2}\\Delta\\tau \\ - \\ \\frac{1}{6}\\Delta\\tau^{2} \\ + \\ \\frac{1}{120}\\Delta\\tau^{3},\n",
"\\end{equation*}\n",
"\n",
"\\begin{equation*}\n",
"\\frac{1}{2\\Delta\\tau} \\left(e^{+\\Delta\\tau} - (1 + \\Delta\\tau) \\right) \\ \\approx \\ \\frac{1}{2} \\Delta\\tau \\ + \\ \\frac{1}{6}\\Delta\\tau^{2} \\ + \\ \\frac{1}{120}\\Delta\\tau^{3} \\ + \\ \\frac{1}{24}\\Delta\\tau^{4},\n",
"\\frac{1}{2\\Delta\\tau} \\left(e^{+\\Delta\\tau} - (1 + \\Delta\\tau) \\right) \\ \\approx \\ \\frac{1}{2} \\Delta\\tau \\ + \\ \\frac{1}{6}\\Delta\\tau^{2} \\ + \\ \\frac{1}{120}\\Delta\\tau^{3},\n",
"\\end{equation*}"
]
},
Expand All @@ -125,7 +120,7 @@
"metadata": {},
"source": [
"in which you can recognize the expansion of the exponential minus the first two terms.\n",
"The implementation of this intensity increment can be found in [src/p3droslo/forward.py](https://github.com/Magritte-code/p3droslo/blob/main/src/p3droslo/forward.py)."
"The implementation of this intensity increment can be found in [src/p3droslo/forward.py](https://github.com/Magritte-code/p3droslo/blob/main/src/p3droslo/forward.py). For the same reaseon as with the line optical depth, we compute both cases for all values, to minimise the use of masks, and we add a small number ($10^{-30}$) to the denominator to avoid NaNs in gradients."
]
},
{
Expand Down
970 changes: 970 additions & 0 deletions docs/src/examples/IK_Tau_NaCl.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit a35c69a

Please sign in to comment.