|
11 | 11 | from .mockdata import write_file |
12 | 12 | from .mockdata.xgm import XGM |
13 | 13 |
|
| 14 | + |
14 | 15 | def test_get_keydata(mock_spb_raw_run): |
15 | 16 | run = RunDirectory(mock_spb_raw_run) |
16 | 17 | print(run.instrument_sources) |
@@ -43,6 +44,7 @@ def test_get_keydata(mock_spb_raw_run): |
43 | 44 | with pytest.raises(TypeError): |
44 | 45 | iter(xgm_beam_x) |
45 | 46 |
|
| 47 | + |
46 | 48 | def test_select_trains(mock_spb_raw_run): |
47 | 49 | run = RunDirectory(mock_spb_raw_run) |
48 | 50 | xgm_beam_x = run['SPB_XTD9_XGM/DOOCS/MAIN', 'beamPosition.ixPos.value'] |
@@ -277,6 +279,7 @@ def test_single_value(mock_sa3_control_data, monkeypatch): |
277 | 279 |
|
278 | 280 | imager = f['SA3_XTD10_IMGFEL/CAM/BEAMVIEW:daqOutput', 'data.image.pixels'] |
279 | 281 | flux = f['SA3_XTD10_XGM/XGM/DOOCS', 'pulseEnergy.photonFlux'] |
| 282 | + state = f['SA3_XTD10_XGM/XGM/DOOCS', 'state'] |
280 | 283 |
|
281 | 284 | # Try without data for a source and key. |
282 | 285 | with pytest.raises(NoDataError): |
@@ -309,6 +312,17 @@ def test_single_value(mock_sa3_control_data, monkeypatch): |
309 | 312 | assert flux.as_single_value(rtol=1, reduce_by=np.mean) == np.mean(data) |
310 | 313 | assert flux.as_single_value(atol=len(data)-1, reduce_by='first') == 0 |
311 | 314 |
|
| 315 | + # Try strings. |
| 316 | + assert state[5:].as_single_value() == 'ON' |
| 317 | + |
| 318 | + with pytest.raises(ValueError): |
| 319 | + # Contains two unique values. |
| 320 | + state.as_single_value() |
| 321 | + |
| 322 | + with pytest.raises(TypeError): |
| 323 | + # Does not accept reduce_by |
| 324 | + state.as_single_value(reduce_by='mean') |
| 325 | + |
312 | 326 | # Try vector data. |
313 | 327 | intensity = f['SA3_XTD10_XGM/XGM/DOOCS:output', 'data.intensityTD'] |
314 | 328 | data = np.repeat(data, intensity.shape[1]).reshape(-1, intensity.shape[-1]) |
@@ -405,6 +419,6 @@ def test_units(mock_sa3_control_data): |
405 | 419 |
|
406 | 420 | # Check that it still works after selecting 0 trains |
407 | 421 | assert xgm_intensity.select_trains(np.s_[:0]).units == 'μJ' |
408 | | - |
| 422 | + |
409 | 423 | # units are added to xarray's attributes |
410 | 424 | assert xgm_intensity.xarray().attrs['units'] == 'μJ' |
0 commit comments