From 169fe88c93b05f75fd38194398522f8dd28aade2 Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Wed, 8 Jan 2025 13:52:32 +0100 Subject: [PATCH 1/3] make facility information accessible --- src/tof/__init__.py | 20 ++++++++++++++++++-- src/tof/facilities/__init__.py | 6 ++++-- src/tof/facilities/ess_pulse.py | 4 ++++ src/tof/source.py | 8 +++----- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/tof/__init__.py b/src/tof/__init__.py index d621bed..8ca42eb 100644 --- a/src/tof/__init__.py +++ b/src/tof/__init__.py @@ -1,11 +1,27 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) -# flake8: noqa F401 - from .chopper import AntiClockwise, Chopper, ChopperReading, Clockwise from .detector import Detector, DetectorReading +from .facilities import library as facilities from .model import Model from .reading import ComponentReading, ReadingData, ReadingField from .result import Result from .source import Source, SourceParameters + +__all__ = [ + 'AntiClockwise', + 'Chopper', + 'ChopperReading', + 'Clockwise', + 'ComponentReading', + 'Detector', + 'DetectorReading', + 'facilities', + 'Model', + 'ReadingData', + 'ReadingField', + 'Result', + 'Source', + 'SourceParameters', +] diff --git a/src/tof/facilities/__init__.py b/src/tof/facilities/__init__.py index b53d376..0d9e839 100644 --- a/src/tof/facilities/__init__.py +++ b/src/tof/facilities/__init__.py @@ -1,6 +1,8 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) -# flake8: noqa F401 +from .ess_pulse import pulse as esspulse -from .ess_pulse import pulse as ess +library = {'ess': esspulse} + +__all__ = ['library'] diff --git a/src/tof/facilities/ess_pulse.py b/src/tof/facilities/ess_pulse.py index ec62796..4e01b8f 100644 --- a/src/tof/facilities/ess_pulse.py +++ b/src/tof/facilities/ess_pulse.py @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) +""" +The data here was obtained from the McStas model of the ESS moderator. +""" + import scipp as sc from ..utils import FacilityPulse diff --git a/src/tof/source.py b/src/tof/source.py index 9b2b603..19042ff 100644 --- a/src/tof/source.py +++ b/src/tof/source.py @@ -10,7 +10,7 @@ import scipp as sc from scipp.scipy.interpolate import interp1d -from . import facilities +from .facilities import library as facilities from .utils import Plot, wavelength_to_speed TIME_UNIT = "us" @@ -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], @@ -208,7 +206,7 @@ def __init__( self.data = None if facility is not None: - facility_params = getattr(facilities, self.facility) + facility_params = facilities[self.facility] self.frequency = facility_params.frequency pulse_params = _make_pulses( neutrons=self.neutrons, From 1cbedc6f361875d3a43805932792897c96f239ff Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Wed, 8 Jan 2025 13:55:26 +0100 Subject: [PATCH 2/3] 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 19042ff..b64e6bd 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 57d6198eb2e9257da06ebe56ed8c962b29f46e81 Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Wed, 8 Jan 2025 13:57:11 +0100 Subject: [PATCH 3/3] add url to mcstas component --- src/tof/facilities/ess_pulse.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tof/facilities/ess_pulse.py b/src/tof/facilities/ess_pulse.py index 4e01b8f..4c81853 100644 --- a/src/tof/facilities/ess_pulse.py +++ b/src/tof/facilities/ess_pulse.py @@ -3,6 +3,7 @@ """ The data here was obtained from the McStas model of the ESS moderator. +See https://www2.mcstas.org/download/components/3.4_current/sources/ESS_butterfly.html. """ import scipp as sc