def test_stack_detector_data_missing(mock_fxe_raw_run): test_run = RunDirectory(mock_fxe_raw_run) tid, data = test_run.train_from_id(10000, devices=[('*/DET/*', 'image.data')]) # Three variants of missing data: # 1. Source missing del data['FXE_DET_LPD1M-1/DET/3CH0:xtdf'] # 2. Key missing del data['FXE_DET_LPD1M-1/DET/7CH0:xtdf']['image.data'] # 3. Empty array missing = [ 'FXE_DET_LPD1M-1/DET/{}CH0:xtdf'.format(m) for m in (1, 5, 9, 15) ] for module in missing: data[module]['image.data'] = np.zeros((0, 1, 256, 256), dtype=np.uint16) comb = stack_detector_data(data, 'image.data', fillvalue=22) assert comb.shape == (128, 1, 16, 256, 256) assert not (comb[:, :, 0] == 22).any() # Control assert (comb[:, :, 3] == 22).all() # Source missing assert (comb[:, :, 7] == 22).all() # Key missing assert (comb[:, :, 5] == 22).all() # Empty array
def test_stack_detector_data(mock_fxe_run): test_run = RunDirectory(mock_fxe_run) tid, data = test_run.train_from_id(10000, devices=[('*/DET/*', 'image.data')]) comb = stack_detector_data(data, 'image.data') assert comb.shape == (128, 1, 16, 256, 256)
def test_stack_detector_data(): test_run = RunDirectory(RUNPATH) tid, data = test_run.train_from_id(1472810853) comb = stack_detector_data(data, 'image.data', only='AGIPD1M-1') print(comb.shape) assert comb.shape == (60, 16, 512, 128) np.testing.assert_equal(comb[:, 0, ...], data['SPB_DET_AGIPD1M-1/DET/0CH0:xtdf']['image.data'])
def test_stack_detector_data_type_error(mock_fxe_raw_run): test_run = RunDirectory(mock_fxe_raw_run) tid, data = test_run.train_from_id(10000, devices=[('*/DET/*', 'image.data')]) module = 'FXE_DET_LPD1M-1/DET/3CH0:xtdf' data[module]['image.data'] = data[module]['image.data'].astype(np.float32) with pytest.raises(ValueError) as excinfo: comb = stack_detector_data(data, 'image.data') assert "dtype('float32')" in str(excinfo.value)
def test_stack_detector_data_2(): test_run = RunDirectory(RUNPATH) tid, data = test_run.train_from_id(1472810853) skip = ['SPB_DET_AGIPD1M-1/DET/{}CH0:xtdf'.format(i) for i in range(3,8)] comb = stack_detector_data(data, 'image.data', axis=0, only='AGIPD1M-1', xcept=skip) print(comb.shape) assert comb.shape == (16, 60, 512, 128) for i in (0, 1, 2, 8, 9, 10): np.testing.assert_equal(comb[i, ...], data['SPB_DET_AGIPD1M-1/DET/{}CH0:xtdf'.format(i)]['image.data']) for i in (3, 4, 5, 6, 7, 11, 12, 13, 14, 15): np.testing.assert_equal(comb[i, ...], np.full((60, 512, 128), np.nan, dtype=np.float32))
def test_stack_detector_data_wrong_pulses(mock_fxe_raw_run): test_run = RunDirectory(mock_fxe_raw_run) tid, data = test_run.train_from_id(10000, devices=[('*/DET/*', 'image.data')]) misshaped = ['FXE_DET_LPD1M-1/DET/{}CH0:xtdf'.format(m) for m in (12, 13)] for module in misshaped: data[module]['image.data'] = np.zeros((64, 1, 256, 256), dtype=np.uint16) with pytest.raises(ValueError) as excinfo: comb = stack_detector_data(data, 'image.data') assert '(64, 1, 256, 256)' in str(excinfo.value)
def test_stack_detector_data_extra_mods(mock_fxe_raw_run): test_run = RunDirectory(mock_fxe_raw_run) tid, data = test_run.train_from_id(10000, devices=[('*/DET/*', 'image.data')]) data.setdefault( 'FXE_DET_LPD1M-1/DET/16CH0:xtdf', {'image.data': np.zeros((128, 1, 256, 256), dtype=np.uint16)}, ) with pytest.raises(IndexError) as excinfo: comb = stack_detector_data(data, 'image.data') assert "16" in str(excinfo.value)
def assemble(self, data, processed): if config["DETECTOR"] == "JungFrau": try: img = np.copy(data[self._source_name]["data.adc"]) except KeyError as ex: print(ex) return elif config["DETECTOR"] == "LPD": try: modules_data = stack_detector_data(data, "image.data", only='LPD') except Exception as ex: print(ex) return if self._geom is not None: img, _ = self._geom.position_all_modules(modules_data) else: return elif config["DETECTOR"] == "AGIPD": try: modules_data = stack_detector_data(data, "image.data", only='AGIPD') except Exception as ex: print(ex) return if self._geom is not None: img, _ = self._geom.position_all_modules(modules_data) else: return else: print("Unknown detector type") return return img