pygmi package

Subpackages

Submodules

pygmi.main module

Main module for PyGMI.

This module comprises a series of classes which are responsible for the primary interface to the software. Credit must go to PyQt’s examples, upon which some of this was originally based.

Although the main interface is controlled here, the content of the menus and routines is not. The menus and corresponding classes are found within the pygmi packages.

class pygmi.main.Arrow(start_item, end_item, parent=None)

Bases: QGraphicsLineItem

Class responsible for drawing arrows on the main interface.

arrow_head

Arrow head polygon.

Type:

QPolygonF

my_start_item

Starting DiagramItem object. This will send information to my_end_item

Type:

DiagramItem

my_end_item

End DiagramItem object. This will get information from my_start_item

Type:

DiagramItem

my_color

Color

Type:

QtCore colour (default is QtCore.Qt.black)

boundingRect()

Bounding Rectangle.

Overloaded bounding rectangle. This is necessary to ensure that the line and arrowhead are cleaned properly when moving.

Returns:

tmp

Return type:

QtCore.QRectF

paint(painter, option, widget=None)

Overloaded paint method.

Parameters:
  • painter (QPainter)

  • option (QStyleOptionGraphicsItem)

  • widget (QWidget, optional)

class pygmi.main.DiagramItem(diagram_type, context_menu, my_class, parent)

Bases: QGraphicsPolygonItem

Diagram Item.

arrows

list of Arrow objects

Type:

list

diagram_type

string denoting the diagram type. Can be ‘StartEnd’, ‘Conditional’ or ‘Step’

Type:

str

context_menu = context_menu
my_class

Class that the diagram item is linked to.

Type:

object

text_item
Type:

None

my_class_name

Class name being referenced

Type:

str

add_arrow(arrow)

Add Arrow.

Parameters:

arrow (Arrow) – Arrow object to add.

contextMenuEvent(event)

Overloaded context menu event.

Parameters:

event (N/A)

mouseDoubleClickEvent(event)

Mouse double click event.

This event is used to activate an item. It does this by calling the settings() method of the item. The event also changes the colour of the item to reflect whether it is busy working.

remove_arrow(arrow)

Remove a single Arrow.

Parameters:

arrow (Arrow) – Arrow object to remove.

remove_arrows()

Remove Arrows. Uses the remove_arrow method.

settings(nodialog=False)

Routine Settings.

Parameters:

nodialog (bool, optional) – Run settings without a dialog. The default is False.

Returns:

iflag – Returns a boolean reflecting success of the my_class.settings() method.

Return type:

bool

update_indata()

Routine to add datasets.

class pygmi.main.DiagramScene(item_menu, parent=None)

Bases: QGraphicsScene

Diagram Scene.

mouseMoveEvent(mouse_event)

Overloaded Mouse Move Event.

Parameters:

mouse_event (QGraphicsSceneMouseEvent) – mouse event.

mousePressEvent(mouse_event)

Overloaded Mouse Press Event.

Parameters:

mouse_event (QGraphicsSceneMouseEvent) – mouse event.

mouseReleaseEvent(mouse_event)

Overloaded Mouse Release Event.

Parameters:

mouse_event (QGraphicsSceneMouseEvent) – mouse event.

selected_item_info()

Display info about selected item.

class pygmi.main.MainWidget(parent=None, nocgs=True)

Bases: QMainWindow

Widget class to call the main interface.

pdlg
Type:

list

context_menu
Type:

dictionary

add_to_context(txt)

Add to a context menu.

Each dataset type which PyGMI uses can have its own context menu. This method allows for the definition of each group of context menu items under a user defined text label.

Parameters:

txt (str) – Label for a group of context menu items

bring_to_front()

Bring the selected item to front.

clearprocesslog()

Clear the process log.

delete_item()

Delete the selected item from main interface.

get_indata()

Get input data from the selected item on the main interface.

Returns:

idata – Input list of PyGMI Data

Return type:

list of PyGMI Data

get_outdata()

Get output data from the selected item on the main interface.

Returns:

odata – Output list of PyGMI Data

Return type:

list of PyGMI Data

help_docs()

Help Routine.

item_insert(item_type, item_name, class_name, projimport=False, **kwargs)

Item insert.

Insert an item on the main interface. The item is an object passed by one of the menu.py routines and is one of the algorithms chosen on the main PyGMI menu.

Parameters:
  • item_type (str) – str describing the shape of the graphic used to describe the item.

  • item_name (str) – str describing the name of the item to be displayed.

  • class_name (object) – class to be called when double clicking on the item.

