Skip to content

Commit b034d63

Browse files
authored
Merge pull request #214 from scipp/update-for-next-scipp
Update for next scipp
2 parents bfbfa94 + f9e7082 commit b034d63

21 files changed

+182
-155
lines changed

docs/instruments/amor/amor_reduction.ipynb

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
"import scipp as sc\n",
2525
"import plopp as pp\n",
2626
"from ess import amor, reflectometry\n",
27-
"import ess\n",
28-
"\n",
29-
"pp.patch_scipp()"
27+
"import ess"
3028
]
3129
},
3230
{
@@ -858,7 +856,7 @@
858856
"name": "python",
859857
"nbconvert_exporter": "python",
860858
"pygments_lexer": "ipython3",
861-
"version": "3.8.17"
859+
"version": "3.10.12"
862860
}
863861
},
864862
"nbformat": 4,

docs/instruments/loki/sans2d_reduction.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,8 @@
547547
"mimetype": "text/x-python",
548548
"name": "python",
549549
"nbconvert_exporter": "python",
550-
"pygments_lexer": "ipython3"
550+
"pygments_lexer": "ipython3",
551+
"version": "3.10.12"
551552
}
552553
},
553554
"nbformat": 4,

docs/instruments/loki/sans2d_to_I_of_Q.ipynb

+3-2
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@
687687
"# Insert a copy of coords needed for conversion to Q.\n",
688688
"# TODO: can this be avoided by copying the Q coords from the converted numerator?\n",
689689
"for coord in ['position', 'sample_position', 'source_position']:\n",
690-
" denominator.coords[coord] = sample.meta[coord]\n",
690+
" denominator.coords[coord] = sample.coords[coord]\n",
691691
"\n",
692692
"denominator"
693693
]
@@ -901,7 +901,8 @@
901901
"mimetype": "text/x-python",
902902
"name": "python",
903903
"nbconvert_exporter": "python",
904-
"pygments_lexer": "ipython3"
904+
"pygments_lexer": "ipython3",
905+
"version": "3.10.12"
905906
}
906907
},
907908
"nbformat": 4,

docs/techniques/sans/sans-beam-center-finder.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,8 @@
598598
"mimetype": "text/x-python",
599599
"name": "python",
600600
"nbconvert_exporter": "python",
601-
"pygments_lexer": "ipython3"
601+
"pygments_lexer": "ipython3",
602+
"version": "3.10.12"
602603
}
603604
},
604605
"nbformat": 4,

docs/techniques/wfm/introduction-to-wfm.ipynb

