Skip to content

Commit 907128b

Browse files
authored
Merge pull request #162 from scipp/fix-estia-detector
fix: shape and size of the estia detector
2 parents 3bd32be + 3885a24 commit 907128b

File tree

10 files changed

+61
-32
lines changed

10 files changed

+61
-32
lines changed

docs/user-guide/estia/estia-mcstas-reduction.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"wf[Filename[ReferenceRun]] = estia_mcstas_example('reference')\n",
5858
"\n",
5959
"wf[YIndexLimits] = sc.scalar(35), sc.scalar(64)\n",
60-
"wf[ZIndexLimits] = sc.scalar(0), sc.scalar(14 * 32)\n",
60+
"wf[ZIndexLimits] = sc.scalar(0), sc.scalar(48 * 32)\n",
6161
"wf[BeamDivergenceLimits] = sc.scalar(-0.75, unit='deg'), sc.scalar(0.75, unit='deg')\n",
6262
"wf[WavelengthBins] = sc.geomspace('wavelength', 3.5, 12, 2001, unit='angstrom')\n",
6363
"wf[QBins] = 1000\n",

src/ess/amor/conversions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def add_masks(
163163
and by wavelength.
164164
"""
165165
da = da.assign_masks(
166-
stripe_range=_not_between(da.coords["stripe"], *ylim),
166+
strip_range=_not_between(da.coords["strip"], *ylim),
167167
z_range=_not_between(da.coords["z_index"], *zlims),
168168
)
169169
da = da.bins.assign_masks(

src/ess/amor/geometry.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class Detector:
1010
nBlades = sc.scalar(14)
1111
# number of wires per blade
1212
nWires = sc.scalar(32)
13-
# number of stripes per blade
14-
nStripes = sc.scalar(64)
13+
# number of strips per blade
14+
nStrips = sc.scalar(64)
1515
# angle of incidence of the beam on the blades (def: 5.1)
1616
angle = sc.scalar(5.1, unit="degree").to(unit="rad")
1717
# height-distance of neighboring pixels on one blade
@@ -34,21 +34,21 @@ def pixel_coordinates_in_detector_system() -> tuple[sc.Variable, sc.Variable]:
3434
'row',
3535
1,
3636
(
37-
Detector.nBlades * Detector.nWires * Detector.nStripes + sc.scalar(1)
37+
Detector.nBlades * Detector.nWires * Detector.nStrips + sc.scalar(1)
3838
).values,
3939
unit=None,
4040
).fold(
4141
'row',
4242
sizes={
4343
'blade': Detector.nBlades,
4444
'wire': Detector.nWires,
45-
'stripe': Detector.nStripes,
45+
'strip': Detector.nStrips,
4646
},
4747
),
4848
coords={
4949
'blade': sc.arange('blade', sc.scalar(0), Detector.nBlades),
5050
'wire': sc.arange('wire', sc.scalar(0), Detector.nWires),
51-
'stripe': sc.arange('stripe', sc.scalar(0), Detector.nStripes),
51+
'strip': sc.arange('strip', sc.scalar(0), Detector.nStrips),
5252
},
5353
)
5454
# x position in detector

src/ess/estia/beamline.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sciline
2+
3+
from ess.reduce.nexus.types import DetectorBankSizes
4+
from ess.reduce.nexus.workflow import GenericNeXusWorkflow
5+
from ess.reflectometry.types import ReferenceRun, SampleRun
6+
7+
DETECTOR_BANK_SIZES = {
8+
"multiblade_detector": {
9+
"blade": 48,
10+
"wire": 32,
11+
"strip": 64,
12+
},
13+
}
14+
15+
16+
def LoadNeXusWorkflow() -> sciline.Pipeline:
17+
"""
18+
Workflow for loading NeXus data.
19+
"""
20+
workflow = GenericNeXusWorkflow(
21+
run_types=[SampleRun, ReferenceRun], monitor_types=[]
22+
)
23+
workflow[DetectorBankSizes] = DETECTOR_BANK_SIZES
24+
return workflow

src/ess/estia/load.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
RunType,
1010
SampleRotationOffset,
1111
)
12+
from .beamline import DETECTOR_BANK_SIZES
1213
from .mcstas import parse_events_ascii, parse_events_h5
1314

1415

@@ -38,11 +39,14 @@ def load_mcstas_events(
3839
unit=da.coords['sample_rotation'].unit
3940
)
4041

41-
xbins = sc.linspace('x', -0.25, 0.25, 14 * 32 + 1)
42-
ybins = sc.linspace('y', -0.25, 0.25, 65)
43-
da = da.bin(x=xbins, y=ybins).rename_dims({'y': 'stripe'})
44-
da.coords['stripe'] = sc.arange('stripe', 0, 64)
45-
da.coords['z_index'] = sc.arange('x', 14 * 32 - 1, -1, -1)
42+
nblades = DETECTOR_BANK_SIZES['multiblade_detector']['blade']
43+
nwires = DETECTOR_BANK_SIZES['multiblade_detector']['wire']
44+
nstrips = DETECTOR_BANK_SIZES['multiblade_detector']['strip']
45+
xbins = sc.linspace('x', -0.25, 0.25, nblades * nwires + 1)
46+
ybins = sc.linspace('y', -0.13, 0.13, nstrips + 1)
47+
da = da.bin(y=ybins, x=xbins).rename_dims({'y': 'strip'})
48+
da.coords['strip'] = sc.arange('strip', 0, nstrips)
49+
da.coords['z_index'] = sc.arange('x', nblades * nwires - 1, -1, -1)
4650

4751
# Information is not available in the mcstas output files, therefore it's hardcoded
4852
da.coords['sample_position'] = sc.vector([0.264298, -0.427595, 35.0512], unit='m')
@@ -64,7 +68,7 @@ def load_mcstas_events(
6468
x=sc.midpoints(da.coords['x']) * sc.scalar(1.0, unit='m'),
6569
y=sc.midpoints(da.coords['y']) * sc.scalar(1.0, unit='m'),
6670
z=sc.scalar(0.0, unit='m'),
67-
)
71+
).transpose(da.dims)
6872
da.coords['position'] = (
6973
da.coords['detector_position'] + rotation_by_detector_rotation * position
7074
)
@@ -82,7 +86,14 @@ def load_mcstas_events(
8286
)
8387
da.coords["beam_size"] = sc.scalar(2.0, unit='mm')
8488

85-
da = da.fold('x', sizes={'blade': 14, 'wire': 32})
89+
da = da.fold(
90+
'x',
91+
sizes={
92+
k: v
93+
for k, v in DETECTOR_BANK_SIZES['multiblade_detector'].items()
94+
if k in ('blade', 'wire')
95+
},
96+
)
8697
da.bins.coords.pop('L')
8798
da.bins.coords.pop('t')
8899
return DetectorData[RunType](da)

src/ess/estia/maskings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def add_masks(
2727
and by wavelength.
2828
"""
2929
da = da.assign_masks(
30-
stripe_range=_not_between(da.coords["stripe"], *ylim),
30+
strip_range=_not_between(da.coords["strip"], *ylim),
3131
z_range=_not_between(da.coords["z_index"], *zlims),
3232
divergence_too_large=_not_between(
3333
da.coords["divergence_angle"],

src/ess/estia/workflow.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@
44
import sciline
55
import scipp as sc
66

7-
from ess.reduce import nexus
8-
97
from ..reflectometry import providers as reflectometry_providers
108
from ..reflectometry import supermirror
119
from ..reflectometry.types import (
1210
BeamDivergenceLimits,
1311
DetectorSpatialResolution,
1412
NeXusDetectorName,
15-
ReferenceRun,
1613
RunType,
1714
SampleRotationOffset,
18-
SampleRun,
1915
)
20-
from . import conversions, corrections, load, maskings, normalization, orso
16+
from . import beamline, conversions, corrections, load, maskings, normalization, orso
2117

2218
_general_providers = (
2319
*reflectometry_providers,
@@ -74,9 +70,7 @@ def EstiaMcStasWorkflow() -> sciline.Pipeline:
7470

7571
def EstiaWorkflow() -> sciline.Pipeline:
7672
"""Workflow for reduction of data for the Estia instrument."""
77-
workflow = nexus.GenericNeXusWorkflow(
78-
run_types=[SampleRun, ReferenceRun], monitor_types=[]
79-
)
73+
workflow = beamline.LoadNeXusWorkflow()
8074
for provider in providers:
8175
workflow.insert(provider)
8276
for name, param in default_parameters().items():

src/ess/reflectometry/normalization.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def reduce_reference(
4040
)
4141
reference = reference.bins.assign_masks(invalid=sc.isnan(R))
4242
reference = reference / R
43-
out = reference.bins.concat(('stripe',)).hist(wavelength=wavelength_bins)
43+
out = reference.bins.concat(('strip',)).hist(wavelength=wavelength_bins)
4444

4545
if 'position' in reference.coords:
46-
out.coords['position'] = reference.coords['position'].mean('stripe')
46+
out.coords['position'] = reference.coords['position'].mean('strip')
4747
return out
4848

4949

@@ -96,7 +96,7 @@ def reduce_sample_over_zw(
9696
9797
Returns reflectivity as a function of ``blade``, ``wire`` and :math:`\\wavelength`.
9898
"""
99-
return sample.bins.concat(('stripe',)).bin(wavelength=wbins) / sc.values(
99+
return sample.bins.concat(('strip',)).bin(wavelength=wbins) / sc.values(
100100
reference.data
101101
)
102102

tests/estia/mcstas_data_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def estia_mcstas_pipeline() -> sciline.Pipeline:
3737
wf[Filename[ReferenceRun]] = estia_mcstas_reference_run()
3838

3939
wf[YIndexLimits] = sc.scalar(35), sc.scalar(64)
40-
wf[ZIndexLimits] = sc.scalar(0), sc.scalar(14 * 32)
40+
wf[ZIndexLimits] = sc.scalar(0), sc.scalar(48 * 32)
4141
wf[BeamDivergenceLimits] = sc.scalar(-1.0, unit='deg'), sc.scalar(1.0, unit='deg')
4242
wf[WavelengthBins] = sc.geomspace('wavelength', 3.5, 12, 2001, unit='angstrom')
4343
wf[QBins] = sc.geomspace('Q', 0.005, 0.1, 200, unit='1/angstrom')
@@ -79,8 +79,8 @@ def estia_mcstas_pipeline() -> sciline.Pipeline:
7979
def test_mcstas_compute_reducible_data(estia_mcstas_pipeline: sciline.Pipeline):
8080
estia_mcstas_pipeline[Filename[SampleRun]] = estia_mcstas_sample_run(11)
8181
da = estia_mcstas_pipeline.compute(ReducibleData[SampleRun])
82-
assert da.dims == ('blade', 'wire', 'stripe')
83-
assert da.shape == (14, 32, 64)
82+
assert da.dims == ('strip', 'blade', 'wire')
83+
assert da.shape == (64, 48, 32)
8484
assert 'position' in da.coords
8585
assert 'sample_rotation' in da.coords
8686
assert 'detector_rotation' in da.coords

tests/reflectometry/normalization_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ def sample(request):
1515
coords={
1616
'wavelength': sc.linspace('events', 1, 5, n),
1717
'wire': sc.array(dims=('events',), values=np.random.randint(0, 5, n)),
18-
'stripe': sc.array(dims=('events',), values=np.random.randint(0, 10, n)),
18+
'strip': sc.array(dims=('events',), values=np.random.randint(0, 10, n)),
1919
},
2020
)
21-
return da.group('wire', 'stripe')
21+
return da.group('wire', 'strip')
2222

2323

2424
@pytest.fixture
@@ -29,7 +29,7 @@ def reference(request):
2929
coords={
3030
'wavelength': sc.linspace('events', 1, 5, n),
3131
'wire': sc.array(dims=('events',), values=np.random.randint(0, 5, n)),
32-
'stripe': sc.array(dims=('events',), values=np.random.randint(0, 10, n)),
32+
'strip': sc.array(dims=('events',), values=np.random.randint(0, 10, n)),
3333
},
3434
)
3535
return da.group('wire').bin(wavelength=2).bins.sum()

0 commit comments

Comments
 (0)