Returns:

item – Return a DiagramItem object

Return type:

DiagramItem

keyPressEvent(event)

Intercept key press for custom key presses.

Parameters:

event (QKeyEvent) – Key press event object.

Return type:

None.

launch_context_item(newitem)

Launch a context menu item, using output data.

Parameters:

newitem (custom class) – newitem is the class to be called by the context menu item

launch_context_item_indata(newitem)

Launch a context menu item, using input data.

Parameters:

newitem (custom class) – newitem is the class to be called by the context menu item

linepointer()

Select line pointer.

load()

Load project state from JSON file.

Return type:

None.

pointer()

Select pointer.

process_is_active(isactive=True)

Change process log colour when a process is active.

Parameters:

isactive (bool, optional) – boolean variable indicating if a process is active.

run()

Run entire script.

Return type:

None.

save()

Save project state to a JSON file.

Return type:

None.

send_to_back()

Send the selected item to the back.

setupui()

Set up UI.

Return type:

None.

showdatainfo(txt)

Show text in the dataset information panel.

Parameters:

txt (str) – Message to be displayed in the datainfo panel

showlog(txt, replacelast=False)

Show text on the process log.

Parameters:
  • txt (str) – Message to be displayed in the process log

  • replacelast (bool, optional) – flag to indicate whether the last row on the log should be overwritten.

update_pdlg(dlg)

Clean deleted objects in self.pdlg and appends a new object.

self.pdlg allows for modeless dialogues to remain in existence until they are closed

Parameters:

dlg (object) – Object to be appended to self.pdlg

class pygmi.main.Startup(pbarmax, parent=None)

Bases: QDialog

Class to provide a startup display while PyGMI loads into memory.

update()

Update the text on the dialog.

pygmi.main.main(nocgs=False)

Entry point for the PyGMI software.

pygmi.menu_default module

Default set of menus for the main interface.

It also includes the about box.

class pygmi.menu_default.FileMenu(parent=None)

Bases: object

Widget class to call the main interface.

This widget class creates the raster menus to be found on the main interface. Normal as well as context menus are defined here.

parent

Reference to MainWidget class found in main.py

Type:

pygmi.main.MainWidget

class pygmi.menu_default.HelpButton(htmlfile=None, parent=None)

Bases: QPushButton

Help Button.

Convenience class to add a Help image to a pushbutton

help_docs()

Help Routine.

class pygmi.menu_default.HelpDocs(parent=None, helptxt=None)

Bases: QDialog

A basic combo box application.

parent

reference to the parent routine

Type:

parent

indata

dictionary of input datasets

Type:

dictionary

outdata

dictionary of output datasets

Type:

dictionary

class pygmi.menu_default.HelpMenu(parent=None)

Bases: object

Widget class to call the main interface.

parent

reference to the parent routine

Type:

parent

about()

About box for PyGMI.

webhelp()

Help File.

pygmi.misc module

Misc is a collection of routines which can be used in PyGMI in general.

class pygmi.misc.BasicModule(parent=None)

Bases: QDialog

Basic Module.

parent

reference to the parent routine

Type:

parent

indata

dictionary of input datasets

Type:

dictionary

outdata

dictionary of output datasets

Type:

dictionary

ifile

input file, used in IO routines and to pass filename back to main.py

Type:

str

piter

reference to a progress bar iterator.

Type:

function

pbar

reference to a progress bar.

Type:

function

showlog

reference to a way to view messages, normally stdout or a Qt text box.

Type:

stdout or alternative

is_import

used to indicate whether a routine contains an import within.

Type:

bool

projdata

Project data.

Type:

dictionary

data_init()

Initialise Data.

Entry point into routine. This entry point exists for the case where data must be initialised before entering at the standard ‘settings’ sub module.

Return type:

None.

loadproj(projdata)

Load project data into class.

Parameters:

projdata (dictionary) – Project data loaded from JSON project file.

Returns:

chk – A check to see if settings was successfully run.

Return type:

bool

saveobj(obj)

Save an object to a dictionary.

This is a convenience function for saving project information.

Parameters:

obj (variable) – A variable to be saved.

Return type:

None.

saveproj()

Save project data from class.

Return type:

None.

settings(nodialog=False)

Entry point into item.

Parameters:

nodialog (bool, optional) – Run settings without a dialog. The default is False.

Returns:

True if successful, False otherwise.

Return type:

bool

class pygmi.misc.ContextModule(parent=None)

Bases: QDialog

Context Module.

parent

