Skip to content
Snippets Groups Projects
Commit dc74d5b0 authored by David Hammer's avatar David Hammer
Browse files

Removing unuseful test device

Testing of the bridge part of the code is much more convenient to (copy-paste
into and) run in a notebook; just use a kernel based on the Karabo environment.
parent 6b29320f
No related branches found
No related tags found
2 merge requests!59Interface CrystFEL with Karabo and allow automatic parameter tunning with rcrystfel,!53Train picker arbiter kernel
......@@ -37,7 +37,6 @@ setup(
"ShmemTrainMatcher = calng.ShmemTrainMatcher:ShmemTrainMatcher",
"FrameSelectionArbiter = calng.FrameSelectionArbiter:FrameSelectionArbiter", # noqa
"CrystfelRunner = calng.CrystfelRunner:CrystfelRunner",
"CrystfelTester = calng.CrystfelTester:CrystfelTester",
"DetectorAssembler = calng.DetectorAssembler:DetectorAssembler",
"Gotthard2Assembler = calng.Gotthard2Assembler:Gotthard2Assembler",
"LpdminiSplitter = calng.LpdminiSplitter:LpdminiSplitter",
......
import itertools
import h5py
import numpy as np
import cfelpyutils.geometry
import cfelpyutils.crystfel_stream
import threading
from karabo.bound import (
BOOL_ELEMENT,
DOUBLE_ELEMENT,
INPUT_CHANNEL,
KARABO_CLASSINFO,
NODE_ELEMENT,
OUTPUT_CHANNEL,
STRING_ELEMENT,
VECTOR_STRING_ELEMENT,
Hash,
PythonDevice,
State,
Unit,
)
@KARABO_CLASSINFO("CrystfelTester", "0.0")
class CrystfelTester(PythonDevice):
@staticmethod
def expectedParameters(expected):
(OUTPUT_CHANNEL(expected).key("output").commit(),)
def __init__(self, config):
super().__init__(config)
self.registerInitialFunction(self._initialization)
def _initialization(self):
with h5py.File(
"/home/hammerd/pro/online-indexing/oleksii/data/indexable/d_01/indexed_p2808_r0024_vds.h5",
"r",
) as fd:
masked = np.array(fd["entry_1/data_1/data"], copy=True)
masked[~np.equal(np.array(fd["entry_1/data_1/mask"]), 0)] = np.nan
def row_to_peak(index_and_row):
row = index_and_row[1]
return (
np.float64(row["ss/px"]) - 0.5, # ss
np.float64(row["fs/px"]) - 0.5, # fs
np.float64(row["Intensity"]), # intensity
)
old_peaks = [
list(map(row_to_peak, event["peaks"].iterrows()))
for event in cfelpyutils.crystfel_stream.parse_chunks(
"/home/hammerd/pro/online-indexing/saved-outputs/output-2023-06-07-pf8-rerun.stream"
)
if "peaks" in event
]
def serve():
# pretend that we're getting some number of frames at a time per train
n_frames = 20
max_peaks = 500
num_peaks = np.empty([n_frames], dtype=np.uint32)
peak_x = np.empty([n_frames, max_peaks], dtype=np.float32)
peak_y = np.empty([n_frames, max_peaks], dtype=np.float32)
peak_intensity = np.empty([n_frames, max_peaks], dtype=np.float32)
while train_data := itertools.islice(
zip(
itertools.cycle(masked),
itertools.cycle(old_peaks),
),
n_frames,
):
frame, peaks = zip(*train_data)
ss, fs, intensity = zip(*peaks)
for i, (ss_, fs_, intensity_) in zip(ss, fs, intensity):
num_peaks_ = len(ss_)
num_peaks[i] = num_peaks_
peak_x[i, :num_peaks_] = ss_
peak_y[i, :num_peaks_] = fs_
peak_intensity[i, :num_peaks_] = intensity_
self.writeChannel(
"output",
Hash(
"peakfinding.numPeaks",
num_peaks,
"peakfinding.peakX",
peak_x,
"peakfinding.peakY",
peak_y,
"peakfinding.peakIntensity",
peak_intensity,
),
)
serve()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment