ImageD11.sinograms.properties module#
- ImageD11.sinograms.properties.compute_storage(peaks)#
make the cumulative sums of peaks to figure out storage space holds the row, npks, nii, nij
- ImageD11.sinograms.properties.countse(se)#
counts the points in a block of start/end
- ImageD11.sinograms.properties.find_ND_labels(i, j, npks, verbose=1)#
- ImageD11.sinograms.properties.get_clean_labels(labels)#
Given the labelling in l, put clean labels in the place.
l = integer array with value = label of lowest 2d peak in this ND group.
- ImageD11.sinograms.properties.get_start_end(n, p)#
For splitting up the scan row over processes n = number of jobs p = number of processes
All processes must do at least two rows to get the overlaps between rows. The work sharing is based on these overlaps.
rows : 0 1 2 3 4 5 etc. overlap 01 12 23 34 45
- ImageD11.sinograms.properties.goforit(ds, sparsename, options)#
- dsfilename = ImageD11.sinograms.dataset FILE
This is how processes all get omega data
sparsename = pixels to read options
- ImageD11.sinograms.properties.main(dsfilename, sparsefile=None, pksfile=None, options={})#
dsname = ImageD11.sinograms.dataset file sparsename = File containing sparse pixels (None = use dsname.sparsefile) pkname = File to receive output peaks (None = use dsname.pksfile)
options : dictionary of options, to override
- ImageD11.sinograms.properties.n_pk2d(s1, sI, srI, scI, frm, omega, dty)#
- ImageD11.sinograms.properties.numbalabelNd(i, j, pkid, flip=0)#
i, j are the pairs of overlapping peaks pkid are the current labels of the peaks
- This scans all pairs and for each pair it makes
pkid[i] = pkid[j] = min(pkid[i], pkid[j])
Run this enough times and eventually all peaks point back to the first one they overlap.
Using parallel seems dodgy to me. Might be a race condition, but it seems like the code is legal so long as only these addresses are touched?
- ImageD11.sinograms.properties.numbapkmerge(labels, pks, omega, dty, out, scale_factor=None, omega_wraps=False)#
for N 2D peaks: labels: spot3(4)d_id label of each 2D peak pks: pk_props: (5, N) array of (s1, sI, srI, scI, frm) for each 2D peak omega, dty, scale_factor: arrays of shape ds.shape (sinogram shape) - indexed by frm omega_wraps: the scan turns more than once, so omega is an angle mod 360 and
a peak can have contributions at 1 and 359 degrees. With it set, out[4] holds the running weighted mean angle instead of the weighted sum, updated in the form of Welford’s online mean:
mean += (w / W) * (o - mean) W = sum of the weights so far
(B. P. Welford, Technometrics 4(3) 419-420, 1962; Knuth, The Art of Computer Programming Vol 2, 3rd ed, p.232.) Welford’s reason is numerical; ours is structural: the update needs the difference o - mean, so that difference can be taken the short way round the circle, and the running mean itself is the reference the unwrapping is measured against. dty is a translation and is never treated as an angle. A cluster spanning more than 180 degrees has no mean angle; nothing here detects that.
- ImageD11.sinograms.properties.pairrow(s, row)#
s = SparseScan
- returns SparseScan which adds a dictionary of pairs:
sourceFrame destFrame
- [ idty, iomega, idty, iomega ]nedge, array( (nedge, 3) )
(src, dest, npixels)
- ImageD11.sinograms.properties.pairscans(s1, s2, omegatol=0.051)#
- class ImageD11.sinograms.properties.pks_table(npk=None, ipk=None, pk_props=None, rc=None, rpk=None, glabel=None, nlabel=0, use_shm=False)#
Bases:
object- create(npk)#
- export()#
- find_uniq(outputfile=None, use_scipy=False)#
find the unique labels from the rc array
- classmethod fromSHM(dct)#
- guesschunk(ar, m=2560)#
- classmethod load(h5name, h5group='pks2d')#
- pk2d(omega, dty, scale_factor=None)#
scale_factor: provide scale_factor with same shape as omega/dty
- pk2dmerge(omega, dty, scale_factor=None, omega_wraps=False, omega0=0.0)#
creates a dictionary of the 3D peaks scale_factor: provide scale_factor with same shape as omega/dty omega_wraps: average omega on the circle rather than linearly. Set this
when the scan turns more than once, so that the same peak is seen at 1 and 361 degrees and omega has been folded into 0-360. See numbapkmerge. dty is a translation and is never treated this way.
- omega0: the low edge of the range to fold the result into, i.e.
ds.obinedges[0]. The running mean itself can land anywhere, depending on which contribution happened to seed it, so without this the same peak’s omega could come out order-dependent, one full turn away from where its own frames are (obinedges[0] is usually not 0: see guessbins/bin_phase). Only used when omega_wraps; ignored otherwise. Default 0.0 folds into [0, 360), matching the plain omega % 360 this replaces.
- save(h5name, group='pks2d', rc=False)#
puts the array into shared memory returns the shared copy
- ImageD11.sinograms.properties.pks_table_from_scan(sparsefilename, ds, row, algorithm='lmlabel', wtmax=None)#
Labels one rotation scan to a peaks table
sparsefilename = sparse pixels file dataset = ImageD11.sinograms.dataset row = index for dataset.scan[ row ]
- returns a pks_table.
You might want to call one of “save” or “pk2d” or “pk2dmerge” on the result
This is probably not threadsafe
- ImageD11.sinograms.properties.process(qin, qshm, qout, hname, dsfilename, options)#
- Worker process.
qin : gives a block of scans from qin to label (start, end) qshm : gives us the (ipk, rpk) pointers into the parent’s table qout : numbers of overlaps, then (row, pk_props, rc) for each row hname = sparse pixels dsfilename = load omega options (passed through)
- ImageD11.sinograms.properties.props(scan, i, algorithm='lmlabel', wtmax=None)#
scan = sparseframe.SparseScan object i = sinogram row id : used for tagging pairs algorithm = ‘lmlabel’ | ‘cplabel’
Labels the peaks with lmlabel Assumes a regular scan for labelling frames returns ( row, properties[(s1,sI,sRow,sCol,frame),:], pairs, scan )
- ImageD11.sinograms.properties.remove_shm_from_resource_tracker()#
Bases:
objectSee: https://bugs.python.org/issue38119 The multiprocessing pool must stick around until the process exits
- ImageD11.sinograms.properties.testit(NPROC)#
sanity check
- class ImageD11.sinograms.properties.tictoc#
Bases:
object