From 9f99498ad601e38948ddf3b2e34136fe4b5aee3d Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Fri, 4 Oct 2024 21:16:17 +0200 Subject: [PATCH 1/3] add ids to neutrons --- src/tof/source.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/tof/source.py b/src/tof/source.py index 38896de..244af15 100644 --- a/src/tof/source.py +++ b/src/tof/source.py @@ -152,9 +152,7 @@ def _make_pulses( unit=TIME_UNIT, ).fold(dim=dim, sizes={"pulse": pulses, dim: neutrons}) + ( sc.arange("pulse", pulses) / frequency - ).to( - unit=TIME_UNIT, copy=False - ) + ).to(unit=TIME_UNIT, copy=False) wavelength = sc.array( dims=[dim], @@ -226,6 +224,9 @@ def __init__( "time": pulse_params["time"], "wavelength": pulse_params["wavelength"], "speed": pulse_params["speed"], + "id": sc.arange("event", pulse_params["time"].size).fold( + "event", sizes=pulse_params["time"].sizes + ), }, ) @@ -270,6 +271,9 @@ def from_neutrons( "time": birth_times, "wavelength": wavelengths, "speed": wavelength_to_speed(wavelengths).to(unit="m/s", copy=False), + "id": sc.arange("event", birth_times.size).fold( + "event", sizes=birth_times.sizes + ), }, ) @@ -326,6 +330,9 @@ def from_distribution( "time": pulse_params["time"], "wavelength": pulse_params["wavelength"], "speed": pulse_params["speed"], + "id": sc.arange("event", pulse_params["time"].size).fold( + "event", sizes=pulse_params["time"].sizes + ), }, ) return source From 70a9d026ddc9aed51e2e02c0f3bae6c56c3abeec Mon Sep 17 00:00:00 2001 From: nvaytet Date: Fri, 4 Oct 2024 19:18:00 +0000 Subject: [PATCH 2/3] Apply automatic formatting --- src/tof/source.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tof/source.py b/src/tof/source.py index 244af15..c308b06 100644 --- a/src/tof/source.py +++ b/src/tof/source.py @@ -152,7 +152,9 @@ def _make_pulses( unit=TIME_UNIT, ).fold(dim=dim, sizes={"pulse": pulses, dim: neutrons}) + ( sc.arange("pulse", pulses) / frequency - ).to(unit=TIME_UNIT, copy=False) + ).to( + unit=TIME_UNIT, copy=False + ) wavelength = sc.array( dims=[dim], From 52e65b148ebb1fc1e11492788b39dc96c84789f2 Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Mon, 7 Oct 2024 11:08:08 +0200 Subject: [PATCH 3/3] unit=None for ids --- pyproject.toml | 3 +++ src/tof/source.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 133f573..6d5ef05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,3 +42,6 @@ skip-string-normalization = true [tool.isort] skip_gitignore = true profile = "black" + +[tool.ruff.format] +quote-style = "preserve" diff --git a/src/tof/source.py b/src/tof/source.py index c308b06..9b2b603 100644 --- a/src/tof/source.py +++ b/src/tof/source.py @@ -226,7 +226,7 @@ def __init__( "time": pulse_params["time"], "wavelength": pulse_params["wavelength"], "speed": pulse_params["speed"], - "id": sc.arange("event", pulse_params["time"].size).fold( + "id": sc.arange("event", pulse_params["time"].size, unit=None).fold( "event", sizes=pulse_params["time"].sizes ), }, @@ -273,7 +273,7 @@ def from_neutrons( "time": birth_times, "wavelength": wavelengths, "speed": wavelength_to_speed(wavelengths).to(unit="m/s", copy=False), - "id": sc.arange("event", birth_times.size).fold( + "id": sc.arange("event", birth_times.size, unit=None).fold( "event", sizes=birth_times.sizes ), }, @@ -332,7 +332,7 @@ def from_distribution( "time": pulse_params["time"], "wavelength": pulse_params["wavelength"], "speed": pulse_params["speed"], - "id": sc.arange("event", pulse_params["time"].size).fold( + "id": sc.arange("event", pulse_params["time"].size, unit=None).fold( "event", sizes=pulse_params["time"].sizes ), },