XSpect package
XSpect.XSpect_Analysis module
- class XSpect.XSpect_Analysis.SpectroscopyAnalysis
Bases:
objectA class to perform analysis on spectroscopy data.
- bin_uniques(run, key)
Bins unique values for a given key within a run.
Parameters
- runspectroscopy_run
The spectroscopy run instance.
- keystr
The key for which unique values are to be binned.
- filter_detector_adu(run, detector, adu_threshold=3.0)
Filters is a misnomer compared to the other filter functions. This sets detector pixel values below a threshold to 0. Specifically, to remove 0-photon noise from detectors.
Parameters
- runspectroscopy_run
The spectroscopy run instance.
- detectorstr
The key corresponding to the detector data.
- adu_thresholdfloat or list of float, optional
The ADU threshold for filtering. Can be a single value or a range (default is 3.0).
Returns
- np.ndarray
The filtered detector data.
- filter_nan(run, shot_mask_key, filter_key='ipm')
A specific filtering implementation for Nans due to various DAQ issues. Filters out shots with NaN values in the specified filter.
Parameters
- runspectroscopy_run
The spectroscopy run instance.
- shot_mask_keystr
The key corresponding to the shot mask.
- filter_keystr, optional
The key corresponding to the filter data (default is ‘ipm’).
- filter_shots(run, shot_mask_key, filter_key='ipm', threshold=10000.0)
Filters shots based on a given threshold.
Parameters
- runspectroscopy_run
The spectroscopy run instance.
- shot_mask_keystr
The key corresponding to the shot mask. An example being [xray,simultaneous,laser] for all x-ray shots
- filter_keystr, optional
The key corresponding to the filter data (default is ‘ipm’).
- thresholdfloat, optional
The threshold value for filtering (default is 1.0E4).
So if we filter: xray,ipm,1E4 then X-ray shots will be filtered out if the ipm is below 1E4.
- patch_pixel(run, detector_key, pixel, mode='average', patch_range=4, deg=1, poly_range=6, axis=1)
EPIX detector pixel patching. TODO: extend to patch regions instead of per pixel. Parameters ———- data : array_like
Array of shots
- pixelinteger
Pixel point to be patched
- modestring
Determines which mode to use for patching the pixel. Averaging works well.
- patch_rangeinteger
Pixels away from the pixel to be patched to be used for patching. Needed if multiple pixels in a row are an issue.
- deginteger
Degree of polynomial if polynomial patching is used.
- poly_rangeinteger
Number of pixels to include in the polynomial or interpolation fitting
Returns
- float
The original data with the new patch values.
- patch_pixel_1d(run, detector_key, pixel, mode='average', patch_range=4, deg=1, poly_range=6)
EPIX detector pixel patching. TODO: extend to patch regions instead of per pixel. Parameters ———- data : array_like
Array of shots
- pixelinteger
Pixel point to be patched
- modestring
Determined which mode to use for patching the pixel. Averaging works well.
- patch_rangeinteger
pixels away from the pixel to be patched to be used for patching. Needed if multiple pixels in a row are an issue.
- deginteger
Degree of polynomial if polynomial patching is used.
- poly_rangeinteger
Number of pixels to include in the polynomial or interpolation fitting
Returns
- float
The original data with the new patch values.
- patch_pixels(run, detector_key, mode='average', patch_range=4, deg=1, poly_range=6, axis=1)
Patches multiple pixels in detector data.
Parameters
- runspectroscopy_run
The spectroscopy run instance.
- detector_keystr
The key corresponding to the detector data.
- modestr, optional
The mode of patching (‘average’, ‘polynomial’, or ‘interpolate’).
- patch_rangeint, optional
The range around the pixel to use for patching (default is 4).
- degint, optional
The degree of the polynomial for polynomial patching (default is 1).
- poly_rangeint, optional
The range of pixels to use for polynomial or interpolation patching (default is 6).
- axisint, optional
The axis along which to apply the patching (default is 1).
- patch_pixels_1d(run, detector_key, mode='average', patch_range=4, deg=1, poly_range=6)
Patches multiple pixels in 1D detector data.
Parameters
- runspectroscopy_run
The spectroscopy run instance.
- detector_keystr
The key corresponding to the detector data.
- modestr, optional
The mode of patching (‘average’, ‘polynomial’, or ‘interpolate’).
- patch_rangeint, optional
The range around the pixel to use for patching (default is 4).
- degint, optional
The degree of the polynomial for polynomial patching (default is 1).
- poly_rangeint, optional
The range of pixels to use for polynomial or interpolation patching (default is 6).
- purge_keys(run, keys)
Purges specific keys from the run to save memory. This is specifically to remove the epix key immediately after processing it from the hdf5 file. To avoid OOM. This is different than the purge all keys method which is used to purge many of the larger analysis steps.
Parameters
- runspectroscopy_run
The spectroscopy run instance.
- keyslist of str
The list of keys to purge.
- reduce_detector_shots(run, detector_key, reduction_function=<function sum>, purge=True, new_key=False)
- reduce_detector_spatial(run, detector_key, shot_range=[0, None], rois=[[0, None]], reduction_function=<function sum>, purge=True, combine=True)
Reduces the spatial dimension of detector data based on specified ROIs.
Parameters
- runspectroscopy_run
The spectroscopy run instance.
- detector_keystr
The key corresponding to the detector data.
- shot_rangelist, optional
The range of shots to consider (default is [0, None]).
- roislist of lists, optional
The list of ROIs (regions of interest) as pixel ranges (default is [[0, None]]).
- reduction_functionfunction, optional
The function to apply for reduction (default is np.sum).
- purgebool, optional
Whether to purge the original detector data after reduction (default is True).
- combinebool, optional
Whether to combine ROIs (default is True).
- reduce_detector_temporal(run, detector_key, timing_bin_key_indices, average=False)
Reduces the temporal dimension of detector data based on timing bins.
Parameters
- runspectroscopy_run
The spectroscopy run instance.
- detector_keystr
The key corresponding to the detector data.
- timing_bin_key_indicesstr
The key corresponding to the timing bin indices.
- averagebool, optional
Whether to average the data within each bin (default is False).
- separate_shots(run, detector_key, filter_keys)
Separates shots into different datasets based on filters. separate_shots(f,’epix_ROI_1’,[‘xray’,’laser’]) means find me the epix_ROI_1 images in shots that were X-ray but NOT laser. If you wanted the inverse you would switch the order of the filter_keys.
Parameters
- runspectroscopy_run
The spectroscopy run instance.
- detector_keystr
The key corresponding to the detector data.
- filter_keyslist of str
The list of filter keys to separate.
- time_binning(run, bins, lxt_key='lxt_ttc', fast_delay_key='encoder', tt_correction_key='time_tool_correction')
Bins data in time based on specified bins.
Parameters
- runspectroscopy_run
The spectroscopy run instance.
- binsarray-like
The bins to use for time binning.
- lxt_keystr, optional
The key for the laser time delay data (default is ‘lxt_ttc’).
- fast_delay_keystr, optional
The key for the fast delay data (default is ‘encoder’).
- tt_correction_keystr, optional
The key for the time tool correction data (default is ‘time_tool_correction’).
- union_shots(run, detector_key, filter_keys, new_key=True)
Combines shots across multiple filters into a single array. So union_shots(f,’timing_bin_indices’,[‘simultaneous’,’laser’]) means go through the timing_bin_indices and find the ones that correspond to X-rays and laser shots.
Parameters
- runspectroscopy_run
The spectroscopy run instance.
- detector_keystr
The key corresponding to the detector data.
- filter_keyslist of str
The list of filter keys to combine.
- class XSpect.XSpect_Analysis.XASAnalysis
Bases:
SpectroscopyAnalysis- ccm_binning(run, ccm_bins_key, ccm_key='ccm')
Generate CCM bin indices from CCM data and bins.
Parameters
- runobject
The spectroscopy run instance.
- ccm_bins_keystr
The key corresponding to the CCM bins.
- ccm_keystr, optional
The key corresponding to the CCM data (default is ‘ccm’).
- make_ccm_axis(run, energies)
Generate CCM bins and centers from given energy values.
Parameters
- runobject
The spectroscopy run instance.
- energiesarray-like
Array of energy values to be used for creating CCM bins.
- reduce_detector_ccm(run, detector_key, ccm_bin_key_indices, average=False, not_ccm=False)
Reduce detector data by CCM bins.
Parameters
- runobject
The spectroscopy run instance.
- detector_keystr
The key corresponding to the detector data.
- ccm_bin_key_indicesstr
The key corresponding to the CCM bin indices.
- averagebool, optional
Whether to average the reduced data (default is False).
- not_ccmbool, optional
Whether to indicate that CCM is not being used (default is False).
- reduce_detector_ccm_temporal(run, detector_key, timing_bin_key_indices, ccm_bin_key_indices, average=True)
Reduce detector data temporally and by CCM bins.
Parameters
- runobject
The spectroscopy run instance.
- detector_keystr
The key corresponding to the detector data.
- timing_bin_key_indicesstr
The key corresponding to the timing bin indices.
- ccm_bin_key_indicesstr
The key corresponding to the CCM bin indices.
- averagebool, optional
Whether to average the reduced data (default is True).
- reduce_detector_temporal(run, detector_key, timing_bin_key_indices, average=False)
Reduce detector data temporally. Specifically the 1d detector output for XAS data.
Parameters
- runobject
The spectroscopy run instance.
- detector_keystr
The key corresponding to the detector data.
- timing_bin_key_indicesstr
The key corresponding to the timing bin indices.
- averagebool, optional
Whether to average the reduced data (default is False).
- class XSpect.XSpect_Analysis.XESAnalysis(xes_line='kbeta')
Bases:
SpectroscopyAnalysis- make_energy_axis(run, energy_axis_length, A, R, mm_per_pixel=0.05, d=0.895)
Determination of energy axis by pixels and crystal configuration
Parameters
- Afloat
The detector to vH distance (mm) and can roughly float. This will affect the spectral offset.
- Rfloat
The vH crystal radii (mm) and should not float. This will affect the spectral stretch.
- pixel_arrayarray-like
Array of pixels to determine the energy of.
- dfloat
Crystal d-spacing. To calculate, visit: spectra.tools/bin/controller.pl?body=Bragg_Angle_Calculator
- normalize_xes(run, detector_key, pixel_range=[300, 550])
Normalize XES data by summing the signal over a specified pixel range.
Parameters
- runobject
The spectroscopy run instance.
- detector_keystr
The key corresponding to the detector data.
- pixel_rangelist of int, optional
The pixel range to sum over for normalization (default is [300, 550]).
- reduce_det_scanvar(run, detector_key, scanvar_key, scanvar_bins_key)
Reduce detector data by binning according to an arbitrary scan variable.
This method bins the detector data based on a specified scan variable and its corresponding bins. The result is stored in the run object under a new attribute.
Parameters
- runobject
The spectroscopy run instance.
- detector_keystr
The key corresponding to the detector data within the run object.
- scanvar_keystr
The key corresponding to the scan variable indices.
- scanvar_bins_keystr
The key corresponding to the scan variable bins.
Returns
- None
The reduced data is stored in the run object with the key formatted as {detector_key}_scanvar_reduced.
- class XSpect.XSpect_Analysis.experiment(lcls_run, hutch, experiment_id)
Bases:
object- get_experiment_directory()
Determines and returns the directory of the experiment based on the hutch and experiment ID. It attempts the various paths LCLS has had over the years with recent S3DF paths being the first attempt.
Returns
- str
The directory of the experiment.
Raises
- Exception
If the directory cannot be found.
- class XSpect.XSpect_Analysis.spectroscopy_experiment(*args, **kwargs)
Bases:
experimentA class to represent a spectroscopy experiment. Trying to integrate methods that incorporate meta parameters of the experiment but did not follow through.
- add_detector(detector_name, detector_dimensions)
- class XSpect.XSpect_Analysis.spectroscopy_run(spec_experiment, run, verbose=False, end_index=-1, start_index=0)
Bases:
objectA class to represent a run within a spectroscopy experiment. Not an LCLS run.
- close_h5()
Closes the HDF5 file handle. Again, avoiding memory issues.
- get_run_shot_properties()
Retrieves shot properties from the run file, including total shots and simultaneous laser and X-ray shots.
- get_scan_val()
Retrieves the scan variable from the HDF5 file of the run. This is specifically for runengine scans that tag the variable in the hdf5 file. E.g. useful for processing alignment scans
- load_run_key_delayed(keys, friendly_names, transpose=False, rois=None, combine=True)
Loads specified keys from the run file into memory without immediate conversion to numpy arrays. Supports applying multiple ROIs in one dimension that can be combined into a single mask or handled separately.
Parameters
- keyslist
List of keys to load.
- friendly_nameslist
Corresponding list of friendly names for the keys.
- transposebool, optional
Flag to transpose the loaded data. Defaults to False.
- roislist of lists, optional
List of ROIs (regions of interest) as pixel ranges along one dimension (default is None). Each ROI should be in the form [start_col, end_col].
- combinebool, optional
Whether to combine ROIs into a single mask. Defaults to True.
- load_run_keys(keys, friendly_names)
Loads specified keys from the run file into memory.
Parameters
- keyslist
List of keys to load from the hdf5 file
- friendly_nameslist
Corresponding list of friendly names for the keys. Some keys are special to the subsequent analyis e.g. epix and ipm.
- load_sum_run_scattering(key, low=20, high=80)
Sums the scattering data across the specified range.
Parameters
- keystr
The key to sum the scattering data from.
- lowint
Low index for summing
- high: int
high index for summing These indices should be chosen over the water ring or some scattering of interest.
- purge_all_keys(keys_to_keep)
Purges all keys from the object except those specified. Again avoid OOM in the analyis object.
Parameters
- keys_to_keeplist
List of keys to retain.
- set_arbitrary_filter(key='arbitrary_filter')
- update_status(update)
Updates the status log for the run and appends it to the objects status/datetime attibutes. If verbose then it prints it. Parameters ———- update : str
The status update message.
XSpect.XSpect_Controller module
- class XSpect.XSpect_Controller.BatchAnalysis(verbose=False)
Bases:
object- add_filter(shot_type, filter_key, threshold)
- break_into_shot_ranges(increment)
- parse_run_shots(experiment, verbose=False)
- primary_analysis()
- primary_analysis_loop(experiment, verbose=False)
- primary_analysis_parallel_loop(cores, experiment, verbose=False)
- primary_analysis_parallel_range(cores, experiment, increment, start_index=None, end_index=None, verbose=False, method=None)
- run_parser(run_array)
- set_key_aliases(keys=['tt/ttCorr', 'epics/lxt_ttc', 'enc/lasDelay', 'ipm4/sum', 'tt/AMPL', 'epix_2/ROI_0_area'], names=['time_tool_correction', 'lxt_ttc', 'encoder', 'ipm', 'time_tool_ampl', 'epix'])
- update_status(update)
- class XSpect.XSpect_Controller.ScanAnalysis_1D(*args, **kwargs)
Bases:
BatchAnalysis- primary_analysis(experiment, run, verbose=False)
- class XSpect.XSpect_Controller.ScanAnalysis_1D_XES(*args, **kwargs)
Bases:
BatchAnalysis- primary_analysis(experiment, run, verbose=False)
- class XSpect.XSpect_Controller.XASBatchAnalysis(*args, **kwargs)
Bases:
BatchAnalysis- primary_analysis(experiment, run, verbose=False)
- class XSpect.XSpect_Controller.XASBatchAnalysis_1D_ccm(*args, **kwargs)
Bases:
BatchAnalysis- primary_analysis(experiment, run, verbose=False)
- class XSpect.XSpect_Controller.XASBatchAnalysis_1D_time(*args, **kwargs)
Bases:
BatchAnalysis- primary_analysis(experiment, run, verbose=False)
- class XSpect.XSpect_Controller.XESBatchAnalysis
Bases:
BatchAnalysis- primary_analysis(experiment, run, verbose=False, start_index=None, end_index=None)
- class XSpect.XSpect_Controller.XESBatchAnalysisRotation
Bases:
XESBatchAnalysis- append_arbitrary_filtering(xes_experiment, verbose=False, basepath='.')
- hit_find(experiment, run, verbose=False, start_index=None, end_index=None)
- primary_analysis(experiment, run, verbose=False, start_index=None, end_index=None)
- primary_analysis_range(experiment, run, shot_ranges, verbose=False, method=None)
- primary_analysis_static(run, experiment, verbose=False, start_index=None, end_index=None)
- primary_analysis_static_parallel_loop(cores, experiment, verbose=False)
- XSpect.XSpect_Controller.analyze_single_run(args)
XSpect.XSpect_Diagnostics module
- class XSpect.XSpect_Diagnostics.diagnostics(run, exp, keys, friendly_names)
Bases:
plotting- adu_histogram(nshots, thresholds, ROIopt=False, energy_dispersive_axis='vert')
- ipm_histogram(thresholds)
- load_run_keys()
- ttAMPL_histogram(thresholds)
- xas_ROI(nshots, horiz_limits=[], vert_limits=[], setrois=False)
- xes_ROI(nshots, kb_limits=[], ka_limits=[], setrois=False, energy_dispersive_axis='vert', angle=0)
XSpect.XSpect_PostProcessing module
- class XSpect.XSpect_PostProcessing.analysis_functions
Bases:
object- expfunc(x, k, amp=[], x0=0)
- expfunc_heaviside(x, k, amp=[], x0=0)
- gaussfunc(x, center, sigma)
- gaussfunc_norm(x, center, sigma)
- irfconv(x, k, center, sigma, amp=[])
- irfconv_ana(x, k, center, sigma, amp=[])
- kmatsolver(kmatrix, x, k, X0, center, sigma, irf_option='numerical', printopt=True)
- class XSpect.XSpect_PostProcessing.plotting
Bases:
object
- class XSpect.XSpect_PostProcessing.post_analysis
Bases:
analysis_functions- construct_theta(theta_parser)
- parse_theta(k=[], center=[], sigma=[], amplitudes=[])
- read_theta(theta, theta_parser)
- svdplot(xval, yval, data, ncomp)
- svdreconstruct(data, ncomp)
- targetanalysis_run(data, x, kmatrix, k_in, center_in, sigma_in, X0_in, y=[], bounds_dict=None)
- targetobjective(theta, x, kmatrix, X0, theta_parser, data)
- varproj(kmatrix, x, k, X0, center, sigma, data)
XSpect.XSpect_Visualization module
- class XSpect.XSpect_Visualization.SpectroscopyVisualization
Bases:
object- plot_2d_difference_spectrum(run, detector_keys)
- plot_2d_spectrum(run, detector_key)
- class XSpect.XSpect_Visualization.XASVisualization
Bases:
SpectroscopyVisualization- combine_spectra(xas_analysis, xas_laser_key, xas_key, norm_laser_key, norm_key, interpolate=False)
- plot_1d_difference_spectrum(xas_analysis)
- plot_1d_difference_time(xas_analysis)
- plot_2d_difference_spectrum(xas_analysis, vmin=None, vmax=None)
- plot_XAS(run, detector_key, ccm_key)
- class XSpect.XSpect_Visualization.XESVisualization
Bases:
SpectroscopyVisualization- combine_spectra(xes_analysis, xes_key, xes_laser_key)
- combine_static_spectra(xes_analysis, xes_key)
- plot_1d_XES(run, detector_key, target_key, low=-inf, high=inf, axis=0)
- plot_2d_difference_spectrum(xes_analysis)