diffractem.tools module¶
- diffractem.tools.analyze_hkl(fn, cell, point_group, foms=('CC', 'CCstar', 'Rsplit'), nshells=10, lowres=35, highres=1.5, fn1=None, fn2=None, shell_dir='shell', bin_path='', check_hkl_args=None, compare_hkl_args=None)[source]¶
Analyze a hkl-file triplet as generated by partialator (comprising hkl, hkl1, `hkl2). Uses the check_hkl and compare_hkl tools included with CrystFEL, and mangles their output into something a bit more friendly.
- Parameters:
fn (str) – [description]
cell (str) – [description]
point_group (str) – [description]
foms (Iterable, optional) – [description]. Defaults to (‘CC’, ‘CCstar’, ‘Rsplit’).
nshells (int, optional) – [description]. Defaults to 10.
lowres (float, optional) – [description]. Defaults to 35.
highres (float, optional) – [description]. Defaults to 1.5.
fn1 (Optional[str], optional) – [description]. Defaults to None.
fn2 (Optional[str], optional) – [description]. Defaults to None.
shell_dir (str, optional) – [description]. Defaults to ‘shell’.
bin_path (str, optional) – [description]. Defaults to ‘’.
- Raises:
cpe – [description]
- Returns:
[description]
- Return type:
[type]
- diffractem.tools.call_indexamajig(input, geometry, output='im_out.stream', cell=None, im_params=None, index_params=None, procs=None, exc='indexamajig', copy_fields=(), script=None, **kwargs)[source]¶
Generates an indexamajig command from a dictionary of indexamajig parameters, a exc dictionary of files names and core number, and an indexer dictionary
e.g.
- im_params = {‘min-res’: 10, ‘max-res’: 300, ‘min-peaks’: 0,
‘int-radius’: ‘3,4,6’, ‘min-snr’: 4, ‘threshold’: 0, ‘min-pix-count’: 2, ‘max-pix-count’:100, ‘peaks’: ‘peakfinder8’, ‘fix-profile-radius’: 0.1e9, ‘indexing’: ‘none’, ‘push-res’: 2, ‘no-cell-combinations’: None, ‘integration’: ‘rings-rescut’,’no-refine’: None, ‘no-non-hits-in-stream’: None, ‘no-retry’: None, ‘no-check-peaks’: None} #’local-bg-radius’: False,
- index_params ={‘pinkIndexer-considered-peaks-count’: 4,
‘pinkIndexer-angle-resolution’: 4, ‘pinkIndexer-refinement-type’: 0, ‘pinkIndexer-thread-count’: 1, ‘pinkIndexer-tolerance’: 0.10}
- diffractem.tools.call_indexamajig_slurm(input, geometry, name='idx', cell=None, im_params=None, procs=None, exc='indexamajig', copy_fields=(), shots_per_run=50, partition='medium', time='01:59:00', folder='partitions', write_tar_file=False, threads=1, local_bin_dir=None, **kwargs)[source]¶
- diffractem.tools.call_partialator(input, options, script_name='partialator_run.sh', cache_streams=False, par_runs=1, slurm=False, split=False, out_dir='merged', slurm_opts=None, exc='partialator')[source]¶
- Return type:
Optional[str]
- diffractem.tools.call_partialator_simple(input, symmetry, output='im_out.stream', model='unity', iterations=1, opts=None, procs=40, exc='partialator')[source]¶
- diffractem.tools.chop_stream(streamfile, shots, query='frame == 1', postfix='fr1')[source]¶
Carve shots with a given frame number from a stream file
- Parameters:
open] (streamfile {str} -- [stream file to) –
extract] (frame {int} -- [frame number to) –
- diffractem.tools.dataframe_hash(df, string=True, signed=True)[source]¶
Generate int32 (or uint32 if signed=False) hashes from a pandas data frame and return as a pandas Series. The hash is generated with md5 from a whitespace-delimited string representation from each data frame row, such as e.g.: “data/file_a.h5 entry//0” (so similar to CrystFEL’s list syntax).
- Return type:
Series
- diffractem.tools.insert_init(shots, predist=100, dxmax=200, xcol='pos_x', initpoints=1)[source]¶
Insert initialization frames into scan list, to mitigate hysteresis and beam tilt streaking when scanning along x. Works by inserting a single frame each time the x coordinate decreases (beam moves left) or increases by more than dxmax (beam moves too quickly). The initialization frame is taken to the left of the position after the jump by predist pixels. Its crystal_id and frame columns are set to -1. :param shots: initial scan list. Note: if you want to have multiple frames, you should always first run set_frames :param predist: distance of the initialization shot from the actual image along x :param dxmax: maximum allowed jump size (in pixels) to the right. :param xcol: name of x position column :param initpoints: number of initialization points added :return: scan list with inserted additional points
- diffractem.tools.make_command(program, arguments=None, params=None, opts=None, *args, **kwargs)[source]¶
- diffractem.tools.make_geometry(opts, file_name=None, image_name='corrected', xsize=None, ysize=None, mask=True, write_mask=False, **kwargs)[source]¶
Generates a CrystFEL geometry file from a PreProcOpts object
- Parameters:
opts (PreProcOpts) – options object holding the required information, which are the ellipticity parameters and camera length, pixel size, wave length, and image dimensions
file_name (str, optional) – filename of a geometry file to be written. If None, returs the file contents as a dict instead. Defaults to None.
image_name (str, optional) – label of the diffraction data stack in the HDF5 files. Defaults to ‘corrected’.
xsize (int, optional) – x image size. If None, use that in opts. Defaults to None.
ysize (int, optional) – y image size. If None, use that in opts. Defaults to None.
mask (bool, optional) – Include reference to a pixel mask. Defaults to True.
write_mask (bool, optional) – Create a file pxmask.h5 containing the pixel mask as defined in the options object (required as CrystFEL needs the masks as HDF5). Defaults to False.
**kwargs – further lines to be included into the geometry file (or overwritten)
- Returns:
if file_name=None, a dict with the geometry file rows is returned
- Return type:
Optional[dict]
- diffractem.tools.make_reference(reference_filename, output_base_fn=None, ref_smooth_range=None, thr_rel_var=0.2, thr_mean=0.2, gap_factor=1, save_stat_imgs=False, per_panel=False)[source]¶
Calculates reference data for dead pixels AND flatfield (=’gain’=’sensitivity’). Returns the boolean dead pixel array, and a floating-point flatfield (normalized to median intensity 1).
- diffractem.tools.quantize_y_scan(shots, maxdev=1, min_rows=30, max_rows=500, inc=10, ycol='pos_y', ycol_to=None, xcol='pos_x', adaptive=True)[source]¶
Reads a DataFrame containing scan points (in columns xcol and ycol), and quantizes the y positions (scan rows) to a reduced number of discrete values, keeping the deviation of the quantized rows to the actual y positions below a specified value. The quantized y positions are determined by K-means clustering and unequally spaced. :param shots: initial scan list :param maxdev: maximum mean standard deviation of row positions from point y coordinates in pixels :param min_rows: minimum number of quantized scan rows. Don’t set to something unreasonably low, otherwise takes long :param max_rows: maximum number of quantized scan rows :param inc: step size for determining row number :param ycol: column of initial y positions in shots :param ycol_to: column of final y row positions in return data frame. If None, overwrite initial y positions :param xcol: column of x positions. Required for final sorting. :return: scan list with quantized y (row) (positions)
- diffractem.tools.set_frames(shots, frames=1)[source]¶
Adds additional frames to each scan position by repeating each line, and adding/setting a frame column :param shots: initial scan list. Each scan points must have a unique index, otherwise behavior may be funny. :param frames: number of frames per scan position :return: scan list with many frames per position
- diffractem.tools.update_det_shift(fn, opt_file='preproc.yaml', panel='p0')[source]¶
Updates the detector shift of a dataset read from fn using a geometry stored in opt_file. Convenience function if you don’t have the dataset open and don’t want to bother with it. See Dataset.update_det_shift for further documentation.