# Graph Data Extractor¶

The Graph Data Extractor is an application to convert image files of axes with data points to comma-separated files that can be used with Myokit, spreadsheets, and more.

## Implementation¶

class myokit.gui.gde.GraphDataExtractor(filename=None)

Main window for the graph data extractor.

action_about()

action_add_data_point(x=0.5, y=0.5)

Adds a data point to the document.

action_add_data_set()

Adds a new data set to the document.

action_extract()

Extracts the data points and saves them in a csv file.

action_license()

Displays this program’s licensing information.

action_new()

Lets the user start a new project.

action_open()

Let the user select an gde file to load.

action_open_recent()

Opens a recent file.

action_redo()

Redo the last action.

action_revert()

Reloads the current file (if any).

action_save(save_as=False)

Saves the current document to a file.

action_save_as()

Saves the current document to a file.

action_set_image()

Sets the image file

action_undo()

Undo the last action.

add_recent_file(filename)

Adds the given filename to the list of recent files.

clear_focus()

Used to clear focus (potentially finishing edit operations!) before any action is performed.

closeEvent(event=None)

Called when window is closed. To force a close (and trigger this function, call self.close())

create_menu()

create_toolbar()

Creates this widget’s toolbar

handle_action_exception(document, exception)

Handles exceptions during an action exception perform or undo method.

handle_mouse_moved(x, y)

Displays the current cursor position.

handle_node_selected(node)

Handles changes in document selection.

handle_undo_redo_change(document)

Handles changes to undo/redo history.

load_config()

Loads the user configuration from an ini file.

load_document(filename=None)

Loads a document into the editor.

prompt_save_changes()

Checks if there were any changes made to this document, if so, it prompts the user to save the current project.

Returns True if the user selected “yes” or “no” or there were no changes to save. Returns False if the user selected “cancel”.

save_config()

Saves the user configuration to an ini file.

set_filename(filename=None)

Changes the current filename.

update_recent_files_menu()

update_window_title()

Sets this window’s title based on the current state.

myokit.gui.gde.icon()

### Actions¶

class myokit.gui.gde.DA_AddVariable(parent, vtype, name, value=None)

Adds a DocumentVariable to a DocumentNode

class myokit.gui.gde.DA_AddNode(parent, ntype, name, variables)

Adds a child to a parent node.

Variables can be added using a list of tuples (type, name, value).

class myokit.gui.gde.DA_ChangeVariable(variable, value)

Changes a value within a DocumentNode

class myokit.gui.gde.DA_ChangeVariables(node, variables)

Changes one or more variables in a node. variables must be a dict mapping variable names to values.

class myokit.gui.gde.DA_RemoveNode(node)

Deletes a child node.

class myokit.gui.gde.DA_RemoveVariable(parent, variable)

Removes a DocumentVariable form a DocumentNode

### Document¶

class myokit.gui.gde.Document(parent, filename=None)

Represents an xml like document.

can_drag(node)

Returns True if the given DocumentNode is drag/drop enabled.

can_redo()

Returns True if there are actions that can be redone.

can_undo()

Returns True if there are actions that can be undone.

delete()

Deletes this document.

get_model()

Returns a model of this document for use with TreeView components.

has_changes()

Returns True if any changes were made to this document (even if they were subsequently undone).

redo()

Redoes the last undone action.

undo()

Undoes the last action.

write(filename)

Writes this document to the given path.

class myokit.gui.gde.DocumentNode(parent, ntype, name)

The DocumentNode class is used to build a tree structure where each node can contain one or more DataValue objects.

A parent must be specified: For document roots this should be the QObject owning the document, for all other nodes it should be the parent node.

Each node has an ntype, which describes the type of node it is. This is a string property that can be set freely.

Data stored in the node can be obtained using get_value()

add_child(ntype, name, variables=None)

Appends a child to this node.

Variables can be added by setting variables to a list of tuples (type, name, value).

add_variable(vtype, name, value=None)

Adds a DocumentVariable to this node.

can_drag()

Returns True if this item is draggable / droppable.

child(k)

Returns the k-th child node.

Required to work with DocumentModel.

clear_selection()

Clears the selection (if any) of this node and any children nodes.

data()

Returns an iterator over the DocumentValue objects stored in this node.

