Commit 2b97afc2 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Convert Crystfel feature list to pandas Dataframe

parent 6196b0aa
......@@ -9,4 +9,7 @@ f = h5py.File(os.path.join(THIS_DIR, 'monolithic_img_1.h5'), 'r')
arr = f['data/data'][()]
print("Image shape:", arr.shape)
find_peaks_single_panel(arr, os.path.join(THIS_DIR, '1panel.geom'))
peaks_tbl = find_peaks_single_panel(arr, os.path.join(THIS_DIR, '1panel.geom'))
print(f"Found {len(peaks_tbl)} peaks")
import os
import numpy as np
import pandas as pd
from libc.stdint cimport uintptr_t
cimport cython
from libc.stdlib cimport malloc, free
cimport numpy as cnp
......@@ -19,6 +20,35 @@ def inspect_geom_file(path):
print("photon energy:", beam.photon_energy)
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
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)
with cython.boundscheck(False), cython.wraparound(False):
for i in range(nfeat):
feat = crystfel.image_get_feature(flist, i)
ss[i] =
fs[i] = feat.fs
rx[i] = feat.rx
ry[i] = feat.ry
rz[i] = feat.rz
it[i] = feat.intensity
return pd.DataFrame({
'ss': ss, 'fs': fs, 'rx': rx, 'ry': ry, 'rz': rz, 'intensity': it,
def find_peaks_single_panel(cnp.ndarray[cnp.npy_float, ndim=2] data, str geom_file):
crystfel.beam_params beam
......@@ -40,9 +70,4 @@ def find_peaks_single_panel(cnp.ndarray[cnp.npy_float, ndim=2] data, str geom_fi
print("Done peak search")
npeaks = crystfel.image_feature_count(image.features)
print(f"Found {npeaks} peaks")
for i in range(min(10, npeaks)):
peak = crystfel.image_get_feature(image.features, i)
print(f"Peak {i}: ({}, {peak.fs})\t Intensity={peak.intensity}")
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