mantidimaging.gui.windows.spectrum_viewer.model module#

class mantidimaging.gui.windows.spectrum_viewer.model.ErrorMode(value)[source]#

Bases: Enum

An enumeration.

PROPAGATED = 'Propagated'#
STANDARD_DEVIATION = 'Standard Deviation'#
classmethod get_by_value(value: str) ErrorMode[source]#
class mantidimaging.gui.windows.spectrum_viewer.model.SpecType(value)[source]#

Bases: Enum

An enumeration.

OPEN = 2#
SAMPLE = 1#
SAMPLE_NORMED = 3#
class mantidimaging.gui.windows.spectrum_viewer.model.SpectrumViewerWindowModel(presenter: SpectrumViewerWindowPresenter)[source]#

Bases: object

The model for the spectrum viewer window. This model is responsible for storing the state of the window and providing the presenter with the data it needs to update the view. The model is also responsible for saving ROI data to a csv file.

export_spectrum_to_rits(path: Path, tof, transmission, absorption) None[source]#

Export spectrum to RITS format

get_averaged_image() ndarray | None[source]#

Get the averaged image from the stack in the model returning as a numpy array or None if it does not

get_image_shape() tuple[int, int][source]#
get_list_of_roi_names() list[str][source]#

Get a list of rois available in the model

get_roi(roi_name: str) SensibleROI[source]#

Get the ROI with the given name from the model

@param roi_name: The name of the ROI to get @return: The ROI with the given name

get_roi_coords_filename(path: Path) Path[source]#

Get the path to save the ROI coordinates to. @param path: The path to save the CSV file to. @return: The path to save the ROI coordinates to.

get_spectrum(roi: str | SensibleROI, mode: SpecType) ndarray[source]#
static get_stack_spectrum(stack: ImageStack | None, roi: SensibleROI)[source]#

Computes the mean spectrum of the given image stack within the specified region of interest (ROI). If the image stack is None, an empty numpy array is returned. Parameters:

stack (Optional[ImageStack]): The image stack to compute the spectrum from.

It can be None, in which case an empty array is returned.

roi (SensibleROI): The region of interest within the image stack.

It is a tuple or list of four integers specifying the left, top, right, and bottom coordinates.

Returns:
numpy.ndarray: The mean spectrum of the image stack within the ROI.

It is a 1D array where each element is the mean of the corresponding layer of the stack within the ROI.

static get_stack_spectrum_summed(stack: ImageStack, roi: SensibleROI)[source]#
get_stack_time_of_flight() ndarray | None[source]#
get_transmission_error_propagated(roi: SensibleROI) ndarray[source]#

Get the transmission error using propagation of sqrt(n) error for a given roi @param: roi_name The roi name @return: a numpy array representing the error of the transmission

get_transmission_error_standard_dev(roi: SensibleROI) ndarray[source]#

Get the transmission error standard deviation for a given roi @param: roi_name The roi name @return: a numpy array representing the standard deviation of the transmission

has_stack() bool[source]#

Check if data is available to export @return: True if data is available to export and False otherwise

normalise_issue() str[source]#
presenter: SpectrumViewerWindowPresenter#
remove_all_roi() None[source]#

Remove all ROIs from the model

remove_roi(roi_name) None[source]#

Remove the selected ROI from the model

@param roi_name: The name of the ROI to remove

rename_roi(old_name: str, new_name: str) None[source]#

Rename the selected ROI from the model

@param old_name: The current name of the ROI @param new_name: The new name of the ROI @raises KeyError: If the ROI does not exist @raises RuntimeError: If the ROI is ‘all’

roi_name_generator() str[source]#

Returns a new Unique ID for newly created ROIs

Returns:

A new unique ID

save_csv(path: Path, normalized: bool) None[source]#

Iterates over all ROIs and saves the spectrum for each one to a CSV file.

@param path: The path to save the CSV file to. @param normalized: Whether to save the normalized spectrum.

save_rits_images(directory: Path, error_mode: ErrorMode, bin_size: int, step: int, progress: Progress | None = None) None[source]#

Saves multiple Region of Interest (ROI) images to RITS files.

This method divides the ROI into multiple sub-regions of size ‘bin_size’ and saves each sub-region as a separate RITS image. The sub-regions are created by sliding a window of size ‘bin_size’ across the ROI with a step size of ‘step’.

During each iteration on a given axis by the step size, a check is made to see if the sub_roi has reached the end of the ROI on that axis and if so, the iteration for that axis is stopped.

Parameters: directory (Path): The directory where the RITS images will be saved. If None, no images will be saved. normalised (bool): If True, the images will be normalised. error_mode (ErrorMode): The error mode to use when saving the images. bin_size (int): The size of the sub-regions. step (int): The step size to use when sliding the window across the ROI.

Returns: None

save_rits_roi(path: Path, error_mode: ErrorMode, roi: SensibleROI) None[source]#

Saves the spectrum for one ROI to a RITS file.

@param path: The path to save the CSV file to. @param error_mode: Which version (standard deviation or propagated) of the error to use in the RITS export

save_roi_coords(path: Path) None[source]#

Save the coordinates of the ROIs to a csv file (ROI name, x_min, x_max, y_min, y_max) following Pascal VOC format. @param path: The path to save the CSV file to.

save_single_rits_spectrum(path: Path, error_mode: ErrorMode) None[source]#

Saves the spectrum for the RITS ROI to a RITS file.

@param path: The path to save the CSV file to. @param normalized: Whether to save the normalized spectrum. @param error_mode: Which version (standard deviation or propagated) of the error to use in the RITS export

set_new_roi(name: str) None[source]#

Sets a new ROI with the given name

@param name: The name of the new ROI

set_normalise_stack(normalise_stack: ImageStack | None) None[source]#
set_relevant_tof_units() None[source]#
set_roi(roi_name: str, roi: SensibleROI)[source]#
set_stack(stack: ImageStack | None) None[source]#

Sets the stack to be used by the model If that stack is None, then the model will be reset If the stack has changed, then the ROI ranges will be reset and additional ROIs excluding default ROIs will be removed

@param stack: The new stack to be used by the model

tof_data: np.ndarray | None = None#
tof_mode: ToFUnitMode#
tof_plot_range: tuple[float, float] | tuple[int, int] = (0, 0)#
tof_range: tuple[int, int] = (0, 0)#
tof_range_full: tuple[int, int] = (0, 0)#
validate_bin_and_step_size(roi, bin_size: int, step_size: int) None[source]#

Validates the bin size and step size for saving RITS images. This method checks the following conditions: - Both bin size and step size must be greater than 0. - Bin size must be larger than or equal to step size. - Both bin size and step size must be less than or equal to the smallest dimension of the ROI. If any of these conditions are not met, a ValueError is raised. Parameters:

roi: The region of interest (ROI) to which the bin size and step size should be compared. bin_size (int): The size of the bins to be validated. step_size (int): The size of the steps to be validated.

Raises:

ValueError: If any of the validation conditions are not met.

class mantidimaging.gui.windows.spectrum_viewer.model.ToFUnitMode(value)[source]#

Bases: Enum

An enumeration.

ENERGY = 4#
IMAGE_NUMBER = 1#
TOF_US = 2#
WAVELENGTH = 3#