+12-13
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
" ax.text(t_B, -height * z_det, r\"$t_{B}$\", ha=\"center\", va=\"top\", fontsize=8)\n",
226226
"\n",
227227
" z_wfm = sc.norm(\n",
228-
" 0.5 * (chopper_wfm1[\"position\"].data + chopper_wfm2[\"position\"].data)\n",
228+
" 0.5 * (chopper_wfm1[\"position\"] + chopper_wfm2[\"position\"])\n",
229229
" ).value\n",
230230
" xmin = ch.time_open(chopper_wfm1).values[0]\n",
231231
" xmax = ch.time_closed(chopper_wfm1).values[0]\n",
@@ -369,7 +369,7 @@
369369
" chopper_wfm1 = coords[\"chopper_wfm_1\"].value\n",
370370
" chopper_wfm2 = coords[\"chopper_wfm_2\"].value\n",
371371
" z_wfm = sc.norm(\n",
372-
" 0.5 * (chopper_wfm1[\"position\"].data + chopper_wfm2[\"position\"].data)\n",
372+
" 0.5 * (chopper_wfm1[\"position\"] + chopper_wfm2[\"position\"])\n",
373373
" ).value\n",
374374
" xmax = ch.time_closed(chopper_wfm1).values[0]\n",
375375
" z_foc = 12.0\n",
@@ -403,7 +403,7 @@
403403
"\n",
404404
" xmid = (\n",
405405
" 0.5\n",
406-
" * ((frames[\"time_min\"] + frames[\"time_min\"] + frames[\"delta_time_min\"]).data)\n",
406+
" * ((frames[\"time_min\"] + frames[\"time_min\"] + frames[\"delta_time_min\"]))\n",
407407
" ).values[0]\n",
408408
" ax.plot([xmid] * 2, [z_det, z_det + 0.5], lw=1, color='k')\n",
409409
"\n",
@@ -432,9 +432,7 @@
432432
" (\n",
433433
" 0.5\n",
434434
" * (\n",
435-
" (\n",
436-
" frames[\"time_max\"] + frames[\"time_max\"] - frames[\"delta_time_max\"]\n",
437-
" ).data\n",
435+
" frames[\"time_max\"] + frames[\"time_max\"] - frames[\"delta_time_max\"]\n",
438436
" )\n",
439437
" ).values,\n",
440438
" z_det + 1.0,\n",
@@ -488,7 +486,7 @@
488486
" chopper_wfm1 = coords[\"chopper_wfm_1\"].value\n",
489487
" chopper_wfm2 = coords[\"chopper_wfm_2\"].value\n",
490488
" z_wfm = sc.norm(\n",
491-
" 0.5 * (chopper_wfm1[\"position\"].data + chopper_wfm2[\"position\"].data)\n",
489+
" 0.5 * (chopper_wfm1[\"position\"] + chopper_wfm2[\"position\"])\n",
492490
" ).value\n",
493491
" z_det = sc.norm(ds.coords[\"position\"]).value\n",
494492
"\n",
@@ -516,11 +514,11 @@
516514
"\n",
517515
" xmid_min = (\n",
518516
" 0.5\n",
519-
" * ((frames[\"time_min\"] + frames[\"time_min\"] + frames[\"delta_time_min\"]).data)\n",
517+
" * ((frames[\"time_min\"] + frames[\"time_min\"] + frames[\"delta_time_min\"]))\n",
520518
" ).values\n",
521519
" xmid_max = (\n",
522520
" 0.5\n",
523-
" * ((frames[\"time_max\"] + frames[\"time_max\"] - frames[\"delta_time_max\"]).data)\n",
521+
" * ((frames[\"time_max\"] + frames[\"time_max\"] - frames[\"delta_time_max\"]))\n",
524522
" ).values\n",
525523
"\n",
526524
" ax.text(\n",
@@ -1046,12 +1044,12 @@
10461044
"source": [
10471045
"# Distance between WFM choppers\n",
10481046
"dz_wfm = sc.norm(\n",
1049-
" ds.coords[\"chopper_wfm_2\"].value[\"position\"].data\n",
1050-
" - ds.coords[\"chopper_wfm_1\"].value[\"position\"].data\n",
1047+
" ds.coords[\"chopper_wfm_2\"].value[\"position\"]\n",
1048+
" - ds.coords[\"chopper_wfm_1\"].value[\"position\"]\n",
10511049
")\n",
10521050
"# Delta_lambda / lambda\n",
10531051
"dlambda_over_lambda = dz_wfm / sc.norm(\n",
1054-
" coords['position'] - frames['wfm_chopper_mid_point'].data\n",
1052+
" coords['position'] - frames['wfm_chopper_mid_point']\n",
10551053
")\n",
10561054
"(1.5 * sc.units.angstrom) * dlambda_over_lambda"
10571055
]
@@ -1291,7 +1289,8 @@
12911289
"mimetype": "text/x-python",
12921290
"name": "python",
12931291
"nbconvert_exporter": "python",
1294-
"pygments_lexer": "ipython3"
1292+
"pygments_lexer": "ipython3",
1293+
"version": "3.10.12"
12951294
}
12961295
},
12971296
"nbformat": 4,

docs/techniques/wfm/reducing-wfm-data.ipynb

