Commit 8d6b8417 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Add Detector class

parent 888f5284
import sys
from pycrystfel.bindings import Detector
det = Detector.from_filename(sys.argv[1])
print(f"{det.n_panels} panels:")
for name in det.panel_names:
print(f"- {name}")
......@@ -44,8 +44,6 @@ cdef featurelist_to_dataframe(crystfel.ImageFeatureList *flist):
arr.T, columns=['ss', 'fs', 'rx', 'ry', 'rz', 'intensity']
def find_peaks_single_panel(cnp.ndarray[cnp.npy_float, ndim=2] data, str geom_file):
crystfel.beam_params beam
......@@ -67,3 +65,40 @@ def find_peaks_single_panel(cnp.ndarray[cnp.npy_float, ndim=2] data, str geom_fi
return featurelist_to_dataframe(image.features)
# Pointer wrapper machinery based on Cython docs:
cdef class Detector:
cdef crystfel.detector* _ptr
cdef bint ptr_owner
def __cinit__(self):
self.ptr_owner = False
def __dealloc__(self):
# De-allocate if not null and flag is set
if self._ptr is not NULL and self.ptr_owner is True:
self._ptr = NULL
cdef Detector from_ptr(crystfel.detector* _ptr, bint owner=False):
# Call to __new__ bypasses __init__ constructor
cdef Detector det = Detector.__new__(Detector)
det._ptr = _ptr
det.ptr_owner = owner
return det
def from_filename(cls, path):
return Detector.from_ptr(
crystfel.get_detector_geometry(os.fsencode(path), NULL), owner=True
def n_panels(self):
return self._ptr.n_panels if self._ptr is not NULL else 0
def panel_names(self):
return [self._ptr.panels[i].name for i in range(self.n_panels)]
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