This reference groups the public API by task. The package re-exports the most
common functions from Dispersive_XAS.__init__, so the examples use:
import Dispersive_XAS as dxas- Image stack:
(frames, rows, columns). - Single image:
(rows, columns). - Spectrum:
(2, N), with axis in row 0 and intensity in row 1. - Calibrated spectra HDF5:
energy,pixel, andspectradatasets. - ROI specs: dictionaries with
kind="row_range"orkind="tilted_band".
Loads an areaDetector/NeXus HDF5 file with /entry/data/data. Returns a dict
containing data, meta, nd_attributes, timestamps, and frame_ids.
Loads a Bluesky HDF5 scan root and returns scan metadata plus the datasets under
the root data group.
Loads legacy raw HDF5 files from a folder. Use detector="Zyla" for the
Andor/Zyla nested layout, detector="Ximea" for the raw_data key, and
None for the default var1 key.
Load outputs written by pre_process and pre_process_scan.
Save a 2-D array through the legacy HDF5 writer. The data is column-reversed to match historical notebook orientation.
Save a mask array to HDF5 and return the output path.
Load a mask saved by save_mask_h5.
Processes one sample image and one flat image. It optionally subtracts a dark
field, median filters both images, clips non-positive values, computes
transmission, and returns absorption mux = -log(data / flat).
Processes pre-dark-corrected stacks frame by frame and returns the same keys as
pre_process.
Estimates a column-wise Ximea detector offset from a crop region and returns both offset-subtracted and offset-divided corrected images.
rotate_image, shift_image, flip_image_horizontal, flip_image_vertical,
invert_image, log_image, threshold_image_min, threshold_image_max,
median_filter_image, and gaussian_filter_image provide simple numpy/scipy
operations used by older notebooks.
register_thresholding(imgs, binary_lower_lm, binary_upper_lm, footprint=None, show=True)find_shifts(register_binary)stitch_scans(imgs, masks, show=True)
These helpers threshold image stacks, estimate phase-correlation shifts, and average registered scans under masks.
Builds a normalized tilted-band ROI from the center row at the left and right detector edges.
Validates and normalizes row-range and tilted-band ROI dictionaries. Adds
row_bounds for downstream chunked processing. When row_range=None and
roi=None, all detector rows are used.
Returns a boolean mask for the requested ROI.
Returns (roi_spec, row_bounds, row_weights, col_weight_sum) for efficient
column-wise weighted averaging. Tilted-band ROIs use fractional pixel-overlap
weights at the ROI boundaries, which reduces row-boundary aliasing when the
shear is adjusted. build_roi_mask() remains boolean for compatibility.
Extracts a spectrum from a 2-D image or a spectrum per frame from a 3-D stack. When no ROI settings are supplied, it averages all detector rows.
Fits a tilted-band ROI automatically from a representative absorption image by thresholding and smoothing the beam footprint column by column.
Builds a representative absorption image from HDF5 sample/flat paths and fits a tilted-band ROI.
Persist ROI specs for reuse across scans.
Creates a TiltedBandROIEditor, displays it in a notebook when show=True,
and returns the editor. Call editor.get_spec() to retrieve the ROI.
Notebook editor for tilted-band ROI center, slope, and width. Key methods:
get_spec(): return the current normalized ROI dictionary.save(path=None, metadata=None): save the current ROI JSON.launch(show=True): create/display the widget UI.
Notebook tools for rotated rectangular ROI selection. PgSpec exposes
getMask, getMaskAndAngle, getAllMasks, and getArrayRegion for legacy
ROI workflows.
show_line, show_lines, show_image, show_image_stack, and
show_mask_overlay return Plotly figures and display them when show=True.
Ensures a spectrum has shape (2, N).
Stacks energy/pixel axis and intensity into a spectrum array.
Collapses a 2-D image into one 1-D spectrum by summing or averaging rows.
Min-max normalizes intensity. x0/x1 can be single bounds or parallel lists
of multiple normalization windows.
Interpolates a spectrum onto a uniform axis.
Crops a spectrum to an axis range.
peak_finder(spec, spec_min=None, spec_max=None, peak_n=None, prominence=0.01, filtering=False, show=True, include_troughs=True, **kwargs)
Finds prominent peaks and optionally troughs. Returns detector indices and axis positions for selected features.
Finds the strongest positive derivative feature as an edge-jump index.
Interpolates axis positions at requested intensity levels.
Interpolates a 1-D spectrum at a specific energy.
Uses xraylib cross-sections to build an attenuation-slope correction curve.
calibrate_regression(train_spec, target_standard, peaks_train, peaks_target, order=1, sample_spec=None, show=True)
Fits a polynomial from selected experimental feature indices to selected standard feature indices.
Polynomial pixel-to-energy calibration class. Important attributes include
coef, order, rmse, train, target, and new_x. Use
sample_spec(sample_spec) to apply the calibration to a spectrum.
Runs the full foil calibration workflow: preprocess foil/flat images, extract
ROI spectrum, normalize, detect edge/peaks, match them to a reference standard,
and return (fit, metadata).
Save/load JSON calibration models for reuse.
Processes a large scan in chunks. When output_h5 is set, writes calibrated
energy and normalized spectra to HDF5; otherwise returns spectra in memory.
Emit human-readable progress lines and optionally update a JSON status file.
Computes spectra for a full scan in chunks and writes one interactive HTML file with heatmap, averaged lines, and individual-frame lines.
Writes one interactive preview HTML per chunk. This is useful for very large scans where a single all-frame HTML file would be too heavy.
Dataclass that holds file names, ROI settings, smoothing parameters, peak search windows, chunk sizes, output naming, and progress settings for the full large-quantity workflow.
Runs the full workflow: resolve scan/flat/foil inputs, optionally write preview HTML, fit foil calibration, apply calibration to forward/reverse scans, calculate transition metrics, write Plotly reports, and emit a summary dashboard plus manifest.
Backward-compatible alias for run_large_quantity_analysis.
List and load built-in reference spectra distributed with the package.
date_today, time_now, timestamp_convert, color_gradient,
change_font_size, binning, make_gif, and make_video support legacy
notebook workflows.
Crystal, Laue_Crystal, and Bragg_Crystal estimate Bragg angle, energy
spread, footprint, focus distance, beam size, and resolution for DXAS crystal
configurations. These classes preserve historical print-summary behavior via
their printlst dictionary and type_writer() method.