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.ColourRangeMode(*values)[source]#
Bases:
Enum- IQR = '1.5×IQR'#
- MAD = 'Median ±3×MAD'#
- PERCENTILE = '2nd - 98th %ile'#
- class mantidimaging.gui.windows.spectrum_viewer.model.ErrorMode(*values)[source]#
Bases:
Enum- PROPAGATED = 'Propagated'#
- STANDARD_DEVIATION = 'Standard Deviation'#
- class mantidimaging.gui.windows.spectrum_viewer.model.SpecType(*values)[source]#
Bases:
Enum- OPEN = 2#
- SAMPLE = 1#
- SAMPLE_NORMED = 3#
- class mantidimaging.gui.windows.spectrum_viewer.model.SpectrumViewerWindowModel(presenter: SpectrumViewerWindowPresenter)[source]#
Bases:
objectThe 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.
- build_full_sample_parameter_map(map_array: np.ndarray, binner: ROIBinner) np.ndarray[source]#
Create array matching sample image size filled with NaN and insert parameter map over ROI region set by binner for overlaying over sample image.
Each bin occupies exactly step_size pixels in both axes to avoid edge artefacts using bin_size which may be larger when bins overlap.
@param map_array: parameter map @param binner: The binner used when generating the map @return: Array of shape (height, width) matching the sample stack dimensions
- build_parameter_map(param_name: str, binner: ROIBinner, chi2_threshold: float | None = None) np.ndarray[source]#
Build a 2D parameter map from stored fit results for the given parameter name.
Grid dimensions are derived from the binner sub-ROIs. Fits higher than chi2_threshold excluded from map.
@param param_name: The name of the fitted parameter to map @param binner: The ROIBinner used when generating for fit @param chi2_threshold: Optional upper bound on rss_per_dof. Exclude fits if reduced chi2 higher than threshold @return np.ndarray: 2D array of parameters (n_rows, n_cols) matching binner dimensions.
- calculate_colour_levels(map_array: ndarray, mode: ColourRangeMode) tuple[float, float][source]#
Handle a various outlier exclusion options to handle various distributions, falling back to full range if needed for IQR and percentile Return (lower, upper) display levels for a parameter map based on user colour range selection
@param map_array: 2D parameter map array @param mode: Colour range selection @return: (lower, upper) tuple image display levels
- static colour_levels_percentile(finite_values: ndarray) tuple[float, float][source]#
Return the 2nd-98th percentile range of the given finite values.
- compute_chi2_threshold(percentile: float = 95.0) float | None[source]#
Return a given percentile of good-fit rss_per_dof values, or None if unavailable. Acts as a good starting point to be altered based on data and preference
@param percentile: The percentile of rss_per_dof values to return as the chi2 threshold @return: The chi2 threshold value or None if no valid fit results are available
- export_spectrum_to_rits(path: Path, tof: ndarray, transmission: ndarray, absorption: ndarray) None[source]#
Export spectrum to RITS format
- fit_single_region(spectrum: ndarray, fitting_region: FittingRegion, tof_data: ndarray, init_params: list[float], bounds: list[tuple[float | None, float | None]] | None = None) tuple[dict[str, float], float, float][source]#
- 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_normalized_averaged_image() ndarray | None[source]#
Get the normalized averaged image if both sample and normalization stacks are available.
- 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, chunk_start: int = 0, chunk_end: int | None = None, open_beam_roi: SensibleROI | None = None) np.ndarray[source]#
- get_stack_shuttercounts(stack: ImageStack | None) ndarray | None[source]#
- static get_stack_spectrum(stack: ImageStack | None, roi: SensibleROI, chunk_start: int = 0, chunk_end: int | None = None) np.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) np.ndarray[source]#
- get_transmission_error_propagated(roi: SensibleROI, normalise_with_shuttercount: bool = False) np.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) np.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#
- 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_parameter_map(path: Path, map_array: ndarray) None[source]#
Save parameter map array to a TIFF file
@param path: File path for the TIFF @param map_array: Parameter Map
- save_rits_images(directory: Path, error_mode: ErrorMode, binner: ROIBinner, 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 defined by the binner
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. binner (ROIBinner): Binner object used to subdivide region normalise (bool): If True, the images will be normalised. progress (Progress | None): Optional progress reporter.
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_single_rits_spectrum(path: Path, error_mode: ErrorMode, roi: SensibleROI) 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_fit_results(results: list[tuple[str, SpectrumFitResult]] | None) None[source]#
Store filtered fit results to only good fits and create a lookup for building parameter maps
- set_normalise_stack(normalise_stack: ImageStack | None) 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.
- store_spectrum(roi: SensibleROI, mode: SpecType, normalise_with_shuttercount: bool, spectrum: np.ndarray, open_beam_roi: SensibleROI | None = None) None[source]#
- tof_data: np.ndarray = array([], dtype=float64)#
- tof_mode: ToFUnitMode = 3#