reference to the parent routine

Type:

parent

indata

dictionary of input datasets

Type:

dictionary

outdata

dictionary of output datasets

Type:

dictionary

piter

reference to a progress bar iterator.

Type:

function

pbar

reference to a progress bar.

Type:

function

showlog

reference to a way to view messages, normally stdout or a Qt text box.

Type:

stdout or alternative

run()

Run context menu item.

Return type:

None.

class pygmi.misc.EmittingStream(textWritten)

Bases: QObject

Class to intercept stdout for later use in a textbox.

fileno()

File number.

Returns:

Returns -1.

Return type:

int

flush()

Flush.

Return type:

None.

write(text)

Write text.

Parameters:

text (str) – Text to write.

Return type:

None.

class pygmi.misc.PTime

Bases: object

PTime class.

Main class in the ptimer module. Once activated, this class keeps track of all time since activation. Times are stored whenever its methods are called.

tchk

List of times generated by the time.perf_counter routine.

Type:

list

since_first_call(msg='since first call', show=True)

Time lapsed since first call.

This function prints out a message and lets you know the time passed since the first call.

Parameters:

msg (str) – Optional message

since_last_call(msg='since last call', show=True)

Time lapsed since last call.

This function prints out a message and lets you know the time passed since the last call.

Parameters:

msg (str) – Optional message

class pygmi.misc.ProgressBar(parent=None)

Bases: QProgressBar

Progress bar.

Progress Bar routine which expands the QProgressBar class slightly so that there is a time function as well as a convenient of calling it via an iterable.

otime

This is the original time recorded when the progress bar starts.

Type:

integer

iter(iterable)

Iterate Routine.

to_max()

Set the progress to maximum.

class pygmi.misc.ProgressBarText

Bases: object

Text Progress bar.

iter(iterable)

Iterate Routine.

printprogressbar(iteration, suffix='')

Call in a loop to create terminal progress bar.

Code by Alexander Veysov. (https://gist.github.com/snakers4).

Parameters:
  • iteration (int) – current iteration

  • suffix (str, optional) – Suffix string. The default is ‘’.

Return type:

None.

to_max()

Set the progress to maximum.

class pygmi.misc.QVStack2Layout(parent=None)

Bases: QGridLayout

QVStack2Layout.

This works like VBoxLayout, except each row takes two widgets.

addWidget(widget1, widget2)

Add two widgets on a row, widget can also be text.

Parameters:
  • widget1 (str or QWidget) – First Widget or Label on the row.

  • widget2 (QWidget) – Last Widget.

Return type:

None.

addWidgetOld(*args, **kwargs)

Original Add Widget.

pygmi.misc.discrete_colorbar(axes, csp, cdat, lbls=None)

Plot colour bar using discrete colours for a small range of values.

Parameters:
  • axes (Matplotlib axes) – Current axes.

  • csp (Plot routine) – Handle to Matplotlib plotting routine.

  • cdat (numpy array) – Array of values.

  • lbls (y tick labels (optional))

Return type:

None.

pygmi.misc.getinfo(txt=None, reset=False)

Get time and memory info.

Parameters:
  • txt (str/int/float, optional) – Descriptor used for headings. The default is None.

  • reset (bool) – Flag used to reset the time difference to zero.

Return type:

None.

pygmi.misc.textwrap2(text, width, placeholder='...', max_lines=None)

Provide slightly different placeholder functionality to textwrap.

Placeholders will be a part of last line, instead of replacing it.

Parameters:
  • text (str) – Text to wrap.

  • width (int) – Maximum line length.

  • placeholder (sre, optional) – Placeholder when lines exceed max_lines. The default is ‘…’.

  • max_lines (int, optional) – Maximum number of lines. The default is None.

Returns:

text2 – Output wrapped text.

Return type:

str

pygmi.misc.tick_formatter(x, pos)

Format thousands separator in ticks for plots.

Parameters:
  • x (float/int) – Number to be formatted.

  • pos (int) – Position of tick.

Returns:

newx – Formatted coordinate.

Return type:

str

pygmi.version module

Module contents

PyGMI stands for Python Geoscience Modelling and Interpretation.

It is a modelling and interpretation suite aimed at magnetic, gravity and other datasets. It includes:

  • Magnetic and Gravity 3D forward modelling

  • Remote sensing tools.

  • Cluster Analysis

  • Routines for cutting, reprojecting and doing simple modifications to data

  • Convenient display of data using pseudo-color, ternary and sunshading

It is released under the Gnu General Public License version 3.0