deselect()

Deselect this node in any listening views.

get(*names)

Returns the child node with the given name.

get_document()

Retuns the document this node is in.

get_model()

Returns the document model for the document this node is in.

get_model_index(column=0)

Returns a QModelIndex object refering to this node.

get_model_selection()

Returns a QItemSelection for this node’s entire row.

get_name()

Returns this node’s name.

get_ntype()

Returns this node’s ntype.

get_parent_node()

Returns this node’s parent, or None if this node is a root node.

get_value(name)

Returns the value of this node’s variable with the given name.

get_values(*names)

Returns all the requested variable values (see get_value())

get_variable(name)

Returns this node’s variable with the given name.

get_xml()

Returns an ElementTree xml version of this node.

has_value(name)

Returns True if this node has a variable with the given name.

index()

Returns the index of this node in its parent’s list of kids.

Required to work with DocumentModel

is_selected()

Returns True if this node is selected.

parent()

Returns this node’s parent.

Required to work with DocumentModel.

remove()

Removes this node.

select()

Tells any views listening to this node that it should be selected.

set_value(**values)

Sets one or more variables in this node using the keyword syntax.

silent_add_child(ntype, name)

Creates and appends a child node without using actions or sending out signals.

Returns the new node.

silent_add_existing_child(child)

Appends a child node without using actions or sending out signals.

silent_add_existing_variable(var)

Appens a variable without using actions or sending out signals.

silent_add_variable(vtype, name, value=None)

Creates and appends a variable to this node without using actions or sending out signals.

Returns the new variable.

silent_remove_child(node)

Removes a child without using actions or sending out signals.

silent_remove_variable(variable)

Removes a variable without using actions or sending out signals.

class myokit.gui.gde.DocumentVariable(node, vtype, name, value=None)

Stores a variable in a document node.

get_name()

Returns this variable’s name.

get_node()

Returns the node this variable belongs to.

get_str_value()

Returns this variable’s value as a string.

get_value()

Returns this variable’s value in its native type.

get_vtype()

Returns this variable’s data type.

get_xml()

Returns an ElementTree object representing this variable.

set_value(value)

Changes this variable’s value.

silent_set_value(value)

Changes this variable’s data type, without using actions or sending signals.

### Penalized Spline¶

myokit.gui.gde.pspline()

Computes a penalized B-spline (or P-spline) that fits the data given by x, y.

If an argument x2 is given, the spline is evaluated at each point in x2 and the resulting values are returned. If no value x2 is given the evaluations at x are returned.

The fitted spline will have nseg segments of degree deg. Data fitting is performed using a penalty of degree pdeg (e.g. a penalty on the pdeg-th derivative). Smoothing is introduced using a smoothing factor s.

Both x and y must be 1D arrays of the same length. The length of x2 is arbitrary.

P-splines are described in:

Flexible Smoothing with B-splines and Penalties Paul H.C. Eilers and Brian D. Marx Statistical Science 1996, Vol. 11, No. 2, 89-121

This method was adapted from a computer lab script by Paul Eilers, 2007 http://www.stat.lsu.edu/faculty/marx/

### Widgets¶

class myokit.gui.gde.AxisItem(node)

Data axis

boundingRect()

Returns this item’s bounding rectangle.

get_sibling_ref(ref)

Given reference point 1, this method returns point 2 and vice versa.

init(scene, node)

Initialize to the given node and scene

is_x()

Returns true if this is an x-axis.

paint(painter, option, widget)

Paints this reference point

update_coords()

Updates the coordinates of this axis.

class myokit.gui.gde.AxisPointItem(node, axis)

Reference point for an axis.

boundingRect()

Returns this item’s bounding rectangle.

get_npos()

Returns this item’s normalised coordinates.

handle_drag(x, y)

Item has been dragged and released.

handle_drag_live(x, y)

Item is being dragged.

handle_variable_changed(node, variable)

Variable in item’s node has changed.

init(scene, node)

Initialize to the given scene and node.

keyPressEvent(event)

A key is pressed while this item has focus.

keyReleaseEvent(event)

A key is released while this item has focus.

paint(painter, option, widget)

Paints this reference point

restrict_movement(x, y)

Used to restrict the drag movement of this item if ctrl is held.

set_npos(x, y)

