diff --git a/docs/api-reference/index.md b/docs/api-reference/index.md index 57d5d73e..ccf9f5e1 100644 --- a/docs/api-reference/index.md +++ b/docs/api-reference/index.md @@ -28,8 +28,6 @@ smoothing types uncertainty - - external.powgen ``` ## ESSdream @@ -43,6 +41,7 @@ :toctree: ../generated/functions instrument_view + DreamGeant4Workflow ``` ### Submodules @@ -56,3 +55,16 @@ data io ``` + +## SNS powder + +```{eval-rst} +.. currentmodule:: ess.snspowder + +.. autosummary:: + :toctree: ../generated/modules + :template: module-template.rst + :recursive: + + powgen +``` diff --git a/docs/user-guide/dream/dream-data-reduction.ipynb b/docs/user-guide/dream/dream-data-reduction.ipynb index 1ade731f..d1f347df 100644 --- a/docs/user-guide/dream/dream-data-reduction.ipynb +++ b/docs/user-guide/dream/dream-data-reduction.ipynb @@ -17,85 +17,61 @@ "source": [ "import scipp as sc\n", "import scippneutron as scn\n", - "import sciline\n", "from ess import dream, powder\n", - "from ess.powder.types import *\n", - "from ess.dream.io.geant4 import providers as geant4_providers" + "from ess.powder.types import *" ] }, { "cell_type": "markdown", - "id": "1252feab-12d2-46ac-bf74-70b32344473d", + "id": "dcaf1d53-2a81-4a31-8379-1fb3791aaeab", "metadata": {}, "source": [ - "## Define reduction parameters\n", + "## Create and configure the workflow\n", "\n", - "We define a dictionary containing the reduction parameters.\n", - "The keys are types defined in [essdiffraction.types](../generated/modules/ess.diffraction.types.rst)." + "We begin by creating the Dream (Geant4) workflow object which is a skeleton for reducing Dream data, with pre-configured steps." ] }, { "cell_type": "code", "execution_count": null, - "id": "502e77cc-0253-4e71-9d97-81ff560ef99d", + "id": "b2d15f12-69d7-4c5d-9d4d-f1c13fc29103", "metadata": {}, "outputs": [], "source": [ - "params = {\n", - " Filename[SampleRun]: dream.data.simulated_diamond_sample(),\n", - " Filename[VanadiumRun]: dream.data.simulated_vanadium_sample(),\n", - " Filename[EmptyCanRun]: dream.data.simulated_empty_can(),\n", - " CalibrationFilename: None,\n", - " NeXusDetectorName: \"mantle\",\n", - " # The upper bounds mode is not yet implemented.\n", - " UncertaintyBroadcastMode: UncertaintyBroadcastMode.drop,\n", - " # Edges for binning in d-spacing\n", - " DspacingBins: sc.linspace(\"dspacing\", 0.0, 2.3434, 201, unit=\"angstrom\"),\n", - " # Mask in time-of-flight to crop to valid range\n", - " TofMask: lambda x: (x < sc.scalar(0.0, unit=\"ns\"))\n", - " | (x > sc.scalar(86e6, unit=\"ns\")),\n", - " TwoThetaMask: None,\n", - " WavelengthMask: None,\n", - "}\n", - "\n", - "# Not available in simulated data\n", - "sample = sc.DataGroup(position=sc.vector([0.0, 0.0, 0.0], unit=\"mm\"))\n", - "params[RawSample[SampleRun]] = sample\n", - "params[RawSample[VanadiumRun]] = sample\n", - "\n", - "source = sc.DataGroup(position=sc.vector([-3.478, 0.0, -76550], unit=\"mm\"))\n", - "params[RawSource[SampleRun]] = source\n", - "params[RawSource[VanadiumRun]] = source\n", - "\n", - "charge = sc.scalar(1.0, unit=\"µAh\")\n", - "params[AccumulatedProtonCharge[SampleRun]] = charge\n", - "params[AccumulatedProtonCharge[VanadiumRun]] = charge" + "workflow = dream.DreamGeant4Workflow()" ] }, { "cell_type": "markdown", - "id": "21cb87f2-4ff7-436e-b603-cc8f60c73e7a", + "id": "1252feab-12d2-46ac-bf74-70b32344473d", "metadata": {}, "source": [ - "## Create pipeline using Sciline\n", - "\n", - "We use the `powder` and `geant4` providers to build our pipeline." + "We then need to set the missing parameters which are specific to each experiment\n", + "(the keys are types defined in [essdiffraction.powder.types](../generated/modules/ess.diffraction.powder.types.rst)):" ] }, { "cell_type": "code", "execution_count": null, - "id": "98e99f33-6f4b-4b60-acaf-added3c6e1b0", + "id": "502e77cc-0253-4e71-9d97-81ff560ef99d", "metadata": {}, "outputs": [], "source": [ - "providers = (\n", - " *geant4_providers,\n", - " *powder.providers,\n", - ")\n", - "\n", - "pipeline = sciline.Pipeline(providers, params=params)\n", - "pipeline = powder.with_pixel_mask_filenames(pipeline, [])" + "workflow[Filename[SampleRun]] = dream.data.simulated_diamond_sample()\n", + "workflow[Filename[VanadiumRun]] = dream.data.simulated_vanadium_sample()\n", + "workflow[Filename[EmptyCanRun]] = dream.data.simulated_empty_can()\n", + "workflow[CalibrationFilename] = None\n", + "workflow[NeXusDetectorName] = \"mantle\"\n", + "# The upper bounds mode is not yet implemented.\n", + "workflow[UncertaintyBroadcastMode] = UncertaintyBroadcastMode.drop\n", + "# Edges for binning in d-spacing\n", + "workflow[DspacingBins] = sc.linspace(\"dspacing\", 0.0, 2.3434, 201, unit=\"angstrom\")\n", + "# Mask in time-of-flight to crop to valid range\n", + "workflow[TofMask] = lambda x: (x < sc.scalar(0.0, unit=\"ns\")) | (x > sc.scalar(86e6, unit=\"ns\"))\n", + "workflow[TwoThetaMask] = None\n", + "workflow[WavelengthMask] = None\n", + "# No pixel masks\n", + "workflow = powder.with_pixel_mask_filenames(workflow, [])" ] }, { @@ -103,6 +79,8 @@ "id": "21fb4492-e836-41d3-a2d4-9678df43b9f9", "metadata": {}, "source": [ + "## Use the workflow\n", + "\n", "We can visualize the graph for computing the final normalized result for intensity as a function of d-spacing:" ] }, @@ -113,7 +91,7 @@ "metadata": {}, "outputs": [], "source": [ - "pipeline.visualize(IofDspacing, graph_attr={\"rankdir\": \"LR\"})" + "workflow.visualize(IofDspacing, graph_attr={\"rankdir\": \"LR\"})" ] }, { @@ -131,7 +109,7 @@ "metadata": {}, "outputs": [], "source": [ - "result = pipeline.compute(IofDspacing)\n", + "result = workflow.compute(IofDspacing)\n", "result" ] }, @@ -186,7 +164,7 @@ "metadata": {}, "outputs": [], "source": [ - "intermediates = pipeline.compute(\n", + "intermediates = workflow.compute(\n", " (\n", " DataWithScatteringCoordinates[SampleRun],\n", " MaskedData[SampleRun],\n", @@ -215,8 +193,8 @@ "source": [ "## Grouping by scattering angle\n", "\n", - "The above pipeline focuses the data by merging all instrument pixels to produce a 1d d-spacing curve.\n", - "If instead we want to group into $2\\theta$ bins, we can alter the pipeline parameters by adding some binning in $2\\theta$:" + "The above workflow focuses the data by merging all instrument pixels to produce a 1d d-spacing curve.\n", + "If instead we want to group into $2\\theta$ bins, we can alter the workflow parameters by adding some binning in $2\\theta$:" ] }, { @@ -226,7 +204,7 @@ "metadata": {}, "outputs": [], "source": [ - "pipeline[TwoThetaBins] = sc.linspace(\n", + "workflow[TwoThetaBins] = sc.linspace(\n", " dim=\"two_theta\", unit=\"rad\", start=0.8, stop=2.4, num=17\n", ")" ] @@ -238,7 +216,7 @@ "metadata": {}, "outputs": [], "source": [ - "grouped_dspacing = pipeline.compute(IofDspacingTwoTheta)\n", + "grouped_dspacing = workflow.compute(IofDspacingTwoTheta)\n", "grouped_dspacing" ] }, @@ -286,8 +264,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/docs/user-guide/sns-instruments/POWGEN_data_reduction.ipynb b/docs/user-guide/sns-instruments/POWGEN_data_reduction.ipynb index 51e32de2..58664917 100644 --- a/docs/user-guide/sns-instruments/POWGEN_data_reduction.ipynb +++ b/docs/user-guide/sns-instruments/POWGEN_data_reduction.ipynb @@ -24,69 +24,61 @@ "source": [ "import scipp as sc\n", "import scippneutron as scn\n", - "import sciline\n", "\n", "from ess import powder\n", - "from ess.powder.external import powgen\n", + "from ess.snspowder import powgen\n", "from ess.powder.types import *" ] }, { "cell_type": "markdown", - "id": "6270f661-099f-4f8a-9380-76050f73f251", + "id": "aa6d0805-0c8b-43a6-a7ba-d4d4941def62", "metadata": {}, "source": [ - "## Define reduction parameters\n", + "## Create and configure the workflow\n", "\n", - "We define a dictionary containing the reduction parameters.\n", - "The keys are types defined in [essdiffraction.types](../generated/modules/ess.diffraction.types.rst)." + "We begin by creating the Powgen workflow object which is a skeleton for reducing Powgen data, with pre-configured steps." ] }, { "cell_type": "code", "execution_count": null, - "id": "67e8d584-016d-422e-add9-a61e5b1fe8bd", + "id": "82926a06-ce84-4cba-9487-b248489d7799", "metadata": {}, "outputs": [], "source": [ - "params = {\n", - " NeXusDetectorName: \"powgen_detector\",\n", - " # Input data\n", - " Filename[SampleRun]: powgen.data.powgen_tutorial_sample_file(),\n", - " Filename[VanadiumRun]: powgen.data.powgen_tutorial_vanadium_file(),\n", - " CalibrationFilename: powgen.data.powgen_tutorial_calibration_file(),\n", - " # The upper bounds mode is not yet implemented.\n", - " UncertaintyBroadcastMode: UncertaintyBroadcastMode.drop,\n", - " # Edges for binning in d-spacing\n", - " DspacingBins: sc.linspace(\"dspacing\", 0.0, 2.3434, 201, unit=\"angstrom\"),\n", - " # Mask in time-of-flight to crop to valid range\n", - " TofMask: lambda x: (x < sc.scalar(0.0, unit=\"us\"))\n", - " | (x > sc.scalar(16666.67, unit=\"us\")),\n", - " TwoThetaMask: None,\n", - " WavelengthMask: None,\n", - "}" + "workflow = powgen.PowgenWorkflow()" ] }, { "cell_type": "markdown", - "id": "e3d9b9bd-6923-4124-954f-e92672845be2", + "id": "96ab84f4-cab5-44c4-ad50-44c457abdb87", "metadata": {}, "source": [ - "## Create pipeline using Sciline\n", - "\n", - "We use the basic providers available in `essdiffraction` as well as the specialised `powder` and `powgen` providers." + "We then need to set the missing parameters which are specific to each experiment\n", + "(the keys are types defined in [essdiffraction.powder.types](../generated/modules/ess.diffraction.powder.types.rst)):" ] }, { "cell_type": "code", "execution_count": null, - "id": "35412429-c039-4591-b8b8-49b11a128b7f", + "id": "67e8d584-016d-422e-add9-a61e5b1fe8bd", "metadata": {}, "outputs": [], "source": [ - "providers = [*powder.providers, *powgen.providers]\n", - "pipeline = sciline.Pipeline(providers, params=params)\n", - "pipeline = powder.with_pixel_mask_filenames(pipeline, [])" + "workflow[Filename[SampleRun]] = powgen.data.powgen_tutorial_sample_file()\n", + "workflow[Filename[VanadiumRun]] = powgen.data.powgen_tutorial_vanadium_file()\n", + "workflow[CalibrationFilename] = powgen.data.powgen_tutorial_calibration_file()\n", + "# The upper bounds mode is not yet implemented.\n", + "workflow[UncertaintyBroadcastMode] = UncertaintyBroadcastMode.drop\n", + "# Edges for binning in d-spacing\n", + "workflow[DspacingBins] = sc.linspace(\"dspacing\", 0.0, 2.3434, 201, unit=\"angstrom\")\n", + "# Mask in time-of-flight to crop to valid range\n", + "workflow[TofMask] = lambda x: (x < sc.scalar(0.0, unit=\"us\")) | (x > sc.scalar(16666.67, unit=\"us\"))\n", + "workflow[TwoThetaMask] = None\n", + "workflow[WavelengthMask] = None\n", + "# No pixel masks\n", + "workflow = powder.with_pixel_mask_filenames(workflow, [])" ] }, { @@ -94,13 +86,23 @@ "id": "b4af9055-385d-41a4-9f1c-35fd1e232565", "metadata": {}, "source": [ - "## Use the pipeline\n", + "## Use the workflow\n", "\n", "### Compute final result\n", "\n", "We can get the graph for computing the final intensity as a function of d-spacing:" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "abbe5682-372a-4a95-9da6-8cb91894c709", + "metadata": {}, + "outputs": [], + "source": [ + "IofDspacing in workflow.get(IofDspacing).keys()" + ] + }, { "cell_type": "code", "execution_count": null, @@ -108,7 +110,7 @@ "metadata": {}, "outputs": [], "source": [ - "pipeline.visualize(IofDspacing, graph_attr={\"rankdir\": \"LR\"})" + "workflow.visualize(IofDspacing, graph_attr={\"rankdir\": \"LR\"})" ] }, { @@ -126,7 +128,7 @@ "metadata": {}, "outputs": [], "source": [ - "result = pipeline.compute(IofDspacing)\n", + "result = workflow.compute(IofDspacing)\n", "result" ] }, @@ -150,7 +152,7 @@ "\n", "We ultimately need to write the reduced data to a file.\n", "This could be done with the `result` we computed above.\n", - "But we can use the pipeline to provide additional parameters (in this case only the file name) as shown below.\n", + "But we can use the workflow to provide additional parameters (in this case only the file name) as shown below.\n", "See also the [File output](https://scipp.github.io/sciline/recipes/recipes.html#File-output) docs of Sciline.\n", "\n", "For simplicity we write a simply xye file with 3 columns: $d$-spacing, intensity, standard deviation of intensity." @@ -188,7 +190,7 @@ "metadata": {}, "outputs": [], "source": [ - "pipeline[OutFilename] = \"reduced.xye\"" + "workflow[OutFilename] = \"reduced.xye\"" ] }, { @@ -196,7 +198,7 @@ "id": "1eb08353-2bbd-4692-9f8d-7349ddc5d400", "metadata": {}, "source": [ - "And use the pipeline to write the file.\n", + "And use the workflow to write the file.\n", "Note that this recomputes the result!" ] }, @@ -207,7 +209,7 @@ "metadata": {}, "outputs": [], "source": [ - "pipeline.bind_and_call(save_xye)" + "workflow.bind_and_call(save_xye)" ] }, { @@ -229,7 +231,7 @@ "metadata": {}, "outputs": [], "source": [ - "results = pipeline.compute(\n", + "results = workflow.compute(\n", " (\n", " ReducibleDetectorData[SampleRun],\n", " MaskedData[SampleRun],\n", @@ -280,8 +282,8 @@ "source": [ "## Group by scattering angle\n", "\n", - "The above pipeline focuses the data by merging all instrument pixels to produce a 1d d-spacing curve.\n", - "If instead we want to group into $2\\theta$ bins, we can alter the pipeline parameters by adding some binning in $2\\theta$:" + "The above workflow focuses the data by merging all instrument pixels to produce a 1d d-spacing curve.\n", + "If instead we want to group into $2\\theta$ bins, we can alter the workflow parameters by adding some binning in $2\\theta$:" ] }, { @@ -291,7 +293,7 @@ "metadata": {}, "outputs": [], "source": [ - "pipeline[TwoThetaBins] = sc.linspace(\n", + "workflow[TwoThetaBins] = sc.linspace(\n", " dim=\"two_theta\", unit=\"deg\", start=25.0, stop=90.0, num=17\n", ").to(unit=\"rad\")" ] @@ -311,7 +313,7 @@ "metadata": {}, "outputs": [], "source": [ - "pipeline.visualize(IofDspacingTwoTheta, graph_attr={\"rankdir\": \"LR\"})" + "workflow.visualize(IofDspacingTwoTheta, graph_attr={\"rankdir\": \"LR\"})" ] }, { @@ -329,7 +331,7 @@ "metadata": {}, "outputs": [], "source": [ - "grouped_dspacing = pipeline.compute(IofDspacingTwoTheta)\n", + "grouped_dspacing = workflow.compute(IofDspacingTwoTheta)\n", "grouped_dspacing" ] }, @@ -385,8 +387,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" + "pygments_lexer": "ipython3" } }, "nbformat": 4, diff --git a/src/ess/dream/__init__.py b/src/ess/dream/__init__.py index 020bf577..15f44b9e 100644 --- a/src/ess/dream/__init__.py +++ b/src/ess/dream/__init__.py @@ -10,6 +10,7 @@ from . import data from .instrument_view import instrument_view from .io import load_geant4_csv, nexus +from .workflow import DreamGeant4Workflow, default_parameters try: __version__ = importlib.metadata.version(__package__ or __name__) @@ -20,10 +21,14 @@ providers = (*nexus.providers,) + __all__ = [ + 'DreamGeant4Workflow', 'data', + 'default_parameters', 'beamline', 'instrument_view', 'load_geant4_csv', 'nexus', + 'providers', ] diff --git a/src/ess/dream/workflow.py b/src/ess/dream/workflow.py new file mode 100644 index 00000000..ffd91093 --- /dev/null +++ b/src/ess/dream/workflow.py @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright (c) 2024 Scipp contributors (https://github.com/scipp) + +import sciline +import scipp as sc +from ess.powder import providers as powder_providers +from ess.powder.types import ( + AccumulatedProtonCharge, + RawSample, + RawSource, + SampleRun, + VanadiumRun, +) + +from .io.geant4 import providers as geant4_providers + + +def default_parameters() -> dict: + # Quantities not available in the simulated data + sample = sc.DataGroup(position=sc.vector([0.0, 0.0, 0.0], unit="mm")) + source = sc.DataGroup(position=sc.vector([-3.478, 0.0, -76550], unit="mm")) + charge = sc.scalar(1.0, unit="µAh") + return { + RawSample[SampleRun]: sample, + RawSample[VanadiumRun]: sample, + RawSource[SampleRun]: source, + RawSource[VanadiumRun]: source, + AccumulatedProtonCharge[SampleRun]: charge, + AccumulatedProtonCharge[VanadiumRun]: charge, + } + + +def DreamGeant4Workflow() -> sciline.Pipeline: + """ + Workflow with default parameters for the Dream Geant4 simulation. + """ + return sciline.Pipeline( + providers=powder_providers + geant4_providers, params=default_parameters() + ) + + +__all__ = ['DreamGeant4Workflow', 'default_parameters'] diff --git a/src/ess/powder/correction.py b/src/ess/powder/correction.py index ee3b5244..8e8fc4dd 100644 --- a/src/ess/powder/correction.py +++ b/src/ess/powder/correction.py @@ -177,7 +177,7 @@ def merge_calibration(*, into: sc.DataArray, calibration: sc.Dataset) -> sc.Data See Also -------- - ess.powder.load_calibration + ess.snspowder.powgen.calibration.load_calibration """ for name, coord in calibration.coords.items(): if not sc.identical(into.coords[name], coord): diff --git a/src/ess/powder/external/powgen/__init__.py b/src/ess/snspowder/powgen/__init__.py similarity index 74% rename from src/ess/powder/external/powgen/__init__.py rename to src/ess/snspowder/powgen/__init__.py index f9d97117..f175f21b 100644 --- a/src/ess/powder/external/powgen/__init__.py +++ b/src/ess/snspowder/powgen/__init__.py @@ -8,7 +8,9 @@ """ from . import beamline, data +from .calibration import load_calibration from .instrument_view import instrument_view +from .workflow import PowgenWorkflow, default_parameters providers = ( *beamline.providers, @@ -16,8 +18,13 @@ ) """Sciline Providers for POWGEN-specific functionality.""" + __all__ = [ + 'PowgenWorkflow', 'beamline', 'data', + 'default_parameters', 'instrument_view', + 'load_calibration', + 'providers', ] diff --git a/src/ess/powder/external/powgen/beamline.py b/src/ess/snspowder/powgen/beamline.py similarity index 98% rename from src/ess/powder/external/powgen/beamline.py rename to src/ess/snspowder/powgen/beamline.py index 11de3f57..7bd82dba 100644 --- a/src/ess/powder/external/powgen/beamline.py +++ b/src/ess/snspowder/powgen/beamline.py @@ -6,7 +6,7 @@ import scipp as sc -from ...types import ( +from ...powder.types import ( NeXusDetectorDimensions, NeXusDetectorName, ) diff --git a/src/ess/powder/external/__init__.py b/src/ess/snspowder/powgen/calibration.py similarity index 99% rename from src/ess/powder/external/__init__.py rename to src/ess/snspowder/powgen/calibration.py index 71c147b0..6e2a47e3 100644 --- a/src/ess/powder/external/__init__.py +++ b/src/ess/snspowder/powgen/calibration.py @@ -15,7 +15,7 @@ import scipp as sc import scippneutron as scn -from ..logging import get_logger +from ...powder.logging import get_logger def _as_boolean_mask(var: sc.Variable) -> sc.Variable: diff --git a/src/ess/powder/external/powgen/data.py b/src/ess/snspowder/powgen/data.py similarity index 99% rename from src/ess/powder/external/powgen/data.py rename to src/ess/snspowder/powgen/data.py index 56490317..aea6e744 100644 --- a/src/ess/powder/external/powgen/data.py +++ b/src/ess/snspowder/powgen/data.py @@ -5,7 +5,7 @@ import scipp as sc -from ...types import ( +from ...powder.types import ( AccumulatedProtonCharge, CalibrationData, CalibrationFilename, diff --git a/src/ess/powder/external/powgen/instrument_view.py b/src/ess/snspowder/powgen/instrument_view.py similarity index 100% rename from src/ess/powder/external/powgen/instrument_view.py rename to src/ess/snspowder/powgen/instrument_view.py diff --git a/src/ess/snspowder/powgen/workflow.py b/src/ess/snspowder/powgen/workflow.py new file mode 100644 index 00000000..96af8743 --- /dev/null +++ b/src/ess/snspowder/powgen/workflow.py @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright (c) 2024 Scipp contributors (https://github.com/scipp) + +import sciline +from ess.powder import providers as powder_providers +from ess.powder.types import NeXusDetectorName + +from . import beamline, data + + +def default_parameters() -> dict: + return {NeXusDetectorName: "powgen_detector"} + + +def PowgenWorkflow() -> sciline.Pipeline: + """ + Workflow with default parameters for the Powgen SNS instrument. + """ + return sciline.Pipeline( + providers=powder_providers + beamline.providers + data.providers, + params=default_parameters(), + ) + + +__all__ = ['PowgenWorkflow', 'default_parameters'] diff --git a/tests/dream/geant4_reduction_test.py b/tests/dream/geant4_reduction_test.py index d3af6d67..b73ca75d 100644 --- a/tests/dream/geant4_reduction_test.py +++ b/tests/dream/geant4_reduction_test.py @@ -4,7 +4,7 @@ import pytest import sciline import scipp as sc -from ess import powder +from ess import dream, powder from ess.powder.types import ( AccumulatedProtonCharge, CalibrationFilename, @@ -30,7 +30,6 @@ @pytest.fixture() def providers(): - from ess import powder from ess.dream.io.geant4 import providers as geant4_providers return [*powder.providers, *geant4_providers] @@ -38,8 +37,6 @@ def providers(): @pytest.fixture(params=["mantle", "endcap_backward", "endcap_forward"]) def params(request): - from ess import dream - # Not available in simulated data sample = sc.DataGroup(position=sc.vector([0.0, 0.0, 0.0], unit='mm')) source = sc.DataGroup(position=sc.vector([-3.478, 0.0, -76550], unit='mm')) @@ -147,3 +144,15 @@ def test_pipeline_two_theta_masking(providers, params): sum_in_masked_region, sc.scalar(0.0, unit=sum_in_masked_region.unit), ) + + +def test_use_workflow_helper(params): + workflow = dream.DreamGeant4Workflow() + for key, value in params.items(): + workflow[key] = value + workflow = powder.with_pixel_mask_filenames(workflow, []) + result = workflow.compute(IofDspacing) + assert result.sizes == { + 'dspacing': len(params[DspacingBins]) - 1, + } + assert sc.identical(result.coords['dspacing'], params[DspacingBins]) diff --git a/tests/powder/load_test.py b/tests/snspowder/powgen/load_test.py similarity index 93% rename from tests/powder/load_test.py rename to tests/snspowder/powgen/load_test.py index a05f54df..22d03b44 100644 --- a/tests/powder/load_test.py +++ b/tests/snspowder/powgen/load_test.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) import pytest -from ess.powder.external import load_calibration -from ess.powder.external.powgen import data +from ess.snspowder.powgen import data, load_calibration @pytest.mark.skip( diff --git a/tests/powder/external/powgen/powgen_reduction_test.py b/tests/snspowder/powgen/powgen_reduction_test.py similarity index 92% rename from tests/powder/external/powgen/powgen_reduction_test.py rename to tests/snspowder/powgen/powgen_reduction_test.py index 9931648c..cbd769f3 100644 --- a/tests/powder/external/powgen/powgen_reduction_test.py +++ b/tests/snspowder/powgen/powgen_reduction_test.py @@ -22,20 +22,18 @@ VanadiumRun, WavelengthMask, ) +from ess.snspowder import powgen @pytest.fixture() def providers(): from ess import powder - from ess.powder.external import powgen return [*powder.providers, *powgen.providers] @pytest.fixture() def params(): - from ess.powder.external import powgen - return { NeXusDetectorName: "powgen_detector", Filename[SampleRun]: powgen.data.powgen_tutorial_sample_file(), @@ -161,3 +159,15 @@ def test_pipeline_two_theta_masking(providers, params): sum_in_masked_region, sc.scalar(0.0, unit=sum_in_masked_region.unit), ) + + +def test_use_workflow_helper(params): + workflow = powgen.PowgenWorkflow() + for key, value in params.items(): + workflow[key] = value + workflow = powder.with_pixel_mask_filenames(workflow, []) + result = workflow.compute(IofDspacing) + assert result.sizes == { + 'dspacing': len(params[DspacingBins]) - 1, + } + assert sc.identical(result.coords['dspacing'], params[DspacingBins])