Skip to content
Snippets Groups Projects
Commit 78547b5a authored by Florian Lauck's avatar Florian Lauck
Browse files

Fix return type in peakfinder

parent ea3a8b48
No related branches found
No related tags found
No related merge requests found
......@@ -18,20 +18,31 @@ Peakfinder8 algorithm for detection of Bragg peaks in detector frame data.
"""
import sys
from typing import Type, List, Union
from collections import namedtuple
from typing import Union
import h5py # type: ignore
import numpy # type: ignore
from mypy_extensions import TypedDict
from .lib import peakfinder_8
PeakList = namedtuple("PeakList", ["num_peaks", "fs", "ss", "intensity"])
"""
Information about Bragg peaks found in a detector data frame (list of peaks).
Arguments:
TypePeakList = TypedDict(
"TypePeakList",
{"num_peaks": int, "fs": List[float], "ss": List[float], "intensity": List[float]},
total=True,
)
num_peaks(int): number of peaks that were detected in the data frame.
fs (List[float]): a list of fractional fs indexes locating the detected peaks
in the detector data frame.
ss (List[float]): a list of fractional ss indexes locating the detected peaks
in the detector data frame.
intensity (List[float]): a list of integrated intensities for the detected
peaks.
"""
class Peakfinder8PeakDetection:
......@@ -167,7 +178,7 @@ class Peakfinder8PeakDetection:
else:
self._mask = None
def find_peaks(self, data: numpy.ndarray) -> TypePeakList:
def find_peaks(self, data: numpy.ndarray) -> PeakList:
"""
Finds peaks in a detector data frame.
......@@ -181,19 +192,19 @@ class Peakfinder8PeakDetection:
Returns:
TypePeakList: a dictionary with information about the Bragg peaks
detected in a data frame. The dictionary has the following keys:
PeakList: a namedtuple with information about the Bragg peaks
detected in a data frame. The object has the following attributes:
- A key named "num_peaks" whose value is the number of peaks that were
- An attribute named "num_peaks" whose value is the number of peaks that were
detected in the data frame.
- A key named 'fs' whose value is a list of fractional fs indexes locating
- An attribute named 'fs' whose value is a list of fractional fs indexes locating
the detected peaks in the data frame.
- A key named 'ss' whose value is a list of fractional ss indexes locating
- An attribute named 'ss' whose value is a list of fractional ss indexes locating
the detected peaks in the data frame.
- A key named 'intensity' whose value is a list of integrated intensities
- An attribute named 'intensity' whose value is a list of integrated intensities
for the detected peaks.
"""
if not self._mask_initialized:
......@@ -223,9 +234,9 @@ class Peakfinder8PeakDetection:
self._local_bg_radius,
)
return {
"num_peaks": len(peak_list[0]),
"fs": peak_list[0],
"ss": peak_list[1],
"intensity": peak_list[2],
}
return PeakList(
num_peaks=len(peak_list[0]),
fs=peak_list[0],
ss=peak_list[1],
intensity=peak_list[2],
)
......@@ -16,7 +16,7 @@
import numpy
import pytest
from cfelpyutils.geometry import compute_pix_maps, load_crystfel_geometry
from cfelpyutils.geometry import compute_pix_maps
from cfelpyutils.peakfinding.peakfinder8 import Peakfinder8PeakDetection
from tests.fixtures import detector_geometry
......@@ -82,7 +82,7 @@ class TestPeakfinder8PeakDetection:
def test_find_peak(self, peakfinder_config, detector_image_with_4_peaks):
peakfinder = Peakfinder8PeakDetection(**peakfinder_config)
peak_list = peakfinder.find_peaks(detector_image_with_4_peaks)
assert peak_list["num_peaks"] == 4
assert len(peak_list["intensity"]) == 4
assert len(peak_list["fs"]) == 4
assert len(peak_list["ss"]) == 4
assert peak_list.num_peaks == 4
assert len(peak_list.intensity) == 4
assert len(peak_list.fs) == 4
assert len(peak_list.ss) == 4
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