psalgos documentation¶
Class pypsalgos
provides access to C++ algorithms from python.
Usage:
# IMPORT MISC
# ===========
import numpy as np
from pyimgalgos.GlobalUtils import print_ndarr
# INPUT PARAMETERS
# ================
shape = (32,185,388) # e.g.
ave, rms = 200, 25
data = np.array(ave + rms*np.random.standard_normal(shape), dtype=np.double)
mask = np.ones(shape, dtype=np.uint16)
#mask = det.mask() # see class Detector.PyDetector
#mask = np.loadtxt(fname_mask) #
# 2-D IMAGE using cython object directly
# ======================================
import psalgos
alg = psalgos.peak_finder_algos(seg=0, pbits=0)
alg.set_peak_selection_parameters(npix_min=1, npix_max=None, amax_thr=0, atot_thr=0, son_min=6)
peaks = alg.peak_finder_v3r3_d2(data, mask, rank=5, r0=7, dr=2, nsigm=5)
peaks = alg.peak_finder_v4r3_d2(data, mask, thr_low=20, thr_high=50, rank=5, r0=7, dr=2)
peaks = alg.list_of_peaks_selected()
peaks_all = alg.list_of_peaks()
p = algo.peak(0)
p = algo.peak_selected(0)
for p in peaks : print ' row:%4d, col:%4d, npix:%4d, son::%4.1f' % (p.row, p.col, p.npix, p.son)
for p in peaks : print p.parameters()
map_u2 = alg.local_maxima()
map_u2 = alg.local_minima()
map_u4 = alg.connected_pixels()
import psalgos.pypsalgos as algos
n = algos.local_minima_2d(data, mask, rank, extrema) # 0.019(sec) for shape=(1000, 1000) on psanaphi110
n = algos.local_maxima_2d(data, mask, rank, extrema) # 0.019(sec)
n = algos.local_maxima_rank1_cross_2d(data, mask, extrema) # 0.014(sec)
n = algos.threshold_maxima_2d(data, mask, rank, thr_low, thr_high, extrema) # 0.0017(sec)
# DIRECT CALL PEAKFINDERS
# =======================
from psalgos.pypsalgos import peaks_adaptive, peaks_droplet, peaks_adaptive_2d, peaks_droplet_2d
# data and mask are 2-d numpy arrays of the same shape
peaks = peaks_adaptive_2d(data, mask, rank=5, r0=7.0, dr=2.0, nsigm=5, seg=0, npix_min=1, npix_max=None, amax_thr=0, atot_thr=0, son_min=8)
peaks = peaks_droplet_2d(data, mask=None, thr_low, thr_high, rank=5, r0=7.0, dr=2.0, seg=0, npix_min=1, npix_max=None, amax_thr=0, atot_thr=0, son_min=8)
# data and mask are N-d numpy arrays or list of 2-d numpy arrays of the same shape
peaks = peaks_adaptive(data, mask, rank=5, r0=7.0, dr=2.0, nsigm=3, npix_min=1, npix_max=None, amax_thr=0, atot_thr=0, son_min=8)
# data and mask are N-d numpy arrays or list of 2-d numpy arrays of the same shape
peaks = peaks_droplet(data, mask=None, thr_low, thr_high, rank=5, r0=7.0, dr=2.0, npix_min=1, npix_max=None, amax_thr=0, atot_thr=0, son_min=8)
# convert peaks (list of peak objects) to somethong else:
from psalgos.pypsalgos import list_of_peak_parameters, numpy_2d_arr_of_peak_parameters
lst_peak_pars = list_of_peak_parameters(peaks) # returns list of tuples, where tuple consists of float peak parameters
arr_peak_pars = numpy_2d_arr_of_peak_parameters(peaks) # returns 2d numpy array of float peak parameters
# Backward compatability support for ImgAlgos.PyAlgos
# ===================================================
# import:
from psalgos.pypsalgos import PyAlgos # replacement for: from ImgAlgos.PyAlgos import PyAlgos
# create object:
alg = PyAlgos(mask=mask, pbits=0)
# set peak-selector parameters:
alg.set_peak_selection_pars(npix_min=1, npix_max=5000, amax_thr=0, atot_thr=0, son_min=8)
# call peakfinders ATTENTION TO REVISION NUMBER: use r3 in stead of r2
# v3 stands for "ranker" a.k.a. "adaptive", r3 stands for revision
peaks = alg.peak_finder_v3r3(nda, rank=2, r0=7.0, dr=2.0, nsigm=0) #, mask=...
# v4 stands for "droplet" a.k.a. "two threshold", r3 stands for revision
peaks = alg.peak_finder_v4r3(nda, thr_low=10, thr_high=50, rank=5, r0=7.0, dr=2.0) #, mask=...
# OPTIONAL for backward compatability
# set mask
alg.set_mask(mask)
# set parameters for S/N evaluation algorithm
alg.set_son_pars(r0=7, dr=2)
# print info
alg.print_attributes() # mask, r0, dr, peak selection parameters
Created: 2017-08-10 by Mikhail Dubrovin
-
class
pypsalgos.
PyAlgos
(windows=None, mask=None, pbits=0)[source]¶ Backward compatability support for ImgAlgos.PyAlgos.
-
__init__
(windows=None, mask=None, pbits=0)[source]¶ Costructor
Parameters: - windows (numpy.array) – is not used.
- mask (numpy.array) – of the same shape as data or None.
- pbits (uint) – level of verbosity bitword: NONE=0, DEBUG=1, INFO=2, WARNING=4, ERROR=8, CRITICAL=16
-
peak_finder_v3r3
(data, rank=5, r0=7, dr=2, nsigm=5, mask=None)[source]¶ Runs “ranker” peakfinder and returns the list of peak parameters.
Parameters: - data (np.array) – n-d numpy array or list of 2-d numpy arrays of data
- rank (int) – radial size or the region [row-rank:row+rank, col-rank:col+rank] where central pixel is a local maximum
- r0 (float) – radius [in pixels] of the ring for background evaluation
- dr (float) – width [in pixels] of the ring for background evaluation
- nsigm (float) – threshold on intensity to include pixel in connected group in terms of number of sigma (rms) estimated for pixels in the ring defined by r0 and dr
- mask (np.array) – mask uint16 shaped as data
Returns: np.array peaks: 2-d numpy.array of float peak parameters; each row contains (seg, row, col, npix, amp_max, amp_tot, row_cgrav, col_cgrav, row_sigma, col_sigma, row_min, row_max, col_min, col_max, bkgd, noise, son)
Rtype numpy.array: ndim=2, dtype=float
-
peak_finder_v4r3
(data, thr_low=20, thr_high=50, rank=5, r0=7, dr=2, mask=None)[source]¶ Runs “droplet-finder” and returns the list of peak parameters.
Parameters: - data (np.array) – n-d numpy array or list of 2-d numpy arrays of data
- thr_low (float) – low threshold [ADU] - used to include pixel in connected group and select pixels to estimate rms and mean in the ring
- thr_high (float) – high threshold [ADU] - used to search for local maxima candidate
- rank (int) – radial size or the region [row-rank, row+rank] where central pixel is a local maximum
- r0 (float) – radius [in pixels] of the ring for background evaluation
- dr (float) – width [in pixels] of the ring for background evaluation
- mask (np.array) – mask uint16 shaped as data
Returns: np.array peaks: 2-d numpy.array of float peak parameters; each row contains (seg, row, col, npix, amp_max, amp_tot, row_cgrav, col_cgrav, row_sigma, col_sigma, row_min, row_max, col_min, col_max, bkgd, noise, son)
Rtype numpy.array: ndim=2, dtype=float - array of peak parameters.
-
-
pypsalgos.
list_of_peak_parameters
(peaks)[source]¶ Converts list of peak objects to the (old style) list of peak parameters.
-
pypsalgos.
local_maxima_1d
(data, mask=None, rank=3, extrema=None)[source]¶ Finds local maxima of specified rank in 1-d array of data with mask and returns results in array extrema.
-
pypsalgos.
local_maxima_2d
(data, mask=None, rank=3, extrema=None)[source]¶ Finds local maxima of specified rank in 2-d array of data with mask and returns results in array extrema.
-
pypsalgos.
local_maxima_rank1_cross_2d
(data, mask=None, extrema=None)[source]¶ Finds local maxima rank=1 cross in 2-d array of data with mask and returns results in array extrema.
-
pypsalgos.
local_minima_1d
(data, mask=None, rank=3, extrema=None)[source]¶ Finds local minima of specified rank in 1-d array of data with mask and returns results in array extrema.
-
pypsalgos.
local_minima_2d
(data, mask=None, rank=3, extrema=None)[source]¶ Finds local minima of specified rank in 2-d array of data with mask and returns results in array extrema.
-
pypsalgos.
numpy_2d_arr_of_peak_parameters
(peaks)[source]¶ Converts list of peak objects to the (old style) numpy array of peak parameters.
-
pypsalgos.
peaks_adaptive
(data, mask, rank=5, r0=7.0, dr=2.0, nsigm=5, npix_min=1, npix_max=None, amax_thr=0, atot_thr=0, son_min=8)[source]¶ Wrapper for liast of 2-d arrays or >2-d arrays data and mask are N-d numpy arrays or list of 2-d numpy arrays of the same shape
-
pypsalgos.
peaks_adaptive_2d
(data, mask=None, rank=5, r0=7.0, dr=2.0, nsigm=5, seg=0, npix_min=1, npix_max=None, amax_thr=0, atot_thr=0, son_min=8)[source]¶ Peak finder for 2-d numpy arrays of data and mask of the same shape
-
pypsalgos.
peaks_droplet
(data, mask, thr_low, thr_high, rank=5, r0=7.0, dr=2.0, npix_min=1, npix_max=None, amax_thr=0, atot_thr=0, son_min=8)[source]¶ Wrapper for liast of 2-d arrays or >2-d arrays data and mask are N-d numpy arrays or list of 2-d numpy arrays of the same shape
-
pypsalgos.
peaks_droplet_2d
(data, mask=None, thr_low=None, thr_high=None, rank=5, r0=7.0, dr=2.0, seg=0, npix_min=1, npix_max=None, amax_thr=0, atot_thr=0, son_min=8)[source]¶ peak finder for 2-d numpy arrays of data and mask of the same shape
-
pypsalgos.
print_matrix_of_diag_indexes
(rank=5)[source]¶ Prints matrix of diagonal indexes for local_maxima_2d and local_minima_2d algorithms.
-
pypsalgos.
print_vector_of_diag_indexes
(rank=5)[source]¶ Prints vector of diagonal indexes for local_maxima_2d and local_minima_2d algorithms.
-
pypsalgos.
shape_as_2d
(sh)[source]¶ Returns 2-d shape for n-d shape if n>2, otherwise returns unchanged shape.
-
pypsalgos.
shape_as_3d
(sh)[source]¶ Returns 3-d shape for n-d shape if n>3, otherwise returns unchanged shape.
-
pypsalgos.
threshold_maxima_2d
(data, mask=None, rank=3, thr_low=None, thr_high=None, extrema=None)[source]¶ Finds local maxima using 2-threshold algorithm in 2-d array of data with mask and returns results in array extrema.