mantidimaging.gui.windows.spectrum_viewer.model module#
- class mantidimaging.gui.windows.spectrum_viewer.model.AllowedModesTypedDict[source]#
Bases:
TypedDict
- mode: ToFUnitMode#
- class mantidimaging.gui.windows.spectrum_viewer.model.ErrorMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum
- PROPAGATED = 'Propagated'#
- STANDARD_DEVIATION = 'Standard Deviation'#
- class mantidimaging.gui.windows.spectrum_viewer.model.SpecType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum
- 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: ndarray, transmission: ndarray, absorption: ndarray) 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_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_shuttercount_normalised_correction_parameter() float [source]#
Normalize ShutterCount values and return only the initial normalized value. We normalise all values to future proof against normalizing against all available ShutterCount values should we find the initial value is not sufficient.
- get_spectrum(roi: SensibleROI, mode: SpecType, normalise_with_shuttercount: bool = False) ndarray [source]#
- get_stack_shuttercounts(stack: ImageStack | None) ndarray | None [source]#
- static get_stack_spectrum(stack: ImageStack | None, roi: SensibleROI) ndarray [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) ndarray [source]#
- get_transmission_error_propagated(roi: SensibleROI, normalise_with_shuttercount: bool = False) ndarray [source]#
Get the transmission error using propagation of sqrt(n) error for a given roi @param: roi_name The roi name @param: normalised Default is True. If False, the normalization is not applied @return: a numpy array representing the error of the transmission
- get_transmission_error_standard_dev(roi: SensibleROI, normalise_with_shuttercount: bool = False) ndarray [source]#
Get the transmission error standard deviation for a given roi @param: roi_name The roi name @param: normalised Default is True. If False, the normalization is not applied @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
- presenter: SpectrumViewerWindowPresenter#
- remove_roi(roi_name: str) 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, rois: dict[str, SensibleROI], normalise: bool, normalise_with_shuttercount: bool = False) 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, normalise: bool = False, 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, normalise: bool = False) 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 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_roi(roi_name: str, roi: SensibleROI) None [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
- shuttercount_issue() str [source]#
Return an error message if there is an issue with the shutter count data.
- tof_mode: ToFUnitMode = 3#
- validate_bin_and_step_size(roi: SensibleROI, 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.