Process images¶
Functions to process image files.
|
Cleans image stack using a fixed threshold value. |
|
Load scans with 2D images. |
|
Get the curvature of an image. |
|
Extract the spectrum of a single image. |
|
Extract several spectrum. |
- polartools.process_images.clean_threshold(images, threshold)[source]¶
Cleans image stack using a fixed threshold value.
Sets all value above the threshold to nan.
- Parameters:
- imagesstack of images
Images to be cleaned.
- thresholdfloat, integer
Value of the threshold to be applied.
- Returns:
- clean_imagesstack of images
Clean images.
- polartools.process_images.get_curvature(image, binx=10, biny=1, constant_offset=None, plot=False)[source]¶
Get the curvature of an image.
A second order polynomial is fit to the cross correlation of each slice using the pyrixs algorithm. See pyrixs for more details. Ideally used with an image with large intensity and a single peak.
- Parameters:
- imagenumpy.array or dask.array
Image to be used.
- binxinteger, optional
Bin size in the horizontal direction in pixels. Defaults to 10.
- binyinteger, optional
Bin size in the vertical direction in pixels. Defaults to 1.
- constant_offsetinteger
Offset for the curvature. This is only relevant for the plot, does not affect the use of the curvature to extract the spectra. Defaults to None, which triggers an automatic offset calculation.
- plotboolean
Flag to plot image and curvature.
- Returns:
- curvaturelist
List of polynomial coefficients [c0, c1, c2] where: y = c0 + c1.x + c2.x^2.
See also
pyrixs.fit_curvature()pyrixs.get_curvature_offsets()
- polartools.process_images.get_spectra(images, curvature, biny=1)[source]¶
Extract several spectrum.
Uses the pyrixs extract function.
- Parameters:
- imagesiterable of numpy.array or dask.array
Images to be processed.
- curvatureiterable
List of polynomial coefficients [c0, c1, c2] where: y = c0 + c1.x + c2.x^2.
- binyinteger, optional
Bin size in the vertical direction in pixels. Defaults to 1.
- Returns:
- spectranumpy.array
List of 1D spectrum.
See also
polartools.process_images.get_spectrum()pyrixs.extract()
- polartools.process_images.get_spectrum(image, curvature, biny=1)[source]¶
Extract the spectrum of a single image.
Uses the pyrixs extract function.
- Parameters:
- imagenumpy.array or dask.array
Image to be processed.
- curvatureiterable
List of polynomial coefficients [c0, c1, c2] where: y = c0 + c1.x + c2.x^2.
- binyinteger, optional
Bin size in the vertical direction in pixels. Defaults to 1.
- Returns:
- spectrumnumpy array
Extracted 1D spectrum.
See also
pyrixs.extract()
- polartools.process_images.load_images(scans, cat, detector_key, cleanup=None, normalize=None, positioner=None)[source]¶
Load scans with 2D images.
Note that this function forces explicity outputs:
If multiple scans are passed, it will return the average of the scans.
If positioner = None, it will average all images. The resulting image will have shape = (pixels_horizontal, pixels_vertical).
If positioner not None, it will not average all images. The resulting image will have shape = (positioner_size, pixels_horizontal, pixels_vertical).
- Parameters:
- scansiterable
List of scan_id or uids.
- catdatabroker catalog
Catalog.
- detector_keystring
Name of item that holds the images
- cleanupdictionary, optional
Clean up functions and arguments. Available functions:
{‘threshold’: threshold_value}
For custom functions, use:
{‘function’: (myfunc, (arg1, arg2, …))} where myfunc is a function with call: myfunc(images, arg1, arg2, …) These function can be stacked. For example, the call: {‘threshold’: 100, ‘threshold’: 10, ‘function’: (myfunc, (arg1, arg2))} will run the threshold function twice with 100 and 10 as argument, then myfunc with (arg1, arg2).
- normalizestring, optional
Name of detector that will be used to normalize data. Default is None.
- positionerstring, optional
Name of positioner to be read. Defaults to None.
- Returns:
- imagesdask array
Processed images.
- positioner_valuesnumpy ndarray, optional
Values of the positioner. It is only returned if positioner is not None.
- polartools.process_images.process_rxes(scans, cat, detector_key, curvature, cleanup=None, normalize=None, positioner=None, biny=1)[source]¶
Wrapper with typical RXES data processing.
- Parameters:
- scansiterable
List of scan_id or uids.
- catdatabroker catalog
Catalog.
- detector_keystring
Name of item that holds the images
- curvatureiterable
List of polynomial coefficients [c0, c1, c2] where: y = c0 + c1.x + c2.x^2.
- cleanupdictionary, optional
Clean up functions and arguments. Available functions:
{‘threshold’: threshold_value}
For custom functions, use:
{‘function’: (myfunc, (arg1, arg2, …))} where myfunc is a function with call: myfunc(images, arg1, arg2, …) These function can be stacked. For example, the call: {‘threshold’: 100, ‘threshold’: 10, ‘function’: (myfunc, (arg1, arg2))} will run the threshold function twice with 100 and 10 as argument, then myfunc with (arg1, arg2).
- normalizestring, optional
Name of detector that will be used to normalize data. Default is None.
- positionerstring, optional
Name of positioner to be read. Defaults to None.
- binyinteger, optional
Bin size in the vertical direction in pixels. Defaults to 1.
- Returns:
- spectrum or spectraarray
Processed spectrum (if positioner is None) or spectra (if positioner is not None).
- positioner_valuesnumpy ndarray, optional
Values of the positioner. It is only returned if positioner is not None.
- polartools.process_images.process_rxes_mcd(scans, cat, detector_key, curvature, cleanup=None, normalize=None, positioner=None, biny=1)[source]¶
Wrapper with typical RXES-MCD data processing.
- Parameters:
- scansiterable
List of scan_id or uids.
- catdatabroker catalog
Catalog.
- detector_keystring
Name of item that holds the images
- curvatureiterable
List of polynomial coefficients [c0, c1, c2] where: y = c0 + c1.x + c2.x^2.
- cleanupdictionary, optional
Clean up functions and arguments. Available functions: - {‘threshold’: threshold_value} For custom functions, use: - {‘function’: (myfunc, (arg1, arg2, …))} where myfunc is a function with call: myfunc(images, arg1, arg2, …) These function can be stacked. For example, the call: {‘threshold’: 100, ‘threshold’: 10, ‘function’: (myfunc, (arg1, arg2))} will run the threshold function twice with 100 and 10 as argument, then myfunc with (arg1, arg2).
- normalizestring, optional
Name of detector that will be used to normalize data. Default is None.
- positionerstring, optional
Name of positioner to be read. Defaults to None.
- binyinteger, optional
Bin size in the vertical direction in pixels. Defaults to 1.
- Returns
- ——-
- rxesarray
Processed x-ray emission spectrum(if positioner is None) or spectra (if positioner is not None).
- mcdarray
Processed x-ray emission dichroism spectrum (if positioner is None) or spectra (if positioner is not None).
- positioner_valuesnumpy ndarray, optional
Values of the positioner. It is only returned if positioner is not None.