pypeit.setup_gui.model module
The model portion of the PypeIt Setup GUI. Responsible for holding the data of the Setup GUI, notifying the view of any changes to that data, and translating PypeIt datastructures to a form usable by Qt.
- class pypeit.setup_gui.model.LogBuffer(log_file, verbosity, max_len=1000)[source]
Bases:
TextIOBase
Imitation file object that is passed to the PypeIt msgs logging system. It maintains a buffer of log messages that the user can view through the GUI. It is also used to monitor progress of background operations, by registering regular expressions to watch the log for.
- Parameters:
log_file (str) – The log file to receive the log messages. If this is None the log is not written to a file.
verbosity (int) – The verbosity of log messages to pass on. 0 = No logging. 1 = INFO, BUG, WARNING, and ERROR only, 2 = All.
max_len (int,Optional) – The maximum number of log lines to buffer. Defaults to 1000.
- __iter__()[source]
Allow iteration through the log buffer.
- Returns:
An iterator over the lines in the log buffer.
- Return type:
- _abc_impl = <_abc._abc_data object>
- watch(name, compiled_re, callback)[source]
Registers a regular expression to watch the log for. If a log message that matches the expression is logged, the client callback is called.
- Parameters:
name (str) – Name to register the regular expression under. This can be passed to
unwatch()
to stop monitoring for that expression.callback (
collections.abc.Callable
) – A function or object that will be called when a matching log message is found. It is called with two arguments: the name used to register the expression and the Match object regurned by the regular expression.compiled_re (
typing.Pattern
, Optional) – A compiled Python regular expression to match log messages against. If this is not given, the caller is notified of all log messages.
- class pypeit.setup_gui.model.ModelState(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
Enum
The state values for a model object.
- CHANGED = 3
The model contains data that has not been saved to a file.
- NEW = 1
The model is in a fresh, uninitialized state.
- UNCHANGED = 2
The model contains data that has not been changed since being read from or saved to a file.
- class pypeit.setup_gui.model.PypeItFileModel(metadata_model, state, name_stem, config_dict=None, params_model=None)[source]
Bases:
QObject
A model representing the contents of a single .pypeit file. This involves a spectrograph, configuration values, file metadata, and PypeIt parameters.
- Parameters:
pypeit_setup (PypeItSetup) – The PypeItSetup object this configuration is a part of.
config_name (str) – The name of this configuration.
config_dict (dict) – The metadata for this configuration, as returned by PypeItMetadata.unique_configurations.
state (ModelState) – The state of the model. “CHANGED” if it was built by running setup or “UNCHANGED” if it came from loading an existing .pypeit file.
- _update_state()[source]
Signal handler that detects changes to the metadata model and updates our model state to ModelState.CHANGED
- setMetadataModel(name_stem, config_dict, metadata_model)[source]
Sets the metadata model containing the list of raw data files and associated metadata.
- Parameters:
name_stem (str) – The name_stem of the metadata which will be used in the name of the pypeit file. This is typially the setup name (e.g. “A”).
config_dict (dict) – The metadata for this configuration, as returned by PypeItMetadata.unique_configurations.
metadata_model (PypeItMetadataModel) – The model object to set.
- class pypeit.setup_gui.model.PypeItMetadataModel(metadata: PypeItMetaData | None)[source]
Bases:
QAbstractTableModel
Provides a Qt model interface for a PypeItMetaData object. This proxy implements a QAbstractItemModel interface to present file metadata to Qt views.
It also supports editing.
- Parameters:
metadata – The PypeItMetaData object being wrapped. If this is None, the model is in a “NEW” state.
- columnCount(parent_index=<PyQt6.QtCore.QModelIndex object>)[source]
Returns number of columns in under a parent. Overridden method from QAbstractItemModel.
- Parameters:
parent_index (QModelIndex) – The index of the parent. Not applicable to a table model as there’s no parent/child heirarchy.
- Returns:
The number of columns in the table.
- Return type:
- commentMetadataRows(rows)[source]
Comment out metadata rows. Rows that are already commented out are not affected.
- createCopyForConfig(config_name)[source]
Create a new copy of this metadata model containing only rows for a given config.
- Parameters:
config_name (str) – Name of one of the unique configurations in the metadata.
- Returns:
A deep copy of the meatdata matching the config_name
- Return type:
- createCopyForRows(rows)[source]
Createa a new copy of this metadata model containing only a given set of rows.
- Parameters:
rows (list) – A list of the indexes of the rows to include in the copy.
- Returns:
A deep copy of the meatdata in the given rows.
- Return type:
- data(index, role)[source]
Returns data for a given role at a given index. Overridden method from QAbstractItemModel.
- Parameters:
index (QModelIndex) – The index in the table to return data form.
role (Qt.DisplayRole) – The role to return data for. This method supports the “TextAlignmentRole” for returning alignment information for a table cell, the “EditRole” for data to edit, and the “DisplayRole” for displaying the data within a table cell.
- Returns:
The requested data, or None if there is no applicable data.
- Return type:
Object
- flags(index)[source]
Returns item flags for a given index. Overridden method from QAbstractItemModel
- Parameters:
index (QModelIndex) – The index to get flags for
- Returns:
The bitmask flags for the index. Currently only Qt.ItemFlag.ItemIsEditable is supported.
- Return type:
flags (Qt.ItemFlag)
- getDefaultColumns()[source]
Return the default columns to display to the user. This can vary based on the current spectrograph.
Return: A list of column names, in order to display.
- getPathsModel()[source]
Returns a model for displaying the paths in this metadata.
- Returns:
A proxy model that only contains the unique ‘directory’ entries of this metadata.
- Return type:
- getSetup(row: int) dict [source]
Return the configuration/setup values for the given row of metadata.
- Parameters:
row – The row within the model to return the setup values for
- Returns:
A dictionary of configuration key/value pairs. An empty dictionary is returned if there is no metadata or the spectrograph has no configuration keys
- getStringColumnSize(colname: str) int | None [source]
Return the maximum size of a string column.
- Parameters:
colname – The name of the column
- Returns:
The maximum size of the column, or None if it is not a string column.
- headerData(section, orientation, role)[source]
Display header data for the table. For columns we give a column name, for rows we return a number. Overridden method from QAbstractItemModel.
- Parameters:
section (int) – The “section” the header is used for. For table models this is the zero based row or column number.
orientation (Qt.Orientation) – Whether the horizontal (column header) or vertical (row header) is being requested.
role (Qt.Role) – The role header data is being requested for. This method supports Qt.InitialSortOrderRole and Qt.DisplayRole.
- Returns:
The name for the column/row, or None if there is no applicable name for the given section/orientation/role.
- Return type:
- isCommentedOut(index: QModelIndex) bool [source]
Return whether a particular row is commented out.
- Parameters:
index – The index of the row to check.
- Returns:
True if the row is commented out, False otherwise.
- Return type:
- removeMetadataRows(rows)[source]
Removes rows from the metadata
- Parameters:
row (Sequence of int) – A sequence of integer row indexes of the rows to remove.
- resizeStringColumn(colname: str, new_size: int) None [source]
Resize a string column to fit a new size.
- Parameters:
colname – The name of the string column.
- rowCount(parent_index=<PyQt6.QtCore.QModelIndex object>)[source]
Returns number of rows under a parent. Overridden method from QAbstractItemModel.
- Parameters:
parent_index (QModelIndex) – The index of the parent. Not applicable to a table model as there’s no parent/child heirarchy.
- Returns:
The number of rows in the table.
- Return type:
- setData(index, value, role=ItemDataRole.EditRole)[source]
Modifies data for a given role at a given index. Overridden method from QAbstractItemModel.
- Parameters:
index (QModelIndex) – The index in the table to return data form.
value (Any) – The value to set in the metadata.
role (Qt.DisplayRole) – The role to set data for. Only the “EditRole” is supported. Defaults to Qt.EditRole.
- Returns:
True if the edit succeeded, false if it failed.
- setMetadata(metadata)[source]
Sets the PypeItMetaData object being wrapped.
- Parameters:
metadata (
pypeit.metadata.PypeItMetaData
) – The metadata being wrapped.
- property spectrograph: <module 'pypeit.spectrographs.spectrograph' from '/home/docs/checkouts/readthedocs.org/user_builds/pypeit/envs/release/lib/python3.12/site-packages/pypeit/spectrographs/spectrograph.py'>
The spectrograph object for the metadata. None if no metadata has been set.
- class pypeit.setup_gui.model.PypeItMetadataUniquePathsProxy(metadata_model)[source]
Bases:
QAbstractListModel
A Proxy model filtering the content of a PypeItMetadataModel object to only show the unique paths within it to Qt views.
- Parameters:
metadata_model (PypeItMetaData) – The model being filtered.
- _setUniqueIndex(*args, **kwargs)[source]
Sets the Numpy index array for the unique paths within the metadata.
- data(index, role)[source]
Returns the path for a given QModelIndex.
- Parameters:
index (QModelIndex) – The QModelIndex for the row to get data for.
role (Qt.DisplayRole) – The role to return data for. This method only supports “DisplayRole”.
- class pypeit.setup_gui.model.PypeItObsLogModel[source]
Bases:
QObject
Model representing an obslog to the GUI.
- add_raw_data_directory(new_directory)[source]
Adds a new directory to the model’s list of directories.
- Parameters:
new_directory (str) – The new directory containing raw data.
- property raw_data_directories
The list directories containing raw data for the PypeItSetup object.
- set_spectrograph(new_spec)[source]
Set the current spectrograph.
- Parameters:
new_spec (str) – The name of the new spectrograph.
- property spectrograph
The currently selected spectrograph, or None if not set.
- spectrograph_changed
Signal sent when the spectrgraph for the setup has changed. Sends the name of the new spectrograph.
- Type:
Signal(str)
- property state
The state of the obslog model. Either NEW or UNCHANGED.
- Type:
- class pypeit.setup_gui.model.PypeItParamsProxy(par, cfg_lines=None)[source]
Bases:
QAbstractItemModel
A Proxy model that maps a PypeIt
PypeItPar
to a QAbstractItemModel suitable for a Qt QTreeView. It uses the _UserConfigTreeNode recursive data structure to represent the parameters.- Parameters:
pypeit_setup (PypeItSetup) – The PypeItSetup object containing the parameters to represent.
- columnCount(parent)[source]
Return the number of columns, which is always 2 because we use column 0 for the name of the parameter or
PypeItPar
and column 1 for the configuration values. Overridden from QAbstractItemModel.Args: parent (QModelIndex): Parent to return the column count for. (Not used)
- Returns:
The number of columns. Always 2.
- Return type:
- data(index, role=ItemDataRole.DisplayRole)[source]
Returns data for a given index. Overridden from QAbstractItemModel.
- Parameters:
index (QModelIndex) – The index of the item, as returned by index()
role (Qt.ItemDataRole) – The role of the data being requested. This method supports Qt.DisplayRole (for displaying text).
- Returns:
A string if there’s something to display at the given index and role, or None if there’s nothing to display.
- Return type:
- headerData(section, orientation, role)[source]
Return data for the header row of the
PypeItPar
tree. For the horizontal header we call section 0 aka column 0 “Setting” and section 1 aka column 1 “Value”.- Parameters:
section (int) – The section aka column of the header.
orientation (Qt.Orientation) – The orientation of the header. This model only supports the horizontal header row.
role (Qt.DisplayRole) – The display role of the data to return. Only Qt.DisplayRole is supported for showing the text labels of the header.
- Returns:
- The name of a column or None if headerData isn’t applicable for the
section/orientation/role passed in.
- Return type:
- index(row, column, parent=<PyQt6.QtCore.QModelIndex object>)[source]
Creates a QModelIndex that points to an item in the PypeItPar parameter tree. Overridden from QAbstractItemModel.
- Parameters:
row (int) – The row of the item underneath parent to create an index for.
column (int) – The column of the item. Typically 0 is used for the name of the
PypeItPar
or value, and 1 is used for actual parameter values (1 is never used for aPypeItPar
).parent (QModelIndex) – An index for the parent. If this is invalid, it refers to the root of the tree.
- Returns:
A new index object to point to the item.
- Return type:
QModelIndex
- parent(index)[source]
Return the parent of an item in the model. Overridden from QAbstractItemModel.
- Parameters:
index (QModelIndex) – The index of the item, as returned by the index() method.
- Returns:
An index for the items parent. Maybe be invalid if the item is at the top level.
- Return type:
QModelIndex
- class pypeit.setup_gui.model.PypeItSetupGUIModel[source]
Bases:
QObject
Maintains the state of the overall PypeItSetupGUI.
- property clipboard
The current metadata that has been copied or pasted within the Setup GUI.
- Type:
- createFilesForConfigs(configs=None, state=ModelState.CHANGED)[source]
Private method to create PypeIt files for new configurations.
- Parameters:
unique_config (dict) – A the new configurations to set.
pypeit_setup (
PypeItSetup
) – The PypeItSetup object with parameter info for the new files.state (ModelState, Optional) – The state of the new model. Defaults to CHANGED, meaning it has not been saved.
- filesAdded
Signal sent when PypeIt files within the GUI have been created or opened. Sends the list of the new files.
- Type:
Signal(list)
- filesDeleted
Signal sent when PypeIt files within the GUI have been closed. Sends the list of removed files.
- Type:
Signal(list)
- open_pypeit_file(pypeit_file)[source]
Open an existing pypeit file and load it into this setup.
- Parameters:
pypeit_file (str) – The pypeit file to open.
- setup_logging(logname, verbosity)[source]
Setup the PypeIt logging mechanism and a log buffer for monitoring the progress of operations and viewing the log.
- property state
The state of the model.
- Type:
- stateChanged
Signal sent when the state attribute of the model has changed.
- Type:
Signal()
- class pypeit.setup_gui.model._UserConfigTreeNode(node, key=None, parent=None)[source]
Bases:
object
Internal class used to represent the tree structure of PypeIt parameters. It is used as the internal pointer in PypeItParamsProxy.
Take this example config:
[rdx] spectrograph = shane_kast_blue [calibrations] bpm_usebias = true [[biasframe]] frametype = bias
The resulting data structure is:
Node 1: parent = None key = None value = None children = [Node 2, Node 4] Node 2: parent = None key = "rdx" value = None children = [Node 3] Node 3: parent = Node 2 key = "spectrograph" value = "shane_kast_blue" children = [] Node 4: parent = None key = "calibrations" value = None children = [Node 5, Node 6] Node 5: parent = Node 4 key = "bpm_usebias" value = True children = [] Node 6: parent = Node 4 key = biasframe value = None children = [Node 7] Node 7: parent = Node 6 key = frametype value = bias children = []
Of note is that the “root” in the data model used by Qt is an invalid entry, i.e. it isn’t shown in the view as a node. This matches the PypeIt parameters format in that there can be multiple top level entries (e.g. [rdx] and [calibrations] above). This is why nodes 2 and 4 have parent = None even though Node 1 is their parent in the data structure. It prevents them from reporting a parent node to Qt and causing issues.
- Parameters:
node (dict or value) – The data for a node within a tree. If it’s a dict, this is a parent node with no value but each entry in the dict is a child. Otherwise it’s treated as a value for the given key.
key (str) – Name of the value or section (e.g. “rdx” or “spectrograph”). If None, this is the root entry which has no equivalent in Qt.
parent (_UserConfigTreeNode) – The parent of this entry. None if the entry is the root entry or a top level entry.