Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/ess/odin.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"metadata": {},
"outputs": [],
"source": [
"source = tof.Source(facility=\"ess\", neutrons=500_000, pulses=4)\n",
"source = tof.Source(facility=\"ess-odin\", neutrons=500_000, pulses=4)\n",
"source.plot()"
]
},
Expand Down
99 changes: 80 additions & 19 deletions docs/sources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@
"\n",
"We first show how to create flat time and wavelength distributions.\n",
"\n",
"<div class=\"alert alert-warning\">\n",
"\n",
"**Changes in version 25.12.0**\n",
"\n",
"Linear interpolation between points in a source profile is no longer performed automatically.\n",
"\n",
"You will now need to create enough sampling points (see the use of `linspace` with 100 points below) in the distribution for good results.\n",
" \n",
"</div>\n",
"\n",
"To create a pulse with 1 million neutrons, uniformly distributed in the ranges of 1-3 ms for birth times,\n",
"and 1-10 Å for wavelengths, we write:"
Expand All @@ -120,13 +129,13 @@
"metadata": {},
"outputs": [],
"source": [
"birth_time = sc.array(dims=['birth_time'], values=[1.0, 3.0], unit='ms')\n",
"birth_time = sc.linspace('birth_time', 1.0, 3.0, 100, unit='ms')\n",
"p_time = sc.DataArray(\n",
" data=sc.ones(sizes=birth_time.sizes),\n",
" coords={'birth_time': birth_time},\n",
")\n",
"\n",
"wavelength = sc.array(dims=['wavelength'], values=[1.0, 10.0], unit='angstrom')\n",
"wavelength = sc.linspace('wavelength', 1.0, 10.0, 100, unit='angstrom')\n",
"p_wav = sc.DataArray(\n",
" data=sc.ones(sizes=wavelength.sizes),\n",
" coords={'wavelength': wavelength},\n",
Expand All @@ -152,8 +161,17 @@
"The array values represent the probabilities, while the associated coordinates represent the values to be sampled from.\n",
"\n",
"As an example, we create a triangular distribution for the neutron birth times,\n",
"and a linearly increasing distribution for the neutron wavelengths\n",
"(note that internally a linear interpolation is performed on the original data)."
"and a linearly increasing distribution for the neutron wavelengths.\n",
"\n",
"<div class=\"alert alert-warning\">\n",
"\n",
"**Changes in version 25.12.0**\n",
"\n",
"Linear interpolation between points in a source profile is no longer performed automatically.\n",
"\n",
"You will now need to create enough sampling points (see the use of `linspace` with 30 points below) in the distribution for good results.\n",
" \n",
"</div>"
]
},
{
Expand All @@ -164,15 +182,14 @@
"outputs": [],
"source": [
"v = np.arange(30.0)\n",
"n = len(v) * 2\n",
"p_time = sc.DataArray(\n",
" data=sc.array(dims=['birth_time'], values=np.concatenate([v, v[::-1]])),\n",
" coords={'birth_time': sc.linspace('birth_time', 0.1, 6.0, len(v) * 2, unit='ms')},\n",
" coords={'birth_time': sc.linspace('birth_time', 0.1, 6.0, n, unit='ms')},\n",
")\n",
"p_wav = sc.DataArray(\n",
" data=sc.array(dims=['wavelength'], values=[1.0, 4.0]),\n",
" coords={\n",
" 'wavelength': sc.array(dims=['wavelength'], values=[1.0, 4.0], unit='angstrom')\n",
" },\n",
" data=sc.linspace('wavelength', 1.0, 4.0, n),\n",
" coords={'wavelength': sc.linspace('wavelength', 1.0, 4.0, n, unit='angstrom')},\n",
")\n",
"\n",
"source = tof.Source.from_distribution(neutrons=200_000, p_time=p_time, p_wav=p_wav)\n",
Expand All @@ -186,13 +203,56 @@
"source": [
"Note that the time and wavelength distributions are independent;\n",
"a neutron with a randomly selected birth time from `p_time` can adopt any wavelength in `p_wav`\n",
"(in other words, the two distributions are simply broadcast into a square 2D parameter space)."
"(in other words, the two distributions are simply broadcast into a square 2D parameter space).\n",
"\n",
"### 2D distributions\n",
"\n",
"You can also specify a single `p` data array which represents a 2D probability distribution:"
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"id": "13",
"metadata": {},
"outputs": [],
"source": [
"y, x = np.indices((300, 300))\n",
"X, Y = x - 150, y - 150\n",
"t = np.pi / 4\n",
"a = np.exp(\n",
" -(\n",
" ((np.cos(t) * X + np.sin(t) * Y) / 80) ** 2\n",
" + ((-np.sin(t) * X + np.cos(t) * Y) / 40) ** 2\n",
" )\n",
")\n",
"\n",
"p = sc.DataArray(\n",
" data=sc.array(dims=['wavelength', 'birth_time'], values=a),\n",
" coords={\n",
" 'birth_time': sc.linspace('birth_time', 0, 6000, a.shape[1], unit='us'),\n",
" 'wavelength': sc.linspace('wavelength', 0.2, 9.0, a.shape[0], unit='angstrom'),\n",
" },\n",
")\n",
"\n",
"p.plot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "14",
"metadata": {},
"outputs": [],
"source": [
"source = tof.Source.from_distribution(neutrons=200_000, p=p)\n",
"source.plot()"
]
},
{
"cell_type": "markdown",
"id": "15",
"metadata": {},
"source": [
"## Specifying neutrons manually\n",
"\n",
Expand All @@ -202,7 +262,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "14",
"id": "16",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -219,7 +279,7 @@
},
{
"cell_type": "markdown",
"id": "15",
"id": "17",
"metadata": {},
"source": [
"## Multiple pulses\n",
Expand All @@ -230,7 +290,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "16",
"id": "18",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -239,7 +299,7 @@
},
{
"cell_type": "markdown",
"id": "17",
"id": "19",
"metadata": {},
"source": [
"If a custom distribution is supplied, a frequency for the pulse repetition rate must be supplied:"
Expand All @@ -248,7 +308,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "18",
"id": "20",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -259,7 +319,7 @@
},
{
"cell_type": "markdown",
"id": "19",
"id": "21",
"metadata": {},
"source": [
"If a source was created from individual neutrons, the same neutrons will be repeated in all the pulses:"
Expand All @@ -268,7 +328,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "20",
"id": "22",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -293,7 +353,8 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
"pygments_lexer": "ipython3",
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ requires-python = ">=3.11"
# Make sure to list one dependency per line.
dependencies = [
"plopp>=23.10.0",
"pooch>=1.5.0",
"scipp>=24.11.0",
"scipy>=1.12.0",
"lazy-loader>=0.3",
]

Expand Down
8 changes: 4 additions & 4 deletions requirements/base.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# --- END OF CUSTOM SECTION ---
# The following was generated by 'tox -e deps', DO NOT EDIT MANUALLY!
plopp
scipp
scipy
lazy-loader
plopp>=23.10.0
pooch>=1.5.0
scipp>=24.11.0
lazy-loader>=0.3
24 changes: 18 additions & 6 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# SHA1:93efe7bb51c682462f1051ef5af0af230a7919ae
# SHA1:57c5f034856b0519923827bc5b12ab41003445e1
#
# This file was generated by pip-compile-multi.
# To update, run:
#
# requirements upgrade
#
certifi==2025.11.12
# via requests
charset-normalizer==3.4.4
# via requests
contourpy==1.3.3
# via matplotlib
cycler==0.12.1
# via matplotlib
fonttools==4.60.1
# via matplotlib
idna==3.11
# via requests
kiwisolver==1.4.9
# via matplotlib
lazy-loader==0.4
Expand All @@ -19,27 +25,33 @@ lazy-loader==0.4
# plopp
matplotlib==3.10.7
# via plopp
numpy==2.3.4
numpy==2.3.5
# via
# contourpy
# matplotlib
# scipp
# scipy
packaging==25.0
# via
# lazy-loader
# matplotlib
# pooch
pillow==12.0.0
# via matplotlib
plopp==25.10.0
platformdirs==4.5.0
# via pooch
plopp==25.11.0
# via -r base.in
pooch==1.8.2
# via -r base.in
pyparsing==3.2.5
# via matplotlib
python-dateutil==2.9.0.post0
# via matplotlib
requests==2.32.5
# via pooch
scipp==25.11.0
# via -r base.in
scipy==1.16.3
# via -r base.in
six==1.17.0
# via python-dateutil
urllib3==2.5.0
# via requests
4 changes: 2 additions & 2 deletions requirements/basetest.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
# will not be touched by ``make_base.py``
# --- END OF CUSTOM SECTION ---
# The following was generated by 'tox -e deps', DO NOT EDIT MANUALLY!
pytest
scippneutron
pytest>=8.0
scippneutron>=24.12.0
11 changes: 5 additions & 6 deletions requirements/basetest.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SHA1:ed95f3d9fbbb40522ea55cda7e22928120aae7db
# SHA1:416b6c94ef7ae6bd7c585fc1a97de56b917092ee
#
# This file was generated by pip-compile-multi.
# To update, run:
Expand Down Expand Up @@ -37,7 +37,7 @@ matplotlib==3.10.7
# plopp
mpltoolbox==25.10.0
# via scippneutron
numpy==2.3.4
numpy==2.3.5
# via
# contourpy
# h5py
Expand All @@ -52,7 +52,7 @@ packaging==25.0
# pytest
pillow==12.0.0
# via matplotlib
plopp==25.10.0
plopp==25.11.0
# via scippneutron
pluggy==1.6.0
# via pytest
Expand All @@ -64,20 +64,19 @@ pygments==2.19.2
# via pytest
pyparsing==3.2.5
# via matplotlib
pytest==9.0.0
pytest==9.0.1
# via -r basetest.in
python-dateutil==2.9.0.post0
# via
# matplotlib
# scippneutron
# scippnexus
scipp==25.11.0
# via
# scippneutron
# scippnexus
scippneutron==25.7.0
# via -r basetest.in
scippnexus==25.6.0
scippnexus==25.11.0
# via scippneutron
scipy==1.16.3
# via
Expand Down
4 changes: 2 additions & 2 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#
# requirements upgrade
#
cachetools==6.2.1
cachetools==6.2.2
# via tox
certifi==2025.10.5
certifi==2025.11.12
# via requests
chardet==5.2.0
# via tox
Expand Down
6 changes: 3 additions & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async-lru==2.0.5
# via jupyterlab
cffi==2.0.0
# via argon2-cffi-bindings
click==8.3.0
click==8.3.1
# via
# pip-compile-multi
# pip-tools
Expand Down Expand Up @@ -69,7 +69,7 @@ jupyter-server==2.17.0
# notebook-shim
jupyter-server-terminals==0.5.3
# via jupyter-server
jupyterlab==4.4.10
jupyterlab==4.5.0
# via -r dev.in
jupyterlab-server==2.28.0
# via jupyterlab
Expand All @@ -81,7 +81,7 @@ overrides==7.7.0
# via jupyter-server
pip-compile-multi==3.2.2
# via -r dev.in
pip-tools==7.5.1
pip-tools==7.5.2
# via pip-compile-multi
plumbum==1.10.0
# via copier
Expand Down
Loading
Loading