ImageD11.sinograms.sinogram module#

class ImageD11.sinograms.sinogram.GrainSinogram(grain_obj, dataset)#

Bases: object

Class to build, hold and reconstruct sinograms of grains for Scanning 3DXRD data

build_sinogram(columns=('omega',), intensity_column='sum_intensity', normalise=True)#

Build the sinogram from self.cf_for_sino. Assumes preparation is done: ‘h’,’k’,’l’ columns exist, any hkl/validity filtering already applied, and the signal lives in intensity_column. normalise divides each projection row by its max (original default); pass False to keep a corrected intensity scale.

compute_corrected_intensity(out_column='corr_sum_intensity', in_column='sum_intensity', sf_correction=None, apply_lf_pol=True)#

Write a corrected-intensity column and return its name. correction = lf/pol (needs tth,eta) and/or 1/structure-factor (needs every hkl tabulated – run filter_valid_hkls first).

compute_hkl(store=True)#

Integer hkl for self.cf_for_sino from grain.ubi. Returns (hkl_real, hkl_int), both (3, N). If store, writes integer ‘h’,’k’,’l’ columns.

correct_halfmask()#

Applies halfmask correction to sinogram

correct_ring_current(is_half_scan=False, min_ring_current_frac=0.5)#

Corrects each row of the sinogram to the ring current of the corresponding scan

filter_hkltol(hkltol=0.25, hkl_real=None, hkl_int=None)#

Drop peaks whose g-vector is > hkltol from an integer hkl.

filter_valid_hkls(sf_correction)#

Drop peaks whose integer hkl is not tabulated in sf_correction. Needs h,k,l columns (prepare_peaks_* / compute_hkl provides them).

classmethod from_h5py_group(group, ds, grain)#

Creates a GrainSinogram object from an h5py group, dataset and grain object

get_shape_mask(method='iradon', cutoff=None)#

Gets a boolean mask representing the grain shape from the grain reconstruction. Performs a binary threshold of the reconstruction. Uses manual threshold value if cutoff value provided. Performs global Otsu threshold if no value provided.

mask_central_zingers(method='iradon', radius=25)#
prepare_peaks_from_2d(cf_2d, grain_label, hkltol=0.25, gv=None)#

cf_2d is an already spatially-corrected 2D columnfile with geometry. Keeps only the columns the sinogram build needs, to save memory.

prepare_peaks_from_4d(cf_4d, gord, inds, grain_label, spatial_corrector, hkltol=0.25)#

Subset THIS grain’s 2D peaks out of ds.pk2d, spatially correct and add geometry on that subset only, then compute/store hkl and apply hkl tolerance. Never materialises a global cf_2d.

recon(method='iradon', workers=1, projections=None, **extra_args)#

Performs reconstruction given reconstruction method

method = “iradon”, “mlem”, “astra” workers = threads to use - passed to the method

projections = which projections to use for reconstruction using a subset of data (twins)

iradon( self.sino[ :, projections ], theta = self.sinoangles[ projections ], … ) effectively a sinogram mask - perhaps this should move to iradon code.

extra_args = passed to the projection function

iradon -> ImageD11.sinograms.roi_iradon.run_iradon { pad=20, shift=0, workers=1, mask=None,

apply_halfmask=False, mask_central_zingers=False, central_mask_radius=25, filter_name=’hamming’}

mlemImageD11.sinograms.roi_iradon.run_mlem

{ mask=None, pad=20, shift=0, workers=1, niter=20, apply_halfmask=False,

mask_central_zingers=False, central_mask_radius=25 }

astrarun_astra in this file

{ shift=0, pad=0, mask=None, niter=100, astra_method=’SIRT_CUDA’, workers=None }

to_h5py_group(parent_group, group_name)#

Creates a H5Py group for this GrainSinogram. parent_group is the parent H5py Group group_name is the name of the H5py Group for this name Very useful for saving lists of GrainSinograms to an H5 file

update_lab_position_from_peaks(cf_4d, grain_label, y0_guess)#

Updates translation of self.grain using peaks in assigned 4D colfile. Also updates self.recon_y0 with centre

update_lab_position_from_recon(method='iradon')#

Updates translation of self.grain by finding centre-of-mass of reconstruction Only really valid for very small grains. Does not update translation if no fitting result found.

update_recon_parameters(pad=None, shift=None, mask=None, niter=None, y0=None)#

