Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Thomas Kluyver
Pycrystfel
Commits
8d6b8417
Commit
8d6b8417
authored
Jan 11, 2021
by
Thomas Kluyver
Browse files
Add Detector class
parent
888f5284
Changes
2
Hide whitespace changes
Inline
Side-by-side
examples/inspect_geom_class.py
0 → 100644
View file @
8d6b8417
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
}
"
)
pycrystfel/bindings.pyx
View file @
8d6b8417
...
...
@@ -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
):
cdef
:
crystfel
.
beam_params
beam
...
...
@@ -67,3 +65,40 @@ def find_peaks_single_panel(cnp.ndarray[cnp.npy_float, ndim=2] data, str geom_fi
crystfel
.
free_detector_geometry
(
image
.
det
)
return
featurelist_to_dataframe
(
image
.
features
)
# Pointer wrapper machinery based on Cython docs:
# https://cython.readthedocs.io/en/latest/src/userguide/extension_types.html#instantiation-from-existing-c-c-pointers
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
:
free
(
self
.
_ptr
)
self
.
_ptr
=
NULL
@
staticmethod
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
@
classmethod
def
from_filename
(
cls
,
path
):
return
Detector
.
from_ptr
(
crystfel
.
get_detector_geometry
(
os
.
fsencode
(
path
),
NULL
),
owner
=
True
)
@
property
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
)]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment