pypeit.setup_gui.model module

The controller portion of the PypeIt Setup GUI.

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.

__bool__()[source]

Return a true status indicating we’re ready to receive data

__iter__()[source]

Allow iteration through the log buffer.

Returns:

An iterator over the lines in the log buffer.

Return type:

(collections.abc.Iterator)

__len__()[source]

Return the number of lines in the buffer.

Returns:

int

_abc_impl = <_abc._abc_data object>
close()[source]

Closes the log file (if any).

unwatch(name)[source]

Stops monitoring the log for a previously registered regular expression.

Parameters:

name (str) – The name passed to watch() to register the regular expression.

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.

write(message)[source]

Simulates the write method of a file object to monitors log messages for for matching messages. The messages are then sent to a log file (if one has been configured).

Parameters:

message (str) – The log message being written to the log.

class pypeit.setup_gui.model.ModelState(value)[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 configurations, 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

property filename

Return the name of the pypeit file.

save()[source]

Save a .pypeit file from this model. The file name is chosen per PypeIt standards.

setMetadataModel(name_stem, config_dict, metadata_model)[source]
property spec_name
stateChanged

Signal sent when the state of the file model changes. The config nasme of the file is sent as the signal parameter.

Type:

Signal(str)

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.

addMetadataRow(metadata_row)[source]

Add a new row to the metadata.

Parameters:

metadata_row (array-like) – A row of data to add.

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:

int

commentMetadataRows(rows)[source]

Comment out metadata rows. Rows that are already commented out are not affected.

Parameters:

rows (list of int) – The indices of the rows to comment out.

Returns:

None

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:

PypeItMetadataModel

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:

PypeItMetadataModel

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)

getAllFrameTypes()[source]

Return the allowable values for the frametype column.

Returns:

List of names of the allowable frame types.

Return type:

list of str

getColumnNameFromNum(index)[source]

Return the name of the column with the given number.

Parameters:

index (str) – The 0 based column number.

Returns:

The name of the column. If the passed in index is out of bounds,

an IndexError value is raised.

Return type:

str

getColumnNumFromName(colname)[source]

Return the column number that has the passed in name.

Parameters:

colname (str) – The name of the column.

Returns:

The column number (0 based) of the named column. -1 if the column

name is not in this model.

Return type:

int

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:

PypeItMetadataUniquePathsProxy

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:

str

isCommentedOut(index: QModelIndex) bool[source]

Return whether a particular row is commented out.

Parameters:

index – The index of the row to check.

Return: True if the row is commented out, False otherwise.

pasteFrom(other_metadata_model)[source]
removeMetadataRows(rows)[source]

Removes rows from the metadata

Parameters:

row (Sequence of int) – A sequence of integer row indexes of the rows to remove.

reset()[source]

Reset the proxy assuming the metadata object has completely changed

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:

int

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.9/site-packages/pypeit/spectrographs/spectrograph.py'>

The spectrograph object for the metadata. None if no metadata has been set.

uncommentMetadataRows(rows)[source]

Uncomment out metadata rows. Rows that are not commented out are not affected.

Parameters:

rows (list of int) – The indices of the rows to comment out.

Returns:

None

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”.

getPaths()[source]

Returns all the paths known to this model.

Returns:

The list of paths, or an empty list of the model is empty.

Return type:

list of str

rowCount(parent_index=<PyQt6.QtCore.QModelIndex object>)[source]

Returns the number of unique paths. Inherited from QAbstractItemModel.

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.

Type:

list of str

reset()[source]

Reset the model to an empty state.

scan_raw_data_directories()[source]

Scans all of the raw data directories for raw data files.

Returns:

The number of raw data files found.

Return type:

int

setMetadata(metadata)[source]

Sets the obslog to reflect a new PypeItMetadata object.

set_spectrograph(new_spec)[source]

Set the current spectrograph.

Parameters:

new_spec (str) – The name of the new spectrograph.

property spec_name

The name of the current spectrograph, or None if not set.

Type:

str

property spectrograph

The currently selected spectrograph, or None if not set.

Type:

pypeit.spectrographs.spectrograph

spectrograph_changed

Signal sent when the spectrgraph for the setup has changed. Sends the name of the new spectrograph.

Type:

Signal(str)

property state
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:

int

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:

str

getConfigLines()[source]
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:

str

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 a PypeItPar).

  • 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

rowCount(parent=<PyQt6.QtCore.QModelIndex object>)[source]

Returns the number of items under a parent node. Overridden from QAbstractItemModel.

Returns:

The number of items under parent. Can be 0 if parent has no child items.

Return type:

int

class pypeit.setup_gui.model.PypeItSetupGUIModel[source]

Bases: QObject

Maintains the state of the overall PypeItSetupGUI.

property clipboard
closeAllFiles()[source]
createEmptyPypeItFile(new_name)[source]
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.

removeFile(name)[source]
reset()[source]

Reset the model to an empty state.

run_setup()[source]

Run setup on the raw data in the obslog.

setup_logging(logname, verbosity)[source]

Setup the PypeIt logging mechanism and a log buffer for monitoring the progress of operations and viewing the log.

Parameters:
  • logname (str) – The filename to log to.

  • verbosity (int) – The verbosity level to log at.

property state

The state of the model.

Type:

ModelState

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.

getConfigLines(level=0)[source]
pypeit.setup_gui.model.available_spectrographs()[source]

Return a list of the supported spectrographs