def test_get_array_roi(mock_fxe_raw_run): run = RunDirectory(mock_fxe_raw_run) det = LPD1M(run.select_trains(by_index[:3])) assert det.detector_name == 'FXE_DET_LPD1M-1' arr = det.get_array('image.data', roi=np.s_[10:60, 100:200]) assert arr.shape == (16, 3, 128, 50, 100) assert arr.dims == ('module', 'train', 'pulse', 'slow_scan', 'fast_scan')
def test_iterate_lpd_parallel_gain(mock_lpd_parallelgain_run): run = RunDirectory(mock_lpd_parallelgain_run) det = LPD1M(run.select_trains(by_index[:3]), parallel_gain=True) tid, d = next(iter(det.trains())) assert d['image.data'].shape == (16, 1, 3, 100, 256, 256) assert d['image.data'].dims == \ ('module', 'train', 'gain', 'pulse', 'slow_scan', 'fast_scan')
def test_get_dask_array_lpd_parallelgain(mock_lpd_parallelgain_run): run = RunDirectory(mock_lpd_parallelgain_run) det = LPD1M(run.select_trains(by_index[:2]), parallel_gain=True) assert det.detector_name == 'FXE_DET_LPD1M-1' arr = det.get_dask_array('image.data') assert arr.shape == (16, 2 * 3 * 100, 1, 256, 256) assert arr.dims[:2] == ('module', 'train_pulse') np.testing.assert_array_equal(arr.coords['pulseId'], np.tile(np.arange(100), 6))
def test_write_virtual_cxi_raw_data(mock_fxe_raw_run, tmpdir, caplog): import logging caplog.set_level(logging.INFO) run = RunDirectory(mock_fxe_raw_run) det = LPD1M(run) test_file = osp.join(str(tmpdir), 'test.cxi') det.write_virtual_cxi(test_file) assert_isfile(test_file)
def test_get_array_with_cell_ids(mock_fxe_raw_run): run = RunDirectory(mock_fxe_raw_run) det = LPD1M(run.select_trains(by_index[:3])) arr = det.get_array('image.data', subtrain_index='cellId') assert arr.shape == (16, 3, 128, 256, 256) assert arr.dims == ('module', 'train', 'cell', 'slow_scan', 'fast_scan') arr = det.get_array('image.data', pulses=by_id[0], subtrain_index='cellId') assert arr.shape == (16, 3, 1, 256, 256) assert (arr.coords['cell'] == 0).all()
def test_get_array_lpd_parallelgain(mock_lpd_parallelgain_run): run = RunDirectory(mock_lpd_parallelgain_run) det = LPD1M(run.select_trains(by_index[:2]), parallel_gain=True) assert det.detector_name == 'FXE_DET_LPD1M-1' arr = det.get_array('image.data') assert arr.shape == (16, 2, 3, 100, 256, 256) assert arr.dims == ('module', 'train', 'gain', 'pulse', 'slow_scan', 'fast_scan') np.testing.assert_array_equal(arr.coords['gain'], np.arange(3)) np.testing.assert_array_equal(arr.coords['pulse'], np.arange(100))
def test_iterate(mock_fxe_raw_run): run = RunDirectory(mock_fxe_raw_run) det = LPD1M(run.select_trains(by_index[:2])) it = iter(det.trains()) tid, d = next(it) assert d['image.data'].shape == (16, 1, 128, 256, 256) assert d['image.data'].dims == ('module', 'train', 'pulse', 'slow_scan', 'fast_scan') tid, d = next(it) assert d['image.data'].shape == (16, 1, 128, 256, 256) with pytest.raises(StopIteration): next(it)
def test_get_array_gap(mock_lpd_mini_gap_run): run = RunDirectory(mock_lpd_mini_gap_run) det = LPD1M(run, modules=[0, 1]) # All pulses arr = det.get_array('image.data') assert arr.shape == (2, 5, 10, 256, 256) np.testing.assert_array_equal(arr[1, :, 8, 0, 0], [1, 2, 0, 3, 4]) # Selected pulses arr = det.get_array('image.data', pulses=[8]) assert arr.shape == (2, 5, 1, 256, 256) np.testing.assert_array_equal(arr[1, :, 0, 0, 0], [1, 2, 0, 3, 4])
def test_write_virtual_cxi_raw_data(mock_fxe_raw_run, tmpdir, caplog): import logging caplog.set_level(logging.INFO) run = RunDirectory(mock_fxe_raw_run) det = LPD1M(run) test_file = osp.join(str(tmpdir), 'test.cxi') det.write_virtual_cxi(test_file) assert_isfile(test_file) with h5py.File(test_file, 'r') as f: det_grp = f['entry_1/instrument_1/detector_1'] ds = det_grp['data'] assert ds.shape[1:] == (16, 1, 256, 256)
def test_get_array(mock_fxe_raw_run): run = RunDirectory(mock_fxe_raw_run) det = LPD1M(run.select_trains(by_index[:3])) assert det.detector_name == 'FXE_DET_LPD1M-1' arr = det.get_array('image.data') assert arr.shape == (16, 3, 128, 256, 256) assert arr.dims == ('module', 'train', 'pulse', 'slow_scan', 'fast_scan') arr = det.get_array('image.data', pulses=by_index[:10], unstack_pulses=False) assert arr.shape == (16, 30, 256, 256) assert arr.dims == ('module', 'train_pulse', 'slow_scan', 'fast_scan')
def test_iterate_pulse_index(mock_fxe_raw_run): run = RunDirectory(mock_fxe_raw_run) det = LPD1M(run.select_trains(by_index[:3])) tid, d = next(iter(det.trains(pulses=by_index[0]))) assert d['image.data'].shape == (16, 1, 1, 256, 256) tid, d = next(iter(det.trains(pulses=by_index[:5]))) assert d['image.data'].shape == (16, 1, 5, 256, 256) tid, d = next(iter(det.trains(pulses=by_index[122:]))) assert d['image.data'].shape == (16, 1, 6, 256, 256) tid, d = next(iter(det.trains(pulses=by_index[[1, 7, 22, 23]]))) assert d['image.data'].shape == (16, 1, 4, 256, 256) assert list(d['image.data'].coords['pulse']) == [1, 7, 22, 23]
def test_get_dask_array(mock_fxe_raw_run): run = RunDirectory(mock_fxe_raw_run) det = LPD1M(run) arr = det.get_dask_array('image.data') assert isinstance(arr.data, da.Array) assert arr.shape == (16, 480 * 128, 1, 256, 256) assert arr.dims == ('module', 'train_pulse', 'dim_0', 'dim_1', 'dim_2') np.testing.assert_array_equal(arr.coords['module'], np.arange(16)) np.testing.assert_array_equal(arr.coords['trainId'], np.repeat(np.arange(10000, 10480), 128)) np.testing.assert_array_equal(arr.coords['pulseId'], np.tile(np.arange(0, 128), 480)) arr_cellid = det.get_dask_array('image.data', subtrain_index='cellId') assert arr_cellid.coords['cellId'].shape == (480 * 128, )
def test_get_array(mock_fxe_raw_run): run = RunDirectory(mock_fxe_raw_run) det = LPD1M(run.select_trains(by_index[:3])) assert det.detector_name == 'FXE_DET_LPD1M-1' arr = det.get_array('image.data') assert arr.shape == (16, 3, 128, 256, 256) assert arr.dims == ('module', 'train', 'pulse', 'slow_scan', 'fast_scan') arr = det.get_array('image.data', pulses=by_index[:10], unstack_pulses=False) assert arr.shape == (16, 30, 256, 256) assert arr.dtype == np.uint16 assert arr.dims == ('module', 'train_pulse', 'slow_scan', 'fast_scan') # fill value with pytest.raises(ValueError): det.get_array('image.data', fill_value=np.nan)
def test_get_array_pulse_indexes(mock_fxe_raw_run): run = RunDirectory(mock_fxe_raw_run) det = LPD1M(run.select_trains(by_index[:3])) arr = det.get_array('image.data', pulses=by_index[0]) assert arr.shape == (16, 3, 1, 256, 256) assert (arr.coords['pulse'] == 0).all() arr = det.get_array('image.data', pulses=by_index[:5]) assert arr.shape == (16, 3, 5, 256, 256) # Empty selection arr = det.get_array('image.data', pulses=by_index[:0]) assert arr.shape == (16, 0, 0, 256, 256) arr = det.get_array('image.data', pulses=by_index[122:]) assert arr.shape == (16, 3, 6, 256, 256) arr = det.get_array('image.data', pulses=by_index[[1, 7, 22, 23]]) assert arr.shape == (16, 3, 4, 256, 256)