+15-10
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,16 @@
335335
" # Compute event arrival times at wfm choppers 1 and 2\n",
336336
" slopes = 1.0 / (alpha * item[\"wavelengths\"])\n",
337337
" intercepts = -slopes * item[\"birth_times\"]\n",
338-
" times_at_wfm1 = (sc.norm(near_wfm_chopper[\"position\"].data) - intercepts) / slopes\n",
339-
" times_at_wfm2 = (sc.norm(far_wfm_chopper[\"position\"].data) - intercepts) / slopes\n",
338+
" times_at_wfm1 = (sc.norm(near_wfm_chopper[\"position\"]) - intercepts) / slopes\n",
339+
" times_at_wfm2 = (sc.norm(far_wfm_chopper[\"position\"]) - intercepts) / slopes\n",
340340
" # Create a mask to see if neutrons go through one of the openings\n",
341341
" mask = sc.zeros(dims=times_at_wfm1.dims, shape=times_at_wfm1.shape, dtype=bool)\n",
342342
" for i in range(len(frames[\"time_min\"])):\n",
343343
" mask |= (\n",
344344
" (times_at_wfm1 >= near_time_open[\"frame\", i])\n",
345345
" & (times_at_wfm1 <= near_time_close[\"frame\", i])\n",
346-
" & (item[\"wavelengths\"] >= frames[\"wavelength_min\"][\"frame\", i]).data\n",
347-
" & (item[\"wavelengths\"] <= frames[\"wavelength_max\"][\"frame\", i]).data\n",
346+
" & (item[\"wavelengths\"] >= frames[\"wavelength_min\"][\"frame\", i])\n",
347+
" & (item[\"wavelengths\"] <= frames[\"wavelength_max\"][\"frame\", i])\n",
348348
" )\n",
349349
" item[\"valid_indices\"] = np.ravel(np.where(mask.values))"
350350
]
@@ -387,6 +387,7 @@
387387
")\n",
388388
"\n",
389389
"# Histogram the data\n",
390+
"histogrammed_data = {}\n",
390391
"for key, item in events.items():\n",
391392
" da = sc.DataArray(\n",
392393
" data=sc.ones(\n",
@@ -401,8 +402,9 @@
401402
" )\n",
402403
" },\n",
403404
" )\n",
404-
" ds[key] = da.hist(time=time_coord)\n",
405+
" histogrammed_data[key] = da.hist(time=time_coord)\n",
405406
"\n",
407+
"ds = sc.Dataset(histogrammed_data, coords=ds.coords)\n",
406408
"ds"
407409
]
408410
},
@@ -700,7 +702,7 @@
700702
" unit=events_no_wfm[\"sample\"][\"arrival_times\"].unit,\n",
701703
")\n",
702704
"\n",
703-
"ds_no_wfm = sc.Dataset(coords=coords)\n",
705+
"data_no_wfm = {}\n",
704706
"\n",
705707
"# Histogram the data\n",
706708
"for key, item in events_no_wfm.items():\n",
@@ -717,8 +719,9 @@
717719
" )\n",
718720
" },\n",
719721
" )\n",
720-
" ds_no_wfm[key] = da.hist(tof=time_coord_no_wfm)\n",
722+
" data_no_wfm[key] = da.hist(tof=time_coord_no_wfm)\n",
721723
"\n",
724+
"ds_no_wfm = sc.Dataset(data_no_wfm, coords=coords)\n",
722725
"ds_no_wfm"
723726
]
724727
},
@@ -875,7 +878,7 @@
875878
" unit=events[\"sample\"][\"arrival_times\"].unit,\n",
876879
")\n",
877880
"\n",
878-
"ds_event = sc.Dataset(coords=coords)\n",
881+
"data_event = {}\n",
879882
"\n",
880883
"# Bin the data\n",
881884
"for key, item in events.items():\n",
@@ -892,8 +895,9 @@
892895
" )\n",
893896
" },\n",
894897
" )\n",
895-
" ds_event[key] = da.bin(time=time_coord)\n",
898+
" data_event[key] = da.bin(time=time_coord)\n",
896899
"\n",
900+
"ds_event = sc.Dataset(data_event, coords=coords)\n",
897901
"ds_event"
898902
]
899903
},
@@ -1114,7 +1118,8 @@
11141118
"mimetype": "text/x-python",
11151119
"name": "python",
11161120
"nbconvert_exporter": "python",
1117-
"pygments_lexer": "ipython3"
1121+
"pygments_lexer": "ipython3",
1122+
"version": "3.8.17"
11181123
}
11191124
},
11201125
"nbformat": 4,

src/ess/_migration.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
3+
4+
from typing import MutableMapping
5+
6+
import scipp as sc
7+
8+
9+
def get_attrs(da: sc.DataArray) -> MutableMapping[str, sc.Variable]:
10+
try:
11+
# During deprecation phase
12+
return da.deprecated_attrs
13+
except AttributeError:
14+
try:
15+
# Before deprecation phase
16+
return da.attrs
17+
except AttributeError:
18+
# After deprecation phase / removal of attrs
19+
return da.coords
20+
21+
22+
def get_meta(da: sc.DataArray) -> MutableMapping[str, sc.Variable]:
23+
try:
24+
# During deprecation phase
25+
return da.deprecated_meta
26+
except AttributeError:
27+
try:
28+
# Before deprecation phase
29+
return da.meta
30+
except AttributeError:
31+
# After deprecation phase / removal of attrs
32+
return da.coords

