Braviz Qt Models¶
This module provides several classes that can be used in the
Model / View Qt pattern,
so they inherit from QAbstractItemModel
.
Only methods that are not part of the Qt interface are shown here.
Generic models¶
This models are designed to be generic, and they don’t make any assumptions about the data.
-
class
SimpleCheckModel
(choices)[source]¶ Provides a model for selecting items from a set of choices (represented with checkboxes in Qt Views)
-
class
DataFrameModel
(data_frame, columns=None, string_columns=(), index_as_column=True, checks=False)[source]¶ This model is used for displaying data frames in a QT table view
Parameters: - data_frame (pandas.DataFrame) – Data Frame
- columns (list) – Optional, names for columns of the data frame
- string_columns (list) – List of column names that should be displayed as strings
- index_as_column (bool) – Display the data frame index as the first column
- checks (bool) – Display checkboxes next to the first column
Tabular Data Models¶
These models are designed to work with the braviz database and to allow users to interact with the data stored there through a graphical interface.
Variables¶
-
class
VarListModel
(parent=None, checkeable=False)[source]¶ List of available variables, optionally with checkboxes
The list can be filtered to include only variables whose name include a certain pattern
Parameters: -
select_items
(items_list)[source]¶ Add checks to variables by id
This will cause checks to appear in the respective boxes when the view is updated
Parameters: items_list (list) – List of variable ids to check
-
select_items_by_name
(items_list)[source]¶ Add variables to the set of checked items
This will cause checks to appear in the respective boxes when the view is updated
Parameters: items_list (list) – List of variable to check
-
-
class
SubjectDetails
(initial_vars=None, initial_subject=None)[source]¶ A table showing variable values for a single subject
The first column contains variable names, and the second column its values, together with the range of values for the reference population
The user may drag table rows to change the order
Parameters: - initial_vars (list) – List of variables codes to include in the table from the start
- initial_subject – Code of the initial subject
-
class
ContextVariablesModel
(context_vars_list=None, parent=None, editable_dict=None)[source]¶ A table with three columns: Variable name, variable type, and a checkbox called “editable”
This table is used to select a list of variables, and decide which of those should be made writable, and which readonly
Parameters:
-
class
NewVariableValues
[source]¶ A table with on column for subject, and a writable second column for variable values
Values are restricted to numbers
-
class
NominalVariablesMeta
(var_name, parent=None)[source]¶ A table with numerical labels in the first column and corresponding text labels in the second column
These labels correspond to the possible values a nominal variable can take Textual labels can be edited
Parameters: var_name (str) – Name of a nominal variable -
save_into_db
(var_idx=None)[source]¶ Save the textual labels into the database
Parameters: var_idx (int) – Index of the variable to which the labels will be saved, only required if var_name is not set.
-
set_checkeable
(checkeable)[source]¶ Choose if check boxes should be displayed next to numerical labels
Parameters: checkeable (bool) – If True
checkboxes will appear
-
Subjects and samples¶
-
class
SampleTree
(columns=None)[source]¶ Creates a tree for representing a sample
Each first level child represents a nominal variable, and its sons are the different values for that variable finally, the leafs contain the subject ids. For each node the number of subjects it contains is represented in the second column
Parameters: columns (list) – List of nominal variable names to include in the tree. -
get_leafs
(QModelIndex)[source]¶ Get subjectids under a certain node
Parameters: QModelIndex (QModelIndex) – Index of a node in the tree
-
-
class
SubjectsTable
(initial_columns=None, sample=None)[source]¶ A table of subjects and values for specified variables
The first column contains subject codes. There are additional columns for each requested variable. Values for nominal variables are shown as textual labels
Parameters:
-
class
SubjectChecklist
(initial_list=(), show_checks=True)[source]¶ A list of subjects with checkboxes
Parameters: -
checked
¶ set of checked subjects
-
-
class
SubjectCheckTable
(initial_list=(), data_cols=(), headers=('', ''))[source]¶ A table of subjects with optional checkboxes
Parameters: - initial_list (list) – List of subject ids
- data_cols (list) – List of columns to shown, where each column is an iterable of the same length as the subject lists, such that the value for the subject in position i is also located at position i
- headers (list) – List of strings used as headers for the table on top of each data column
-
checked
¶ Set of checked subjects
-
class
SamplesSelectionModel
[source]¶ A table showing available subsamples
It has three columns: sample size, sample name, and sample description
-
get_sample
(QModelIndex)[source]¶ Get the set of subjects in a subsample located at a certain row
Parameters: QModelIndex (QModelIndex) – Index of a cell in the table (only the row is important)
-
get_sample_index
(QModelIndex)[source]¶ Get the database index of a subsample located at a certain row
Parameters: QModelIndex (QModelIndex) – Index of a cell in the table (only the row is important)
-
get_sample_name
(QModelIndex)[source]¶ Get the name of a subsample located at a certain row
Parameters: QModelIndex (QModelIndex) – Index of a cell in the table (only the row is important)
-
-
class
SamplesFilterModel
[source]¶ A list of filters that can be applied to a sample
-
apply_filters
(input_set)[source]¶ Apply all filters to a given set
Parameters: input_set (set) – Set of subject ids Returns: filtered set of subject ids
-
remove_filter
(index)[source]¶ Removes a filter located at a given row
Parameters: index (QModelIndex) – Index of the row containing the filter
-
Statistics¶
-
class
VarAndGiniModel
(outcome_var=None, parent=None, sample=None)[source]¶ A table of variables which can include the gini index.
The gini index is associated to each variable when predicting an outcome variable
Parameters:
-
class
AnovaRegressorsModel
(regressors_list=(), parent=None)[source]¶ Holds the regressors and interaction terms for a linear model
The model exposes two columns, regressor name and degrees of freedom. Internally it keeps track if each regressor is a single term or an interaction of multiple variables
It is possible to show only interactions, or only single term regressors
Parameters: -
add_interactor
(factor_rw_indexes)[source]¶ Add an interaction term to the model
Parameters: factor_rw_indexes (list) – Positions of single term regressors that compose the interaction. This positions are the row number of the variable in this model, without counting interaction terms (or the row number when interaction terms are hidden)
-
add_interactor_by_names
(factor_names)[source]¶ Add an interaction term by giving the name of its terms
Parameters: factor_names (list) – List of variable names, already in the model, which make up the interaction
-
add_regressor
(var_name)[source]¶ Add a regressor to the list
Parameters: var_name (str) – Name of a variable
-
get_data_frame
()[source]¶ Get the internal data frame
Returns: pandas.DataFrame
with three columns – regressor name, degrees of freedom, and interaction. The last column has zeros for single variable regressors and 1 for interaction terms.
-
get_interactors_dict
()[source]¶ Get the interactions dictionary
Returns: A dictionary that maps dataframe indices of interactions terms to the dataframe indices of its factors.
-
reset_data
(regressors_list)[source]¶ Sets a new list of regressors
Parameters: regressors_list (list) – List of variable names
-
-
class
AnovaResultsModel
(results_df=None, residuals=None, intercept=None, fitted=None)[source]¶ A model to represent the results of an anova regression
It has columns for factor names, sum of squares, degrees of freedom, F statistic, and p value. Internally it also holds residuals, fitted values and intercept.
Parameters: - results_df (pandas.DataFrame) – A Data Frame containing the columns indicated above
- residuals (list) – A vector of the regression residuals
- intercept (float) – Value of the intercept term of the regression
- fitted (list) – Vector of fitted values
Bundles¶
-
class
SimpleBundlesList
[source]¶ A list of database fiber bundles
An optional special bundle, called “<From Segment>” may also be shown
-
get_bundle_name
(bid)[source]¶ Get the name used to show a bundle with the given id
Parameters: bid (int) – Bundle database id
-
Scenarios¶
Structures model¶
-
class
StructureTreeModel
(reader, subj=None, dominant=False)[source]¶ A tree of freesurfer segmented structures
Parameters: - reader (braviz.readAndFilter.base_reader.BaseReader) – A reader from which to get available models
- subj – Id of a subject to use as reference for getting available models
- dominant (bool) – If
False
the tree will have left and right hemispheres, otherwise it will have dominant and non-dominant hemispheres
-
optimistic_reload_hierarchy
(dominant)[source]¶ Rebuilds the tree from the models of the first subject with models
Parameters: dominant (bool) – If False
the tree will have left and right hemispheres, otherwise it will have dominant and non-dominant hemispheres
Helper¶
-
class
StructureTreeNode
(parent=None, name='', son_number=0)[source]¶ Node for the freesurfer structures tree
Parameters: - parent (braviz.interaction.qt_structures_model.StructureTreeNode) – Reference to the parent node
- name (str) – Name of this node
- son_number (int) – How many siblings are before this node
Logic bundle model¶
-
class
LogicBundleQtTree
(root=None)[source]¶ A Qt representation of a logical fiber bundle
Parameters: root (braviz.interaction.logic_bundle_model.LogicBundleNode) – Root of the logic bundle tree -
add_node
(parent, node_type, value, extra_data=None)[source]¶ Add a son to an specific node in the tree
Parameters: - parent (braviz.interaction.logic_bundle_model.LogicBundleNode) – Node to which the son will be added
- node_type (int) – Type of the new node
- value – Value of the new node
- extra_data – Extra data for the new node
-
get_node
(index)[source]¶ Get the node at a given index
Parameters: index (QAbstractModelIndex) – Index of a node
-
remove_node
(index)[source]¶ Remove a node from the tree
Parameters: index (QAbstractModelIndex) – Index of node to remove
-
root
¶ root node of the underlying tree
-
set_root
(new_root)[source]¶ Sets a new tree for the model
Parameters: new_root (braviz.interaction.logic_bundle_model.LogicBundleNode) – Root of new tree
-
Helpers¶
-
class
LogicBundleNode
(parent, son_number, node_type, value, extra_data=None)[source]¶ A node for a bundle based on a logical hierarchy
See
braviz.readAndFilter.bundles_db.get_logic_bundle_dict()
for more informationParameters: - parent (braviz.interaction.logic_bundle_model.LogicBundleNode) – Reference to parent node,
None
if root - son_number (int) – Number of siblings before the current node
- node_type (int) – Type of the current node. May be 0 for logic, 1 for structure or 2 for roi
- value – Logical operation for logic nodes, or structure name for structure nodes
- extra_data (int) – Roi database index for roi nodes
-
add_son
(node_type, value, extra_data=None)[source]¶ Add a son to the current node
Parameters: - node_type (int) – Node type of the new son
- value – Value for the new son
- extra_data – Extra data for the new son
-
add_son_from_dict
(values)[source]¶ Adds a son from a dictionary
Parameters: values (dict) – Recursive dictionary with the following keys: node_type, value, extra_data, children (each of them as another dictionary with these keys)
-
static
from_dict
(values)[source]¶ Construct a tree from a dictionary
Parameters: values (dict) – Recursive dictionary with the following keys for each node: node_type, value, extra_data, children (each of them as another dictionary with these keys) Returns: The root node of the resulting tree
-
node_type
¶ Type of this node, 0: Logical, 1: Structure or 2: Roi
-
parent
¶ Parent node
-
remove_kid
(index)[source]¶ Remove a child
Younger brother numbers are updated
Parameters: index (int) – number of son to remove
-
son_number
¶ Number of sons added before this one
- parent (braviz.interaction.logic_bundle_model.LogicBundleNode) – Reference to parent node,
-
class
LogicBundleNodeWithVTK
(parent, son_number, node_type, value, extra_data=None, reader=None, subj=None, space='subject')[source]¶ Adds VTK drawing capabilities to the
LogicBundleNode
Parameters: - parent (braviz.interaction.logic_bundle_model.LogicBundleNode) – Reference to parent node,
None
if root - son_number (int) – Number of siblings before the current node
- node_type (int) – Type of the current node. May be 0 for logic, 1 for structure or 2 for roi
- value – Logical operation for logic nodes, or structure name for structure nodes
- extra_data (int) – Roi database index for roi nodes
- reader (braviz.readAndFilter.base_reader.BaseReader) – Reader object to get data from
- subj – Subject index for the subject fibers you want to draw
- space – Coordinate systems in which you want the drawing.
See
braviz.readAndFilter.base_reader.BaseReader.get()
-
set_color
(color)[source]¶ Set color for the actor
Parameters: color (tuple) – RGB components of the color
-
set_opacity
(int_opac)[source]¶ Sets the opacity of the actor
Parameters: int_opac (int) – From 0 to 100 where 0 is invisible and 100 is opaque
-
update
(subj, space)[source]¶ Change subject or coordinate system
Parameters: - subj – New subject id
- space – New coordinate system
See
braviz.readAndFilter.base_reader.BaseReader.get()
-
static
vtk_from_dict
(values, reader, subj=None, space='subject')[source]¶ Create a tree from a recursive dictionary
Parameters: - values (dict) – Recursive dictionary with the following keys for each node: node_type, value, extra_data, children (each of them as another dictionary with these keys)
- reader (braviz.readAndFilter.base_reader.BaseReader) – Reader object to get data from
- subj – Subject index for the subject fibers you want to draw
- space – Coordinate systems in which you want the drawing.
See
braviz.readAndFilter.base_reader.BaseReader.get()
Returns: The root node of the resulting tree
- parent (braviz.interaction.logic_bundle_model.LogicBundleNode) – Reference to parent node,