Commit 888f5284 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Use Cython memoryviews in conversion to pandas

parent 2b97afc2
......@@ -12,4 +12,4 @@ print("Image shape:", arr.shape)
peaks_tbl = find_peaks_single_panel(arr, os.path.join(THIS_DIR, '1panel.geom'))
print(f"Found {len(peaks_tbl)} peaks")
......@@ -24,14 +24,11 @@ cdef featurelist_to_dataframe(crystfel.ImageFeatureList *flist):
int i, nfeat = crystfel.image_feature_count(flist)
crystfel.imagefeature *feat
cnp.ndarray[cnp.npy_double, ndim=1] ss, fs, rx, ry, rz, it
cnp.ndarray arr
double[:] ss, fs, rx, ry, rz, it
ss = np.zeros(nfeat, np.double)
fs = np.zeros(nfeat, np.double)
rx = np.zeros(nfeat, np.double)
ry = np.zeros(nfeat, np.double)
rz = np.zeros(nfeat, np.double)
it = np.zeros(nfeat, np.double)
arr = np.zeros((6, nfeat), dtype=np.double)
ss, fs, rx, ry, rz, it = arr
with cython.boundscheck(False), cython.wraparound(False):
for i in range(nfeat):
......@@ -43,9 +40,9 @@ cdef featurelist_to_dataframe(crystfel.ImageFeatureList *flist):
rz[i] = feat.rz
it[i] = feat.intensity
return pd.DataFrame({
'ss': ss, 'fs': fs, 'rx': rx, 'ry': ry, 'rz': rz, 'intensity': it,
return pd.DataFrame(
arr.T, columns=['ss', 'fs', 'rx', 'ry', 'rz', 'intensity']
......@@ -53,11 +50,9 @@ def find_peaks_single_panel(cnp.ndarray[cnp.npy_float, ndim=2] data, str geom_fi
crystfel.beam_params beam
crystfel.image image
void* bad_px_mask
image.dp[0] = <float*>
bad_px_mask = malloc(data.size * sizeof(int))
image.bad = <int**>&bad_px_mask
image.bad = NULL
image.det = crystfel.get_detector_geometry(os.fsencode(geom_file), &beam)
print(f"Loaded geometry with {image.det.n_panels} panels")
......@@ -68,6 +63,7 @@ def find_peaks_single_panel(cnp.ndarray[cnp.npy_float, ndim=2] data, str geom_fi
max_pix_count=200, local_bg_radius=3, min_res=0, max_res=1200,
print("Done peak search")
return featurelist_to_dataframe(image.features)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment