Compiled code#
ImageD11 uses two sister packages for its compiled code. Their docstrings are repeated here for convenience. These pages are built from the versions on PyPI when the documentation was built, which may differ from the version you have installed.
c2ImageD11#
ImageD11.cImageD11 imports everything from c2ImageD11. Full
documentation: https://fable-3dxrd.github.io/c2ImageD11/
c2ImageD11 - compiled C extensions for ImageD11, built with c2py23.
- Provides:
All C functions re-exported from the arch-named .so
Blob property constants (s_1, s_I, NPROPERTY, etc.)
Allocation wrappers for f2py-compatible tuple returns
__version__
- c2ImageD11.array_histogram(img: buffer, low: float, high: float, hist: buffer) void
computes the histogram for an image Go through the data to compute a histogram of the values
- Previous call of array_stats would help to set up this call
compare to np.bincount - this does not gain much better implementations can be done
img[] Input data array (1D or 2D.ravel(), so sparse or dense) npx length of data array (contiguous) low Lower edge of first bin high Upper edge of last bin hist[] Histogram to be output nhist Number of bins in the histogram
- Parameters:
img (buffer) – Type: float32 (format ‘f’)
low (float)
high (float)
hist (buffer) – Writable
Checks
img.format == 'f' [ValueError] (hist.format == 'i' or hist.format == 'l') [ValueError]
Overloads
void array_histogram(const float *img, intptr_t npx, float low, float high, int32_t *hist, intptr_t nhist) Map: img = img.ptr (const float *) npx = img.n (intptr_t) low = low (float) high = high (float) hist = hist.ptr (int32_t *) nhist = hist.n (intptr_t)
- c2ImageD11.array_mean_var_cut(img: buffer, n: int = 3, cut: float = 3.0, verbose: int = 0) void
computes the mean and variance of an image with pixels above the value mean+cut*stddev removed. This is iterated n times as the mean and variance change as pixels are removed.
- Parameters:
img (buffer) – Type: float32 (format ‘f’)
n (int)
cut (float)
verbose (int)
Checks
img.format == 'f' [ValueError]
Overloads
void array_mean_var_cut(const float *img, intptr_t npx, float *mean, float *std, int n, float cut, int verbose) Map: img = img.ptr (const float *) npx = img.n (intptr_t) n = n (int) cut = cut (float) verbose = verbose (int) Outputs: mean (float), std (float)
- c2ImageD11.array_mean_var_msk(img: buffer, msk: buffer, n: int = 3, cut: float = 3.0, verbose: int = 0) void
computes the mean and variance of an image with pixels above the value mean+cut*stddev removed. This is iterated n times as the mean and variance change as pixels are removed.
- Parameters:
img (buffer) – Type: float32 (format ‘f’)
msk (buffer) – Writable Size must equal img
n (int)
cut (float)
verbose (int)
Checks
img.format == 'f' [ValueError] (msk.format == 'B' or msk.format == 'b') [ValueError] msk.n == img.n [ValueError]
Overloads
void array_mean_var_msk(const float *img, uint8_t *msk, intptr_t npx, float *mean, float *std, int n, float cut, int verbose) Map: img = img.ptr (const float *) msk = msk.ptr (uint8_t *) npx = img.n (intptr_t) n = n (int) cut = cut (float) verbose = verbose (int) Outputs: mean (float), std (float)
- c2ImageD11.array_stats(img: buffer) void
- computes statistics for an image.
img Input data array (1D or 2D.ravel(), so sparse or dense)
npx length of data array (contiguous) *minval minimum of the pixels *maxval maximum of the pixels s1 Sum of all pixel s2 Sum of pixel^2
- Parameters:
img (buffer) – Type: float32 (format ‘f’)
Checks
img.format == 'f' [ValueError]
Overloads
void array_stats(const float *img, intptr_t npx, float *minval, float *maxval, float *mean, float *var) Map: img = img.ptr (const float *) npx = img.n (intptr_t) Outputs: maxval (float), mean (float), minval (float), var (float)
- c2ImageD11.bgcalc(img: buffer, bg: buffer, msk: buffer, gain: float, sp: float, st: float) void
computes a background on a 1d signal where gain and sp and st are defined by:
diff = difference to neighbors or bg estimate sigmap = weight for abs background value sigmat = constant weight gain for b += diff * gain
img - source data bg - computed background msk - mask
- Parameters:
img (buffer) – Type: float32 (format ‘f’) Shape: 2D
bg (buffer) – Type: float32 (format ‘f’) Writable Size must equal img
msk (buffer) – Writable Size must equal img
gain (float)
sp (float)
st (float)
Checks
img.format == 'f' [ValueError] img.ndim == 2 [ValueError] img.slow_axis == 0 [ValueError] bg.format == 'f' [ValueError] bg.n == img.n [ValueError] (msk.format == 'B' or msk.format == 'b') [ValueError] msk.n == img.n [ValueError]
Overloads
void bgcalc(const float *img, float *bg, uint8_t *msk, intptr_t ns, intptr_t nf, float gain, float sigmap, float sigmat) Map: img = img.ptr (const float *) bg = bg.ptr (float *) msk = msk.ptr (uint8_t *) ns = img.shape[0] (intptr_t) nf = img.shape[1] (intptr_t) gain = gain (float) sigmap = sp (float) sigmat = st (float)
- c2ImageD11.blob_moments(results: buffer) void
fills in the reduced moments in results array. … FIXME - this would be clearer in python, fast anyway.
- Parameters:
results (buffer) – Type: float64 (format ‘d’) Writable Shape: 2D Axis 1: 36 elements I/O array (np, 36). Raw moments in, reduced out.
Checks
results.format == 'd' [ValueError] results.ndim == 2 [ValueError] results.shape[1] == 36 [ValueError]
Overloads
void blob_moments(double *res, intptr_t np) Map: res = results.ptr (double *) np = results.shape[0] (intptr_t)
- c2ImageD11.bloboverlaps(labels1: buffer, npk1: int, results1: buffer, labels2: buffer, npk2: int, results2: buffer, verbose: int = 0) int
determines the overlaps between labels1 and labels2 for an image series. Peaks in labels2 may be merged if they were joined by a peak on labels1. Results in results1 are accumulated into results2 if peaks are overlapped.
- Parameters:
labels1 (buffer) – Writable Shape: 2D First frame labels (int32 2D).
npk1 (int) – Objects in first frame.
results1 (buffer) – Type: float64 (format ‘d’) Writable Axis 1: 36 elements First frame properties.
labels2 (buffer) – Writable Size must equal labels1 Second frame labels.
npk2 (int) – Objects in second frame.
results2 (buffer) – Type: float64 (format ‘d’) Writable Axis 1: 36 elements Second frame properties.
verbose (int) – Print diagnostics.
Checks
(labels1.format == 'i' or labels1.format == 'l') [ValueError] labels1.ndim == 2 [ValueError] (labels2.format == 'i' or labels2.format == 'l') [ValueError] labels2.n == labels1.n [ValueError] results1.format == 'd' [ValueError] results1.shape[0] == npk1 [ValueError] results1.shape[1] == 36 [ValueError] results2.format == 'd' [ValueError] results2.shape[0] == npk2 [ValueError] results2.shape[1] == 36 [ValueError]
Overloads
int bloboverlaps(int32_t *b1, int32_t n1, double *res1, int32_t *b2, int32_t n2, double *res2, int verbose, intptr_t ns, intptr_t nf) -> int Map: b1 = labels1.ptr (int32_t *) n1 = npk1 (int32_t) res1 = results1.ptr (double *) b2 = labels2.ptr (int32_t *) n2 = npk2 (int32_t) res2 = results2.ptr (double *) verbose = verbose (int) ns = labels1.shape[0] (intptr_t) nf = labels1.shape[1] (intptr_t)
- c2ImageD11.blobproperties(data, labels, npk, omega=0.0, verbose=0)
Allocate results and call C blobproperties, matching f2py convention.
- c2ImageD11.check_multiprocessing(patch=False)
Warn about fork+threads interaction with OpenMP.
You cannot safely use os.fork together with threads. But the cImageD11 codes uses threads via openmp, and you are importing them. So please use forkserver or spawn for multiprocessing.
- c2ImageD11.cimaged11_omp_get_max_threads() int
Return the maximum number of OpenMP threads available.
Overloads
int cimaged11_omp_get_max_threads()
- c2ImageD11.cimaged11_omp_get_min_ng() int
Return the minimum number of g-vectors before the score family parallelizes with OpenMP.
Overloads
int cimaged11_omp_get_min_ng()
- c2ImageD11.cimaged11_omp_set_min_ng(n: int) void
Set the minimum number of g-vectors before the score family parallelizes with OpenMP. Negative values are clamped to 0.
- Parameters:
n (int) – Minimum ng. Pass 0 to always parallelize (with >1 thread);
single-threaded. (pass a huge value to force)
Overloads
void cimaged11_omp_set_min_ng(int n) Map: n = n (int)
- c2ImageD11.cimaged11_omp_set_num_threads(n: int) void
Sets the openmp number of threads to use. Change if you use multiprocessing or do not like os.environ[‘OMP_NUM_THREADS’] see also: multiprocessing.cpu_count(), see also os.cpu_count() see docs/sphx/parallel.rst
- Parameters:
n (int) – Number of OpenMP threads. Pass 1 for single-threaded execution.
Overloads
void cimaged11_omp_set_num_threads(int n) Map: n = n (int)
- c2ImageD11.clean_mask(msk: buffer, ret: buffer) int
removes pixels which are not 4 connected from msk while copying into ret.
- Parameters:
msk (buffer) – Shape: 2D Input int8 2D mask.
ret (buffer) – Writable Size must equal msk Output cleaned int8 mask.
Checks
(msk.format == 'b' or msk.format == 'B') [ValueError] msk.ndim == 2 [ValueError] msk.slow_axis == 0 [ValueError] (ret.format == 'b' or ret.format == 'B') [ValueError] ret.n == msk.n [ValueError]
Overloads
int clean_mask(const int8_t *msk, int8_t *ret, intptr_t ns, intptr_t nf) -> int Map: msk = msk.ptr (const int8_t *) ret = ret.ptr (int8_t *) ns = msk.shape[0] (intptr_t) nf = msk.shape[1] (intptr_t)
- c2ImageD11.closest(x: buffer, v: buffer) void
finds the value and index in x closest to a value in v. e.g. x = cosine of angles between pairs of peaks
v = idealised values based on hkl geometry
ibest set to the x[i] matching to a v[j] with diff “best”
- Parameters:
x (buffer) – Type: float64 (format ‘d’) Array of candidate values to search (e.g. ideal cosines from hkl geometry).
v (buffer) – Type: float64 (format ‘d’) Array of values to search for (e.g. experimental cosines).
Checks
x.format == 'd' [ValueError] v.format == 'd' [ValueError]
Overloads
void closest(const double *x, const double *v, int *ribest, double *rbest, intptr_t nx, intptr_t nv) Standard O(nx*nv) scan-find-closest. Map: x = x.ptr (const double *) v = v.ptr (const double *) nx = x.n (intptr_t) nv = v.n (intptr_t) Outputs: rbest (double), ribest (int)
- c2ImageD11.closest_vec(x: buffer, ic: buffer) void
finds the closest neighbors for each row of X ignoring the self. Treated as a X=[v1,v2,v3,…], computes sum{(vi-vj)**2} for all i!=j and places minimum in ic.
- Parameters:
x (buffer) – Type: float64 (format ‘d’) Shape: 2D 2D array of feature vectors, shape (nv, dim). Each row is a vector.
ic (buffer) – Writable Output array of shape (nv,). For each row i, ic[i] = index j of the nearest neighbor (j != i).
Checks
x.format == 'd' [ValueError] x.ndim == 2 [ValueError] x.shape[1] >= 1 [ValueError] (ic.format == 'i' or ic.format == 'l') [ValueError] ic.n == x.shape[0] [ValueError]
Overloads
void closest_vec(const double *x, intptr_t dim, intptr_t nv, int *ic) Map: x = x.ptr (const double *) dim = x.shape[1] (intptr_t) nv = x.shape[0] (intptr_t) ic = ic.ptr (int *)
- c2ImageD11.cluster1d(ar: buffer, order: buffer, tol: float, ids: buffer, avgs: buffer) void
is used in sandbox/friedel.py to find clusters of peaks work in progress
- Parameters:
ar (buffer) – Type: float64 (format ‘d’) Array of values to cluster.
order (buffer) – Size must equal ar Permutation that sorts ar ascending.
tol (float) – Distance tolerance for cluster membership.
ids (buffer) – Writable Size must equal ar Output: cluster id for each element.
avgs (buffer) – Type: float64 (format ‘d’) Writable Size must equal ar Output: average value of each cluster.
Checks
ar.format == 'd' [ValueError] (order.format == 'i' or order.format == 'l') [ValueError] order.n == ar.n [ValueError] (ids.format == 'i' or ids.format == 'l') [ValueError] ids.n == ar.n [ValueError] avgs.format == 'd' [ValueError] avgs.n == ar.n [ValueError]
Overloads
void cluster1d(const double *ar, intptr_t n, const int *order, double tol, int *nclusters, int *ids, double *avgs) Map: ar = ar.ptr (const double *) n = ar.n (intptr_t) order = order.ptr (const int *) tol = tol (double) ids = ids.ptr (int *) avgs = avgs.ptr (double *) Outputs: nclusters (int)
- c2ImageD11.compress_duplicates(i: buffer, j: buffer, oi: buffer, oj: buffer, tmp: buffer) int
removes duplicate i,j labels. On entry then i and j are set as the labels from two images. They are sorted and on exit i,j hold the unique pairs and oi holds the count for the number of overlaps. oj and tmp are temporaries.
- Parameters:
i (buffer) – Writable I/O int32 col 0.
j (buffer) – Writable Size must equal i I/O int32 col 1.
oi (buffer) – Writable Size must equal i Output counts.
oj (buffer) – Writable Size must equal i Temp.
tmp (buffer) – Writable Temp.
Checks
(i.format == 'i' or i.format == 'l') [ValueError] (j.format == 'i' or j.format == 'l') [ValueError] j.n == i.n [ValueError] (oi.format == 'i' or oi.format == 'l') [ValueError] oi.n == i.n [ValueError] (oj.format == 'i' or oj.format == 'l') [ValueError] oj.n == i.n [ValueError] (tmp.format == 'i' or tmp.format == 'l') [ValueError]
Overloads
int compress_duplicates(int *i, int *j, int *oi, int *oj, int *tmp, intptr_t n, intptr_t nt) -> int Map: i = i.ptr (int *) j = j.ptr (int *) oi = oi.ptr (int *) oj = oj.ptr (int *) tmp = tmp.ptr (int *) n = i.n (intptr_t) nt = tmp.n (intptr_t)
- c2ImageD11.compute_geometry(xlylzl: buffer, omega: buffer, omegasign: float, wvln: float, wedge: float, chi: float, t: buffer, out: buffer) void
is for the “updateGeometry” method of columnfiles from xlylzl it will compute tth, eta, ds, gve into out in the laboratory in xlylzl[npks], the omega rotation[npks], and the rest of the parameters (wedge,wvln,chi,t[3] and omegasign) out should contain : (tth, eta, ds, gx, gy, gz)
- Parameters:
xlylzl (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Shape: 2D Spot positions in lab frame, (n,3) AoS or (3,n) SoA.
omega (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Omega rotation per spot (radians), shape (n,).
omegasign (float) – Omega rotation sign (+1 or -1).
wvln (float) – Wavelength (angstroms).
wedge (float) – Wedge angle (detector tilt, radians).
chi (float) – Chi angle (radians).
t (buffer) – Axis 0: 3 elements Translation vector (3 elements).
out (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Writable Shape: 2D Output (n,6) AoS or (6,n) SoA: tth, eta, ds, gx, gy, gz.
Checks
xlylzl.ndim == 2 [ValueError] t.n == 3 [ValueError] out.ndim == 2 [ValueError] xlylzl.slow_axis == 0 [ValueError] omega.slow_axis == 0 [ValueError] t.slow_axis == 0 [ValueError] t.shape[0] == 3 [ValueError] out.slow_axis == 0 [ValueError] GIL: released
Overloads
void compute_geometry(const double xlylzl[], const double omega[], double omegasign, double wvln, double wedge, double chi, const double t[3], double out[], intptr_t n) (When: ((((xlylzl.format == 'd' and omega.format == 'd') and out.format == 'd') and xlylzl.shape[1] == 3) and xlylzl.slow_axis == 0)) Map: xlylzl = xlylzl.ptr (const double *) omega = omega.ptr (const double *) omegasign = omegasign (double) wvln = wvln (double) wedge = wedge (double) chi = chi (double) t = t.ptr (const double *) out = out.ptr (double *) n = xlylzl.shape[0] (intptr_t) void compute_geometry_f32(const float xlylzl[], const float omega[], double omegasign, double wvln, double wedge, double chi, const float t[3], float out[], intptr_t n) (When: ((((xlylzl.format == 'f' and omega.format == 'f') and out.format == 'f') and xlylzl.shape[1] == 3) and xlylzl.slow_axis == 0)) Map: xlylzl = xlylzl.ptr (const float *) omega = omega.ptr (const float *) omegasign = omegasign (double) wvln = wvln (double) wedge = wedge (double) chi = chi (double) t = t.ptr (const float *) out = out.ptr (float *) n = xlylzl.shape[0] (intptr_t) void compute_geometry_soa_f64(const double xlylzl[], const double omega[], double omegasign, double wvln, double wedge, double chi, const double t[3], double out[], intptr_t n) (When: (((((xlylzl.format == 'd' and omega.format == 'd') and out.format == 'd') and xlylzl.shape[0] == 3) and xlylzl.slow_axis == 0) and xlylzl.shape[1] != 3)) Map: xlylzl = xlylzl.ptr (const double *) omega = omega.ptr (const double *) omegasign = omegasign (double) wvln = wvln (double) wedge = wedge (double) chi = chi (double) t = t.ptr (const double *) out = out.ptr (double *) n = xlylzl.shape[1] (intptr_t) void compute_geometry_soa_f32(const float xlylzl[], const float omega[], double omegasign, double wvln, double wedge, double chi, const float t[3], float out[], intptr_t n) (When: (((((xlylzl.format == 'f' and omega.format == 'f') and out.format == 'f') and xlylzl.shape[0] == 3) and xlylzl.slow_axis == 0) and xlylzl.shape[1] != 3)) Map: xlylzl = xlylzl.ptr (const float *) omega = omega.ptr (const float *) omegasign = omegasign (double) wvln = wvln (double) wedge = wedge (double) chi = chi (double) t = t.ptr (const float *) out = out.ptr (float *) n = xlylzl.shape[1] (intptr_t)
- c2ImageD11.compute_geometry_soa(xl: buffer, yl: buffer, zl: buffer, omega: buffer, omegasign: float, wvln: float, wedge: float, chi: float, t: buffer, tth: buffer, eta: buffer, ds: buffer, gx: buffer, gy: buffer, gz: buffer) void
- Parameters:
xl (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’)
yl (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’)
zl (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’)
omega (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’)
omegasign (float)
wvln (float)
wedge (float)
chi (float)
t (buffer) – Axis 0: 3 elements
tth (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Writable
eta (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Writable
ds (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Writable
gx (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Writable
gy (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Writable
gz (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Writable
Checks
xl.slow_axis == 0 [ValueError] yl.slow_axis == 0 [ValueError] zl.slow_axis == 0 [ValueError] omega.slow_axis == 0 [ValueError] t.slow_axis == 0 [ValueError] t.shape[0] == 3 [ValueError] tth.slow_axis == 0 [ValueError] eta.slow_axis == 0 [ValueError] ds.slow_axis == 0 [ValueError] gx.slow_axis == 0 [ValueError] gy.slow_axis == 0 [ValueError] gz.slow_axis == 0 [ValueError]
Overloads
void compute_geometry_soa_split_f64(const double xl[], const double yl[], const double zl[], const double omega[], double omegasign, double wvln, double wedge, double chi, const double t[3], double tth[], double eta[], double ds[], double gx[], double gy[], double gz[], intptr_t n) (When: ((((((((((((((((((xl.format == 'd' and yl.format == 'd') and zl.format == 'd') and omega.format == 'd') and tth.format == 'd') and eta.format == 'd') and ds.format == 'd') and gx.format == 'd') and gy.format == 'd') and gz.format == 'd') and xl.n == yl.n) and yl.n == zl.n) and zl.n == omega.n) and omega.n == tth.n) and tth.n == eta.n) and eta.n == ds.n) and ds.n == gx.n) and gx.n == gy.n) and gy.n == gz.n)) Map: xl = xl.ptr (const double *) yl = yl.ptr (const double *) zl = zl.ptr (const double *) omega = omega.ptr (const double *) omegasign = omegasign (double) wvln = wvln (double) wedge = wedge (double) chi = chi (double) t = t.ptr (const double *) tth = tth.ptr (double *) eta = eta.ptr (double *) ds = ds.ptr (double *) gx = gx.ptr (double *) gy = gy.ptr (double *) gz = gz.ptr (double *) n = xl.n (intptr_t) void compute_geometry_soa_split_f32(const float xl[], const float yl[], const float zl[], const float omega[], double omegasign, double wvln, double wedge, double chi, const float t[3], float tth[], float eta[], float ds[], float gx[], float gy[], float gz[], intptr_t n) (When: ((((((((((((((((((xl.format == 'f' and yl.format == 'f') and zl.format == 'f') and omega.format == 'f') and tth.format == 'f') and eta.format == 'f') and ds.format == 'f') and gx.format == 'f') and gy.format == 'f') and gz.format == 'f') and xl.n == yl.n) and yl.n == zl.n) and zl.n == omega.n) and omega.n == tth.n) and tth.n == eta.n) and eta.n == ds.n) and ds.n == gx.n) and gx.n == gy.n) and gy.n == gz.n)) Map: xl = xl.ptr (const float *) yl = yl.ptr (const float *) zl = zl.ptr (const float *) omega = omega.ptr (const float *) omegasign = omegasign (double) wvln = wvln (double) wedge = wedge (double) chi = chi (double) t = t.ptr (const float *) tth = tth.ptr (float *) eta = eta.ptr (float *) ds = ds.ptr (float *) gx = gx.ptr (float *) gy = gy.ptr (float *) gz = gz.ptr (float *) n = xl.n (intptr_t)
- c2ImageD11.compute_gv(xlylzl: buffer, omega: buffer, omegasign: float, wvln: float, wedge: float, chi: float, t: buffer, gv: buffer) void
computes scattering vectors given thr positions of the spot in the laboratory in xlylzl[npks], the omega rotation[npks], and the rest of the parameters (wedge,wvln,chi,t[3] and omegasign)
- Parameters:
xlylzl (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Shape: 2D Spot positions in lab frame, (n,3) AoS or (3,n) SoA.
omega (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Omega rotation per spot (radians), shape (n,).
omegasign (float) – Omega rotation sign.
wvln (float) – Wavelength (angstroms).
wedge (float) – Wedge angle (radians).
chi (float) – Chi angle (radians).
t (buffer) – Axis 0: 3 elements Translation vector (3 elements).
gv (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Writable Shape: 2D Output g-vectors, (n,3) AoS or (3,n) SoA.
Checks
xlylzl.ndim == 2 [ValueError] t.n == 3 [ValueError] gv.ndim == 2 [ValueError] xlylzl.slow_axis == 0 [ValueError] omega.slow_axis == 0 [ValueError] t.slow_axis == 0 [ValueError] t.shape[0] == 3 [ValueError] gv.slow_axis == 0 [ValueError] GIL: released
Overloads
void compute_gv(const double xlylzl[], const double omega[], double omegasign, double wvln, double wedge, double chi, const double t[3], double gv[], intptr_t n) (When: ((((xlylzl.format == 'd' and omega.format == 'd') and gv.format == 'd') and xlylzl.shape[1] == 3) and xlylzl.slow_axis == 0)) Map: xlylzl = xlylzl.ptr (const double *) omega = omega.ptr (const double *) omegasign = omegasign (double) wvln = wvln (double) wedge = wedge (double) chi = chi (double) t = t.ptr (const double *) gv = gv.ptr (double *) n = xlylzl.shape[0] (intptr_t) void compute_gv_f32(const float xlylzl[], const float omega[], double omegasign, double wvln, double wedge, double chi, const float t[3], float gv[], intptr_t n) (When: ((((xlylzl.format == 'f' and omega.format == 'f') and gv.format == 'f') and xlylzl.shape[1] == 3) and xlylzl.slow_axis == 0)) Map: xlylzl = xlylzl.ptr (const float *) omega = omega.ptr (const float *) omegasign = omegasign (double) wvln = wvln (double) wedge = wedge (double) chi = chi (double) t = t.ptr (const float *) gv = gv.ptr (float *) n = xlylzl.shape[0] (intptr_t) void compute_gv_soa_f64(const double xlylzl[], const double omega[], double omegasign, double wvln, double wedge, double chi, const double t[3], double gv[], intptr_t n) (When: (((((xlylzl.format == 'd' and omega.format == 'd') and gv.format == 'd') and xlylzl.shape[0] == 3) and xlylzl.slow_axis == 0) and xlylzl.shape[1] != 3)) Map: xlylzl = xlylzl.ptr (const double *) omega = omega.ptr (const double *) omegasign = omegasign (double) wvln = wvln (double) wedge = wedge (double) chi = chi (double) t = t.ptr (const double *) gv = gv.ptr (double *) n = xlylzl.shape[1] (intptr_t) void compute_gv_soa_f32(const float xlylzl[], const float omega[], double omegasign, double wvln, double wedge, double chi, const float t[3], float gv[], intptr_t n) (When: (((((xlylzl.format == 'f' and omega.format == 'f') and gv.format == 'f') and xlylzl.shape[0] == 3) and xlylzl.slow_axis == 0) and xlylzl.shape[1] != 3)) Map: xlylzl = xlylzl.ptr (const float *) omega = omega.ptr (const float *) omegasign = omegasign (double) wvln = wvln (double) wedge = wedge (double) chi = chi (double) t = t.ptr (const float *) gv = gv.ptr (float *) n = xlylzl.shape[1] (intptr_t)
- c2ImageD11.compute_gv_soa(xl: buffer, yl: buffer, zl: buffer, omega: buffer, omegasign: float, wvln: float, wedge: float, chi: float, t: buffer, gx: buffer, gy: buffer, gz: buffer) void
- Parameters:
xl (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’)
yl (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’)
zl (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’)
omega (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’)
omegasign (float)
wvln (float)
wedge (float)
chi (float)
t (buffer) – Axis 0: 3 elements
gx (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Writable
gy (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Writable
gz (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Writable
Checks
xl.slow_axis == 0 [ValueError] yl.slow_axis == 0 [ValueError] zl.slow_axis == 0 [ValueError] omega.slow_axis == 0 [ValueError] t.slow_axis == 0 [ValueError] t.shape[0] == 3 [ValueError] gx.slow_axis == 0 [ValueError] gy.slow_axis == 0 [ValueError] gz.slow_axis == 0 [ValueError]
Overloads
void compute_gv_soa_split_f64(const double xl[], const double yl[], const double zl[], const double omega[], double omegasign, double wvln, double wedge, double chi, const double t[3], double gx[], double gy[], double gz[], intptr_t n) (When: ((((((((((((xl.format == 'd' and yl.format == 'd') and zl.format == 'd') and omega.format == 'd') and gx.format == 'd') and gy.format == 'd') and gz.format == 'd') and xl.n == yl.n) and yl.n == zl.n) and zl.n == omega.n) and omega.n == gx.n) and gx.n == gy.n) and gy.n == gz.n)) Map: xl = xl.ptr (const double *) yl = yl.ptr (const double *) zl = zl.ptr (const double *) omega = omega.ptr (const double *) omegasign = omegasign (double) wvln = wvln (double) wedge = wedge (double) chi = chi (double) t = t.ptr (const double *) gx = gx.ptr (double *) gy = gy.ptr (double *) gz = gz.ptr (double *) n = xl.n (intptr_t) void compute_gv_soa_split_f32(const float xl[], const float yl[], const float zl[], const float omega[], double omegasign, double wvln, double wedge, double chi, const float t[3], float gx[], float gy[], float gz[], intptr_t n) (When: ((((((((((((xl.format == 'f' and yl.format == 'f') and zl.format == 'f') and omega.format == 'f') and gx.format == 'f') and gy.format == 'f') and gz.format == 'f') and xl.n == yl.n) and yl.n == zl.n) and zl.n == omega.n) and omega.n == gx.n) and gx.n == gy.n) and gy.n == gz.n)) Map: xl = xl.ptr (const float *) yl = yl.ptr (const float *) zl = zl.ptr (const float *) omega = omega.ptr (const float *) omegasign = omegasign (double) wvln = wvln (double) wedge = wedge (double) chi = chi (double) t = t.ptr (const float *) gx = gx.ptr (float *) gy = gy.ptr (float *) gz = gz.ptr (float *) n = xl.n (intptr_t)
- c2ImageD11.compute_xlylzl(s: buffer, f: buffer, p: buffer, r: buffer, dist: buffer, xlylzl: buffer) void
compute_xlylzl finds spot positions in the laboratory frame using packed parameters.
- Parameters:
s (buffer) – Type: float64 (format ‘d’) Slow-scan pixel positions (double).
f (buffer) – Type: float64 (format ‘d’) Size must equal s Fast-scan pixel positions (double, same size as s).
p (buffer) – Type: float64 (format ‘d’) Axis 0: 4 elements Detector params (4): [s_cen, f_cen, s_size, f_size].
r (buffer) – Type: float64 (format ‘d’) Axis 0: 9 elements Rotation matrix (9): det(rotation)*flip.
dist (buffer) – Type: float64 (format ‘d’) Axis 0: 3 elements Detector distance (3): [dx, dy, dz].
xlylzl (buffer) – Type: float64 (format ‘d’) Writable Shape: 2D Axis 1: 3 elements Output spot positions (n, 3).
Checks
s.format == 'd' [ValueError] f.format == 'd' [ValueError] f.n == s.n [ValueError] p.format == 'd' [ValueError] p.n == 4 [ValueError] r.format == 'd' [ValueError] r.n == 9 [ValueError] dist.format == 'd' [ValueError] dist.n == 3 [ValueError] xlylzl.format == 'd' [ValueError] xlylzl.ndim >= 1 [ValueError] s.slow_axis == 0 [ValueError] f.slow_axis == 0 [ValueError] p.slow_axis == 0 [ValueError] p.shape[0] == 4 [ValueError] r.slow_axis == 0 [ValueError] r.shape[0] == 9 [ValueError] dist.slow_axis == 0 [ValueError] dist.shape[0] == 3 [ValueError] xlylzl.slow_axis == 0 [ValueError] xlylzl.ndim == 2 [ValueError] xlylzl.shape[1] == 3 [ValueError] GIL: released
Overloads
void compute_xlylzl(const double s[], const double f[], const double p[4], const double r[9], const double dist[3], double xlylzl[][3], intptr_t n) (When: ((s.format == 'd' and f.format == 'd') and xlylzl.format == 'd')) Map: s = s.ptr (const double *) f = f.ptr (const double *) p = p.ptr (const double *) r = r.ptr (const double *) dist = dist.ptr (const double *) xlylzl = xlylzl.ptr (double (*)[3]) n = s.n (intptr_t)
- c2ImageD11.compute_xlylzl_xpos_variable(s: buffer, f: buffer, p: buffer, r: buffer, dist: buffer, xpos: buffer, xlylzl: buffer) void
finds spot positions in the laboratory frame like compute_xlylzl but with an extra per-spot x-offset xpos s = slow pixel position f = fast pixel position p = [s_cen, f_cen, s_size, f_size] r[9] = dot( transform.detector_rotation_matrix, flipmatrix ) dist = [distancex, distancey, distancez] xpos = extra x-offset per spot, same length as s,f
- Parameters:
s (buffer) – Type: float64 (format ‘d’) Slow-scan pixel positions (double).
f (buffer) – Type: float64 (format ‘d’) Size must equal s Fast-scan pixel positions (double).
p (buffer) – Type: float64 (format ‘d’) Axis 0: 4 elements Detector params (4).
r (buffer) – Type: float64 (format ‘d’) Axis 0: 9 elements Rotation matrix (9).
dist (buffer) – Type: float64 (format ‘d’) Axis 0: 3 elements Detector distance (3).
xpos (buffer) – Type: float64 (format ‘d’) Size must equal s Per-spot x-axis offset (double, same size as s).
xlylzl (buffer) – Type: float64 (format ‘d’) Writable Shape: 2D Axis 1: 3 elements Output spot positions.
Checks
s.format == 'd' [ValueError] f.format == 'd' [ValueError] f.n == s.n [ValueError] p.format == 'd' [ValueError] p.n == 4 [ValueError] r.format == 'd' [ValueError] r.n == 9 [ValueError] dist.format == 'd' [ValueError] dist.n == 3 [ValueError] xpos.format == 'd' [ValueError] xpos.n == s.n [ValueError] xlylzl.format == 'd' [ValueError] xlylzl.ndim >= 1 [ValueError] s.slow_axis == 0 [ValueError] f.slow_axis == 0 [ValueError] p.slow_axis == 0 [ValueError] p.shape[0] == 4 [ValueError] r.slow_axis == 0 [ValueError] r.shape[0] == 9 [ValueError] dist.slow_axis == 0 [ValueError] dist.shape[0] == 3 [ValueError] xpos.slow_axis == 0 [ValueError] xlylzl.slow_axis == 0 [ValueError] xlylzl.ndim == 2 [ValueError] xlylzl.shape[1] == 3 [ValueError] GIL: released
Overloads
void compute_xlylzl_xpos_variable(const double s[], const double f[], const double p[4], const double r[9], const double dist[3], const double xpos[], double xlylzl[][3], intptr_t n) (When: ((s.format == 'd' and f.format == 'd') and xlylzl.format == 'd')) Map: s = s.ptr (const double *) f = f.ptr (const double *) p = p.ptr (const double *) r = r.ptr (const double *) dist = dist.ptr (const double *) xpos = xpos.ptr (const double *) xlylzl = xlylzl.ptr (double (*)[3]) n = s.n (intptr_t)
- c2ImageD11.connectedpixels(data: buffer, labels: buffer, threshold: float, verbose: int = 0, con8: int = 1) int
Determines which pixels in data are above the user supplied threshold and assigns them into connected objects which are output in labels. Connectivity is 3x3 box (8) by default and reduces to a +(4) is con8==0
- Parameters:
data (buffer) – Type: uint8 (format ‘B’) or uint16 (format ‘H’) or uint32 (format ‘I’) or ? (format ‘L’) or float32 (format ‘f’) Shape: 2D Input float32 2D.
labels (buffer) – Writable Size must equal data Output int32 labels.
threshold (float) – Threshold.
verbose (int) – Print diagnostics.
con8 (int) – 8-connected (1) or 4-connected (0).
Checks
data.ndim == 2 [ValueError] data.slow_axis == 0 [ValueError] (labels.format == 'i' or labels.format == 'l') [ValueError] labels.n == data.n [ValueError]
Overloads
int connectedpixels_u32(const uint32_t *data, int32_t *labels, double threshold, int verbose, int eightconnected, intptr_t ns, intptr_t nf) -> int (When: ((((data.format == 'I' or data.format == 'L') and data.itemsize == 4) and data.ndim == 2) and data.slow_axis == 0)) Map: data = data.ptr (const uint32_t *) labels = labels.ptr (int32_t *) threshold = threshold (double) verbose = verbose (int) eightconnected = con8 (int) ns = data.shape[0] (intptr_t) nf = data.shape[1] (intptr_t) int connectedpixels_u16(const uint16_t *data, int32_t *labels, double threshold, int verbose, int eightconnected, intptr_t ns, intptr_t nf) -> int (When: ((data.format == 'H' and data.ndim == 2) and data.slow_axis == 0)) Map: data = data.ptr (const uint16_t *) labels = labels.ptr (int32_t *) threshold = threshold (double) verbose = verbose (int) eightconnected = con8 (int) ns = data.shape[0] (intptr_t) nf = data.shape[1] (intptr_t) int connectedpixels_u8(const uint8_t *data, int32_t *labels, double threshold, int verbose, int eightconnected, intptr_t ns, intptr_t nf) -> int (When: ((data.format == 'B' and data.ndim == 2) and data.slow_axis == 0)) Map: data = data.ptr (const uint8_t *) labels = labels.ptr (int32_t *) threshold = threshold (double) verbose = verbose (int) eightconnected = con8 (int) ns = data.shape[0] (intptr_t) nf = data.shape[1] (intptr_t) int connectedpixels(const float *data, int32_t *labels, double threshold, int verbose, int eightconnected, intptr_t ns, intptr_t nf) -> int (When: ((data.format == 'f' and data.ndim == 2) and data.slow_axis == 0)) Map: data = data.ptr (const float *) labels = labels.ptr (int32_t *) threshold = threshold (double) verbose = verbose (int) eightconnected = con8 (int) ns = data.shape[0] (intptr_t) nf = data.shape[1] (intptr_t)
- c2ImageD11.count_shared(pi: buffer, pj: buffer) int
takes two sorted arrays in pi and pj and counts how many collisions there are. Useful to compare two lists of peak to grain assignments, or pixel to peak assignments, etc
- Parameters:
pi (buffer) – First sorted array of integer labels.
pj (buffer) – Second sorted array of integer labels.
Checks
(pi.format == 'i' or pi.format == 'l') [ValueError] (pj.format == 'i' or pj.format == 'l') [ValueError]
Overloads
int count_shared(const int *pi, intptr_t ni, const int *pj, intptr_t nj) -> int Map: pi = pi.ptr (const int *) ni = pi.n (intptr_t) pj = pj.ptr (const int *) nj = pj.n (intptr_t)
- c2ImageD11.coverlaps(row1: buffer, col1: buffer, labels1: buffer, row2: buffer, col2: buffer, labels2: buffer, mat: buffer, results: buffer) int
Determine overlapping labels between two sparse frames.
- Parameters:
row1 (buffer) – Rows 1 (uint16).
col1 (buffer) – Size must equal row1 Cols 1 (uint16).
labels1 (buffer) – Size must equal row1 Labels 1 (int32).
row2 (buffer) – Rows 2 (uint16).
col2 (buffer) – Size must equal row2 Cols 2 (uint16).
labels2 (buffer) – Size must equal row2 Labels 2 (int32).
mat (buffer) – Writable Shape: 2D Output overlap matrix (int32).
results (buffer) – Writable Output triples (int32).
Checks
row1.slow_axis == 0 [ValueError] (row1.format == 'H' or row1.itemsize == 2) [ValueError] (col1.format == 'H' or col1.itemsize == 2) [ValueError] col1.n == row1.n [ValueError] (labels1.format == 'i' or labels1.format == 'l') [ValueError] labels1.n == row1.n [ValueError] (row2.format == 'H' or row2.itemsize == 2) [ValueError] (col2.format == 'H' or col2.itemsize == 2) [ValueError] col2.n == row2.n [ValueError] (labels2.format == 'i' or labels2.format == 'l') [ValueError] labels2.n == row2.n [ValueError] (mat.format == 'i' or mat.format == 'l') [ValueError] mat.ndim == 2 [ValueError] (results.format == 'i' or results.format == 'l') [ValueError]
Overloads
int coverlaps(const uint16_t *row1, const uint16_t *col1, const int *labels1, intptr_t nnz1, const uint16_t *row2, const uint16_t *col2, const int *labels2, intptr_t nnz2, int *mat, intptr_t npk1, intptr_t npk2, int *results) -> int Map: row1 = row1.ptr (const uint16_t *) col1 = col1.ptr (const uint16_t *) labels1 = labels1.ptr (const int *) nnz1 = row1.n (intptr_t) row2 = row2.ptr (const uint16_t *) col2 = col2.ptr (const uint16_t *) labels2 = labels2.ptr (const int *) nnz2 = row2.n (intptr_t) mat = mat.ptr (int *) npk1 = mat.shape[0] (intptr_t) npk2 = mat.shape[1] (intptr_t) results = results.ptr (int *)
- c2ImageD11.frelon_lines(img: buffer, cut: float) void
Subtract per-row baseline using quiet pixels (value < cut).
- Parameters:
img (buffer) – Type: float32 (format ‘f’) Writable Shape: 2D
cut (float)
Checks
img.format == 'f' [ValueError] img.ndim == 2 [ValueError]
Overloads
void frelon_lines(float *img, intptr_t ns, intptr_t nf, float cut) Map: img = img.ptr (float *) ns = img.shape[0] (intptr_t) nf = img.shape[1] (intptr_t) cut = cut (float)
- c2ImageD11.frelon_lines_sub(img: buffer, drk: buffer, cut: float) void
Dark subtract then per-row baseline removal.
- Parameters:
img (buffer) – Type: float32 (format ‘f’) Writable Shape: 2D
drk (buffer) – Type: float32 (format ‘f’) Size must equal img
cut (float)
Checks
img.format == 'f' [ValueError] img.ndim == 2 [ValueError] img.slow_axis == 0 [ValueError] drk.format == 'f' [ValueError] drk.n == img.n [ValueError]
Overloads
void frelon_lines_sub(float *img, const float *drk, intptr_t ns, intptr_t nf, float cut) Map: img = img.ptr (float *) drk = drk.ptr (const float *) ns = img.shape[0] (intptr_t) nf = img.shape[1] (intptr_t) cut = cut (float)
- c2ImageD11.localmaxlabel(data: buffer, labels: buffer, wrk: buffer) int
assigns a label for each pixel so they are grouped to the local maximum. Equal values choose to assign towards the earlier value in memory. cpu arg (1)0=C, (1)1=SSE2, (1)2=AVX2; if > 9 prints timing
- Parameters:
data (buffer) – Type: uint8 (format ‘B’) or uint16 (format ‘H’) or uint32 (format ‘I’) or ? (format ‘L’) or float32 (format ‘f’) Shape: 2D Input float32 2D.
labels (buffer) – Writable Size must equal data Output int32 labels.
wrk (buffer) – Writable Size must equal data Temp uint8 workspace.
Checks
data.ndim == 2 [ValueError] data.slow_axis == 0 [ValueError] (labels.format == 'i' or labels.format == 'l') [ValueError] labels.n == data.n [ValueError] (wrk.format == 'B' or wrk.format == 'b') [ValueError] wrk.n == data.n [ValueError]
Overloads
int localmaxlabel_u32(const uint32_t *im, int32_t *lout, uint8_t *l, intptr_t dim0, intptr_t dim1) -> int (When: ((((data.format == 'I' or data.format == 'L') and data.itemsize == 4) and data.ndim == 2) and data.slow_axis == 0)) Map: im = data.ptr (const uint32_t *) lout = labels.ptr (int32_t *) l = wrk.ptr (uint8_t *) dim0 = data.shape[0] (intptr_t) dim1 = data.shape[1] (intptr_t) int localmaxlabel_u16(const uint16_t *im, int32_t *lout, uint8_t *l, intptr_t dim0, intptr_t dim1) -> int (When: ((data.format == 'H' and data.ndim == 2) and data.slow_axis == 0)) Map: im = data.ptr (const uint16_t *) lout = labels.ptr (int32_t *) l = wrk.ptr (uint8_t *) dim0 = data.shape[0] (intptr_t) dim1 = data.shape[1] (intptr_t) int localmaxlabel_u8(const uint8_t *im, int32_t *lout, uint8_t *l, intptr_t dim0, intptr_t dim1) -> int (When: ((data.format == 'B' and data.ndim == 2) and data.slow_axis == 0)) Map: im = data.ptr (const uint8_t *) lout = labels.ptr (int32_t *) l = wrk.ptr (uint8_t *) dim0 = data.shape[0] (intptr_t) dim1 = data.shape[1] (intptr_t) int localmaxlabel(const float *im, int32_t *lout, uint8_t *l, intptr_t dim0, intptr_t dim1) -> int (When: ((data.format == 'f' and data.ndim == 2) and data.slow_axis == 0)) Map: im = data.ptr (const float *) lout = labels.ptr (int32_t *) l = wrk.ptr (uint8_t *) dim0 = data.shape[0] (intptr_t) dim1 = data.shape[1] (intptr_t)
- c2ImageD11.make_clean_mask(img: buffer, cut: float, msk: buffer, ret: buffer) int
is a lot like clean msk but it generates the msk using img and cut. Beware: work in progress
- Parameters:
img (buffer) – Type: uint8 (format ‘B’) or uint16 (format ‘H’) or uint32 (format ‘I’) or ? (format ‘L’) or float32 (format ‘f’) Shape: 2D Input float32 2D.
cut (float) – Threshold.
msk (buffer) – Writable Size must equal img Priority mask (int8).
ret (buffer) – Writable Size must equal img Output cleaned mask.
Checks
img.ndim == 2 [ValueError] img.slow_axis == 0 [ValueError] (msk.format == 'b' or msk.format == 'B') [ValueError] msk.n == img.n [ValueError] (ret.format == 'b' or ret.format == 'B') [ValueError] ret.n == img.n [ValueError]
Overloads
int make_clean_mask_u32(const uint32_t *img, double cut, int8_t *msk, int8_t *ret, intptr_t ns, intptr_t nf) -> int (When: ((((img.format == 'I' or img.format == 'L') and img.itemsize == 4) and img.ndim == 2) and img.slow_axis == 0)) Map: img = img.ptr (const uint32_t *) cut = cut (double) msk = msk.ptr (int8_t *) ret = ret.ptr (int8_t *) ns = img.shape[0] (intptr_t) nf = img.shape[1] (intptr_t) int make_clean_mask_u16(const uint16_t *img, double cut, int8_t *msk, int8_t *ret, intptr_t ns, intptr_t nf) -> int (When: ((img.format == 'H' and img.ndim == 2) and img.slow_axis == 0)) Map: img = img.ptr (const uint16_t *) cut = cut (double) msk = msk.ptr (int8_t *) ret = ret.ptr (int8_t *) ns = img.shape[0] (intptr_t) nf = img.shape[1] (intptr_t) int make_clean_mask_u8(const uint8_t *img, double cut, int8_t *msk, int8_t *ret, intptr_t ns, intptr_t nf) -> int (When: ((img.format == 'B' and img.ndim == 2) and img.slow_axis == 0)) Map: img = img.ptr (const uint8_t *) cut = cut (double) msk = msk.ptr (int8_t *) ret = ret.ptr (int8_t *) ns = img.shape[0] (intptr_t) nf = img.shape[1] (intptr_t) int make_clean_mask(const float *img, double cut, int8_t *msk, int8_t *ret, intptr_t ns, intptr_t nf) -> int (When: ((img.format == 'f' and img.ndim == 2) and img.slow_axis == 0)) Map: img = img.ptr (const float *) cut = cut (double) msk = msk.ptr (int8_t *) ret = ret.ptr (int8_t *) ns = img.shape[0] (intptr_t) nf = img.shape[1] (intptr_t)
- c2ImageD11.mask_to_coo(msk: buffer, i: buffer, j: buffer, w: buffer) int
takes a mask and converts it to a list of i,j coordinates in a sparse array coo format returns :
0 => success 1 => ns out of range ; 2 => nf out of range 3 => nnz < 1 empty mask 4 => nnz did not match this mask
- Parameters:
msk (buffer) – Shape: 2D Input int8 2D mask.
i (buffer) – Writable Output row indices (uint16).
j (buffer) – Writable Size must equal i Output col indices (uint16).
w (buffer) – Writable Output per-row counts (int32).
Checks
(msk.format == 'b' or msk.format == 'B') [ValueError] msk.ndim == 2 [ValueError] msk.slow_axis == 0 [ValueError] (i.format == 'H' or i.itemsize == 2) [ValueError] (j.format == 'H' or j.itemsize == 2) [ValueError] j.n == i.n [ValueError] (w.format == 'i' or w.format == 'l') [ValueError] w.n == msk.shape[0] [ValueError]
Overloads
int mask_to_coo(const int8_t *msk, intptr_t ns, intptr_t nf, uint16_t *i, uint16_t *j, intptr_t nnz, int *nrow) -> int Map: msk = msk.ptr (const int8_t *) ns = msk.shape[0] (intptr_t) nf = msk.shape[1] (intptr_t) i = i.ptr (uint16_t *) j = j.ptr (uint16_t *) nnz = i.n (intptr_t) nrow = w.ptr (int *)
- c2ImageD11.misori_cubic(u1: buffer, u2: buffer) float
- computes the trace of the smallest misorientation
for cubic symmetry u1 and u2 are both orientation matrices “U”
compute u1. u2.T to get the rotation from one to the other find the permutation that will maximise the trace
- one of six…
xyz yxz zxy xzy yzx zyx
Beware : work in progress. Which point group is this?
- Parameters:
u1 (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix U (9-element flattened double).
u2 (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix U (9-element flattened double).
Checks
u1.format == 'd' [ValueError] u1.n == 9 [ValueError] u2.format == 'd' [ValueError] u2.n == 9 [ValueError] u1.slow_axis == 0 [ValueError] u1.ndim == 2 [ValueError] u1.shape[0] == 3 [ValueError] u1.shape[1] == 3 [ValueError] u2.slow_axis == 0 [ValueError] u2.ndim == 2 [ValueError] u2.shape[0] == 3 [ValueError] u2.shape[1] == 3 [ValueError]
Overloads
double misori_cubic(const double u1[3][3], const double u2[3][3]) -> double Map: u1 = u1.ptr (const double (*)[3]) u2 = u2.ptr (const double (*)[3])
- c2ImageD11.misori_monoclinic(u1: buffer, u2: buffer) float
assumes a unique b axis and only checks the flip of b -> -b Not sure about the point group here. Is is 2/m ??
Beware: work in progress
- Parameters:
u1 (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix U (9-element flattened double).
u2 (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix U (9-element flattened double).
Checks
u1.format == 'd' [ValueError] u1.n == 9 [ValueError] u2.format == 'd' [ValueError] u2.n == 9 [ValueError] u1.slow_axis == 0 [ValueError] u1.ndim == 2 [ValueError] u1.shape[0] == 3 [ValueError] u1.shape[1] == 3 [ValueError] u2.slow_axis == 0 [ValueError] u2.ndim == 2 [ValueError] u2.shape[0] == 3 [ValueError] u2.shape[1] == 3 [ValueError]
Overloads
double misori_monoclinic(const double u1[3][3], const double u2[3][3]) -> double Map: u1 = u1.ptr (const double (*)[3]) u2 = u2.ptr (const double (*)[3])
- c2ImageD11.misori_orthorhombic(u1: buffer, u2: buffer) float
- computes the trace of the smallest misorientation
- u1 and u2 are both orientation matrices “U”
compute u1. u2.T to get the rotation from one to the other find the flips that will maximise the trace:
abs( trace(dot(u1,u2.T) ))
Looks like point group mmm. Not sure why this is in C? Beware: work in progress
- Parameters:
u1 (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix U (9-element flattened double).
u2 (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix U (9-element flattened double).
Checks
u1.format == 'd' [ValueError] u1.n == 9 [ValueError] u2.format == 'd' [ValueError] u2.n == 9 [ValueError] u1.slow_axis == 0 [ValueError] u1.ndim == 2 [ValueError] u1.shape[0] == 3 [ValueError] u1.shape[1] == 3 [ValueError] u2.slow_axis == 0 [ValueError] u2.ndim == 2 [ValueError] u2.shape[0] == 3 [ValueError] u2.shape[1] == 3 [ValueError]
Overloads
double misori_orthorhombic(const double u1[3][3], const double u2[3][3]) -> double Map: u1 = u1.ptr (const double (*)[3]) u2 = u2.ptr (const double (*)[3])
- c2ImageD11.misori_tetragonal(u1: buffer, u2: buffer) float
- computes the trace of the smallest misorientation
- u1 and u2 are both orientation matrices “U”
compute u1. u2.T to get the rotation from one to the other finds the flips a/b and c->-c that will maximise the trace:
abs( trace(dot(u1,u2.T) ))
Looks like point group 4/mmm. What about 4/m ? Beware: work in progress
- Parameters:
u1 (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix U (9-element flattened double).
u2 (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix U (9-element flattened double).
Checks
u1.format == 'd' [ValueError] u1.n == 9 [ValueError] u2.format == 'd' [ValueError] u2.n == 9 [ValueError] u1.slow_axis == 0 [ValueError] u1.ndim == 2 [ValueError] u1.shape[0] == 3 [ValueError] u1.shape[1] == 3 [ValueError] u2.slow_axis == 0 [ValueError] u2.ndim == 2 [ValueError] u2.shape[0] == 3 [ValueError] u2.shape[1] == 3 [ValueError]
Overloads
double misori_tetragonal(const double u1[3][3], const double u2[3][3]) -> double Map: u1 = u1.ptr (const double (*)[3]) u2 = u2.ptr (const double (*)[3])
- c2ImageD11.put_incr32(data: buffer, ind: buffer, vals: buffer, boundscheck: int = 0) void
does the simple loop : data[ind] += vals not sure why this isn’t in numpy uses 32 bit addressing
- Parameters:
data (buffer) – Type: float32 (format ‘f’) Writable Destination array (float32).
ind (buffer) – Type: int32 (format ‘i’) or ? (format ‘l’) Size must equal vals Indices array (int32).
vals (buffer) – Type: float32 (format ‘f’) Values array (float32) to add.
boundscheck (int) – If non-zero, enables bounds checking on ind.
Checks
data.format == 'f' [ValueError] (ind.format == 'i' or ind.format == 'l') [ValueError] ind.n == vals.n [ValueError] vals.format == 'f' [ValueError] GIL: released
Overloads
void put_incr32(float *data, const int32_t *ind, const float *vals, int boundscheck, intptr_t n, intptr_t m) (When: ((data.format == 'f' and vals.format == 'f') and (ind.format == 'i' or ind.format == 'l'))) Map: data = data.ptr (float *) ind = ind.ptr (const int32_t *) vals = vals.ptr (const float *) boundscheck = boundscheck (int) n = ind.n (intptr_t) m = data.n (intptr_t)
- c2ImageD11.put_incr64(data: buffer, ind: buffer, vals: buffer, boundscheck: int = 0) void
does the simple loop : data[ind] += vals not sure why this isn’t in numpy uses 64 bit addressing
- Parameters:
data (buffer) – Type: float32 (format ‘f’) Writable Destination array (float32). Updated in place with scatter-add.
ind (buffer) – Size must equal vals Indices array (int64).
vals (buffer) – Type: float32 (format ‘f’) Values array (float32) to add.
boundscheck (int) – If non-zero, enables bounds checking on ind. Default 0 (no check).
Checks
data.format == 'f' [ValueError] (ind.format == 'q' or ind.itemsize == 8) [ValueError] ind.n == vals.n [ValueError] vals.format == 'f' [ValueError] GIL: released
Overloads
void put_incr64(float *data, const int64_t *ind, const float *vals, int boundscheck, intptr_t n, intptr_t m) (When: (data.format == 'f' and vals.format == 'f')) Map: data = data.ptr (float *) ind = ind.ptr (const int64_t *) vals = vals.ptr (const float *) boundscheck = boundscheck (int) n = ind.n (intptr_t) m = data.n (intptr_t)
- c2ImageD11.quickorient(ubi: buffer, bt: buffer) void
takes two g-vectors in UBI[0] and UBI[1] and overwrites with UBI orientation using cache in bt (from h1,h2) … computes cross product 0x1 = ubi[0]xubi[1] … normalises u0=ubi0 and u2=0x1 and computes u1=u0xu2 … returns in UBI BT.(u1,u2,u3) algorithm was due to Busing and Levy
- Parameters:
ubi (buffer) – Type: float64 (format ‘d’) Writable Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix (9-element). First 2 rows are g-vectors on entry; overwritten with UBI on exit.
bt (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Busing-Levy cache (9-element).
Checks
ubi.format == 'd' [ValueError] ubi.ndim == 2 [ValueError] ubi.shape[0] == 3 [ValueError] ubi.shape[1] == 3 [ValueError] bt.format == 'd' [ValueError] bt.ndim == 2 [ValueError] bt.shape[0] == 3 [ValueError] bt.shape[1] == 3 [ValueError] ubi.slow_axis == 0 [ValueError] bt.slow_axis == 0 [ValueError]
Overloads
void quickorient(double ubi[3][3], const double bt[3][3]) Map: ubi = ubi.ptr (double (*)[3]) bt = bt.ptr (const double (*)[3])
- c2ImageD11.refine_assigned(ubi: buffer, gv: buffer, labels: buffer, label: int) void
fits a ubi matrix to a set of g-vectors and assignments in labels. e.g. where(labels==label) it uses the peaks.
… perhaps this is not what you want for overlapping peaks in twins!
- Parameters:
ubi (buffer) – Type: float64 (format ‘d’) Writable Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix (9-element flattened double).
gv (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 1: 3 elements G-vectors array, shape (ng, 3) flattened.
labels (buffer) – Peak-to-grain assignments (ng ints).
label (int) – Grain label to refine.
Checks
ubi.format == 'd' [ValueError] ubi.n == 9 [ValueError] gv.format == 'd' [ValueError] (labels.format == 'i' or labels.format == 'l') [ValueError] labels.n == gv.shape[0] [ValueError] ubi.slow_axis == 0 [ValueError] ubi.ndim == 2 [ValueError] ubi.shape[0] == 3 [ValueError] ubi.shape[1] == 3 [ValueError] gv.slow_axis == 0 [ValueError] gv.ndim == 2 [ValueError] gv.shape[1] == 3 [ValueError]
Overloads
void refine_assigned(double ubi[3][3], const double gv[][3], const int *labels, int label, int *npk, double *drlv2, intptr_t ng) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const double (*)[3]) labels = labels.ptr (const int *) label = label (int) ng = gv.shape[0] (intptr_t) Outputs: drlv2 (double), npk (int)
- c2ImageD11.reorder_f32_a32(data: buffer, adr: buffer, out: buffer) void
called in sandbox/fazit.py simple loop with openmp saying out[adr[i]] in data[i] e.g. semi-random writing
- Parameters:
data (buffer) – Type: float32 (format ‘f’)
adr (buffer) – Size must equal data
out (buffer) – Type: float32 (format ‘f’) Writable Size >= data
Checks
data.format == 'f' [ValueError] (adr.format == 'I' or adr.itemsize == 4) [ValueError] adr.n == data.n [ValueError] out.format == 'f' [ValueError] out.n >= data.n [ValueError] GIL: released
Overloads
void reorder_f32_a32(const float *data, const uint32_t *adr, float *out, intptr_t N) (When: (data.format == 'f' and out.format == 'f')) Map: data = data.ptr (const float *) adr = adr.ptr (const uint32_t *) out = out.ptr (float *) N = data.n (intptr_t)
- c2ImageD11.reorder_u16_a32(data: buffer, adr: buffer, out: buffer) void
called in sandbox/fazit.py simple loop with openmp saying out[adr[i]] in data[i] e.g. semi-random writing
- Parameters:
data (buffer)
adr (buffer) – Type: uint32 (format ‘I’) Size must equal data
out (buffer) – Writable Size >= data
Checks
(data.format == 'H' or data.itemsize == 2) [ValueError] (adr.format == 'I' or adr.itemsize == 4) [ValueError] adr.n == data.n [ValueError] (out.format == 'H' or out.itemsize == 2) [ValueError] out.n >= data.n [ValueError] GIL: released
Overloads
void reorder_u16_a32(const uint16_t *data, const uint32_t *adr, uint16_t *out, intptr_t N) (When: (adr.format == 'I' or adr.itemsize == 4)) Map: data = data.ptr (const uint16_t *) adr = adr.ptr (const uint32_t *) out = out.ptr (uint16_t *) N = data.n (intptr_t)
- c2ImageD11.reorder_u16_a32_a16(data: buffer, adr0: buffer, adr1: buffer, out: buffer) void
2D reorder with per-row base + per-pixel offsets.
- Parameters:
data (buffer) – Shape: 2D
adr0 (buffer)
adr1 (buffer) – Size must equal data
out (buffer) – Writable Size >= data
Checks
(data.format == 'H' or data.itemsize == 2) [ValueError] data.ndim == 2 [ValueError] (adr0.format == 'I' or adr0.itemsize == 4) [ValueError] adr0.n == data.shape[0] [ValueError] (adr1.format == 'h' or adr1.itemsize == 2) [ValueError] adr1.n == data.n [ValueError] (out.format == 'H' or out.itemsize == 2) [ValueError] out.n >= data.n [ValueError]
Overloads
void reorder_u16_a32_a16(const uint16_t *data, const uint32_t *a0, const int16_t *a1, uint16_t *out, intptr_t ns, intptr_t nf) Map: data = data.ptr (const uint16_t *) a0 = adr0.ptr (const uint32_t *) a1 = adr1.ptr (const int16_t *) out = out.ptr (uint16_t *) ns = data.shape[0] (intptr_t) nf = data.shape[1] (intptr_t)
- c2ImageD11.reorderlut_f32_a32(data: buffer, adr: buffer, out: buffer) void
lut called in sandbox/fazit.py simple loop with openmp saying out[i] in data[adr[i]] e.g. semi-random reading
- Parameters:
data (buffer) – Type: float32 (format ‘f’)
adr (buffer) – Size must equal data
out (buffer) – Type: float32 (format ‘f’) Writable Size must equal data
Checks
data.format == 'f' [ValueError] (adr.format == 'I' or adr.itemsize == 4) [ValueError] adr.n == data.n [ValueError] out.format == 'f' [ValueError] out.n == data.n [ValueError] GIL: released
Overloads
void reorderlut_f32_a32(const float *data, const uint32_t *adr, float *out, intptr_t N) (When: (data.format == 'f' and out.format == 'f')) Map: data = data.ptr (const float *) adr = adr.ptr (const uint32_t *) out = out.ptr (float *) N = data.n (intptr_t)
- c2ImageD11.reorderlut_u16_a32(data: buffer, adr: buffer, out: buffer) void
out[i] = data[adr[i]].
- Parameters:
data (buffer)
adr (buffer) – Type: uint32 (format ‘I’) Size must equal data
out (buffer) – Writable Size must equal data
Checks
(data.format == 'H' or data.itemsize == 2) [ValueError] (adr.format == 'I' or adr.itemsize == 4) [ValueError] adr.n == data.n [ValueError] (out.format == 'H' or out.itemsize == 2) [ValueError] out.n == data.n [ValueError] GIL: released
Overloads
void reorderlut_u16_a32(const uint16_t *data, const uint32_t *adr, uint16_t *out, intptr_t N) (When: (adr.format == 'I' or adr.itemsize == 4)) Map: data = data.ptr (const uint16_t *) adr = adr.ptr (const uint32_t *) out = out.ptr (uint16_t *) N = data.n (intptr_t)
- c2ImageD11.score(ubi: buffer, gv: buffer, tol: float) int
takes a ubi matrix and list of g-vectors and computes hkl = dot(ubi, gv), then rounds these g-vectors to integer and computes drlv2 = (h-int(h))**2 + (k-int(k))**2 + (l-int(l))**2 If drlv2 is less than tol*tol then the peak is considered to be indexed. Returns the number of peaks found.
- Parameters:
ubi (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix UBI (UB inverse), shape (9,) flattened double.
gv (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Shape: 2D G-vectors array, shape (ng, 3) flattened.
tol (float) – Tolerance on |h - round(h)|.
Checks
ubi.format == 'd' [ValueError] ubi.n == 9 [ValueError] gv.ndim == 2 [ValueError] ubi.slow_axis == 0 [ValueError] ubi.ndim == 2 [ValueError] ubi.shape[0] == 3 [ValueError] ubi.shape[1] == 3 [ValueError] gv.slow_axis == 0 [ValueError] GIL: released
Overloads
int score_f64_soa_avx512(const double ubi[3][3], const double gv[], double tol, intptr_t ng) -> int (When: (((((ubi.format == 'd' and gv.format == 'd') and gv.shape[0] == 3) and gv.slow_axis == 0) and gv.shape[1] != 3) and c2py_amd64_avx512f)) Map: ubi = ubi.ptr (const double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[1] (intptr_t) int score_f64_avx512(const double ubi[3][3], const double gv[], double tol, intptr_t ng) -> int (When: ((((ubi.format == 'd' and gv.format == 'd') and gv.shape[1] == 3) and gv.slow_axis == 0) and c2py_amd64_avx512f)) Map: ubi = ubi.ptr (const double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[0] (intptr_t) int score_f32_soa_avx512(const double ubi[3][3], const float gv[], double tol, intptr_t ng) -> int (When: (((((ubi.format == 'd' and gv.format == 'f') and gv.shape[0] == 3) and gv.slow_axis == 0) and gv.shape[1] != 3) and c2py_amd64_avx512f)) Map: ubi = ubi.ptr (const double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[1] (intptr_t) int score_f32_avx512(const double ubi[3][3], const float gv[], double tol, intptr_t ng) -> int (When: ((((ubi.format == 'd' and gv.format == 'f') and gv.shape[1] == 3) and gv.slow_axis == 0) and c2py_amd64_avx512f)) Map: ubi = ubi.ptr (const double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[0] (intptr_t) int score_f64_soa_avx2(const double ubi[3][3], const double gv[], double tol, intptr_t ng) -> int (When: (((((ubi.format == 'd' and gv.format == 'd') and gv.shape[0] == 3) and gv.slow_axis == 0) and gv.shape[1] != 3) and c2py_amd64_avx2)) Map: ubi = ubi.ptr (const double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[1] (intptr_t) int score_f64_avx2(const double ubi[3][3], const double gv[], double tol, intptr_t ng) -> int (When: ((((ubi.format == 'd' and gv.format == 'd') and gv.shape[1] == 3) and gv.slow_axis == 0) and c2py_amd64_avx2)) Map: ubi = ubi.ptr (const double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[0] (intptr_t) int score_f32_soa_avx2(const double ubi[3][3], const float gv[], double tol, intptr_t ng) -> int (When: (((((ubi.format == 'd' and gv.format == 'f') and gv.shape[0] == 3) and gv.slow_axis == 0) and gv.shape[1] != 3) and c2py_amd64_avx2)) Map: ubi = ubi.ptr (const double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[1] (intptr_t) int score_f32_avx2(const double ubi[3][3], const float gv[], double tol, intptr_t ng) -> int (When: ((((ubi.format == 'd' and gv.format == 'f') and gv.shape[1] == 3) and gv.slow_axis == 0) and c2py_amd64_avx2)) Map: ubi = ubi.ptr (const double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[0] (intptr_t) int score(const double ubi[3][3], const double gv[], double tol, intptr_t ng) -> int (When: (((ubi.format == 'd' and gv.format == 'd') and gv.shape[1] == 3) and gv.slow_axis == 0)) Map: ubi = ubi.ptr (const double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[0] (intptr_t) int score_f32(const double ubi[3][3], const float gv[], double tol, intptr_t ng) -> int (When: (((ubi.format == 'd' and gv.format == 'f') and gv.shape[1] == 3) and gv.slow_axis == 0)) Map: ubi = ubi.ptr (const double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[0] (intptr_t)
- c2ImageD11.score_and_assign(ubi: buffer, gv: buffer, tol: float, drlv2: buffer, labels: buffer, label: int) int
is similar to score but it assigns peaks to this ubi only if they fit the data better than the current UBI. It updates drlv2 and labels to use best fitting grain for each peak.
… perhaps this is not what you want for overlapping peaks in twins!
- Parameters:
ubi (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix (9-element flattened double).
gv (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 1: 3 elements G-vectors array, shape (ng, 3) flattened.
tol (float) – Matching tolerance.
drlv2 (buffer) – Type: float64 (format ‘d’) Writable Input/output array (ng). Current best squared residuals per peak.
labels (buffer) – Writable Input/output array (ng). Current grain labels per peak.
label (int) – Grain label assigned to peaks that match this UBI.
Checks
ubi.format == 'd' [ValueError] ubi.n == 9 [ValueError] gv.format == 'd' [ValueError] drlv2.format == 'd' [ValueError] drlv2.n == gv.shape[0] [ValueError] (labels.format == 'i' or labels.format == 'l') [ValueError] labels.n == gv.shape[0] [ValueError] ubi.slow_axis == 0 [ValueError] ubi.ndim == 2 [ValueError] ubi.shape[0] == 3 [ValueError] ubi.shape[1] == 3 [ValueError] gv.slow_axis == 0 [ValueError] gv.ndim == 2 [ValueError] gv.shape[1] == 3 [ValueError] GIL: released
Overloads
int score_and_assign(const double ubi[3][3], const double gv[][3], double tol, double *drlv2, int *labels, int label, intptr_t ng) -> int (When: (ubi.format == 'd' and gv.format == 'd')) Map: ubi = ubi.ptr (const double (*)[3]) gv = gv.ptr (const double (*)[3]) tol = tol (double) drlv2 = drlv2.ptr (double *) labels = labels.ptr (int *) label = label (int) ng = gv.shape[0] (intptr_t)
- c2ImageD11.score_and_refine(ubi: buffer, gv: buffer, tol: float) int
is very similar to score but it also refines the UB matrix using the assigned peaks and overwrite the argument. It returns the number of peaks and fit prior to refinement.
- Parameters:
ubi (buffer) – Type: float64 (format ‘d’) Writable Shape: 2D Axis 0: 3 elements Axis 1: 3 elements Orientation matrix UBI (9-element flattened double).
gv (buffer) – Type: float64 (format ‘d’) or float32 (format ‘f’) Shape: 2D G-vectors array, shape (ng, 3) flattened.
tol (float) – Matching tolerance on |h - round(h)|.
Checks
ubi.format == 'd' [ValueError] ubi.n == 9 [ValueError] gv.ndim == 2 [ValueError] ubi.slow_axis == 0 [ValueError] ubi.ndim == 2 [ValueError] ubi.shape[0] == 3 [ValueError] ubi.shape[1] == 3 [ValueError] gv.slow_axis == 0 [ValueError] GIL: released
Overloads
void score_and_refine_f64_soa_avx512(double ubi[3][3], const double gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: (((((ubi.format == 'd' and gv.format == 'd') and gv.shape[0] == 3) and gv.slow_axis == 0) and gv.shape[1] != 3) and c2py_amd64_avx512f)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[1] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f64_avx512(double ubi[3][3], const double gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: ((((ubi.format == 'd' and gv.format == 'd') and gv.shape[1] == 3) and gv.slow_axis == 0) and c2py_amd64_avx512f)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[0] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f32_soa_avx512(double ubi[3][3], const float gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: (((((ubi.format == 'd' and gv.format == 'f') and gv.shape[0] == 3) and gv.slow_axis == 0) and gv.shape[1] != 3) and c2py_amd64_avx512f)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[1] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f32_avx512(double ubi[3][3], const float gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: ((((ubi.format == 'd' and gv.format == 'f') and gv.shape[1] == 3) and gv.slow_axis == 0) and c2py_amd64_avx512f)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[0] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f64_soa_avx2(double ubi[3][3], const double gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: (((((ubi.format == 'd' and gv.format == 'd') and gv.shape[0] == 3) and gv.slow_axis == 0) and gv.shape[1] != 3) and c2py_amd64_avx2)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[1] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f64_avx2(double ubi[3][3], const double gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: ((((ubi.format == 'd' and gv.format == 'd') and gv.shape[1] == 3) and gv.slow_axis == 0) and c2py_amd64_avx2)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[0] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f32_soa_avx2(double ubi[3][3], const float gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: (((((ubi.format == 'd' and gv.format == 'f') and gv.shape[0] == 3) and gv.slow_axis == 0) and gv.shape[1] != 3) and c2py_amd64_avx2)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[1] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f32_avx2(double ubi[3][3], const float gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: ((((ubi.format == 'd' and gv.format == 'f') and gv.shape[1] == 3) and gv.slow_axis == 0) and c2py_amd64_avx2)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[0] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f64_sse41(double ubi[3][3], const double gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: ((((ubi.format == 'd' and gv.format == 'd') and c2py_amd64_sse4_1) and gv.shape[1] == 3) and gv.slow_axis == 0)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[0] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f64_soa_sse41(double ubi[3][3], const double gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: (((((ubi.format == 'd' and gv.format == 'd') and gv.shape[0] == 3) and gv.slow_axis == 0) and gv.shape[1] != 3) and c2py_amd64_sse4_1)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[1] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f32_sse41(double ubi[3][3], const float gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: ((((ubi.format == 'd' and gv.format == 'f') and c2py_amd64_sse4_1) and gv.shape[1] == 3) and gv.slow_axis == 0)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[0] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f32_soa_sse41(double ubi[3][3], const float gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: (((((ubi.format == 'd' and gv.format == 'f') and gv.shape[0] == 3) and gv.slow_axis == 0) and gv.shape[1] != 3) and c2py_amd64_sse4_1)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[1] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f64_soa(double ubi[3][3], const double gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: ((((ubi.format == 'd' and gv.format == 'd') and gv.shape[0] == 3) and gv.slow_axis == 0) and gv.shape[1] != 3)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[1] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f64(double ubi[3][3], const double gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: (((ubi.format == 'd' and gv.format == 'd') and gv.shape[1] == 3) and gv.slow_axis == 0)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[0] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f32_soa(double ubi[3][3], const float gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: ((((ubi.format == 'd' and gv.format == 'f') and gv.shape[0] == 3) and gv.slow_axis == 0) and gv.shape[1] != 3)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[1] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine_f32(double ubi[3][3], const float gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: (((ubi.format == 'd' and gv.format == 'f') and gv.shape[1] == 3) and gv.slow_axis == 0)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const float *) tol = tol (double) ng = gv.shape[0] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double) void score_and_refine(double ubi[3][3], const double gv[], double tol, int *n_arg, double *sumdrlv2_arg, intptr_t ng) (When: (((ubi.format == 'd' and gv.format == 'd') and gv.shape[1] == 3) and gv.slow_axis == 0)) Map: ubi = ubi.ptr (double (*)[3]) gv = gv.ptr (const double *) tol = tol (double) ng = gv.shape[0] (intptr_t) Outputs: n_arg (int), sumdrlv2_arg (double)
- c2ImageD11.score_gvec_z(ubi: buffer, ub: buffer, gv: buffer, g0: buffer, g1: buffer, g2: buffer, e: buffer, recompute: int) void
reads ubi, ub, gv and recompute if (recompute) it fills directions to project errors per peak:
For all peaks it computes h = ubi.g, rounds to nearest ih = int(h) and then computes gcalc = ub.ih = dot( ub, ( round( dot( ubi, g) ) ) ) The error gv - gcalc is then projected into the co-ordinate system g0,g1,g2 for errors along g, z and the rhs Beware : work in progress. Is z always the right axis?
- Parameters:
ubi (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements UBI matrix (9-element flattened double).
ub (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 0: 3 elements Axis 1: 3 elements UB matrix (9-element flattened double).
gv (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 1: 3 elements Experimental g-vectors, shape (ng, 3) flattened.
g0 (buffer) – Type: float64 (format ‘d’) Writable Error along g component.
g1 (buffer) – Type: float64 (format ‘d’) Writable Error along z component.
g2 (buffer) – Type: float64 (format ‘d’) Writable Error along rhs component.
e (buffer) – Type: float64 (format ‘d’) Writable Output error array.
recompute (int) – If non-zero, recompute gcalc from ub.
Checks
ubi.format == 'd' [ValueError] ubi.n == 9 [ValueError] ub.format == 'd' [ValueError] ub.n == 9 [ValueError] gv.format == 'd' [ValueError] gv.ndim >= 1 [ValueError] g0.format == 'd' [ValueError] g1.format == 'd' [ValueError] g2.format == 'd' [ValueError] e.format == 'd' [ValueError] ubi.slow_axis == 0 [ValueError] ubi.ndim == 2 [ValueError] ubi.shape[0] == 3 [ValueError] ubi.shape[1] == 3 [ValueError] ub.slow_axis == 0 [ValueError] ub.ndim == 2 [ValueError] ub.shape[0] == 3 [ValueError] ub.shape[1] == 3 [ValueError] gv.slow_axis == 0 [ValueError] gv.ndim == 2 [ValueError] gv.shape[1] == 3 [ValueError] g0.slow_axis == 0 [ValueError] g1.slow_axis == 0 [ValueError] g2.slow_axis == 0 [ValueError] e.slow_axis == 0 [ValueError]
Overloads
void score_gvec_z(const double ubi[3][3], const double ub[3][3], const double gv[][3], double g0[], double g1[], double g2[], double e[], int recompute, intptr_t n) Map: ubi = ubi.ptr (const double (*)[3]) ub = ub.ptr (const double (*)[3]) gv = gv.ptr (const double (*)[3]) g0 = g0.ptr (double *) g1 = g1.ptr (double *) g2 = g2.ptr (double *) e = e.ptr (double *) recompute = recompute (int) n = gv.shape[0] (intptr_t)
- c2ImageD11.sparse_blob2Dproperties(v, i, j, labels, npk)
Allocate results and call C sparse_blob2Dproperties, matching f2py convention.
- c2ImageD11.sparse_connectedpixels(v: buffer, i: buffer, j: buffer, threshold: float, labels: buffer) int
runs the connectedpixels algorithm on a sparse image using a supplied threshold putting labels into labels array and returning the number of blobs found
- Parameters:
v (buffer) – Type: uint8 (format ‘B’) or uint16 (format ‘H’) or uint32 (format ‘I’) or ? (format ‘L’) or float32 (format ‘f’) Size must equal i Values (float32).
i (buffer) – Rows (uint16).
j (buffer) – Size must equal i Cols (uint16).
threshold (float) – Threshold.
labels (buffer) – Writable Size must equal i Output labels (int32).
Checks
v.slow_axis == 0 [ValueError] (i.format == 'H' or i.itemsize == 2) [ValueError] (j.format == 'H' or j.itemsize == 2) [ValueError] j.n == i.n [ValueError] v.n == i.n [ValueError] (labels.format == 'i' or labels.format == 'l') [ValueError] labels.n == i.n [ValueError]
Overloads
int sparse_connectedpixels_u32(const uint32_t *v, const uint16_t *i, const uint16_t *j, intptr_t nnz, double threshold, int32_t *labels) -> int (When: (((v.format == 'I' or v.format == 'L') and v.itemsize == 4) and v.slow_axis == 0)) Map: v = v.ptr (const uint32_t *) i = i.ptr (const uint16_t *) j = j.ptr (const uint16_t *) nnz = i.n (intptr_t) threshold = threshold (double) labels = labels.ptr (int32_t *) int sparse_connectedpixels_u16(const uint16_t *v, const uint16_t *i, const uint16_t *j, intptr_t nnz, double threshold, int32_t *labels) -> int (When: (v.format == 'H' and v.slow_axis == 0)) Map: v = v.ptr (const uint16_t *) i = i.ptr (const uint16_t *) j = j.ptr (const uint16_t *) nnz = i.n (intptr_t) threshold = threshold (double) labels = labels.ptr (int32_t *) int sparse_connectedpixels_u8(const uint8_t *v, const uint16_t *i, const uint16_t *j, intptr_t nnz, double threshold, int32_t *labels) -> int (When: (v.format == 'B' and v.slow_axis == 0)) Map: v = v.ptr (const uint8_t *) i = i.ptr (const uint16_t *) j = j.ptr (const uint16_t *) nnz = i.n (intptr_t) threshold = threshold (double) labels = labels.ptr (int32_t *) int sparse_connectedpixels(const float *v, const uint16_t *i, const uint16_t *j, intptr_t nnz, double threshold, int32_t *labels) -> int (When: (v.format == 'f' and v.slow_axis == 0)) Map: v = v.ptr (const float *) i = i.ptr (const uint16_t *) j = j.ptr (const uint16_t *) nnz = i.n (intptr_t) threshold = threshold (double) labels = labels.ptr (int32_t *)
- c2ImageD11.sparse_connectedpixels_splat(v: buffer, i: buffer, j: buffer, th: float, lbl: buffer, Z: buffer, ni: int, nj: int) int
is for debugging/timing. It splats the sparse array into a dense array and runs the old connectedpixels code on that.
- Parameters:
v (buffer) – Type: float32 (format ‘f’) Size must equal i Values (float32).
i (buffer) – Rows (uint16).
j (buffer) – Size must equal i Cols (uint16).
th (float) – Threshold.
lbl (buffer) – Writable Size must equal i Output labels.
Z (buffer) – Writable Temp buffer.
ni (int) – Rows.
nj (int) – Cols.
Checks
v.slow_axis == 0 [ValueError] v.format == 'f' [ValueError] (i.format == 'H' or i.itemsize == 2) [ValueError] (j.format == 'H' or j.itemsize == 2) [ValueError] j.n == i.n [ValueError] v.n == i.n [ValueError] (lbl.format == 'i' or lbl.format == 'l') [ValueError] lbl.n == i.n [ValueError] (Z.format == 'i' or Z.format == 'l') [ValueError]
Overloads
int sparse_connectedpixels_splat(const float *v, const uint16_t *i, const uint16_t *j, intptr_t nnz, float threshold, int32_t *labels, int32_t *Z, intptr_t imax, intptr_t jmax) -> int Map: v = v.ptr (const float *) i = i.ptr (const uint16_t *) j = j.ptr (const uint16_t *) nnz = i.n (intptr_t) threshold = th (float) labels = lbl.ptr (int32_t *) Z = Z.ptr (int32_t *) imax = ni (intptr_t) jmax = nj (intptr_t)
- c2ImageD11.sparse_is_sorted(i: buffer, j: buffer) int
checks whether the indices in i and j of a sparse coo format come in the order that they would appear inside an image * @param i, j index arrays * @param nnz dimension of i, j
- returns 0 for all OK
k for first non-sorted element -k for first duplicate
- Parameters:
i (buffer) – Row indices (uint16).
j (buffer) – Size must equal i Col indices (uint16).
Checks
i.slow_axis == 0 [ValueError] (i.format == 'H' or i.itemsize == 2) [ValueError] (j.format == 'H' or j.itemsize == 2) [ValueError] j.n == i.n [ValueError]
Overloads
int sparse_is_sorted(const uint16_t *i, const uint16_t *j, intptr_t nnz) -> int Map: i = i.ptr (const uint16_t *) j = j.ptr (const uint16_t *) nnz = i.n (intptr_t)
- c2ImageD11.sparse_localmaxlabel(v: buffer, i: buffer, j: buffer, MV: buffer, iMV: buffer, labels: buffer) int
assigns labels to sparse array in sorted coo format supplied in (v,(i,j)). MV and iMV are temporaries. single threaded
- Parameters:
v (buffer) – Type: uint8 (format ‘B’) or uint16 (format ‘H’) or uint32 (format ‘I’) or ? (format ‘L’) or float32 (format ‘f’) Size must equal i Values (float32).
i (buffer) – Rows (uint16).
j (buffer) – Size must equal i Cols (uint16).
MV (buffer) – Type: float32 (format ‘f’) Writable Size must equal i Temp float32.
iMV (buffer) – Writable Size must equal i Temp int32.
labels (buffer) – Writable Size must equal i Output labels (int32).
Checks
v.slow_axis == 0 [ValueError] (i.format == 'H' or i.itemsize == 2) [ValueError] (j.format == 'H' or j.itemsize == 2) [ValueError] j.n == i.n [ValueError] v.n == i.n [ValueError] MV.format == 'f' [ValueError] MV.n == i.n [ValueError] (iMV.format == 'i' or iMV.format == 'l') [ValueError] iMV.n == i.n [ValueError] (labels.format == 'i' or labels.format == 'l') [ValueError] labels.n == i.n [ValueError]
Overloads
int sparse_localmaxlabel_u32(const uint32_t *v, const uint16_t *i, const uint16_t *j, intptr_t nnz, float *MV, int32_t *iMV, int32_t *labels) -> int (When: (((v.format == 'I' or v.format == 'L') and v.itemsize == 4) and v.slow_axis == 0)) Map: v = v.ptr (const uint32_t *) i = i.ptr (const uint16_t *) j = j.ptr (const uint16_t *) nnz = i.n (intptr_t) MV = MV.ptr (float *) iMV = iMV.ptr (int32_t *) labels = labels.ptr (int32_t *) int sparse_localmaxlabel_u16(const uint16_t *v, const uint16_t *i, const uint16_t *j, intptr_t nnz, float *MV, int32_t *iMV, int32_t *labels) -> int (When: (v.format == 'H' and v.slow_axis == 0)) Map: v = v.ptr (const uint16_t *) i = i.ptr (const uint16_t *) j = j.ptr (const uint16_t *) nnz = i.n (intptr_t) MV = MV.ptr (float *) iMV = iMV.ptr (int32_t *) labels = labels.ptr (int32_t *) int sparse_localmaxlabel_u8(const uint8_t *v, const uint16_t *i, const uint16_t *j, intptr_t nnz, float *MV, int32_t *iMV, int32_t *labels) -> int (When: (v.format == 'B' and v.slow_axis == 0)) Map: v = v.ptr (const uint8_t *) i = i.ptr (const uint16_t *) j = j.ptr (const uint16_t *) nnz = i.n (intptr_t) MV = MV.ptr (float *) iMV = iMV.ptr (int32_t *) labels = labels.ptr (int32_t *) int sparse_localmaxlabel(const float *v, const uint16_t *i, const uint16_t *j, intptr_t nnz, float *MV, int32_t *iMV, int32_t *labels) -> int (When: (v.format == 'f' and v.slow_axis == 0)) Map: v = v.ptr (const float *) i = i.ptr (const uint16_t *) j = j.ptr (const uint16_t *) nnz = i.n (intptr_t) MV = MV.ptr (float *) iMV = iMV.ptr (int32_t *) labels = labels.ptr (int32_t *)
- c2ImageD11.sparse_overlaps(i1: buffer, j1: buffer, k1: buffer, i2: buffer, j2: buffer, k2: buffer) int
identifies the pixels in i1,j1 which overlap i2,j2. The list of overlaps is returned in k1/k2 such that i1[k1]==i2[k2] and j1[k1]==j2[k2]. Probably assumes that sparse_is_sorted was true.
- Parameters:
i1 (buffer) – Rows 1 (uint16).
j1 (buffer) – Size must equal i1 Cols 1 (uint16).
k1 (buffer) – Writable Size must equal i1 Output indices into 1.
i2 (buffer) – Rows 2 (uint16).
j2 (buffer) – Size must equal i2 Cols 2 (uint16).
k2 (buffer) – Writable Size must equal i2 Output indices into 2.
Checks
i1.slow_axis == 0 [ValueError] (i1.format == 'H' or i1.itemsize == 2) [ValueError] (j1.format == 'H' or j1.itemsize == 2) [ValueError] j1.n == i1.n [ValueError] (k1.format == 'i' or k1.format == 'l') [ValueError] k1.n == i1.n [ValueError] (i2.format == 'H' or i2.itemsize == 2) [ValueError] (j2.format == 'H' or j2.itemsize == 2) [ValueError] j2.n == i2.n [ValueError] (k2.format == 'i' or k2.format == 'l') [ValueError] k2.n == i2.n [ValueError]
Overloads
int sparse_overlaps(const uint16_t *i1, const uint16_t *j1, int *k1, intptr_t nnz1, const uint16_t *i2, const uint16_t *j2, int *k2, intptr_t nnz2) -> int Map: i1 = i1.ptr (const uint16_t *) j1 = j1.ptr (const uint16_t *) k1 = k1.ptr (int *) nnz1 = i1.n (intptr_t) i2 = i2.ptr (const uint16_t *) j2 = j2.ptr (const uint16_t *) k2 = k2.ptr (int *) nnz2 = i2.n (intptr_t)
- c2ImageD11.sparse_smooth(v: buffer, i: buffer, j: buffer, s: buffer) void
smooths data in coo format. Workaround for avoiding equal pixels on peak tails for localmaxlabel single threaded
- Parameters:
v (buffer) – Type: float32 (format ‘f’) Size must equal i Values (float32).
i (buffer) – Rows (uint16).
j (buffer) – Size must equal i Cols (uint16).
s (buffer) – Type: float32 (format ‘f’) Writable Size must equal i Output smoothed (float32).
Checks
v.slow_axis == 0 [ValueError] v.format == 'f' [ValueError] (i.format == 'H' or i.itemsize == 2) [ValueError] (j.format == 'H' or j.itemsize == 2) [ValueError] j.n == i.n [ValueError] v.n == i.n [ValueError] s.format == 'f' [ValueError] s.n == i.n [ValueError]
Overloads
void sparse_smooth(const float *v, const uint16_t *i, const uint16_t *j, intptr_t nnz, float *s) Map: v = v.ptr (const float *) i = i.ptr (const uint16_t *) j = j.ptr (const uint16_t *) nnz = i.n (intptr_t) s = s.ptr (float *)
- c2ImageD11.splat(rgba: buffer, gve: buffer, u: buffer, npx: int) void
draws gvectors into an rgba image. The horror of maintaining plot3d over the years motivated this code. See test/demo/tksplat * set the color and markersize per peak * perhaps also a draw order (back to front, top to bottom) ?
- Parameters:
rgba (buffer) – Writable Output uint8 RGBA (h, w, 4).
gve (buffer) – Type: float64 (format ‘d’) Shape: 2D Axis 1: 3 elements G-vectors (ng, 3).
u (buffer) – Type: float64 (format ‘d’) Projection matrix (9).
npx (int) – Marker half-size.
Checks
(rgba.format == 'B' or rgba.format == 'b') [ValueError] rgba.ndim >= 1 [ValueError] gve.format == 'd' [ValueError] gve.ndim >= 1 [ValueError] u.format == 'd' [ValueError] u.n == 9 [ValueError] gve.slow_axis == 0 [ValueError] gve.ndim == 2 [ValueError] gve.shape[1] == 3 [ValueError]
Overloads
void splat(uint8_t *rgba, intptr_t w, intptr_t h, const double gve[][3], intptr_t ng, const double *u, intptr_t npx) Map: rgba = rgba.ptr (uint8_t *) w = rgba.shape[1] (intptr_t) h = rgba.shape[0] (intptr_t) gve = gve.ptr (const double (*)[3]) ng = gve.shape[0] (intptr_t) u = u.ptr (const double *) npx = npx (intptr_t)
- c2ImageD11.tosparse_f32(img: buffer, msk: buffer, row: buffer, col: buffer, val: buffer, cut: float) int
Convert dense float32 image to sparse COO.
- Parameters:
img (buffer) – Type: float32 (format ‘f’) Shape: 2D Input float32 2D.
msk (buffer) – Size must equal img Mask (uint8).
row (buffer) – Writable Output rows.
col (buffer) – Writable Output cols.
val (buffer) – Type: float32 (format ‘f’) Writable Output values.
cut (float) – Threshold.
Checks
img.format == 'f' [ValueError] img.ndim == 2 [ValueError] img.slow_axis == 0 [ValueError] ((msk.format == 'B' or msk.format == 'b') or msk.format == '?') [ValueError] msk.n == img.n [ValueError] (row.format == 'H' or row.itemsize == 2) [ValueError] (col.format == 'H' or col.itemsize == 2) [ValueError] val.format == 'f' [ValueError]
Overloads
int tosparse_f32(const float *img, const uint8_t *msk, uint16_t *row, uint16_t *col, float *val, double cut, intptr_t ns, intptr_t nf) -> int Map: img = img.ptr (const float *) msk = msk.ptr (const uint8_t *) row = row.ptr (uint16_t *) col = col.ptr (uint16_t *) val = val.ptr (float *) cut = cut (double) ns = img.shape[0] (intptr_t) nf = img.shape[1] (intptr_t)
- c2ImageD11.tosparse_u16(img: buffer, msk: buffer, row: buffer, col: buffer, val: buffer, cut: int) int
stores pixels from img into row/col/val. msk determines whether pixels are masked (e.g. eiger mask) returns the number of pixels found
- Parameters:
img (buffer) – Shape: 2D Input uint16 2D.
msk (buffer) – Size must equal img Mask (uint8, 0=include).
row (buffer) – Writable Output rows.
col (buffer) – Writable Output cols.
val (buffer) – Writable Output values.
cut (int) – Threshold.
Checks
(img.format == 'H' or img.itemsize == 2) [ValueError] img.ndim == 2 [ValueError] img.slow_axis == 0 [ValueError] ((msk.format == 'B' or msk.format == 'b') or msk.format == '?') [ValueError] msk.n == img.n [ValueError] (row.format == 'H' or row.itemsize == 2) [ValueError] (col.format == 'H' or col.itemsize == 2) [ValueError] (val.format == 'H' or val.itemsize == 2) [ValueError]
Overloads
int tosparse_u16(const uint16_t *img, const uint8_t *msk, uint16_t *row, uint16_t *col, uint16_t *val, int cut, intptr_t ns, intptr_t nf) -> int Map: img = img.ptr (const uint16_t *) msk = msk.ptr (const uint8_t *) row = row.ptr (uint16_t *) col = col.ptr (uint16_t *) val = val.ptr (uint16_t *) cut = cut (int) ns = img.shape[0] (intptr_t) nf = img.shape[1] (intptr_t)
- c2ImageD11.tosparse_u32(img: buffer, msk: buffer, row: buffer, col: buffer, val: buffer, cut: float) int
Convert dense uint32 image to sparse COO.
- Parameters:
img (buffer) – Shape: 2D Input uint32 2D.
msk (buffer) – Size must equal img Mask (uint8).
row (buffer) – Writable Output rows.
col (buffer) – Writable Output cols.
val (buffer) – Writable Output values.
cut (float) – Threshold (float).
Checks
((img.format == 'I' or img.format == 'L') and img.itemsize == 4) [ValueError] img.ndim == 2 [ValueError] img.slow_axis == 0 [ValueError] ((msk.format == 'B' or msk.format == 'b') or msk.format == '?') [ValueError] msk.n == img.n [ValueError] (row.format == 'H' or row.itemsize == 2) [ValueError] (col.format == 'H' or col.itemsize == 2) [ValueError] (val.format == 'I' or val.itemsize == 4) [ValueError]
Overloads
int tosparse_u32(const uint32_t *img, const uint8_t *msk, uint16_t *row, uint16_t *col, uint32_t *val, double cut, intptr_t ns, intptr_t nf) -> int Map: img = img.ptr (const uint32_t *) msk = msk.ptr (const uint8_t *) row = row.ptr (uint16_t *) col = col.ptr (uint16_t *) val = val.ptr (uint32_t *) cut = cut (double) ns = img.shape[0] (intptr_t) nf = img.shape[1] (intptr_t)
- c2ImageD11.uint16_to_float_darkflm(img: buffer, drk: buffer, flm: buffer, data: buffer) void
subtracts image drk(float32) from raw data in data (uint16), multiples by flm(float32) and returns in img.
- Parameters:
img (buffer) – Type: float32 (format ‘f’) Writable
drk (buffer) – Type: float32 (format ‘f’) Size must equal img
flm (buffer) – Type: float32 (format ‘f’) Size must equal img
data (buffer) – Size must equal img
Checks
img.format == 'f' [ValueError] drk.format == 'f' [ValueError] drk.n == img.n [ValueError] flm.format == 'f' [ValueError] flm.n == img.n [ValueError] (data.format == 'H' or data.itemsize == 2) [ValueError] data.n == img.n [ValueError] GIL: released
Overloads
void uint16_to_float_darkflm(float *img, const float *drk, const float *flm, const uint16_t *data, intptr_t npx) (When: ((img.format == 'f' and drk.format == 'f') and flm.format == 'f')) Map: img = img.ptr (float *) drk = drk.ptr (const float *) flm = flm.ptr (const float *) data = data.ptr (const uint16_t *) npx = img.n (intptr_t)
- c2ImageD11.uint16_to_float_darksub(img: buffer, drk: buffer, data: buffer) void
subtracts image drk(float32) from raw data in data (uint16) and returns in img.
- Parameters:
img (buffer) – Type: float32 (format ‘f’) Writable
drk (buffer) – Type: float32 (format ‘f’) Size must equal img
data (buffer) – Size must equal img
Checks
img.format == 'f' [ValueError] drk.format == 'f' [ValueError] drk.n == img.n [ValueError] (data.format == 'H' or data.itemsize == 2) [ValueError] data.n == img.n [ValueError] GIL: released
Overloads
void uint16_to_float_darksub(float *img, const float *drk, const uint16_t *data, intptr_t npx) (When: (img.format == 'f' and drk.format == 'f')) Map: img = img.ptr (float *) drk = drk.ptr (const float *) data = data.ptr (const uint16_t *) npx = img.n (intptr_t)
- c2ImageD11.verify_rounding(n: int) int
checks the round to nearest int code is correct
- Parameters:
n (int) – ask jon about this parameter
Overloads
int verify_rounding(int n) Map: n = n (int)
bslz4_to_sparse#
Reads bitshuffle-lz4 compressed HDF5 chunks straight into sparse arrays. Source: jonwright/bslz4_to_sparse
bslz4_to_sparse: decode bitshuffle-lz4/zstd detector frames straight into sparse pixel lists, optionally with a sparse matrix product (pyFAI integration) in the same pass.
chunk2sparse(mask, dtype, codec, pipeline) sparsify chunk2sparseCSC(mask, csc, dtype, codec, pipeline) sparsify + matrix dot
Each object has a pipeline (src/_pipeline.py): one value per processing step, resolved when the object is made (0 / None: the best guess for this CPU, data and matrix) and kept in .pipeline; describe() names the values. An automatic mask step on uint16 data with masked pixels is settled by the first frame decoded: ‘planes’ when most masked pixels hold 65535 there (and the decode block is at most 8192 pixels, a multiple of 64), ‘pixel’ otherwise. Nothing is global, so objects with different pipelines can run in different threads.
plan(mask, csc, dtype, codec, pipeline) the matrix of a chunk2sparseCSC, prepared once plan.context(howmany, thresholds) a chunk2sparseCSC on that plan, per thread
A chunk2sparseCSC owns a copy of its matrix (mask folded, analysed, laid out for the dot). A plan is that copy made once and shared: every object made from it (chunk2sparseCSC(mask, plan, …) or plan.context()) builds each layout at most once between them, and only reads the plan’s arrays, which are read-only. Workspace, output buffers and the pipeline stay per object.
Threads: the GIL is released while decoding, and on free-threaded Python (3.14t, 3.15t) the module runs without a GIL. There are no locks (a plan has one, for building a layout), so:
use one chunk2sparse / chunk2sparseCSC object per thread; an object keeps its workspace and output arrays and reuses them on every call;
the arrays a call returns are those buffers (except coo(), which copies): the next call on the same object overwrites them;
leave a call’s inputs alone until it returns: do not modify, resize or close the chunks, the from_buffer base buffer (e.g. an mmap) or the mask from another thread meanwhile.
Sharing an object between threads, or breaking these rules, gives wrong results or a crash rather than an error.
- bslz4_to_sparse.block_starts(chunks, dtype, out=None)
Where each compressed block of each chunk starts, found on the CPU without decoding: the block index the GPU decoder needs (cuda unblock=’cpu’). Block b holds pixels [b * B, (b + 1) * B) with B = the chunk’s block size in pixels.
Returns starts, a uint32 array (nchunks, nblocks): the byte offset, from the start of its chunk, of each block’s 4-byte big-endian compressed size; the compressed block follows it. The last block may be partial, and up to 8 * dtype.itemsize - 1 bytes of pixels are stored raw right after it. Bytes after those are ignored, as by the HDF5 filter. lz4 or zstd. Every chunk must have the same total size and block size; a chunk whose blocks or raw bytes run past its end raises (corrupt or truncated). out = None, or a uint32 array of nchunks * nblocks elements to fill
- bslz4_to_sparse.block_starts_from_buffer(base, offsets, lengths, dtype, out=None)
As block_starts, for the chunks at byte offsets[i] (lengths[i]) inside the one buffer base; the starts stay relative to each chunk.
- bslz4_to_sparse.bslz4_to_sparse(ds, num, cut, mask=None, pixelbuffer=None, workspace=None, codec=None, pipeline=None)
Reads a bitshuffle compressed hdf5 dataset and converts this directly into a sparse format (indices, values) when decoding the data.
ds = hdf5 dataset containing [nframes, ni, nj] pixels num = frame number to read cut = threshold, pixels not above this value are ignored (compared in the pixel type) mask = detector mask. Active pixels > 0. pixelbuffer = None or (values, indices) storage space workspace = None or a uint8 array to use as decode scratch space codec = None to auto-detect lz4 vs zstd, or an explicit CODEC_LZ4 / CODEC_ZSTD pipeline = None (best guess), or step values: see describe()
returns (number_of_pixels, (values, indices))
- bslz4_to_sparse.build_info()
How the loaded native extension was built, as a dict: the package “version”, “git” (git describe –tags –always –dirty of the source tree: a tag when built clean on a tagged commit, “-dirty” when it had local changes, None outside a git checkout), “modified” (the changed tracked files when dirty), “src_sha256” (of the compiled sources and headers, also for builds without git), “compiler”, “platform” and “built_utc”.
- class bslz4_to_sparse.chunk2sparse(mask, dtype=<class 'numpy.uint16'>, codec=None, pipeline=None, howmany=None, thresholds=None, negatives='drop')
Decode bitshuffle-lz4/zstd chunks of (ni, nj) frames into the pixels above a cut (and not masked).
mask = detector mask, (ni, nj) uint8, active pixels > 0 dtype = the pixel dtype of the dataset codec = None (default): found from the first chunk decoded, or CODEC_LZ4 /
CODEC_ZSTD (detect_codec(dataset) reads it from the HDF5 file). Until then .codec is CODEC_LZ4 and .pipeline is resolved for lz4; it is resolved again if the first chunk is zstd.
pipeline = None (best guess), or step values: see describe() howmany = None (default): every pixel above the cut is returned. An
integer: at most that many per frame, chosen as ImageD11’s top_pixels does. A frame with more pixels above the cut keeps those above the first of the sorted thresholds that leaves fewer than howmany (else above the last), and then the first howmany of them in pixel order.
- thresholds = None: max(cut, 1) * 2**i for i in 0..15, or up to 16 sorted
values. Only used when howmany is set.
- negatives = “drop” (default) or “list”, for signed integer pixels (i8 .. i64). “drop”: the
list holds the pixels above the cut only, so negative pixels never appear in it (CCD frames with the dark subtracted). “list”: every negative pixel is in the list too, whatever the cut – for detectors that mark gaps and bad pixels with negative values that change from frame to frame (older Pilatus: -1, -2), so the caller can correct for them: see docs/index.md, “Pixel types and negative values”. Not with howmany.
cut is compared in the pixel type: for integer pixels a fractional cut is floored and a cut above the type’s maximum selects nothing; a negative cut is an error. So with signed pixels (i8 .. i64) negative values are only returned with negatives=”list”.
c(chunk, cut) -> npixels, (values, indices) for one frame (the arrays are full size: slice [:npixels]); c.multi(chunks, cut) -> the same per frame for a batch, npixels an array and the arrays (nframes, ni*nj). After a call, last_cut[i] is the cut frame i ended up with (the call’s cut unless howmany reduced it) and last_nabove[i] the number of pixels above that cut, before the list was truncated to howmany.
- coo(buffer, cut)
Decode one chunk to (npixels, row, col, values): uint16 row and column of each pixel above cut, and its value. These are new arrays (copies), unlike the buffers __call__ returns.
- from_buffer(base, offsets, lengths, cut)
As multi, for the chunks at byte offsets[i] (lengths[i]) inside the one buffer base (an mmap of the HDF5 file, or the file read into memory): see locate_chunks and offsets_lengths.
- from_frames(frames, cut)
As multi, for uncompressed frames: an array (nframes, ni, nj) or (nframes, ni*nj) of this object’s pixel dtype. Only the back half of the pipeline runs (mask, collect, matrix product, howmany): the same results as multi on the compressed frames. A C-contiguous array of the right dtype is used in place, else a copy is made.
- multi(chunks, cut)
Decode a batch of chunks (one frame each) of this dataset: returns npixels[nframes], (values, indices) of shape (nframes, ni*nj).
- class bslz4_to_sparse.chunk2sparseCSC(mask, csc, dtype=<class 'numpy.uint16'>, codec=None, pipeline=None, howmany=None, thresholds=None, negatives='drop')
As chunk2sparse, and every frame also goes through a sparse matrix product (a pyFAI integration): powder = csc @ frame.
mask = detector mask, (ni, nj) uint8, active pixels > 0 csc = scipy.sparse matrix (nout, ni*nj), or a pyFAI CSC integrator
(data, indices, indptr, bins): used as it is, float32 weights, float64 powder. Or a plan(mask, csc, …), which holds the matrix prepared once (mask folded, analysed, layouts built on demand) for any number of objects; mask must be the one the plan was made with, else ValueError. Or the result of fixed_point_matrix(csc, mask, dtype): integer weights, and the powder is the int64 sums of weight x pixel, exact, not converted to float: float powder = powder / powder_scale (an integer power of two, 2**b). With a matrix of weight 1 per pixel (no pixel splitting) these are exactly the photon counts summed per bin. Either way the matrix is not changed here: preparing it is a step of its own.
- dtype, codec, pipeline: as chunk2sparse; pipeline’s dot step picks the
matrix layout (auto: from what the matrix is; “csc-int” for a fixed_point_matrix, which also takes csc-run-int and, made with wbits=16, csc-run-int16). A matrix of weight 1 and one bin per pixel (a histogram) of integer pixels of at most 32 bits is auto “csc-nosplit-int”: the sums are accumulated in int64 (no weights, no conversion to float) and returned as float64 like any float dot; a bin sum above 2**53 is rounded in that last cast
- howmany, thresholds, negatives: as chunk2sparse; they choose the pixels returned only:
the powder always uses every unmasked pixel as it is, negative ones included
Signed pixels: the powder sums negative pixels as values either way (right for CCD frames with the dark subtracted). For negative markers that change from frame to frame (older Pilatus: -1, -2), negatives=”list” returns them in the pixel list, and the caller removes them from the powder and from the normalisation afterwards (docs/index.md, “Pixel types and negative values”).
The array of the powder is the object’s own and is overwritten by the next call. The object owns copies of the matrix and the mask, taken here (read-only): later changes to the arrays you passed do not reach it. The mask is folded into a raw matrix once, here: masked pixels contribute nothing to the powder (fixed_point_matrix does it for the matrix it makes). Objects made again from the same csc each repeat this and hold their own copy: for one object per thread, make a plan(mask, csc, …) and give it to each in place of csc (or use plan.context()); they then share the copy and the layouts, each built once. c(chunk, cut) -> npixels, (values, indices), powder; c.multi(chunks, cut) -> the same per frame for a batch.
- coo(buffer, cut)
Decode one chunk to (npixels, row, col, values, powder): as chunk2sparse.coo, plus the frame’s powder. All are new arrays (copies), unlike the buffers __call__ returns.
- from_buffer(base, offsets, lengths, cut)
As multi, for the chunks at byte offsets[i] (lengths[i]) inside the one buffer base: see locate_chunks and offsets_lengths.
- from_frames(frames, cut)
As multi, for uncompressed frames: an array (nframes, ni, nj) or (nframes, ni*nj) of this object’s pixel dtype. Only the back half of the pipeline runs (mask, collect, matrix product, howmany): the same results as multi on the compressed frames. A C-contiguous array of the right dtype is used in place, else a copy is made.
- multi(chunks, cut)
Decode a batch of chunks (one frame each) of this dataset: returns npixels[nframes], (values, indices) of shape (nframes, ni*nj), powder (nframes, nout).
- property powder_scale
The integer (2**b) an integer powder is divided by to get float; None for a float dot.
- bslz4_to_sparse.decompress(chunks, dtype, unshuffle=True, out=None, codec=None)
Decompress bitshuffle-lz4/zstd chunks (one frame each, as h5py’s read_direct_chunk gives them) without any sparse processing: the front half of the pipeline alone. The GIL is released, so threads decompress in parallel; nothing touches HDF5.
dtype = the pixel dtype of the dataset unshuffle = True: the pixel values, array (nframes, npixels) of dtype.
False: each block as the HDF5 filter’s decompressor yields it, before the bit unshuffle: uint8 array (nframes, nbytes), for a later stage (the GPU, from_frames after a separate unshuffle)
- out = None, or a writeable C-contiguous array to fill (at least
nframes * the decoded size in bytes), returned
codec = None (found from the first chunk), CODEC_LZ4 or CODEC_ZSTD
- bslz4_to_sparse.decompress_from_buffer(base, offsets, lengths, dtype, unshuffle=True, out=None, codec=None)
As decompress, for the chunks at byte offsets[i] (lengths[i]) inside the one buffer base (an mmap of the HDF5 file, or the file read into memory): see locate_chunks and offsets_lengths.
- bslz4_to_sparse.describe(pipeline=None)
The step names of a pipeline (a dict step -> name; None for a step left auto (0), or not used), or, with no argument, every step’s values with whether this CPU/build can run them (a dict step -> list of (value, name, usable, what it needs)).
- bslz4_to_sparse.detect_codec(ds)
Detect which block codec (CODEC_LZ4 or CODEC_ZSTD) a dataset’s bitshuffle filter was configured with, from its HDF5 filter pipeline (cd_values[4]). Falls back to CODEC_LZ4 if it can’t be determined.
- bslz4_to_sparse.fixed_point_matrix(csc, mask, dtype, maxval=None, wbits=32)
Prepare a csc matrix (scipy csc, pyFAI CSC engine, …) for exact integer sums: fold the mask in (masked pixels add nothing), then store the weights as fixed-point integers of wbits (32 or 16) bits. Give the result to chunk2sparseCSC in place of the matrix.
dtype: the pixel dtype of the data (integer). The weights get b fractional bits, b <= wbits (their width) and b <= 62 - log2(maxval + 1) - log2(the largest sum of weights in a bin), so that the int64 sums cannot overflow; each doubling of maxval costs a bit. maxval is the dtype’s maximum unless given: the largest value the data can hold. For 16-bit pixels b is about 31, for 32-bit pixels at their maximum about 17 for a 1D matrix (weight step 2**-17: a relative error of a few 1e-6 in a bin sum). Pixels above maxval (saturated ones) can make a sum wrap: the dots add modulo 2**64, so the sum is exact again once those pixels, which are in the sparse output when the cut is at most maxval, are clipped or subtracted from it (test/test_wrap.py). tools/fixed_point_precision.py prints b for a matrix and data.
Raises ValueError for a matrix that cannot be fixed-point (negative weights beyond rounding noise, no room for 4 fractional bits). The result has .scale (the integer 2**b to divide the int64 sums by) and .nbins.
- bslz4_to_sparse.locate_chunks(ds)
Where each frame’s compressed chunk lies in the HDF5 file: a dict {frame: (byte_offset, byte_size)} for a (nframes, ni, nj) dataset chunked one frame per chunk. With offsets_lengths, it lets from_buffer read the chunks from one buffer holding the file (e.g. an np.memmap) with no h5py call per frame. Raises ValueError for other chunk shapes, and for a chunk stored with the bitshuffle filter skipped.
- bslz4_to_sparse.offsets_lengths(frame_offsets, frames)
The (offsets int64, lengths int32) arrays from_buffer takes, for the given frame numbers, from locate_chunks’ {frame: (offset, size)}.
- class bslz4_to_sparse.plan(mask, csc, dtype=<class 'numpy.uint16'>, codec=None, pipeline=None)
A matrix prepared once for any number of chunk2sparseCSC objects, one per thread: the plan holds its own read-only copy of csc (mask folded in, or the fixed_point_matrix copied), what the matrix is (for the automatic dot) and the layouts the objects ask for, each built once however many ask at the same time. Later changes to the arrays passed in do not reach it.
p = plan(mask, csc, dtype, codec, pipeline) c = p.context(howmany, thresholds) # or chunk2sparseCSC(mask, p, dtype, …)
mask, csc, dtype, codec, pipeline: as chunk2sparseCSC. They are the defaults of context(); chunk2sparseCSC(mask, p, …) takes its own. A plan is never changed by its objects except by adding a built layout.
- context(howmany=None, thresholds=None, negatives='drop')
A chunk2sparseCSC on this plan, for one thread: its own workspace, output arrays and pipeline; the matrix and layouts are the plan’s. howmany, thresholds, negatives: as chunk2sparse.