From 57a00a32de8025b1c77d35ff7fa558d62cb4d111 Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Wed, 27 Nov 2024 10:44:39 +0100 Subject: [PATCH] update static formatting versions and run formatting --- .pre-commit-config.yaml | 18 +++++----- docs/components.ipynb | 66 ++++++++++++++++++------------------ docs/ess/dream.ipynb | 36 ++++++++++---------- docs/multiple-pulses.ipynb | 46 +++++++++++++------------- docs/short-example.ipynb | 48 +++++++++++++-------------- docs/sources.ipynb | 42 +++++++++++------------ docs/wfm.ipynb | 68 +++++++++++++++++++------------------- src/tof/chopper.py | 4 ++- src/tof/result.py | 6 ++-- 9 files changed, 168 insertions(+), 166 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3b98a2d..6672ffe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.6.0 hooks: - id: check-added-large-files - id: check-json @@ -14,41 +14,41 @@ repos: args: [ --markdown-linebreak-ext=md ] exclude: '\.svg' - repo: https://github.com/pycqa/isort - rev: 5.12.0 + rev: 5.13.0 hooks: - id: isort name: isort (python) - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 24.10.0 hooks: - id: black - repo: https://github.com/kynan/nbstripout - rev: 0.6.0 + rev: 0.8.1 hooks: - id: nbstripout types: [ "jupyter" ] args: [ "--drop-empty-cells", "--extra-keys 'metadata.language_info.version cell.metadata.jp-MarkdownHeadingCollapsed cell.metadata.pycharm'" ] - repo: https://github.com/pycqa/flake8 - rev: 4.0.1 + rev: 7.1.1 hooks: - id: flake8 types: ["python"] - additional_dependencies: ["flake8-bugbear==22.10.27"] + additional_dependencies: ["flake8-bugbear==24.10.31"] - repo: https://github.com/pycqa/bandit - rev: 1.7.4 + rev: 1.8.0 hooks: - id: bandit additional_dependencies: ["bandit[toml]"] args: ["-c", "pyproject.toml"] - repo: https://github.com/codespell-project/codespell - rev: v2.2.2 + rev: v2.3.0 hooks: - id: codespell additional_dependencies: - tomli - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.9.0 + rev: v1.10.0 hooks: - id: python-no-eval exclude: "object_list.py" diff --git a/docs/components.ipynb b/docs/components.ipynb index 878ac0a..2ae048b 100644 --- a/docs/components.ipynb +++ b/docs/components.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "32ad7110-b627-4e52-b014-a70ad3d5193a", + "id": "0", "metadata": {}, "source": [ "# Component guide\n", @@ -14,7 +14,7 @@ { "cell_type": "code", "execution_count": null, - "id": "1d69bb0a-4b4d-47c6-9465-318c21e72e7c", + "id": "1", "metadata": {}, "outputs": [], "source": [ @@ -29,7 +29,7 @@ }, { "cell_type": "markdown", - "id": "0543c13d-847d-4642-8736-14a75ed5fd01", + "id": "2", "metadata": {}, "source": [ "We begin by making a source pulse using the profile from ESS." @@ -38,7 +38,7 @@ { "cell_type": "code", "execution_count": null, - "id": "35b39244-c45b-4bdb-8138-7d0e56a40478", + "id": "3", "metadata": {}, "outputs": [], "source": [ @@ -48,7 +48,7 @@ }, { "cell_type": "markdown", - "id": "3c6ecb82-a47f-4f66-a067-9224e9d67be9", + "id": "4", "metadata": {}, "source": [ "## Adding a detector\n", @@ -60,7 +60,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e2ced2be-d642-4886-9281-37cd90102c31", + "id": "5", "metadata": {}, "outputs": [], "source": [ @@ -74,7 +74,7 @@ { "cell_type": "code", "execution_count": null, - "id": "75dd1359-d990-482c-b0d6-4a0ae094b0fc", + "id": "6", "metadata": {}, "outputs": [], "source": [ @@ -85,7 +85,7 @@ }, { "cell_type": "markdown", - "id": "a2c80ee1-5729-4a09-88c0-3c4e04610772", + "id": "7", "metadata": {}, "source": [ "As expected, the detector sees all the neutrons from the pulse.\n", @@ -96,7 +96,7 @@ { "cell_type": "code", "execution_count": null, - "id": "112124d4-689b-408a-9be6-de1bef8a6205", + "id": "8", "metadata": {}, "outputs": [], "source": [ @@ -105,7 +105,7 @@ }, { "cell_type": "markdown", - "id": "34267819-4f83-48c6-b51b-9f13742ac3da", + "id": "9", "metadata": {}, "source": [ "The data itself is available via the `.toas`, `.wavelengths`, `.birth_times`, and `.speeds` properties,\n", @@ -119,7 +119,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bbda2581-ebfa-44ce-ae58-1f4f2db832d9", + "id": "10", "metadata": {}, "outputs": [], "source": [ @@ -128,7 +128,7 @@ }, { "cell_type": "markdown", - "id": "89ad197a-4304-4cff-a332-e865a2c93f43", + "id": "11", "metadata": {}, "source": [ "## Adding a chopper\n", @@ -141,7 +141,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e7e49cac-affd-4c01-860f-03934bc348e9", + "id": "12", "metadata": {}, "outputs": [], "source": [ @@ -166,7 +166,7 @@ }, { "cell_type": "markdown", - "id": "6893e0a2-70c9-424f-aeb2-aac010fc02bd", + "id": "13", "metadata": {}, "source": [ "We can directly set this on our existing model, and re-run the simulation." @@ -175,7 +175,7 @@ { "cell_type": "code", "execution_count": null, - "id": "48909c2a-51e8-4532-a8eb-7c7bbba7544d", + "id": "14", "metadata": {}, "outputs": [], "source": [ @@ -186,7 +186,7 @@ }, { "cell_type": "markdown", - "id": "3155b564-12e1-4d06-a2dd-d376314713f4", + "id": "15", "metadata": {}, "source": [ "As expected, the two openings now create two bursts of neutrons,\n", @@ -198,7 +198,7 @@ { "cell_type": "code", "execution_count": null, - "id": "94bc5f13-4e58-4ae4-ba15-86078ab8311d", + "id": "16", "metadata": {}, "outputs": [], "source": [ @@ -207,7 +207,7 @@ }, { "cell_type": "markdown", - "id": "7ce2e25e-e21f-442b-b729-9b1c7a97893b", + "id": "17", "metadata": {}, "source": [ "we notice that the chopper sees all the incoming neutrons,\n", @@ -219,7 +219,7 @@ { "cell_type": "code", "execution_count": null, - "id": "90341882-625a-432d-8625-3d0850403f85", + "id": "18", "metadata": {}, "outputs": [], "source": [ @@ -228,7 +228,7 @@ }, { "cell_type": "markdown", - "id": "68e35c62-6072-47b1-8c3e-e610826da008", + "id": "19", "metadata": {}, "source": [ "## Multiple choppers\n", @@ -241,7 +241,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ac5f9697-a2a6-45a8-ad99-af6ad1a60be7", + "id": "20", "metadata": {}, "outputs": [], "source": [ @@ -269,7 +269,7 @@ }, { "cell_type": "markdown", - "id": "62d721c5-3c3e-457c-ab05-60659fccdaaa", + "id": "21", "metadata": {}, "source": [ "The distribution of neutrons that are blocked and pass through the second chopper looks as follows:" @@ -278,7 +278,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ab11bd09-73ba-4bf8-9b52-e503d77f3f5c", + "id": "22", "metadata": {}, "outputs": [], "source": [ @@ -287,7 +287,7 @@ }, { "cell_type": "markdown", - "id": "09d6cbef-f2f3-48db-a696-b4ed912817c8", + "id": "23", "metadata": {}, "source": [ "while the detector now sees 4 peaks" @@ -296,7 +296,7 @@ { "cell_type": "code", "execution_count": null, - "id": "20349f5e-bfd3-4ccb-bde4-119f3e3d423a", + "id": "24", "metadata": {}, "outputs": [], "source": [ @@ -305,7 +305,7 @@ }, { "cell_type": "markdown", - "id": "55c8ca14-e885-43b2-8409-48c1eb964625", + "id": "25", "metadata": {}, "source": [ "To view the blocked rays on the time-distance diagram of the model, use" @@ -314,7 +314,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a3e040c6-afee-495f-a32f-7fdcad506df1", + "id": "26", "metadata": {}, "outputs": [], "source": [ @@ -323,7 +323,7 @@ }, { "cell_type": "markdown", - "id": "b3c4a5fb-010b-4d6a-a391-4fb48aa4b1d2", + "id": "27", "metadata": {}, "source": [ "## Adding a monitor\n", @@ -335,7 +335,7 @@ { "cell_type": "code", "execution_count": null, - "id": "1c8bdc32-583a-4c7c-8c6d-34dab8061c6f", + "id": "28", "metadata": {}, "outputs": [], "source": [ @@ -349,7 +349,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2f008516-af80-4c55-a6bb-a71a86fa9132", + "id": "29", "metadata": {}, "outputs": [], "source": [ @@ -358,7 +358,7 @@ }, { "cell_type": "markdown", - "id": "021f81eb-42c3-4094-981e-ada20eca3fdb", + "id": "30", "metadata": {}, "source": [ "## Counter-rotating chopper\n", @@ -373,7 +373,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0e978761-f2de-423e-9e43-a9e664a85a48", + "id": "31", "metadata": {}, "outputs": [], "source": [ @@ -402,7 +402,7 @@ { "cell_type": "code", "execution_count": null, - "id": "354e87fd-05e4-4237-84d7-3599610e3403", + "id": "32", "metadata": {}, "outputs": [], "source": [ diff --git a/docs/ess/dream.ipynb b/docs/ess/dream.ipynb index 1f44217..0e77b0a 100644 --- a/docs/ess/dream.ipynb +++ b/docs/ess/dream.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "2b54cd42-dfc2-4ad7-b9af-b165d5709888", + "id": "0", "metadata": {}, "source": [ "# DREAM in WFM mode\n", @@ -14,7 +14,7 @@ { "cell_type": "code", "execution_count": null, - "id": "69e77a24-0c1b-49dd-855b-0c5b5bbb936e", + "id": "1", "metadata": {}, "outputs": [], "source": [ @@ -31,7 +31,7 @@ }, { "cell_type": "markdown", - "id": "72a1ba68-dae3-4d61-8313-f8801bb69bb6", + "id": "2", "metadata": {}, "source": [ "## Create a source\n", @@ -42,7 +42,7 @@ { "cell_type": "code", "execution_count": null, - "id": "659a8cff-06ab-43f2-9566-c1679e693915", + "id": "3", "metadata": {}, "outputs": [], "source": [ @@ -52,7 +52,7 @@ }, { "cell_type": "markdown", - "id": "305d1424-637c-4d4a-9d1a-8c4e28102691", + "id": "4", "metadata": {}, "source": [ "## Component set-up\n", @@ -70,7 +70,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0b01dbf4-9f05-4eea-82b4-89c310dbd340", + "id": "5", "metadata": {}, "outputs": [], "source": [ @@ -165,7 +165,7 @@ }, { "cell_type": "markdown", - "id": "ab93843a-0da5-414d-a215-efe3fa78d569", + "id": "6", "metadata": {}, "source": [ "### Detector banks and monitors\n", @@ -178,7 +178,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8a720e32-5fef-41ce-9afe-7415a539a779", + "id": "7", "metadata": {}, "outputs": [], "source": [ @@ -194,7 +194,7 @@ }, { "cell_type": "markdown", - "id": "741cd7ae-075b-4a04-b71a-f9c977fab9a8", + "id": "8", "metadata": {}, "source": [ "## Run the simulation\n", @@ -205,7 +205,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4de7426f-90be-45da-89ac-5de1a2d3bb6f", + "id": "9", "metadata": {}, "outputs": [], "source": [ @@ -216,7 +216,7 @@ }, { "cell_type": "markdown", - "id": "ad7f2d08-a50f-4a19-b65f-5010173bc3b5", + "id": "10", "metadata": {}, "source": [ "## Wavelength as a function of time-of-arrival\n", @@ -232,7 +232,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e6fdf820-fb80-43e8-995f-e43f049d503b", + "id": "11", "metadata": {}, "outputs": [], "source": [ @@ -247,7 +247,7 @@ }, { "cell_type": "markdown", - "id": "2ffa0a00-cdc7-492d-a0b2-191325980f43", + "id": "12", "metadata": {}, "source": [ "### Defining a conversion from `toa` to `wavelength`\n", @@ -260,7 +260,7 @@ { "cell_type": "code", "execution_count": null, - "id": "afc57e9d-9766-450e-aa60-d2a86fb6c9da", + "id": "13", "metadata": {}, "outputs": [], "source": [ @@ -279,7 +279,7 @@ }, { "cell_type": "markdown", - "id": "97112112-efd3-47b6-bd7d-2c045ef660fe", + "id": "14", "metadata": {}, "source": [ "## Computing wavelengths\n", @@ -290,7 +290,7 @@ { "cell_type": "code", "execution_count": null, - "id": "dd01c024-dff6-4c4a-b733-7ee26acacdf9", + "id": "15", "metadata": {}, "outputs": [], "source": [ @@ -315,7 +315,7 @@ }, { "cell_type": "markdown", - "id": "35aff0f0-a1a1-4247-9f40-e75f0a73ba8d", + "id": "16", "metadata": {}, "source": [ "We can now compare our computed wavelengths to the true wavelengths of the neutrons." @@ -324,7 +324,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5256b1e7-b0b2-464c-889c-0cb14da400b5", + "id": "17", "metadata": {}, "outputs": [], "source": [ diff --git a/docs/multiple-pulses.ipynb b/docs/multiple-pulses.ipynb index 842bd29..5908697 100644 --- a/docs/multiple-pulses.ipynb +++ b/docs/multiple-pulses.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "6b645603-12c0-4b3d-ab3c-529ad4f373e3", + "id": "0", "metadata": {}, "source": [ "# Multiple pulses\n", @@ -13,7 +13,7 @@ { "cell_type": "code", "execution_count": null, - "id": "899a245a-0ae7-45dd-b684-3b9d1c034cc6", + "id": "1", "metadata": {}, "outputs": [], "source": [ @@ -27,7 +27,7 @@ }, { "cell_type": "markdown", - "id": "3890d24c-93ab-4faa-b653-c9208b5eba23", + "id": "2", "metadata": {}, "source": [ "## Create a source with 3 pulses\n", @@ -38,7 +38,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a2699065-309c-439c-bcda-bf15d20edd0b", + "id": "3", "metadata": {}, "outputs": [], "source": [ @@ -49,7 +49,7 @@ { "cell_type": "code", "execution_count": null, - "id": "49fec301-52a4-45a7-9438-b3f736e50b9f", + "id": "4", "metadata": {}, "outputs": [], "source": [ @@ -58,7 +58,7 @@ }, { "cell_type": "markdown", - "id": "b5ffdab6-10cd-4719-8ff2-86e5e1d10571", + "id": "5", "metadata": {}, "source": [ "## Chopper and detector set-up\n", @@ -69,7 +69,7 @@ { "cell_type": "code", "execution_count": null, - "id": "34314bcc-978c-468c-b5a1-d84ce33e53d5", + "id": "6", "metadata": {}, "outputs": [], "source": [ @@ -147,7 +147,7 @@ }, { "cell_type": "markdown", - "id": "4c3b69b7-5ebe-4188-aa4b-2c6621ec8017", + "id": "7", "metadata": {}, "source": [ "## Results\n", @@ -159,7 +159,7 @@ { "cell_type": "code", "execution_count": null, - "id": "05c191a2-81ef-41d3-8f64-343f72d7555d", + "id": "8", "metadata": {}, "outputs": [], "source": [ @@ -171,7 +171,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7eea136a-4c5f-420c-8fd5-1cdc64be939f", + "id": "9", "metadata": {}, "outputs": [], "source": [ @@ -180,7 +180,7 @@ }, { "cell_type": "markdown", - "id": "9b761887-12f7-49f1-bbdb-a607c2376e47", + "id": "10", "metadata": {}, "source": [ "The time-distance diagram reveals that a small number of long-wavelength neutrons from one pulse are polluting the counts detected by the detector for the next pulse (red lines).\n", @@ -192,7 +192,7 @@ { "cell_type": "code", "execution_count": null, - "id": "95df472c-bc86-41b7-87f3-a1b8455e8fbc", + "id": "11", "metadata": {}, "outputs": [], "source": [ @@ -201,7 +201,7 @@ }, { "cell_type": "markdown", - "id": "77d9a554-3cfc-4f24-a5a6-8c5e171ffbef", + "id": "12", "metadata": {}, "source": [ "To try and obtain as clean as possible of a detector signal,\n", @@ -211,7 +211,7 @@ { "cell_type": "code", "execution_count": null, - "id": "42bc9c07-1f3e-474d-9434-40e6596ba193", + "id": "13", "metadata": {}, "outputs": [], "source": [ @@ -239,7 +239,7 @@ }, { "cell_type": "markdown", - "id": "e39cbf07-deee-447b-835d-9812d6ed69c3", + "id": "14", "metadata": {}, "source": [ "We can now see that the pulses do not overlap at the detector,\n", @@ -249,7 +249,7 @@ { "cell_type": "code", "execution_count": null, - "id": "977385c0-cfd5-4e20-97b0-c82ac4f55640", + "id": "15", "metadata": {}, "outputs": [], "source": [ @@ -258,7 +258,7 @@ }, { "cell_type": "markdown", - "id": "83c62115-bab6-4060-a3cf-d40529595f27", + "id": "16", "metadata": {}, "source": [ "## Data inspection\n", @@ -269,7 +269,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f31387fc-87a0-4d93-832f-4380c6e1103a", + "id": "17", "metadata": {}, "outputs": [], "source": [ @@ -278,7 +278,7 @@ }, { "cell_type": "markdown", - "id": "af9d5348-8e5e-4f64-8425-5e1f4e5c8168", + "id": "18", "metadata": {}, "source": [ "It is possible to inspect just a single pulse using the usual slicing notation `[0]` for an array:" @@ -287,7 +287,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a792d72e-cf31-42ca-85e3-e7114dad52d0", + "id": "19", "metadata": {}, "outputs": [], "source": [ @@ -297,7 +297,7 @@ { "cell_type": "code", "execution_count": null, - "id": "151caf0f-582d-4982-bcc0-64792ec5c6f1", + "id": "20", "metadata": {}, "outputs": [], "source": [ @@ -306,7 +306,7 @@ }, { "cell_type": "markdown", - "id": "e3388ce1-f766-4162-b254-22c3f564f3d1", + "id": "21", "metadata": {}, "source": [ "and the same is available one level above on the `toas` property,\n", @@ -316,7 +316,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f9230062-3748-439d-b222-149dee9b0ae7", + "id": "22", "metadata": {}, "outputs": [], "source": [ diff --git a/docs/short-example.ipynb b/docs/short-example.ipynb index 8d0d035..ef6933b 100644 --- a/docs/short-example.ipynb +++ b/docs/short-example.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "6b645603-12c0-4b3d-ab3c-529ad4f373e3", + "id": "0", "metadata": {}, "source": [ "# A short example\n", @@ -13,7 +13,7 @@ { "cell_type": "code", "execution_count": null, - "id": "899a245a-0ae7-45dd-b684-3b9d1c034cc6", + "id": "1", "metadata": {}, "outputs": [], "source": [ @@ -27,7 +27,7 @@ }, { "cell_type": "markdown", - "id": "3890d24c-93ab-4faa-b653-c9208b5eba23", + "id": "2", "metadata": {}, "source": [ "## Create a source pulse\n", @@ -38,7 +38,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a2699065-309c-439c-bcda-bf15d20edd0b", + "id": "3", "metadata": {}, "outputs": [], "source": [ @@ -49,7 +49,7 @@ { "cell_type": "code", "execution_count": null, - "id": "49fec301-52a4-45a7-9438-b3f736e50b9f", + "id": "4", "metadata": {}, "outputs": [], "source": [ @@ -58,7 +58,7 @@ }, { "cell_type": "markdown", - "id": "b5ffdab6-10cd-4719-8ff2-86e5e1d10571", + "id": "5", "metadata": {}, "source": [ "## Chopper set-up\n", @@ -71,7 +71,7 @@ { "cell_type": "code", "execution_count": null, - "id": "34314bcc-978c-468c-b5a1-d84ce33e53d5", + "id": "6", "metadata": {}, "outputs": [], "source": [ @@ -161,7 +161,7 @@ }, { "cell_type": "markdown", - "id": "bd6e1399-7f05-4d5c-83e3-7d249d9e0a61", + "id": "7", "metadata": {}, "source": [ "## Detector set-up\n", @@ -172,7 +172,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a377e75c-51a5-4994-af9c-92139d27bee3", + "id": "8", "metadata": {}, "outputs": [], "source": [ @@ -184,7 +184,7 @@ }, { "cell_type": "markdown", - "id": "4c3b69b7-5ebe-4188-aa4b-2c6621ec8017", + "id": "9", "metadata": {}, "source": [ "## Run the model\n", @@ -196,7 +196,7 @@ { "cell_type": "code", "execution_count": null, - "id": "05c191a2-81ef-41d3-8f64-343f72d7555d", + "id": "10", "metadata": {}, "outputs": [], "source": [ @@ -207,7 +207,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9a2d019b-5c0d-4bf1-8b38-3ed18f6f687c", + "id": "11", "metadata": {}, "outputs": [], "source": [ @@ -217,7 +217,7 @@ }, { "cell_type": "markdown", - "id": "02212233-58b6-44cb-bb76-6f3b552942db", + "id": "12", "metadata": {}, "source": [ "## Results\n", @@ -231,7 +231,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7eea136a-4c5f-420c-8fd5-1cdc64be939f", + "id": "13", "metadata": {}, "outputs": [], "source": [ @@ -241,7 +241,7 @@ { "cell_type": "code", "execution_count": null, - "id": "95df472c-bc86-41b7-87f3-a1b8455e8fbc", + "id": "14", "metadata": {}, "outputs": [], "source": [ @@ -251,7 +251,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e21c1906-84b4-4055-9761-0f4df56b7ed1", + "id": "15", "metadata": {}, "outputs": [], "source": [ @@ -260,7 +260,7 @@ }, { "cell_type": "markdown", - "id": "3d2fbae9-1480-4a29-93ab-4d18a09dd64e", + "id": "16", "metadata": {}, "source": [ "### Data inspection\n", @@ -272,7 +272,7 @@ { "cell_type": "code", "execution_count": null, - "id": "72fce589-389d-4597-997c-9cde65a6f6be", + "id": "17", "metadata": {}, "outputs": [], "source": [ @@ -281,7 +281,7 @@ }, { "cell_type": "markdown", - "id": "9b01bb60-da73-442c-a734-36d455375b8d", + "id": "18", "metadata": {}, "source": [ "The `.toas`, `.wavelengths`, `.birth_times`, and `.speeds` properties of the beamline components return a proxy object,\n", @@ -293,7 +293,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5ad98bcb-6181-4c54-949e-e61a412e1c31", + "id": "19", "metadata": {}, "outputs": [], "source": [ @@ -302,7 +302,7 @@ }, { "cell_type": "markdown", - "id": "ee85b045-19f6-448a-ac0d-73ee75690a72", + "id": "20", "metadata": {}, "source": [ "To inspect individual components, one can for example use the `.data` property of the `.visible` accessor" @@ -311,7 +311,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a8cb6b72-f98c-4497-8872-941b0fd19a0b", + "id": "21", "metadata": {}, "outputs": [], "source": [ @@ -320,7 +320,7 @@ }, { "cell_type": "markdown", - "id": "abc519bb-cb22-4169-97f2-2cc2be21ec48", + "id": "22", "metadata": {}, "source": [ "This is a data group that contains a single pulse.\n", @@ -331,7 +331,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8009886a-b355-41f5-a3ae-2a997bc613cb", + "id": "23", "metadata": {}, "outputs": [], "source": [ diff --git a/docs/sources.ipynb b/docs/sources.ipynb index 2b0859d..e61ed41 100644 --- a/docs/sources.ipynb +++ b/docs/sources.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "6b645603-12c0-4b3d-ab3c-529ad4f373e3", + "id": "0", "metadata": {}, "source": [ "# Creating sources\n", @@ -13,7 +13,7 @@ { "cell_type": "code", "execution_count": null, - "id": "899a245a-0ae7-45dd-b684-3b9d1c034cc6", + "id": "1", "metadata": {}, "outputs": [], "source": [ @@ -26,7 +26,7 @@ }, { "cell_type": "markdown", - "id": "2294ac91-961b-4347-a1df-80662721fe49", + "id": "2", "metadata": {}, "source": [ "## The ESS source\n", @@ -47,7 +47,7 @@ { "cell_type": "code", "execution_count": null, - "id": "1e356a02-0c4c-42b9-8115-6abe7741ad8d", + "id": "3", "metadata": {}, "outputs": [], "source": [ @@ -57,7 +57,7 @@ }, { "cell_type": "markdown", - "id": "1bf9e593-fb94-4174-b4f1-7cab27b7cf49", + "id": "4", "metadata": {}, "source": [ "To inspect the data in the pulse, we can either look at the source's `data` property" @@ -66,7 +66,7 @@ { "cell_type": "code", "execution_count": null, - "id": "88514d20-4fcc-4b33-b428-708e5cb0b1a5", + "id": "5", "metadata": {}, "outputs": [], "source": [ @@ -75,7 +75,7 @@ }, { "cell_type": "markdown", - "id": "75969bc3-9d28-4aa0-9f0b-7a6eafb3ed93", + "id": "6", "metadata": {}, "source": [ "or we can plot it with" @@ -84,7 +84,7 @@ { "cell_type": "code", "execution_count": null, - "id": "74b69926-a979-4f41-a4ad-128477a8eebf", + "id": "7", "metadata": {}, "outputs": [], "source": [ @@ -93,7 +93,7 @@ }, { "cell_type": "markdown", - "id": "78fc25ec-39f0-43fb-a324-b522e050485f", + "id": "8", "metadata": {}, "source": [ "## Specifying time and wavelength distributions\n", @@ -116,7 +116,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a2699065-309c-439c-bcda-bf15d20edd0b", + "id": "9", "metadata": {}, "outputs": [], "source": [ @@ -142,7 +142,7 @@ }, { "cell_type": "markdown", - "id": "af4c567b-86bb-46a5-b8e5-7c8e829ce49d", + "id": "10", "metadata": {}, "source": [ "### Custom distributions\n", @@ -159,7 +159,7 @@ { "cell_type": "code", "execution_count": null, - "id": "1d006ca3-3ea0-4071-bc10-cd65e535bd3d", + "id": "11", "metadata": {}, "outputs": [], "source": [ @@ -181,7 +181,7 @@ }, { "cell_type": "markdown", - "id": "142ac37a-b456-4d97-9b8e-a27443de6d0a", + "id": "12", "metadata": {}, "source": [ "Note that the time and wavelength distributions are independent;\n", @@ -191,7 +191,7 @@ }, { "cell_type": "markdown", - "id": "60077d8d-224d-404a-8768-7b18a973cbb2", + "id": "13", "metadata": {}, "source": [ "## Specifying neutrons manually\n", @@ -202,7 +202,7 @@ { "cell_type": "code", "execution_count": null, - "id": "43177e0c-652e-4665-a31c-1f7abf2897ee", + "id": "14", "metadata": {}, "outputs": [], "source": [ @@ -219,7 +219,7 @@ }, { "cell_type": "markdown", - "id": "8aece779-85f0-4662-97e2-9f64b8a2d562", + "id": "15", "metadata": {}, "source": [ "## Multiple pulses\n", @@ -230,7 +230,7 @@ { "cell_type": "code", "execution_count": null, - "id": "06baecce-dc05-4142-aed4-0c22b7d8a129", + "id": "16", "metadata": {}, "outputs": [], "source": [ @@ -239,7 +239,7 @@ }, { "cell_type": "markdown", - "id": "560fb19b-4ead-4116-946c-c2ff682fe94c", + "id": "17", "metadata": {}, "source": [ "If a custom distribution is supplied, a frequency for the pulse repetition rate must be supplied:" @@ -248,7 +248,7 @@ { "cell_type": "code", "execution_count": null, - "id": "47610f5d-9cc3-46ab-a1ca-3b9961b44a7f", + "id": "18", "metadata": {}, "outputs": [], "source": [ @@ -259,7 +259,7 @@ }, { "cell_type": "markdown", - "id": "26e348c4-e053-46a6-aa5e-8d57bbbd0176", + "id": "19", "metadata": {}, "source": [ "If a source was created from individual neutrons, the same neutrons will be repeated in all the pulses:" @@ -268,7 +268,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3b765974-fe8f-4694-b64f-cba13fae4c43", + "id": "20", "metadata": {}, "outputs": [], "source": [ diff --git a/docs/wfm.ipynb b/docs/wfm.ipynb index b461582..cdace24 100644 --- a/docs/wfm.ipynb +++ b/docs/wfm.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "6b645603-12c0-4b3d-ab3c-529ad4f373e3", + "id": "0", "metadata": {}, "source": [ "# WFM beamlines\n", @@ -16,7 +16,7 @@ { "cell_type": "code", "execution_count": null, - "id": "899a245a-0ae7-45dd-b684-3b9d1c034cc6", + "id": "1", "metadata": {}, "outputs": [], "source": [ @@ -32,7 +32,7 @@ }, { "cell_type": "markdown", - "id": "3890d24c-93ab-4faa-b653-c9208b5eba23", + "id": "2", "metadata": {}, "source": [ "## Create a source pulse\n", @@ -43,7 +43,7 @@ { "cell_type": "code", "execution_count": null, - "id": "872800a5-4cf7-424e-8d2d-0db81292456c", + "id": "3", "metadata": {}, "outputs": [], "source": [ @@ -54,7 +54,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3b39e97a-d6d7-4e75-8095-f7b0206a1bd0", + "id": "4", "metadata": {}, "outputs": [], "source": [ @@ -63,7 +63,7 @@ }, { "cell_type": "markdown", - "id": "b5ffdab6-10cd-4719-8ff2-86e5e1d10571", + "id": "5", "metadata": {}, "source": [ "## Component set-up\n", @@ -81,7 +81,7 @@ { "cell_type": "code", "execution_count": null, - "id": "34314bcc-978c-468c-b5a1-d84ce33e53d5", + "id": "6", "metadata": {}, "outputs": [], "source": [ @@ -171,7 +171,7 @@ }, { "cell_type": "markdown", - "id": "bd6e1399-7f05-4d5c-83e3-7d249d9e0a61", + "id": "7", "metadata": {}, "source": [ "### Detectors\n", @@ -182,7 +182,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a377e75c-51a5-4994-af9c-92139d27bee3", + "id": "8", "metadata": {}, "outputs": [], "source": [ @@ -193,7 +193,7 @@ }, { "cell_type": "markdown", - "id": "4deb2f50-92b7-4838-b180-17e3ce43743d", + "id": "9", "metadata": {}, "source": [ "## Run the simulation\n", @@ -204,7 +204,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e5812eda-2e56-4f72-89bc-4e778046243f", + "id": "10", "metadata": {}, "outputs": [], "source": [ @@ -215,7 +215,7 @@ }, { "cell_type": "markdown", - "id": "51e45cee-a630-4886-bc9f-a744a20cba28", + "id": "11", "metadata": {}, "source": [ "## Wavelength as a function of time-of-arrival\n", @@ -231,7 +231,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c3f48d70-7836-4e6a-aa9c-e278303af30c", + "id": "12", "metadata": {}, "outputs": [], "source": [ @@ -245,7 +245,7 @@ }, { "cell_type": "markdown", - "id": "aadc3250-f49d-462f-8aac-2d3500596b6b", + "id": "13", "metadata": {}, "source": [ "### Defining a conversion from `toa` to `wavelength`\n", @@ -258,7 +258,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9e8f056e-8c8e-4c1b-8dbf-5b350bba5c94", + "id": "14", "metadata": {}, "outputs": [], "source": [ @@ -277,7 +277,7 @@ }, { "cell_type": "markdown", - "id": "fb5cddc2-9ebf-427f-b38f-cf25b2c5cdfc", + "id": "15", "metadata": {}, "source": [ "We can now overlay our mean wavelength function on the image above:" @@ -286,7 +286,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b0a83ab4-af22-40a4-851a-4a80ce358f45", + "id": "16", "metadata": {}, "outputs": [], "source": [ @@ -306,7 +306,7 @@ }, { "cell_type": "markdown", - "id": "d3675286-e36e-4d65-9d6c-012f5b4c39e5", + "id": "17", "metadata": {}, "source": [ "## Computing wavelengths\n", @@ -317,7 +317,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0f231769-8e79-4692-b4f0-a1e9e11782e1", + "id": "18", "metadata": {}, "outputs": [], "source": [ @@ -338,7 +338,7 @@ }, { "cell_type": "markdown", - "id": "a6512644-d9b7-47e1-861b-9dde24fa012a", + "id": "19", "metadata": {}, "source": [ "We can now compare our computed wavelengths to the true wavelengths of the neutrons.\n", @@ -348,7 +348,7 @@ { "cell_type": "code", "execution_count": null, - "id": "35824517-786d-41f4-ad3a-a96629ae81e2", + "id": "20", "metadata": {}, "outputs": [], "source": [ @@ -362,7 +362,7 @@ { "cell_type": "code", "execution_count": null, - "id": "1f4aad58-a1b0-4c90-9215-ab2e52191bbb", + "id": "21", "metadata": {}, "outputs": [], "source": [ @@ -378,7 +378,7 @@ { "attachments": {}, "cell_type": "markdown", - "id": "ce1df677-098e-4bec-9278-07fe16d0379f", + "id": "22", "metadata": {}, "source": [ "We can see that the WFM estimate clearly outperforms the naive computation.\n", @@ -402,7 +402,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c5d10e75-dd29-4b9b-aaff-2856d28e288a", + "id": "23", "metadata": {}, "outputs": [], "source": [ @@ -420,7 +420,7 @@ }, { "cell_type": "markdown", - "id": "fc47024e-33a4-4fe1-9076-083bcf5b51f4", + "id": "24", "metadata": {}, "source": [ "We can now concatenate all the readings along the `distance` dimension into a single data array:" @@ -429,7 +429,7 @@ { "cell_type": "code", "execution_count": null, - "id": "53ea9234-a691-4cc4-aa6c-850cc6e3637a", + "id": "25", "metadata": {}, "outputs": [], "source": [ @@ -443,7 +443,7 @@ }, { "cell_type": "markdown", - "id": "b3120ab4-0b6e-46b1-82e3-23cb594566f4", + "id": "26", "metadata": {}, "source": [ "### Relation between `toa` and `wavelength` in 2D\n", @@ -457,7 +457,7 @@ { "cell_type": "code", "execution_count": null, - "id": "32b87b94-5fa5-4e9f-8750-a1d7f7bfdf94", + "id": "27", "metadata": {}, "outputs": [], "source": [ @@ -473,7 +473,7 @@ }, { "cell_type": "markdown", - "id": "10f0e39b-12dc-497f-b3b5-a53a666b937a", + "id": "28", "metadata": {}, "source": [ "### Computing wavelengths with a 2D interpolator\n", @@ -484,7 +484,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d4947938-6f5a-436b-8d59-796a26914807", + "id": "29", "metadata": {}, "outputs": [], "source": [ @@ -508,7 +508,7 @@ }, { "cell_type": "markdown", - "id": "24e01273-1dcc-4885-9a7c-52e72c519f69", + "id": "30", "metadata": {}, "source": [ "We can now compare the results to the original wavelengths.\n", @@ -519,7 +519,7 @@ { "cell_type": "code", "execution_count": null, - "id": "226cb305-3eb5-4409-be6b-be2aedf6de92", + "id": "31", "metadata": {}, "outputs": [], "source": [ @@ -542,7 +542,7 @@ }, { "cell_type": "markdown", - "id": "1d28f370-dd84-41f9-af44-d1363a069772", + "id": "32", "metadata": {}, "source": [ "This once again illustrates the superiority of the WFM estimate.\n", @@ -554,7 +554,7 @@ { "cell_type": "code", "execution_count": null, - "id": "23dde7e5-c2d2-4601-bf1e-fc3b85be7c85", + "id": "33", "metadata": {}, "outputs": [], "source": [ diff --git a/src/tof/chopper.py b/src/tof/chopper.py index 5f64a6a..56d6b8b 100644 --- a/src/tof/chopper.py +++ b/src/tof/chopper.py @@ -60,7 +60,7 @@ def __init__( frequency: sc.Variable, distance: sc.Variable, name: str, - phase: sc.Variable = sc.scalar(0.0, unit='rad'), + phase: Optional[sc.Variable] = None, open: Optional[sc.Variable] = None, close: Optional[sc.Variable] = None, centers: Optional[sc.Variable] = None, @@ -75,6 +75,8 @@ def __init__( "Chopper direction must be Clockwise or AntiClockwise" f", got {direction}." ) + if phase is None: + phase = sc.scalar(0.0, unit='deg') self.direction = direction # Check that either open/close or centers/widths are provided, but not both if tuple(x for x in (open, close, centers, widths) if x is not None) not in ( diff --git a/src/tof/result.py b/src/tof/result.py index ea071be..4f0a119 100644 --- a/src/tof/result.py +++ b/src/tof/result.py @@ -33,9 +33,9 @@ def _make_reading_data(component, dim, is_chopper=False): blocked[name] = sc.DataArray(data=bsel.data, coords={dim: bsel.coords[dim]}) return ReadingField( visible=ReadingData(data=sc.DataGroup(visible), dim=dim), - blocked=ReadingData(data=sc.DataGroup(blocked), dim=dim) - if is_chopper - else None, + blocked=( + ReadingData(data=sc.DataGroup(blocked), dim=dim) if is_chopper else None + ), )