Skip to content

Commit e57adb6

Browse files
committed
Docs and small fix
1 parent a586f29 commit e57adb6

File tree

4 files changed

+73
-16
lines changed

4 files changed

+73
-16
lines changed

docs/user-guide/workflow.ipynb

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# He3 Cell Workflow\n",
7+
"# Workflows\n",
8+
"\n",
9+
"## He3 Cell Workflow\n",
810
"\n",
911
"The `he3` submodule provides a helper `He3CellWorkflow`:"
1012
]
@@ -24,7 +26,7 @@
2426
"cell_type": "markdown",
2527
"metadata": {},
2628
"source": [
27-
"## Opacity\n",
29+
"### Opacity\n",
2830
"\n",
2931
"There are two ways of computing the opacity, from cell parameters and from direct-beam measurements."
3032
]
@@ -53,7 +55,7 @@
5355
"cell_type": "markdown",
5456
"metadata": {},
5557
"source": [
56-
"## Transmission function\n",
58+
"### Transmission function\n",
5759
"\n",
5860
"The opacity can be used to obtain the transmission function of the cells.\n",
5961
"We show the in-situ case, but it works equivalently for the more precise definition of opacity:"
@@ -71,6 +73,56 @@
7173
")"
7274
]
7375
},
76+
{
77+
"cell_type": "markdown",
78+
"metadata": {},
79+
"source": [
80+
"There is a variant of the workflow using an incoming polarized beam for computing the transmission function of the analyzer:"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": null,
86+
"metadata": {},
87+
"outputs": [],
88+
"source": [
89+
"workflow = pol.he3.He3CellWorkflow(in_situ=False, incoming_polarized=True)\n",
90+
"workflow.visualize(\n",
91+
" (pol.TransmissionFunction[pol.Polarizer], pol.TransmissionFunction[pol.Analyzer]),\n",
92+
" graph_attr={\"rankdir\": \"LR\"},\n",
93+
")"
94+
]
95+
},
96+
{
97+
"cell_type": "markdown",
98+
"metadata": {},
99+
"source": [
100+
"## Supermirror Workflow\n",
101+
"\n",
102+
"The `supermirror` submodule provides a helper `SupermirrorWorkflow`:"
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": null,
108+
"metadata": {},
109+
"outputs": [],
110+
"source": [
111+
"from ess import polarization as pol\n",
112+
"\n",
113+
"workflow = pol.supermirror.SupermirrorWorkflow()\n",
114+
"print(workflow.__doc__)"
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": null,
120+
"metadata": {},
121+
"outputs": [],
122+
"source": [
123+
"workflow.visualize(pol.TransmissionFunction[pol.Polarizer])"
124+
]
125+
},
74126
{
75127
"cell_type": "markdown",
76128
"metadata": {},

src/ess/polarization/he3.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def compute_transmission_fraction_from_direct_beam(
236236
)
237237

238238

239-
def get_he3_transmission_from_fit_to_direct_beam(
239+
def get_he3_transmission_incoming_unpolarized_from_fit_to_direct_beam(
240240
transmission_fraction: He3CellTransmissionFraction[PolarizingElement, Polarized],
241241
opacity_function: He3OpacityFunction[PolarizingElement],
242242
transmission_empty_glass: He3TransmissionEmptyGlass[PolarizingElement],
@@ -283,7 +283,7 @@ def expected_transmission(
283283
def get_he3_transmission_incoming_polarized_from_fit_to_direct_beam(
284284
transmission_fraction_up: He3AnalyzerTransmissionFraction[Up, Polarized],
285285
transmission_fraction_down: He3AnalyzerTransmissionFraction[Down, Polarized],
286-
opacity_function: He3OpacityFunction[PolarizingElement],
286+
opacity_function: He3OpacityFunction[Analyzer],
287287
transmission_empty_glass: He3TransmissionEmptyGlass[Analyzer],
288288
) -> TransmissionFunction[Analyzer]:
289289
"""
@@ -430,7 +430,9 @@ def He3CellWorkflow(
430430
*, in_situ: bool = True, incoming_polarized: bool = False
431431
) -> sl.Pipeline:
432432
"""
433-
Workflow performing polarization correction for beam lines with two He3 cells.
433+
Workflow for computing transmission functions for He3 cells.
434+
435+
This can handle polarizers as well as analyzers.
434436
435437
Parameters
436438
----------
@@ -439,20 +441,20 @@ def He3CellWorkflow(
439441
parameters, or an ex-situ definition based on direct beam data. The latter
440442
requires a direct-beam measurement with depolarized cells.
441443
incoming_polarized :
442-
Whether the incoming beam for computing the cell transmission is polarized.
443-
This is the case in beamlines with a supermirror polarizer.
444+
Whether the incoming beam for computing the analyzer transmission is polarized.
445+
This is the case in beamlines with a supermirror polarizer, but also if the
446+
polarizer is not removed from the beam during the analyzer transmission
447+
measurement.
444448
"""
445449
workflow = sl.Pipeline(providers)
446450
if in_situ:
447451
workflow.insert(he3_opacity_function_from_cell_opacity)
448452
else:
449453
workflow.insert(he3_opacity_function_from_beam_data)
450-
# TODO It is error-prone to rely on setting the correct workflow parameter here.
451-
# Can PolarizationAnalysisWorkflow do this automatically if the polarizer workflow
452-
# is a supermirror workflow? Or are there cases whether the polarizer is a He3 cell
453-
# but the incoming beam is nevertheless polarized?
454+
# Note that the incoming-unpolarized function is inserted even if
455+
# incoming_polarized=True, since the incoming-unpolarized function is still
456+
# required for computing the *polarizer* transmission calculation.
457+
workflow.insert(get_he3_transmission_incoming_unpolarized_from_fit_to_direct_beam)
454458
if incoming_polarized:
455459
workflow.insert(get_he3_transmission_incoming_polarized_from_fit_to_direct_beam)
456-
else:
457-
workflow.insert(get_he3_transmission_from_fit_to_direct_beam)
458460
return workflow

src/ess/polarization/supermirror.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ def get_supermirror_transmission_function(
5959

6060

6161
def SupermirrorWorkflow() -> sciline.Pipeline:
62+
"""
63+
Workflow for computing transmission functions for supermirror polarizing elements.
64+
"""
6265
return sciline.Pipeline(supermirror_providers)

tests/he3/polarization_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_incoming_unpolarized_reproduces_input_params_within_errors() -> None:
2323
polarization=polarization,
2424
)
2525

26-
result = he3.get_he3_transmission_from_fit_to_direct_beam(
26+
result = he3.get_he3_transmission_incoming_unpolarized_from_fit_to_direct_beam(
2727
transmission_fraction=transmission,
2828
opacity_function=opacity_function,
2929
transmission_empty_glass=transmission_empty_glass,
@@ -39,7 +39,7 @@ def test_incoming_unpolarized_reproduces_input_params_within_errors() -> None:
3939
transmission_noisy = transmission.copy()
4040
transmission_noisy.values += rng.normal(0.0, 0.01, transmission_noisy.shape)
4141

42-
result = he3.get_he3_transmission_from_fit_to_direct_beam(
42+
result = he3.get_he3_transmission_incoming_unpolarized_from_fit_to_direct_beam(
4343
transmission_fraction=transmission_noisy,
4444
opacity_function=opacity_function,
4545
transmission_empty_glass=transmission_empty_glass,

0 commit comments

Comments
 (0)