Peakfinder
A set of peak-finding algorithms developed for analysis of data from LCLS pixel array detectors.
Interface
from ... import peakfinder peaks = peakfinder(*args, **kwargs) peaks = peakfinder(mode, data, mask=mask, **kwargs)
Input
arguments:
mode : str -
selects the algorithm of the "seed" peak definition:
'Droplet'
- uses keyword arguments
and peak selection parametersthr
_low, thr_high
, rank
, r0
, dr
,
'Ranker'
- uses keyword arguments
and peak selection parameters
nsigm,rank
, r0
, dr
,
data :
2-d numpy.array
- data for processing
n-d numpy.array
- (n>2) a set of 2-d arrays of data for processing. Last two indexes are used as 2-d row and column
[2-d numpy.array
] - list of 2-d arrays of data for processing
keyword arguments for peak finding:
mask : numpy.array(shape,dtype=np.uint16) | None
- expected the same structure as data
- pixel mask with 0/1 for bad/good pixel
rank : int -
radial size of the region (2*rank+1 rows and columns) around pixel for peak finding
thr
_low : float
- low threshold on pixel intensity for 'Droplet'
finder
thr_high
: float
- high threshold on pixel intensity for 'Droplet'
finder
r0 : float
- internal radius of the ring for evaluation of background and noise rms
dr : float
- width of the ring for evaluation of background and noise rms
nsigm : float -
threshold in number of noise rms
keyword arguments for peak selection:
npix_min
: int-
minimal number of pixels in the peak
npix_max
: int
- maximal number of pixels in the peak
amax_thr
- threshold on pixel with maximal intensity : float
atot_thr
: float
- threshold on total peak intensity
son_min
: float
- threshold on S/N value
Output
peaks
:
list
of peak
objects, where peak
is a container of attributes.
peak attributes:
seg : int
- 2-d segment index beginning from 0, e.g. in CSPAD this index should be in the range from 0 to 31row : int
- row (beginning from 0) of the pixel with maximal intensitycol : int
- column (beginning from 0) of the pixel with maximal intensitynpix : int
- number of pixels accounted in the peakamp_max : float
- maximal intensity among peak pixelsamp_total : float
- total intensity of all pixels accounted in the peakrow_cgrav : float
- row coordinate of the peak evaluated as a "center of gravity" over pixels accounted in the peak using their intensities as weightscol_cgrav : float
- column coordinate of the peak evaluated as a "center of gravity" over pixels accounted in the peak using their intensities as weightsraw_sigma : float
- row coordinate spread rms evaluated in the "center of gravity" algorithmcol_sigma : float
- column coordinate spread rms evaluated in the "center of gravity" algorithmrow_min : int
- minimal row of the pixel group accounted in the peakrow_max : int
- maximal row of the pixel group accounted in the peakcol_min : int
- minimal column of the pixel group accounted in the peakcol_max : int
- maximal column of the pixel group accounted in the peakbkgd : float
- background averaged level estimated for pixels in the ring region (parameters
) around peak centerr0
, dr
noise : float
- r.m.s. of the background estimated for pixels in the ring region (parameters
) around peak centerr0
, dr
son : float
- signal over noise ratio estimated for pixels in the ring region (parameters
) around peak centerr0
, dr
pixinds : list
- list of peak index tuple (seg, row, col
) for pixels accounted in the peak
Peak-finding algorithms
Method peakfinder is a wrapper around a few algorithms. First argument mode
switches between different peak-finding algorithms. Each algorithm works in a few stages. First stage is a search for peak candidates or "seed" peaks and this is a most distinctive part between algorithms:
- Droplet - or droplet-finder is a two-threshold algorithm searching for a group of connected pixels with intensity above
thr
_low
around central pixel with group-maximal intensity exceedingthr_high
in the region restricted by the radial parameterrank
. In the loop over all pixels each pixel with intensity grater or equalthr_high
is considered as a peak candidate. For each candidate recursive algorithm is launched and searches for a group of connected pixels with intensity grater or equalthr
_low
in the square region (2*rank+1
pixels in rows and columns). Pixels of the group are marked as busy on 2-d map. Pixel-candidate should have maximal intensity in the group of connected pixels, otherwise recursion is terminated and all group pixels released for further search. Two neighbor pixels with intensity abovethr
_low
and having common boarder are assumed connected. Pixels having a single common vertex are assumed disconnected. - Ranker - searches peak candidate among local pixel intensity maximums of specified
rank
.
in the square region of specified radial parameterrank
(2*rank+1
pixels in rows and columns). Group of connected pixels abovensigm
threshold in the rank restricted region is used to form the peak.
Other stages of all algorithms are about the same.
- background mean value
bkgd
andnoise
are estimated using pixels in the ring with internal radiusr0
and widthdr,
- returned values of
amp_max
andamp_total
are background corrected, - signal over noise
son
is evaluated asamp_total
/noise
, - output list of peaks is generated from the list of seed peaks using selection parameters.