Update some or all of the reconstruction parameters in one go

class ImageD11.sinograms.sinogram.StructureFactorCorrection(sf_dense, valid, hkl_min)#

Bases: object

hkl lookup + structure factors used to correct peak intensities when building a sinogram. Build once per phase and reuse across grains.

sf_dense3D float array; sf_dense[h - h0, k - k0, l - l0] is the

structure-factor scale for that reflection (intensities are divided by this). Entries where valid is False are ignored.

valid : 3D bool array, same shape, True where a reflection is tabulated. hkl_min : length-3 int (h0, k0, l0) mapped to index (0,0,0).

classmethod from_cif(cif_path, wavelength, tth_max, min_fraction=0.001)#

X-ray structure factors |F|^2 of every reflection up to tth_max (degrees) at wavelength (Angstrom), computed from a CIF with Dans_Diffraction. The hkl are in the cell of the CIF, which should be the standard setting. Reflections weaker than min_fraction of the strongest are not tabulated (systematic absences and nearly absent ones), so dividing by sf_values stays finite.

sf_values(hkl)#

Structure-factor scale for each peak (shape (N,)); intensities are divided by this. hkl (shape (3, N)) must already be filtered via valid_mask.

valid_mask(hkl)#
ImageD11.sinograms.sinogram.build_slice_arrays(grainsinos, cutoff_level=0.0, method='iradon', grain_labels=None)#

Build grain maps from individual grain reonstructions Optionally provide a different list of grain labels to label the grains

ImageD11.sinograms.sinogram.build_slice_arrays_clean(grainsinos, method='iradon', grain_labels=None)#

Build grain maps from individual grain reonstructions Cleans and normalises reconstructions before building slice arrays Saves cleaned and normalised reconstruction to gs.recons[method_norm] Optionally provide a different list of grain labels to label the grains

ImageD11.sinograms.sinogram.counting_sort(ary, maxval=None, minval=None)#

Radix sort for integer array. Single threaded. O(n) Numpy should be doing this…

ImageD11.sinograms.sinogram.filter_normalise_recon(recon)#

Function to filter and normalise reconstructions

ImageD11.sinograms.sinogram.find_grain_id(spot3d_id, grain_id, spot2d_label, grain_label, order, nthreads=20)#

Assignment grain labels into the peaks 2d array spot3d_id = the 3d spot labels that are merged and indexed grain_id = the grains assigned to the 3D merged peaks spot2d_label = the 3d label for each 2d peak grain_label => output, which grain is this peak order = the order to traverse spot2d_label sorted

ImageD11.sinograms.sinogram.get_2d_peaks_from_4d_peaks(p2d, cf, return_labels=False)#

inds tells you, for each grain, where its 2D spots live in the sorted order. return_labels also returns grain_2d_id: one int per 2D peak giving its grain, a compact selector into p2d you can store once and reuse.

ImageD11.sinograms.sinogram.norm(r)#
ImageD11.sinograms.sinogram.palloc(shape, dtype)#

Allocate and fill an array with zeros in parallel

ImageD11.sinograms.sinogram.pmax(ary)#

Find the min/max of an array in parallel

ImageD11.sinograms.sinogram.read_h5(filename, ds, group_name='grains')#

Read list of GrainSinogram objects from H5Py file Will also create self.grain objects from the H5Py file Because GrainSinogram objects can’t exist without corresponding grain objects

ImageD11.sinograms.sinogram.read_slice_recon(filename)#
ImageD11.sinograms.sinogram.run_astra(sino, angles, shift=0, pad=0, mask=None, niter=100, astra_method='SIRT_CUDA', workers=None, min_constraint=0, max_constraint=None)#
ImageD11.sinograms.sinogram.save_array(grp, name, ary)#
ImageD11.sinograms.sinogram.shift_sinogram(sino, shift_amount, order=1)#

Shift a sinogram along dty by a possibly non-integer amount, equivalent to astra.functions.geom_postalignment(proj_geom, shift).

ImageD11.sinograms.sinogram.write_h5(filename, list_of_sinos, overwrite_grains=False, group_name='grains')#

Write list of GrainSinogram objects to H5Py file If overwrite_grains is True, will replace grains in group_name

ImageD11.sinograms.sinogram.write_pbp_strain(filename, pbp_strain_slice_arrays)#
ImageD11.sinograms.sinogram.write_slice_recon(filename, slice_arrays)#