MDA Folder#
MVC implementation of mda files.
MVC: Model View Controller
- class mdaviz.mda_folder.MDA_MVC(*args: Any, **kwargs: Any)[source]#
Model View Controller class for mda files.
- _doPlot2D(action, selection)[source]#
Handle 2D plotting with the given selection.
- Parameters:
action (str): ‘add’ or ‘replace’ selection (dict): 2D selection with X1, X2, Y, I0, plot_type keys
- applySelectionChanges(new_selection)[source]#
Applies changes to the field selection and updates checkboxes accordingly: - Updates the selection field with the new selection. - Updates checkboxes in the current file’s table view based on the new selection.
- currentFileTableview()[source]#
Gets the current file TableView being displayed in the active tab.
- Returns:
QTableView: The TableView widget associated with the currently selected MDA file.
- dataPath()[source]#
Retrieves the path of the currently selected data folder.
- Returns:
str: The path to the data folder as determined by the folder + subfolder comboBoxes in the mainWindow.
- detRemoved#
alias of
str
- doPlot(*args, **kwargs)[source]#
Initiates plotting based on the currently selected file & selection field, and the specified action (‘add’, ‘replace’, or ‘clear’). - Retrieves and plots datasets based on the selection for actions ‘add’ or ‘replace’. - Uses a ChartView widget for plotting within a specified layout.
Parameters: - args[0] (str or int): The plotting action to be taken (‘add’, ‘replace’, or ‘clear’),
or an integer representing the X2 value change.
kwargs (dict): Additional options for plotting, if any.
Behavior: - ‘clear’: Removes all tabs and clears the visualization. - ‘add’/’replace’: Plots new data according to the current selection, adding to existing plots or replacing them. - X2 value change: Replots the current selection with the new X2 slice. - Exits with a status message if no file is selected or no detectors (Y) are selected for plotting.
- goToNext()[source]#
Navigates to and selects the next file relative to the current selection in the folder table view.
- goToPrevious()[source]#
Navigates to and selects the previous file relative to the current selection in the folder table view.
- handlePlotBasedOnMode()[source]#
Handle plotting based on the current mode (add, replace, or auto-off).
- mdaFileList()[source]#
Fetches a list of MDA file names from the currently selected folder.
- Returns:
list: A list of strings representing the names of MDA files in the selected folder.
- mdaInfoList()[source]#
Fetches a list of MDA file info from the currently selected folder.
- Returns:
list: A list of dictionary containing the high level info for the MDA files in the selected folder.
- onCheckboxStateChanged(selection, det_removed)[source]#
- Responds to changes in checkbox states within the file’s data view.
adjusts the plot based on the selection of detectors and I0.
updates the selection field with the new selection and initiates plotting based
on the current mode (Auto-add, Auto-replace, or Auto-off).
Parameters: - selection (dict): The current selection of detectors (Y), positioner (X), and I0 for plotting. - det_removed (bool): Indicates if a detector has been removed (unchecked).
Notes: - The selection dict format: {‘X’: int, ‘Y’: list[int], ‘I0’: int}. - If ‘Auto-off’ mode is active, the method returns without updating the plot. - If no positioner is selected, default to Index. - If no detectors are selected or if all curves are removed, the plot is cleared. - If a detector is unchecked, the corresponding curve is removed from the plot. - If I0 is selected, Y data will be normalized as Y/I0.
- onFileSelected(index, verbose=False)[source]#
Handles the selection of a new file in the folder table view.
- Updates the UI to:
Add a tab with the selected file content in a table view.
Display the data for the selected file.
Display the metadata for the selected file.
- Manages connections for:
Selection changes in the folder table view.
Checkbox state changes in the file’s data view.
- Initiates plotting based on the current mode, which can be:
Auto-add: Automatically adds new data to the existing plot.
Auto-replace: Automatically replaces the existing plot with new data.
Auto-off: Does not automatically plot new data; requires manual action to plot.
This method ensures the selection of positioners and detectors reflects the PVs available in the newly selected file, accounting for index changes from the previously selected file.
- addFileTab -> tabWidget.setCurrentIndex updates -> onTabChanged triggered
-> setCurrentFileTableview() -> updateSelectionField() (if selectionField was None only) -> mda_file.setData() -> mda_file.displayMetadata(metadata) -> mda_file.displayData(tabledata)
- Args:
index (QModelIndex): The model index of the selected file in the file list.
- onTabChanged(index, file_path, file_data, selection_field)[source]#
Updates UI to reflect the content of the newly selected tab or resets UI if no tab is selected. - Activates the corresponding table view for the new tab, displaying the selected file’s metadata and data. - Resets UI to a default state if no tab is selected (index == -1), indicating no active file. - Connected to the tabChanged signal to handle UI updates when a tab is switched.
Parameters: - index (int): Index of the newly selected tab; -1 indicates no tab is selected. - file_path (str): Path of the file associated with the newly selected tab. - file_data (dict): Contains metadata and table data for the file. Expected keys: ‘metadata’, ‘tabledata’. - selection_field (dict or None): Specifies the fields (POS/DET) selected for plotting.
Notes: This method is connected to the tabChanged signal of the MDAFile’s QTabWidget: In MDAFile:
- self.mda_file.tabWidget.currentChanged.connect [signal: emits new_tab_index]
- –> self.mda_file.updateCurrentTabInfo(new_tab_index) [slot]
- –> self.mda_file.tabChanged.emit [QtCore.pyqtSignal]
emits: new_tab_index, _file_path, _tab_data, _selection_field
- In MDA_MVC:
- self.mda_file.tabChanged.connect
–> self.onTabChanged(new_tab_index, _file_path, _tab_data, _selection_field)
- selectAndShowIndex(index)[source]#
Selects a file by its index in the folder table view and ensures it is visible to the user.
Parameters: - index (QModelIndex): Index of the file to select.
Details: - Focuses on the table view for visual feedback (blue highlight in Mac OS). - Adjusts scroll position based on the file’s position in the list. - Trigger actions associated with file selection (onFileSelected).
- selectionField()[source]#
Retrieves the current field selection for plotting. - Returns a dictionary with selected positioner, detectors, and I0 indices. - Format: {‘X’: positioner_index, ‘Y’: [detector_indices], ‘I0’: i0_index}. - Returns None if no selection is made.
- selectionModel()[source]#
Accesses the selection model of the view (e.g. MDAFolderTableView) managing the selection state.
- Returns:
QItemSelectionModel: The selection model associated with a view, managing which rows/items are selected.
- setCurrentFileTableview(tableview=None)[source]#
Sets the current file TableView to be displayed.
- Args:
tableview (QTableView, optional): The TableView widget to be set as the current file TableView. Defaults to None.
- setSelectionField(new_selection=None)[source]#
Updates the current field selection for plotting. - Accepts a dictionary specifying new selection of positioner, detectors, and I0. - Resets to None if given an empty dictionary. - Format for new_selection: {‘X’: positioner_index, ‘Y’: [detector_indices], ‘I0’: i0_index}.
- setSelectionModel(selection=None)[source]#
Sets the selection model for managing view selections.
- Args:
selection (QItemSelectionModel, optional): The selection model to be associated with the view. Defaults to None.
- splitter_moved(key, *arg, **kwargs)[source]#
Handles a splitter’s movement by initiating a delay before updating the settings. - Sets a deadline for changes and starts a new thread if one isn’t already monitoring changes. - Ensures settings are updated only after movement has ceased for a defined interval.
Parameters: - key (str): Identifier for the splitter (‘hsplitter’ or ‘vsplitter’).
- splitter_settings_name(key)[source]#
Generates a unique settings name for the given splitter. - Formats the name based on the class name and splitter identifier.
Parameters: - key (str): Identifier for the splitter.
Returns: - str: A unique name for storing splitter settings.
- updateDetectorSelection(oldPvList, old_selection, newPvList, new_selection, verbose=False)[source]#
Helper function to update detector selections in the new selection field. - Iterates through old detector selections and updates based on new PVs. - Adds updated detector indices to new_selection[‘Y’]. - Returns True if changes were made, otherwise False.
- updateSelectionForNewPVs(old_selection, oldPvList, newPvList, verbose=False)[source]#
Updates field selection based on new PV list when a new file is selected. - Adjusts selection indices for POS, DET, and I0 to match new PVs indexes. - Directly updates the selection field if changes are made.
- Args:
old_selection (dict): selection fields for the previously selected file. oldPvList (list): PVs in the previously selected file. newPvList (list): Matching PVs in the newly selected file. verbose (bool): If True, print detailed changes.
- Returns:
None: Updates the selection field directly if changes are made.