CrystData#
- class cbclib.CrystData(input_file=None, transform=None, num_threads=2, output_file=None, data=None, good_frames=None, mask=None, frames=None, whitefield=None, cor_data=None, background=None, streak_mask=None)[source]#
Convergent beam crystallography data container class. Takes a
cbclib.CXIStorefile handler. Provides an interface to work with the detector images and detect the diffraction streaks. Also provides an interface to load from a file and save to a file any of the data attributes. The data frames can be tranformed using any of thecbclib.Transformclasses.- Parameters
input_file (
Optional[CXIStore]) – Input filecbclib.CXIStorefile handler.transform (
Optional[Transform]) – An image transform object.num_threads (
int) – Number of threads used in the calculations.output_file (
Optional[CXIStore]) – On output filecbclib.CXIStorefile handler.good_frames (
Optional[ndarray]) – An array of good frames’ indices.frames (
Optional[ndarray]) – List of frame indices inside the container.whitefield (
Optional[ndarray]) – Measured frames’ white-field.background (
Optional[ndarray]) – Detector image backgrounds.streak_mask (
Optional[ndarray]) – A mask of detected diffraction streaks.
- blur_pupil(setup, padding=0.0, blur=0.0)[source]#
Blur pupil region in the background corrected images.
- contents()#
Return a list of the attributes stored in the container that are initialised.
- get(attr, value=None)#
Retrieve a dataset, return
valueif the attribute is not found.
- get_pca()[source]#
Perform the Principal Component Analysis [PCA] of the measured data and return a set of eigen flat-fields (EFF).
- Return type
- Returns
A tuple of (‘effs’, ‘eig_vals’). The elements are as follows:
’effs’ : Set of eigen flat-fields.
’eig_vals’ : Corresponding eigen values for each of the eigen flat-fields.
- Raises
ValueError – If there is no
whitefieldinside the container.
References
- PCA
Vincent Van Nieuwenhove, Jan De Beenhouwer, Francesco De Carlo, Lucia Mancini, Federica Marone, and Jan Sijbers, “Dynamic intensity normalization using eigen flat fields in X-ray imaging,” Opt. Express 23, 27975-27989 (2015).
- import_mask(mask, update='reset')[source]#
Return a new
CrystDataobject with the new mask.- Parameters
- Raises
ValueError – If the mask shape is incompatible with the data.
ValueError – If there is no
datainside the container.
- Return type
- Returns
New
CrystDataobject with the updatedmask.
- import_patterns(table)[source]#
Import a streak mask from a CBC table.
- Parameters
table (
DataFrame) – CBC table inpandas.DataFrameformat.- Return type
- Returns
New container with updated
streak_mask.
See also
cbclib.CBCTable : More info about the CBC table.
- import_whitefield(whitefield)[source]#
Return a new
CrystDataobject with the new whitefield.- Parameters
whitefield (
ndarray) – New whitefield array.- Raises
ValueError – If the whitefield shape is incompatible with the data.
ValueError – If there is no
datainside the container.
- Return type
- Returns
New
CrystDataobject with the updatedwhitefield.
- items()#
Return (key, value) pairs of the datasets stored in the container.
- Return type
- Returns
(key, value) pairs of the datasets stored in the container.
- keys()#
Return a list of the attributes available in the container.
- load(attributes=None, idxs=None, processes=1, verbose=True)[source]#
Load data attributes from the input files in files file handler object.
- Parameters
attributes (
Union[str,List[str],None]) – List of attributes to load. Loads all the data attributes contained in the file(s) by default.idxs (
Union[int,slice,ndarray,List[int],Tuple[int],None]) – List of frame indices to load.processes (
int) – Number of parallel workers used during the loading.verbose (
bool) – Set the verbosity of the loading process.
- Raises
ValueError – If attribute is not existing in the input file(s).
ValueError – If attribute is invalid.
- Return type
- Returns
New
CrystDataobject with the attributes loaded.
- lsd_detector()[source]#
Return a new
cbclib.LSDetectorobject based oncor_dataattribute.- Raises
ValueError – If there is no
whitefieldinside the container.- Return type
- Returns
A CBC pattern detector based on
cbclib.bin.LSDLine Segment Detection [LSD] algorithm.
- mask_frames(frames=None)[source]#
Return a new
CrystDataobject with the updated good frames mask. Mask empty frames by default.
- mask_pupil(setup, padding=0.0)[source]#
Return a new
CrystDataobject with the pupil region masked.- Parameters
- Raises
ValueError – If there is no
datainside the container.- Return type
- Returns
New
CrystDataobject with the updatedmask.
- mask_region(roi)[source]#
Return a new
CrystDataobject with the updated mask. The region defined by the [y_min, y_max, x_min, x_max] will be masked out.
- model_detector(basis, samples, setup)[source]#
Return a new
cbclib.ModelDetectorobject based oncor_dataattribute and the solution of sample and indexing refinement.- Parameters
basis (
Basis) – Indexing solution.samples (
ScanSamples) – Sample refinement solution.setup (
ScanSetup) – Experimental setup.
- Raises
ValueError – If there is no
whitefieldinside the container.- Return type
- Returns
A CBC pattern detector based on
cbclib.CBDModelCBD pattern prediction model.
- replace(**kwargs)[source]#
Return a new
cbclib.CrystDatacontainer with replaced data.- Parameters
kwargs (Any) – Replaced attributes.
- Return type
- Returns
A new
cbclib.CrystDatacontainer.
- save(attributes=None, apply_transform=False, mode='append', idxs=None)[source]#
Save data arrays of the data attributes contained in the container to an output file.
- Parameters
attributes (
Union[str,List[str],None]) – List of attributes to save. Saves all the data attributes contained in the container by default.apply_transform (
bool) – Apply transform to the data arrays if True.mode (
str) –Writing modes. The following keyword values are allowed:
append : Append the data array to already existing dataset.
insert : Insert the data under the given indices idxs.
overwrite : Overwrite the existing dataset.
idxs (
Union[int,slice,ndarray,List[int],Tuple[int],None]) – Indices where the data is saved. Used only ifmodeis set to ‘insert’.
- Raises
ValueError – If the
output_fileis not defined inside the container.- Return type
- update_background()[source]#
Return a new
CrystDataobject with a new set of backgrounds. A set of backgrounds is generated by fitting a white-field profile to the measured data.- Raises
ValueError – If there is no
whitefieldinside the container.- Return type
- Returns
New
CrystDataobject with the updatedbackground.
- update_cor_data()[source]#
Return a new
CrystDataobject with new background corrected detector images.- Raises
ValueError – If there is no
whitefieldinside the container.- Return type
- Returns
New
CrystDataobject with the updatedcor_data.
- update_mask(method='range-bad', pmin=0.0, pmax=99.99, vmin=0, vmax=65535, update='reset')[source]#
Return a new
CrystDataobject with the updated bad pixels mask.- Parameters
method (
str) –Bad pixels masking methods. The following keyword values are allowed:
’no-bad’ (default) : No bad pixels.
’range-bad’ : Mask the pixels which values lie outside of (vmin, vmax) range.
’perc-bad’ : Mask the pixels which values lie outside of the (pmin, pmax) percentiles.
vmin (
int) – Lower intensity bound of ‘range-bad’ masking method.vmax (
int) – Upper intensity bound of ‘range-bad’ masking method.pmin (
float) – Lower percentage bound of ‘perc-bad’ masking method.pmax (
float) – Upper percentage bound of ‘perc-bad’ masking method.update (
str) – Multiply the new mask and the old one if ‘multiply’, use the new one if ‘reset’.
- Raises
ValueError – If there is no
datainside the container.ValueError – If
methodkeyword is invalid.ValueError – If
updatekeyword is invalid.ValueError – If
vminis larger thanvmax.ValueError – If
pminis larger thanpmax.
- Return type
- Returns
New
CrystDataobject with the updatedmask.
- update_output_file(output_file)[source]#
Return a new
CrystDataobject with the new output file handler.
- update_transform(transform)[source]#
Return a new
CrystDataobject with the updated transform object.
- update_whitefield(method='median', num_medians=5)[source]#
Return a new
CrystDataobject with new whitefield as the median taken through the stack of measured frames.- Parameters
method (
str) –Choose a method to generate a white-field. The following keyboard attributes are allowed:
mean : Taking a mean through the stack of frames.
median : Taking a median through the stack of frames.
median + mean : Taking
num_mediansmedians through subsets of frames and then taking a mean through the stack of medians.
num_medians (
int) – Number of medians to generate for median + mean method.
- Raises
ValueError – If there is no
datainside the container.- Return type
- Returns
New
CrystDataobject with the updatedwhitefield.
- values()#
Return the attributes’ data stored in the container.
- Return type
- Returns
List of data stored in the container.