Repositions this item using normalised coordinates (range 0..1)

class myokit.gui.gde.BoolVariableField(parent, variable)

Editor field for text based values.

handleFieldChanged()

Called when this field initiates a change.

handleVariableChanged(variable)

Called when the underlying variable is changed (including changes made by this field).

class myokit.gui.gde.DataPointItem(node, parent)

Data point view on the image.

boundingRect()

Returns this item’s bounding rectangle.

handle_drag(x, y)

Item has been dragged and released.

handle_variable_added(node, variable)

handle_variable_changed(node, variable)

Variable in item’s node has changed.

keyPressEvent(event)

A key is pressed while this item has focus.

paint(painter, option, widget)

Paints this reference point

set_scene(scene)

Scene is set or replaced.

class myokit.gui.gde.DataSetItem(node)

Data Set item. Usually empty, but can draw an interpolating p-spline.

boundingRect()

Returns this item’s bounding rectangle.

disconnect()

Disconnects any listeners attached to this item.

handle_child_added(parent, child)

Handle addition of a data point.

handle_child_removed(parent, child)

Handle removal of a data point.

handle_variable_changed()

Handles the event where a child variable is changed.

init(scene, node)

Initialize to the given node and scene

paint(painter, option, widget)

Paints this spline

update_spline()

Creates a spline based on the current data set.

class myokit.gui.gde.DocumentAction

Represents an action that can be performed on a document.

perform()

Performs this action. Return type depends on action.

undo()

Undoes this action. Return type depends on action.

class myokit.gui.gde.DocumentEditDock(parent)

A dock for selecting properties to edit.

set_document(document)

Sets or replaces this dock’s document.

class myokit.gui.gde.DocumentModel(document)

Implements the Qt abstract item model for a Document.

columnCount(node)

Return number of columns in this node

data(index, role)

Returns the data stored at the given index (where index is given as a qt QModelIndex).

flags(index)

Returns the relevant flags for the item at this index.

headerData(section, orientation, role)

Return the header for the row/column requested as section.

index(row, column, parent)

Create an index for the selected row and column, counted from the given parent index (as a QModelIndex object).

parent(index)

Return an index to the parent of the item at the given index.

rowCount(parent)

Returns the number of children in the DocumentNode at the given index.

supportedDropActions()

Returns a flag indicating the supported drop actions for QItems.

class myokit.gui.gde.DocumentTreeView(parent)

Treeview for documents.

node_selected(node)

Selection changed in any view.

node_selected_local(event)

Selection changed in this view.

set_document(document)

Sets or replaces this view’s document.

class myokit.gui.gde.DocumentVariableEditDock(parent, select_dock)

A dock for editing a node’s variables.

set_document(document)

Sets or replaces this dock’s document.

class myokit.gui.gde.DocumentVariableField(parent, variable)

Abstract class to be extended by variable edit fields of different types

static create(parent, variable)

Creates a new DocumentVariableField of the appropriate class.

handleFieldChanged()

Called when the field initiates a change.

handleVariableChanged(variable)

Called when the underlying variable is changed (including changes made by this field).

class myokit.gui.gde.DocumentVariableList(parent)

Displays a list of properties and allows them to be edited.

handle_node_deleted(document, node)

Called when a node is deleted.

handle_node_selected(node)

Called when a node is selected in one of the views.

set_document(document)

Tells this variable list to work with the given document.

set_node(node)

Sets or replaces this variable list’s node.

class myokit.gui.gde.DraggableItem(node, parent=None)

Item on the scene that can be picked up and moved around.

handle_drag(x, y)

Called if the user has dragged to node to scene coordinates (x, y) and released it.

handle_drag_live(x, y)

Called while the user is dragging the node to scene coordinates (x, y).

itemChange(change, value)

Stay on the scene. (Like a sex machine).

mouseMoveEvent(event)

Item being moved using the mouse.

mousePressEvent(event)

Mouse pressed? Then show drag icon and allow moving

mouseReleaseEvent(event)

Mouse button released again.

restrict_movement(x, y)

Allows restricted movement of points. Called with the scene coordinates. Should return a tuple (x, y).

class myokit.gui.gde.GdeDocument(parent, filename=None)

Represents a document used by the GDE.

The argument parent should be a QObject owning this document.

