1111from .mockdata import write_file
1212from .mockdata .xgm import XGM
1313
14+
1415def test_get_keydata (mock_spb_raw_run ):
1516 run = RunDirectory (mock_spb_raw_run )
1617 print (run .instrument_sources )
@@ -43,6 +44,7 @@ def test_get_keydata(mock_spb_raw_run):
4344 with pytest .raises (TypeError ):
4445 iter (xgm_beam_x )
4546
47+
4648def test_select_trains (mock_spb_raw_run ):
4749 run = RunDirectory (mock_spb_raw_run )
4850 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):
277279
278280 imager = f ['SA3_XTD10_IMGFEL/CAM/BEAMVIEW:daqOutput' , 'data.image.pixels' ]
279281 flux = f ['SA3_XTD10_XGM/XGM/DOOCS' , 'pulseEnergy.photonFlux' ]
282+ state = f ['SA3_XTD10_XGM/XGM/DOOCS' , 'state' ]
280283
281284 # Try without data for a source and key.
282285 with pytest .raises (NoDataError ):
@@ -309,6 +312,17 @@ def test_single_value(mock_sa3_control_data, monkeypatch):
309312 assert flux .as_single_value (rtol = 1 , reduce_by = np .mean ) == np .mean (data )
310313 assert flux .as_single_value (atol = len (data )- 1 , reduce_by = 'first' ) == 0
311314
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+
312326 # Try vector data.
313327 intensity = f ['SA3_XTD10_XGM/XGM/DOOCS:output' , 'data.intensityTD' ]
314328 data = np .repeat (data , intensity .shape [1 ]).reshape (- 1 , intensity .shape [- 1 ])
@@ -332,6 +346,15 @@ def test_ndarray_out(mock_spb_raw_run):
332346 assert buf_in is buf_out
333347
334348
349+ def test_string_arrays (mock_spb_raw_run ):
350+ f = RunDirectory (mock_spb_raw_run )
351+ state = f ['SPB_XTD9_XGM/DOOCS/MAIN' , 'state' ]
352+
353+ for data in [state .ndarray (), state .xarray (), state .series ()]:
354+ assert data .dtype .hasobject
355+ assert (data [3 :8 ] == ['OFF' , 'OFF' , 'ON' , 'ON' , 'ON' ]).all ()
356+
357+
335358def test_xarray_structured_data (mock_remi_run ):
336359 run = RunDirectory (mock_remi_run )
337360 dset = run ['SQS_REMI_DLD6/DET/TOP:output' , 'rec.hits' ].xarray ()
@@ -396,6 +419,6 @@ def test_units(mock_sa3_control_data):
396419
397420 # Check that it still works after selecting 0 trains
398421 assert xgm_intensity .select_trains (np .s_ [:0 ]).units == 'μJ'
399-
422+
400423 # units are added to xarray's attributes
401424 assert xgm_intensity .xarray ().attrs ['units' ] == 'μJ'
0 commit comments