def testGeneral(self): # --------------------- # pulse-resolved data # --------------------- data = ProcessedData(1234) self.assertEqual(1234, data.tid) self.assertEqual(0, data.n_pulses) data.image = ImageData.from_array(np.zeros((1, 2, 2))) self.assertEqual(1, data.n_pulses) data = ProcessedData(1235) data.image = ImageData.from_array(np.zeros((3, 2, 2))) self.assertEqual(3, data.n_pulses) # --------------------- # train-resolved data # --------------------- data = ProcessedData(1236) data.image = ImageData.from_array(np.zeros((2, 2))) self.assertEqual(1236, data.tid) self.assertEqual(1, data.n_pulses)
def processed_data(cls, tid, shape, *, gen='random', dtype=config['SOURCE_PROC_IMAGE_DTYPE'], roi_histogram=False, histogram=False, correlation=False, binning=False, **kwargs): processed = ProcessedData(tid) imgs = cls._gen_images(gen, shape, dtype) processed.image = ImageData.from_array(imgs, **kwargs) if roi_histogram: pass if histogram: hist = processed.hist hist.hist = np.arange(10) hist.bin_centers = np.arange(10) / 100. hist.mean, hist.median, hist.std = 1., 0, 0.1 if correlation: pass if binning: pass return processed
def testBulletinView(self): processed = ProcessedData(1357) processed.image = ImageData.from_array(np.ones((10, 4, 4), np.float32)) processed.image.dark_count = 99 processed.image.n_dark_pulses = 10 processed.pidx.mask([1, 3, 5, 6]) self.gui._queue.append(processed) self.image_tool.updateWidgetsF() view = self.image_tool._bulletin_view self.assertEqual(1357, int(view._latest_tid.intValue())) self.assertEqual(10, int(view._n_total_pulses.intValue())) self.assertEqual(6, int(view._n_kept_pulses.intValue())) self.assertEqual(99, int(view._dark_train_counter.intValue())) self.assertEqual(10, int(view._n_dark_pulses.intValue()))
def processed_data(cls, tid, shape, *, gen='random', dtype=config['SOURCE_PROC_IMAGE_DTYPE'], roi_histogram=False, histogram=False, correlation=False, binning=False, **kwargs): processed = ProcessedData(tid) imgs = cls._gen_images(gen, shape, dtype) processed.image = ImageData.from_array(imgs, **kwargs) if roi_histogram: pass if histogram: hist = processed.hist hist.hist = np.arange(10) hist.bin_centers = np.arange(10) / 100. hist.mean, hist.median, hist.std = 1., 0, 0.1 if correlation: corr_resolution = 2 for i in range(2): corr = processed.corr[i] if i == 0: data = SimplePairSequence() else: data = OneWayAccuPairSequence(corr_resolution) for j in range(5): data.append((j, 5 * j)) corr.x, corr.y = data.data() corr.source = f"abc - {i}" corr.resolution = 0 if i == 0 else corr_resolution if binning: pass return processed
def testBulletinView(self): processed = ProcessedData(1357) processed.image = ImageData.from_array(np.ones((10, 4, 4), np.float32)) processed.image.dark_count = 99 processed.image.n_dark_pulses = 10 processed.pidx.mask([1, 3, 5, 6]) self.gui._queue.append(processed) self.image_tool.updateWidgetsF() view = self.image_tool._bulletin_view self.assertEqual(1357, int(view._displayed_tid.intValue())) self.assertEqual(10, int(view._n_total_pulses.intValue())) self.assertEqual(6, int(view._n_kept_pulses.intValue())) self.assertEqual(99, int(view._dark_train_counter.intValue())) self.assertEqual(10, int(view._n_dark_pulses.intValue())) with patch.object(view._mon, "reset_process_count") as reset: view._reset_process_count_btn.clicked.emit() reset.assert_called_once()
def data_with_assembled(cls, tid, shape, *, src_type=DataSource.BRIDGE, dtype=config['SOURCE_PROC_IMAGE_DTYPE'], gen='random', slicer=None, with_xgm=False, with_digitizer=False, **kwargs): imgs = cls._gen_images(gen, shape, dtype) processed = ProcessedData(tid) processed.image = ImageData.from_array(imgs, **kwargs) if imgs.ndim == 2: slicer = None else: slicer = slice(None, None) if slicer is None else slicer src_list = [('Foo', 'oof'), ('Bar', 'rab'), ('karaboFAI', 'extra_foam')] src_name, key_name = random.choice(src_list) catalog = SourceCatalog() ctg = 'ABCD' src = f'{src_name} {key_name}' catalog.add_item(SourceItem(ctg, src_name, [], key_name, slicer, None)) catalog._main_detector = src n_pulses = processed.n_pulses if with_xgm: # generate XGM data processed.pulse.xgm.intensity = np.random.rand(n_pulses) processed.xgm.intensity = random.random() processed.xgm.x = random.random() processed.xgm.y = random.random() if with_digitizer: # generate digitizer data digitizer = processed.pulse.digitizer digitizer.ch_normalizer = 'B' for ch in digitizer: digitizer[ch].pulse_integral = np.random.rand(n_pulses) data = { 'processed': processed, 'catalog': catalog, 'meta': { src: { 'timestamp.tid': tid, 'source_type': src_type, } }, 'raw': { src: dict() }, 'assembled': { 'data': imgs, } } if imgs.ndim == 2: data['assembled']['sliced'] = imgs else: data['assembled']['sliced'] = imgs[slicer] return data, processed