ModelDetector#
- class cbclib.ModelDetector(data, frames, num_threads, parent, models, streaks=<factory>, patterns=None)[source]#
A streak detector class based on the CBD pattern prediction. Uses
cbclib.CBDModelto predict a pattern and filters out all the predicted streaks, that correspond to the measured intensities above the certain threshold. Provides an interface to generate an indexing tabular data.- Parameters
data (
ndarray) – Background corrected detector data.frames (
ndarray) – Frame indices of the detector images.num_threads (
int) – Number of threads used in the calculations.parent (
ReferenceType[CrystData]) – A reference to the parentcbclib.CrystDatacontainer.streaks (
Dict[int,Streaks]) – A dictionary of detectedcbclib.Streaksstreaks.patterns (
Optional[ndarray]) – Normalized diffraction patterns.
- contents()#
Return a list of the attributes stored in the container that are initialised.
- count_outliers(hkl, width=4.0, alpha=0.05)[source]#
Count the number of photon counts for a set of diffraction orders
hkl, that lie above the \(\alpha\) quantile for the Poisson distribution with the mean equal to the background signal.
- detect(hkl, width=4.0, hkl_index=False)[source]#
Perform the streak detection based on prediction. Generate a predicted pattern and filter out all the streaks, which pertain to the set of reciprocal lattice points
hkl.- Parameters
- Return type
ModelDetectorFull- Returns
New
cbclib.ModelDetectorstreak detector with updatedstreaks.
- draw(max_val=1, dilation=0.0, profile='tophat')#
Draw a pattern mask by using the detected streaks
streaks.- Parameters
max_val (
int) – Maximal mask valuedilation (
float) – Line mask dilation in pixels.profile (
str) –Line width profiles. The following keyword values are allowed:
tophat : Top-hat (rectangular) function profile.
linear : Linear (triangular) function profile.
quad : Quadratic (parabola) function profile.
gauss : Gaussian function profile.
- Raises
ValueError – If there is no
streaksinside the container.- Return type
- Returns
A pattern mask.
- export_streaks()#
Export
streak_maskto the parentcbclib.CrystDatadata container.- Raises
ValueError – If there is no
streaksinside the container.ValueError – If there is no
streak_maskinside the container.
- export_table(dilation=0.0, concatenate=True)#
Export normalised pattern into a
pandas.DataFrametable.- Parameters
- Raises
ValueError – If there is no
streaksinside the container.- Return type
- Returns
List of
pandas.DataFrametables for each frame inframesifconcatenateis False, a singlepandas.DataFrameotherwise. Table contains the following information:frames : Frame index.
x, y : Pixel coordinates.
p : Normalised pattern values.
rp : Reflection profiles.
I_raw : Measured intensity.
bgd : Background values.
- get(attr, value=None)#
Retrieve a dataset, return
valueif the attribute is not found.
- 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.
- mask_frames(idxs)#
Choose a subset of frames stored in the container and return a new detector object.
- refine_streaks(dilation=0.0)#
Refine detected diffraction streaks by fitting a Gaussian across the line.
- replace(**kwargs)#
Return a new container object with a set of attributes replaced.
- to_dataframe(concatenate=True)#
Export detected streak lines
streaksto apandas.DataFrametable.- Parameters
concatenate (
bool) – Concatenate sets of streaks for each frame into a single table if True.- Raises
ValueError – If there is no
streaksinside the container.- Return type
- Returns
List of
pandas.DataFrametables for each frame inframesifconcatenateis False, a singlepandas.DataFrameotherwise. Table contains the following information:frames : Frame index.
streaks : Line index.
x0, y0, x1, y1 : Line point coordinates in pixels.
width : Line width.
length : Line length.
- update_patterns(dilations=(1.0, 3.0, 7.0))#
Return a new detector object with updated normalised CBC patterns. The image is segmented into two region around each reflection to calculate the local background and local peak intensity. The estimated values are used to normalise each diffraction streak separately.
- Parameters
dilations (
Tuple[float,float,float]) –A tuple of three dilations (d0, d1, d2) in pixels of the streak mask that is used to define the inner and outer streak zones:
The inner zone is based on the mask dilated by d0.
The outer zone is based on the difference between a mask dilated by d2 and by d1.
- Return type
- Returns
A new detector object with updated
patterns.
- values()#
Return the attributes’ data stored in the container.
- Return type
- Returns
List of data stored in the container.