src/ess/amor/conversions.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ def incident_beam(
1616
instead of the source_position vector.
1717
"""
1818
chopper_midpoint = (
19-
source_chopper_1.value['position'].data
20-
+ source_chopper_2.value['position'].data
19+
source_chopper_1.value['position'] + source_chopper_2.value['position']
2120
) * sc.scalar(0.5)
2221
return sample_position - chopper_midpoint
2322

src/ess/amor/load.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ def _tof_correction(data: sc.DataArray, dim: str = 'tof') -> sc.DataArray:
3333
data.attrs['orso'].value.reduction.corrections += ['chopper ToF correction']
3434
tof_unit = data.bins.coords[dim].bins.unit
3535
tau = sc.to_unit(
36-
1 / (2 * data.coords['source_chopper_2'].value['frequency'].data),
36+
1 / (2 * data.coords['source_chopper_2'].value['frequency']),
3737
tof_unit,
3838
)
39-
chopper_phase = data.coords['source_chopper_2'].value['phase'].data
39+
chopper_phase = data.coords['source_chopper_2'].value['phase']
4040
tof_offset = tau * chopper_phase / (180.0 * sc.units.deg)
4141
# Make 2 bins, one for each pulse
4242
edges = sc.concat([-tof_offset, tau - tof_offset, 2 * tau - tof_offset], dim)

src/ess/amor/resolution.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ def wavelength_resolution(
2929
The angular resolution variable, as standard deviation.
3030
"""
3131
distance_between_choppers = (
32-
chopper_2_position.data.fields.z - chopper_1_position.data.fields.z
33-
)
34-
chopper_midpoint = (chopper_1_position.data + chopper_2_position.data) * sc.scalar(
35-
0.5
32+
chopper_2_position.fields.z - chopper_1_position.fields.z
3633
)
34+
chopper_midpoint = (chopper_1_position + chopper_2_position) * sc.scalar(0.5)
3735
chopper_detector_distance = pixel_position.fields.z - chopper_midpoint.fields.z
3836
return fwhm_to_std(distance_between_choppers / chopper_detector_distance)
3937

src/ess/choppers/make_chopper.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def make_chopper(
1414
cutout_angles_begin: sc.Variable = None,
1515
cutout_angles_end: sc.Variable = None,
1616
kind: str = None,
17-
) -> sc.Dataset:
17+
) -> sc.DataGroup:
1818
"""
19-
Create a Dataset that holds chopper parameters.
20-
This ensures the Dataset is compatible with the other functions in the choppers
19+
Create a DataGroup that holds chopper parameters.
20+
This ensures the DataGroup is compatible with the other functions in the choppers
2121
module.
2222
Defining a chopper's cutout angles can either constructed from an array of cutout
2323
centers and an array of angular widths, or two arrays containing the begin (leading)
@@ -33,20 +33,19 @@ def make_chopper(
3333
:param kind: The chopper kind. Any string can be supplied, but WFM choppers should
3434
be given 'wfm' as their kind.
3535
"""
36-
data = {"frequency": frequency, "position": position}
36+
chopper = sc.DataGroup({"frequency": frequency, "position": position})
3737
if phase is not None:
38-
data["phase"] = phase
38+
chopper["phase"] = phase
3939
if cutout_angles_center is not None:
40-
data["cutout_angles_center"] = cutout_angles_center
40+
chopper["cutout_angles_center"] = cutout_angles_center
4141
if cutout_angles_width is not None:
42-
data["cutout_angles_width"] = cutout_angles_width
42+
chopper["cutout_angles_width"] = cutout_angles_width
4343
if cutout_angles_begin is not None:
44-
data["cutout_angles_begin"] = cutout_angles_begin
44+
chopper["cutout_angles_begin"] = cutout_angles_begin
4545
if cutout_angles_end is not None:
46-
data["cutout_angles_end"] = cutout_angles_end
46+
chopper["cutout_angles_end"] = cutout_angles_end
4747
if kind is not None:
48-
data["kind"] = kind
49-
chopper = sc.Dataset(data=data)
48+
chopper["kind"] = kind
5049

5150
# Sanitize input parameters
5251
if (None not in [cutout_angles_begin, cutout_angles_end]) or (

0 commit comments

Comments
 (0)