ImageD11.sparseframe module#

class ImageD11.sparseframe.SparseScan(hname, scan, start=0, n=None, names=('row', 'col', 'intensity'), omeganames=['measurement/rot_center', 'measurement/rot', 'measurement/diffrz_center', 'measurement/diffrz'], dtynames=['measurement/dty_center', 'measurement/dty', 'measurement/diffty_center', 'measurement/diffty'])#

Bases: object

cplabel(threshold=0, countall=True)#

Label pixels using the connectedpixels assigment code Fills in:

self.nlabels = number of peaks per frame self.labels = peak labels (should be unique) self.total_labels = total number of peaks

if countall == Truelabels all peaks from zero

== False : labels from 1 on each frame

property frame_id#

returns the frame ID of each pixel

getframe(i)#
lmlabel(threshold=0, countall=True, smooth=True)#

Label pixels using the localmax assigment code Fills in:

self.nlabels = number of peaks per frame self.labels = peak labels (should be unique) self.total_labels = total number of peaks

if countall == Truelabels all peaks from zero

== False : labels from 1 on each frame

moments()#

Computes the center of mass in s/f/omega

to_dense(out=None)#

returns a dense image stack

ImageD11.sparseframe.from_data_cut(data, cut, header={}, detectormask=None)#
ImageD11.sparseframe.from_data_mask(mask, data, header)#

Create a sparse from a dense array

ImageD11.sparseframe.from_hdf_group(group)#
ImageD11.sparseframe.nnz_to_pointer(nnz, out=None)#

nnz = number of pixels per frame pointer = position in a single flat array

ImageD11.sparseframe.overlaps(frame1, labels1, frame2, labels2)#

figures out which label of self matches which label of other Assumes the zero label does not exist (background) Returns sparse array of: label in self (row) label in other (col) number of shared pixels (data)

class ImageD11.sparseframe.overlaps_linear(nnzmax=16384)#

Bases: object

Memory caching object for the linear time algorithm to find peak overlaps

Given (row1, col1, label1) and (row2, col2, label2) it finds pixels where (row[i] == row2[i]) and (col1[i] == col2[i]) and returns (labels1[i], labels2[i], sum_pixels[i]) … so the number of overlapping pixels for that pair of labels

realloc()#
class ImageD11.sparseframe.overlaps_matrix(npkmax=256)#

Bases: object

Memory caching object for the quadratic time algorithm to find peak overlaps

Given (row1, col1, label1) and (row2, col2, label2) it finds pixels where (row[i] == row2[i]) and (col1[i] == col2[i]) and returns (labels1[i], labels2[i], sum_pixels[i]) … so the number of overlapping pixels for that pair of labels

This is easier to understand and faster for small number of peaks per frame

realloc()#
ImageD11.sparseframe.sparse_connected_pixels(frame, label_name='connectedpixels', data_name='intensity', threshold=None)#

frame = a sparse frame label_name = the array to save labels to in that frame data_name = an array in that frame threshold = float value or take data.threshold

class ImageD11.sparseframe.sparse_frame(row, col, shape, itype=<class 'numpy.uint16'>, pixels=None)#

Bases: object

Indices / shape mapping

This was developed for a single 2D frame

See SparseScan below for something aiming towards many frames

is_sorted()#

Tests whether the data are sorted into slow/fast order rows are slow direction columns are fast

mask(msk)#

returns a subset of itself

reorder(order)#

Put the pixels into a different order (in place)

set_pixels(name, values, meta=None)#

Named arrays sharing these labels

sort()#

Puts you into slow / fast looping order

sort_by(name)#

Not sure when you would do this. For sorting by a peak labelling to get pixels per peak

threshold(threshold, name='intensity')#

returns a new sparse frame with pixels > threshold

to_dense(data=None, out=None)#

returns the full 2D image data = name in self.pixels or 1D array matching self.nnz Does not handle repeated indices e.g. obj.to_dense( obj.pixels[‘raw_intensity’] )

to_hdf_group(group)#

Save a 2D sparse frame to a hdf group Makes 1 single frame per group

ImageD11.sparseframe.sparse_localmax(frame, label_name='localmax', data_name='intensity', smooth=False)#

smooth=True applies the same cImageD11.sparse_smooth pre-filter that SparseScan.lmlabel already applies before localmax labelling. Default is False to keep existing behaviour/output unchanged.

ImageD11.sparseframe.sparse_moments(frame, intensity_name, labels_name)#

We rely on a labelling array carrying nlabel metadata (==labels.data.max())

ImageD11.sparseframe.sparse_smooth(frame, data_name='intensity')#