Skip to content

Commit

Permalink
Loader version 2 with much less steps.
Browse files Browse the repository at this point in the history
  • Loading branch information
YooSunYoung committed Dec 11, 2023
1 parent 1aa688f commit 63890d2
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 336 deletions.
37 changes: 22 additions & 15 deletions docs/examples/workflow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,22 @@
"source": [
"import sciline as sl\n",
"from ess.nmx.workflow import collect_default_parameters, providers\n",
"from ess.nmx.loader import FileTypeMcStas, InputFileName, MaximumProbability, DefaultMaximumProbability\n",
"from ess.nmx.loader import InputFileName, MaximumProbability, DefaultMaximumProbability\n",
"from ess.nmx.data import small_mcstas_sample\n",
"from ess.nmx.reduction import TimeBinned, TimeBinStep\n",
"from ess.nmx.reduction import TimeBinned, TimeBinStep, get_intervals_mcstas\n",
"from ess.nmx.logging import get_logger as get_nmx_logger\n",
"\n",
"file_path = small_mcstas_sample() # Replace it with your data file path\n",
"\n",
"nmx_workflow = sl.Pipeline(list(providers), params={\n",
"nmx_workflow = sl.Pipeline(list(providers)+[get_nmx_logger, get_intervals_mcstas],\n",
" params={\n",
" **collect_default_parameters(),\n",
" MaximumProbability: DefaultMaximumProbability,\n",
" TimeBinStep: TimeBinStep(1),\n",
" InputFileName: InputFileName(file_path),\n",
" })\n",
"\n",
"time_binned = nmx_workflow.compute(TimeBinned[FileTypeMcStas])\n",
"time_binned = nmx_workflow.compute(TimeBinned)\n",
"time_binned"
]
},
Expand Down Expand Up @@ -89,7 +91,8 @@
"## Collect Providers and Parameters\n",
"\n",
"There is a helper to collect default parameters and collection of all providers in ``ess.nmx.workflow`` module. <br>\n",
"If you need to replace any parameters, you can replace them in the dictionary and use it to build a pipeline. <br>"
"If you need to replace any parameters, you can replace them in the dictionary and use it to build a pipeline. <br>\n",
"For example, in order to load McStas events, you can set which schema to use by setting ``McStasEventDataSchema`` as a parameter."
]
},
{
Expand All @@ -101,13 +104,16 @@
"import scipp as sc\n",
"from ess.nmx.workflow import collect_default_parameters, providers\n",
"from ess.nmx.loader import InputFileName\n",
"from ess.nmx.loader import McStasEventDataSchema, DefaultMcStasEventDataSchema, MaximumProbability, DefaultMaximumProbability\n",
"\n",
"# Collect Parameters\n",
"# ``TimeBinStep`` and ``InputFileName`` are not included in the default parameters.\n",
"params = {\n",
" **collect_default_parameters(),\n",
" TimeBinStep: TimeBinStep(1),\n",
" InputFileName: small_mcstas_sample()\n",
" InputFileName: small_mcstas_sample(),\n",
" MaximumProbability: DefaultMaximumProbability,\n",
" McStasEventDataSchema: DefaultMcStasEventDataSchema \n",
"}\n",
"\n",
"# Parameters to run the workflow:\n",
Expand All @@ -118,7 +124,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Build Pipeline"
"## Build Pipeline\n",
"\n",
"To read McStas file, you might need to insert more providers. <br>\n",
"Otherwise, it will use default parameters."
]
},
{
Expand All @@ -128,17 +137,15 @@
"outputs": [],
"source": [
"import sciline as sl\n",
"from ess.nmx.loader import FileTypeMcStas\n",
"from ess.nmx.reduction import TimeBinned\n",
"\n",
"pl = sl.Pipeline(\n",
" list(providers),\n",
" list(providers)+[get_intervals_mcstas],\n",
" params=params\n",
")\n",
"\n",
"file_type = FileTypeMcStas\n",
"mcstas_workflow_graph = pl.get(TimeBinned[FileTypeMcStas])\n",
"mcstas_workflow_diagram = mcstas_workflow_graph.visualize(graph_attr={'rankdir': 'LR'})\n",
"mcstas_workflow_graph = pl.get(TimeBinned)\n",
"mcstas_workflow_diagram = mcstas_workflow_graph.visualize()\n",
"mcstas_workflow_diagram.render('mcstas_workflow_graph', 'png')\n",
"mcstas_workflow_diagram"
]
Expand All @@ -158,7 +165,7 @@
"metadata": {},
"outputs": [],
"source": [
"time_binned = mcstas_workflow_graph.compute(TimeBinned[FileTypeMcStas])\n",
"time_binned = mcstas_workflow_graph.compute(TimeBinned)\n",
"time_binned"
]
},
Expand All @@ -178,8 +185,8 @@
"source": [
"from ess.nmx.reduction import GroupedByPixelID\n",
"\n",
"multiple_results = pl.get((GroupedByPixelID[file_type], TimeBinned[file_type])).compute()\n",
"grouped = multiple_results[GroupedByPixelID[file_type]]\n",
"multiple_results = pl.get((GroupedByPixelID, TimeBinned)).compute()\n",
"grouped = multiple_results[GroupedByPixelID]\n",
"\n",
"grouped"
]
Expand Down
4 changes: 3 additions & 1 deletion src/ess/nmx/detector.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
from dataclasses import dataclass
from typing import NewType
from typing import NewType, TypeVar

MaxNumberOfPixelsPerAxis = NewType("MaxNumberOfPixelsPerAxis", int)
PixelStep = NewType("PixelStep", int)
NumberOfDetectors = NewType("NumberOfDetectors", int)
NumberOfAxes = NewType("NumberOfAxes", int)
Detector = TypeVar("Detector")
DetectorID = NewType("DetectorID", int)


@dataclass
Expand Down
Loading

0 comments on commit 63890d2

Please sign in to comment.