add_data_fit()

Adds a data fit to this document.

add_data_set()

Adds a data set to this document.

can_drag(node)

Returns True if the given node is draggable.

extract_data(path)

Extracts the data from every data set in the scene and writes it to a series of csv files.

get_active_data_set()

Returns the currently active dataset. If the document doesn’t contain any datasets a new set is created.

get_xml()

Returns an ElementTree xml version of this document.

handle_axis_changed()

Updates the coordinate conversion scheme when the axes are changed.

handle_data_set_added(parent, dset)

Called when a data set is added to the data node.

handle_data_set_removed(parent, dset)

Called when a data set is removed from the data node.

handle_node_selected(node)

Called when a node is selected in this document.

set_active_data_set(data_set)

Sets the currently active data set.

class myokit.gui.gde.GdeScene(gde)

Editable scene displaying the current Gde document

clear()

Clears this scene, disconnects from document.

get_item_for_node(node)

Returns the first scene item found for the given node.

handle_node_added(parent, child)

A node is added to the document.

handle_node_removed(parent, child)

A node is removed from the document.

mouseDoubleClickEvent(event)

Double-click: set background image.

mouseMoveEvent(event)

Show mouse position in status bar

mousePressEvent(event)

norm2scene(x, y)

Converts normalised coordinates to scene coordinates.

scene2norm(x, y)

Converts scene coordinates to normalised coordinates.

set_document(document)

Constructs a scene based on a document

class myokit.gui.gde.GdeView(scene)

Views the main GDE scene.

resizeEvent(event)

Called when the view is resized.

class myokit.gui.gde.ImageItem(node)

Draws a full-size background image onto the scene.

boundingRect()

Returns this item’s bounding rectangle.

handle_variable_changed(node, variable)

Variable in item’s node has changed.

init(scene, node)

Initialize to the given scene and node.

paint(painter, option, widget)

Paints this item.

class myokit.gui.gde.Line2D(a, b=None, c=None, d=None)

Represents a line segment in 2D euclidean space. A line is defined using two points, representing the ‘head’ and ‘tail’ of a vector connecting the points.

A Line2D can be created in three ways:

1. Using x = Line2D(y), where y is another instance of Line2D.
2. Using x = Line2D(tail, head), where both tail and head are instances of Point2D.
3. Using x = Line2D(tail_x, tail_y, head_x, head_y) where all arguments are of types that can be converted to float.
intersect(other)

Returns the point where the given lines intersect.

move_to(point)

Moves this line definition vector so that its tail is at the given point.

point(k)

Returns a point p on the line according to:

p = tail + k * (head - tail)


where k is a scalar value and p, tail and head are 2D points.

translate(distance)

Moves this vector an x and y distance specified by the given Point2D.

class myokit.gui.gde.Point2D(x, y=None)

Represents a point in R2.

transform(a, b, c, d)

Transforms this point by multiplying with the matrix ((a, b),(c, d)).

class myokit.gui.gde.TextVariableField(parent, variable)

Editor field for text based values.

focusOutEvent(event)

Called when this field loses focus.

handleFieldChanged()

Called when the value is changed by the user.

handleVariableChanged(variable)

Called when the underlying variable is changed (including changes made by this field).

class myokit.gui.gde.SceneItem(node, parent=None)

Item on the scene that is connected to a part of the model.

Items are hierarchical: most items have parent=None, but items can be created as child items by setting the parent argument to another SceneItem.

deselect()

Deselects this node, if possible.

disconnect()

Disconnect all listeners connected to by this item. Implementing subclasses that override this method should still make a call to the parent method.

get_node()

Returns this item’s DocumentNode.

get_npos()

Returns this item’s normalised coordinates.

handle_document_deleted(doc)

Called when the document this item’s node is in is deleted.

handle_variable_changed(node, variable)

Called when a variable inside this item’s node is changed.

init(scene, node)

Called when this item needs to be (re-)set to the given scene and node. Both scene and node may be None.

itemChange(change, value)

Handles event when this item has changed

select()

Selects this node, if possible.

set_node(node=None)

Sets or replaces this item’s node.

set_npos(x, y)

Sets this item’s position based on the normalized coordinates (x, y)

set_scene(scene)

Sets or replaces this item’s scene