gui.snuffling
¶
Snuffling infrastructure
This module provides the base class Snuffling
for user-defined
snufflings and some utilities for their handling.
-
class
Param
(name, ident, default, minimum, maximum, low_is_none=None, high_is_none=None, low_is_zero=False, tracking=True, type=<class 'float'>)[source]¶ Definition of an adjustable floating point parameter for the snuffling. The snuffling may display controls for user input for such parameters.
Parameters: - name – labels the parameter on the snuffling’s control panel
- ident – identifier of the parameter
- default – default value
- minimum – minimum value for the parameter
- maximum – maximum value for the parameter
- low_is_none – if
True
: parameter is set to None at lowest value of parameter range (optional) - high_is_none – if
True
: parameter is set to None at highest value of parameter range (optional) - low_is_zero – if
True
: parameter is set to value 0 at lowest value of parameter range (optional)
-
class
Switch
(name, ident, default)[source]¶ Definition of a boolean switch for the snuffling. The snuffling may display a checkbox for such a switch.
Parameters: - name – labels the switch on the snuffling’s control panel
- ident – identifier of the parameter
- default – default value
-
class
Choice
(name, ident, default, choices)[source]¶ Definition of a string choice for the snuffling. The snuffling may display a menu for such a choice.
Parameters: - name – labels the menu on the snuffling’s control panel
- ident – identifier of the parameter
- default – default value
- choices – tuple of other options
-
class
Snuffling
[source]¶ Base class for user snufflings.
Snufflings are plugins for snuffler (and other applications using the
pyrocko.pile_viewer.PileOverview
class defined inpile_viewer.py
). They can be added, removed and reloaded at runtime and should provide a simple way of extending the functionality of snuffler.A snuffling has access to all data available in a pile viewer, can process this data and can create and add new traces and markers to the viewer.
-
setup
()[source]¶ Setup the snuffling.
This method should be implemented in subclass and contain e.g. calls to
set_name()
andadd_parameter()
.
-
module_dir
()[source]¶ Returns the path of the directory where snufflings are stored.
The default path is
$HOME/.snufflings
.
-
init_gui
(viewer, panel_parent, menu_parent, reloaded=False)[source]¶ Set parent viewer and hooks to add panel and menu entry.
This method is called from the
pyrocko.pile_viewer.PileOverview
object. Callssetup_gui()
.
-
setup_gui
(reloaded=False)[source]¶ Create and add gui elements to the viewer.
This method is initially called from
init_gui()
. It is also called, e.g. when new parameters have been added or if the name of the snuffling has been changed.
-
set_force_panel
(bool=True)[source]¶ Force to create a panel.
Parameters: bool – if True
will create a panel with Help, Clear and Run button.
-
delete_gui
()[source]¶ Remove the gui elements of the snuffling.
This removes the panel and menu entry of the widget from the viewer and also removes all traces and markers added with the
add_traces()
andadd_markers()
methods.
-
set_name
(name)[source]¶ Set the snuffling’s name.
The snuffling’s name is shown as a menu entry and in the panel header.
-
enable_pile_changed_notifications
()[source]¶ Get informed when pile changed.
When activated, the
pile_changed()
method is called on every update in the viewer’s pile.
-
pile_changed
()[source]¶ Called when the connected viewer’s pile has changed.
Must be activated with a call to
enable_pile_changed_notifications()
.
-
show_message
(kind, message)[source]¶ Display a message box.
Parameters: - kind – string defining kind of message
- message – the message to be displayed
-
fail
(message)[source]¶ Show an error message box and raise
SnufflingCallFailed
exception.Parameters: message – specifying the error
-
pylab
(name=None, get='axes')[source]¶ Create a
FigureFrame
and return either the frame, amatplotlib.figure.Figure
instance or amatplotlib.axes.Axes
instance.Parameters: - name – labels the figure frame’s tab
- get – ‘axes’|’figure’|’frame’ (optional)
-
figure
(name=None)[source]¶ Returns a
matplotlib.figure.Figure
instance which can be displayed within snuffler by callingcanvas.draw()
.Parameters: name – labels the tab of the figure
-
axes
(name=None)[source]¶ Returns a
matplotlib.axes.Axes
instance.Parameters: name – labels the tab of axes
-
figure_frame
(name=None)[source]¶ Create a
pyrocko.gui.util.FigureFrame
.Parameters: name – labels the tab figure frame
-
pixmap_frame
(filename=None, name=None)[source]¶ Create a
pyrocko.gui.util.PixmapFrame
.Parameters: - name – labels the tab
- filename – name of file to be displayed
-
web_frame
(url=None, name=None)[source]¶ Creates a
WebKitFrame
which can be used as a browser within snuffler.Parameters: - url – url to open
- name – labels the tab
-
vtk_frame
(name=None, actors=None)[source]¶ Create a
pyrocko.gui.util.VTKFrame
to render interactive 3D graphics.Parameters: - actors – list of VTKActors
- name – labels the tab
Initialize the interactive rendering by calling the frames’ :py:meth`initialize` method after having added all actors to the frames renderer.
Requires installation of vtk including python wrapper.
-
tempdir
()[source]¶ Create a temporary directory and return its absolute path.
The directory and all its contents are removed when the Snuffling instance is deleted.
-
set_live_update
(live_update)[source]¶ Enable/disable live updating.
When live updates are enabled, the
call()
method is called whenever the user changes a parameter. If it is disabled, the user has to initiate such a call manually by triggering the snuffling’s menu item or pressing the call button.
-
add_parameter
(param)[source]¶ Add an adjustable parameter to the snuffling.
Parameters: param – object of type Param
,Switch
, orChoice
.For each parameter added, controls are added to the snuffling’s panel, so that the parameter can be adjusted from the gui.
-
add_trigger
(name, method)[source]¶ Add a button to the snuffling’s panel.
Parameters: - name – string that labels the button
- method – method associated with the button
-
get_parameters
()[source]¶ Get the snuffling’s adjustable parameter definitions.
Returns a list of objects of type
Param
.
-
get_parameter
(ident)[source]¶ Get one of the snuffling’s adjustable parameter definitions.
Parameters: ident – identifier of the parameter Returns an object of type
Param
orNone
.
-
set_parameter
(ident, value)[source]¶ Set one of the snuffling’s adjustable parameters.
Parameters: - ident – identifier of the parameter
- value – new value of the parameter
Adjusts the control of a parameter without calling
call()
.
-
set_parameter_range
(ident, vmin, vmax)[source]¶ Set the range of one of the snuffling’s adjustable parameters.
Parameters: - ident – identifier of the parameter
- vmin,vmax – new minimum and maximum value for the parameter
Adjusts the control of a parameter without calling
call()
.
-
set_parameter_choices
(ident, choices)[source]¶ Update the choices of a Choice parameter.
Parameters: - ident – identifier of the parameter
- choices – list of strings
-
get_parameter_value
(ident)[source]¶ Get the current value of a parameter.
Parameters: ident – identifier of the parameter
-
get_settings
()[source]¶ Returns a dictionary with identifiers of all parameters as keys and their values as the dictionaries values.
-
get_viewer
()[source]¶ Get the parent viewer.
Returns a reference to an object of type
PileOverview
, which is the main viewer widget.If no gui has been initialized for the snuffling, a
NoViewerSet
exception is raised.
-
get_pile
()[source]¶ Get the pile.
If a gui has been initialized, a reference to the viewer’s internal pile is returned. If not, the
make_pile()
method (which may be overloaded in subclass) is called to create a pile. This can be utilized to make hybrid snufflings, which may work also in a standalone mode.
-
get_active_event_and_stations
(trange=(-3600.0, 3600.0), missing='warn')[source]¶ Get event and stations with available data for active event.
Parameters: - trange – (begin, end), time range around event origin time to query for available data
- missing – string, what to do in case of missing station
information:
'warn'
,'raise'
or'ignore'
.
Returns: (event, stations)
-
get_active_event_and_phase_markers
()[source]¶ Get the marker of the active event and any associated phase markers
-
get_viewer_trace_selector
(mode='inview')[source]¶ Get currently active trace selector from viewer.
Parameters: mode – set to 'inview'
(default) to only include selections currently shown in the viewer,'visible' to include all traces not currenly hidden by hide or quick-select commands, or ``'all'
to disable any restrictions.
-
chopper_selected_traces
(fallback=False, marker_selector=None, mode='inview', main_bandpass=False, progress=None, responsive=False, *args, **kwargs)[source]¶ Iterate over selected traces.
Shortcut to get all trace data contained in the selected markers in the running snuffler. For each selected marker,
pyrocko.pile.Pile.chopper()
is called with the arguments tmin, tmax, and trace_selector set to values according to the marker. Additional arguments to the chopper are handed over from *args and **kwargs.Parameters: - fallback – If
True
, if no selection has been marked, use the content currently visible in the viewer. - marker_selector – If not
None
a callback to filter markers. - mode – Set to
'inview'
(default) to only include selections currently shown in the viewer (excluding traces accessible through vertical scrolling),'visible'
to include all traces not currently hidden by hide or quick-select commands (including traces accessible through vertical scrolling), or'all'
to disable any restrictions. - main_bandpass – If
True
, apply main control high- and lowpass filters to traces. Note: use with caution. Processing is fixed to use 4th order Butterworth highpass and lowpass and the signal is always demeaned before filtering. FFT filtering, rotation, demean and bandpass settings from the graphical interface are not respected here. Padding is not automatically adjusted so results may include artifacts. - progress – If given a string a progress bar is shown to the user. The string is used as the label for the progress bar.
- responsive – If set to
True
, occasionally allow UI events to be processed. If used in combination withprogress
, this allows the iterator to be aborted by the user.
- fallback – If
-
get_selected_time_range
(fallback=False)[source]¶ Get the time range spanning all selected markers.
Parameters: fallback – if True
and no marker is selected return begin and end of visible time range
-
panel_visibility_changed
(bool)[source]¶ Called when the snuffling’s panel becomes visible or is hidden.
Can be overloaded in subclass, e.g. to perform additional setup actions when the panel is activated the first time.
-
make_pile
()[source]¶ Create a pile.
To be overloaded in subclass. The default implementation just calls
pyrocko.pile.make_pile()
to create a pile from command line arguments.
-
make_panel
(parent)[source]¶ Create a widget for the snuffling’s control panel.
Normally called from the
setup_gui()
method. ReturnsNone
if no panel is needed (e.g. if the snuffling has no adjustable parameters).
Create the help menu item for the snuffling.
Create the menu item for the snuffling.
This method may be overloaded in subclass and return
None
, if no menu entry is wanted.
-
output_filename
(caption='Save File', dir='', filter='', selected_filter=None)[source]¶ Query user for an output filename.
This is currently a wrapper to
QFileDialog.getSaveFileName()
. AUserCancelled
exception is raised if the user cancels the dialog.
-
input_directory
(caption='Open Directory', dir='')[source]¶ Query user for an input directory.
This is a wrapper to
QFileDialog.getExistingDirectory()
. AUserCancelled
exception is raised if the user cancels the dialog.
-
input_filename
(caption='Open File', dir='', filter='', selected_filter=None)[source]¶ Query user for an input filename.
This is currently a wrapper to
QFileDialog.getOpenFileName()
. AUserCancelled
exception is raised if the user cancels the dialog.
-
input_dialog
(caption='', request='', directory=False)[source]¶ Query user for a text input.
This is currently a wrapper to
QInputDialog.getText()
. AUserCancelled
exception is raised if the user cancels the dialog.
-
modified_snuffling_panel
(value, iparam)[source]¶ Called when the user has played with an adjustable parameter.
The default implementation sets the parameter, calls the snuffling’s
call()
method and finally triggers an update on the viewer widget.
-
switch_on_snuffling_panel
(ident, state)[source]¶ Called when the user has toggled a switchable parameter.
-
choose_on_snuffling_panel
(ident, state)[source]¶ Called when the user has made a choice about a choosable parameter.
Called when the user has triggered the snuffling’s menu.
The default implementation calls the snuffling’s
call()
method and triggers an update on the viewer widget.
Called when the user has clicked the snuffling’s call button.
The default implementation calls the snuffling’s
call()
method and triggers an update on the viewer widget.
Called when the user has clicked the snuffling’s clear button.
This calls the
cleanup()
method and triggers an update on the viewer widget.
Creates a
QLabel
which contains the documentation as given in the snufflings’ __doc__ string.
-
add_traces
(traces)[source]¶ Add traces to the viewer.
Parameters: traces – list of objects of type pyrocko.trace.Trace
The traces are put into a
pyrocko.pile.MemTracesFile
and added to the viewer’s internal pile for display. Note, that unlike with the traces from the files given on the command line, these traces are kept in memory and so may quickly occupy a lot of ram if a lot of traces are added.This method should be preferred over modifying the viewer’s internal pile directly, because this way, the snuffling has a chance to automatically remove its private traces again (see
cleanup()
method).
-
add_trace
(tr)[source]¶ Add a trace to the viewer.
See
add_traces()
.
-
add_markers
(markers)[source]¶ Add some markers to the display.
Takes a list of objects of type
pyrocko.gui.util.Marker
and adds these to the viewer.
-
add_marker
(marker)[source]¶ Add a marker to the display.
See
add_markers()
.
-
-
exception
NoViewerSet
[source]¶ This exception is raised, when no viewer has been set on a Snuffling.
-
exception
NoTracesSelected
[source]¶ This exception is raised, when no traces have been selected in the viewer and we cannot fallback to using the current view.
-
exception
UserCancelled
[source]¶ This exception is raised, when the user has cancelled a snuffling dialog.
-
exception
SnufflingCallFailed
[source]¶ This exception is raised, when
Snuffling.fail()
is called fromSnuffling.call()
.
-
class
SnufflingModule
(path, name, handler)[source]¶ Utility class to load/reload snufflings from a file.
The snufflings are created by user modules which have the special function
__snufflings__()
which return the snuffling instances to be exported. The snuffling module is attached to a handler class, which makes use of the snufflings (e.g.pyrocko.pile_viewer.PileOverwiew
frompile_viewer.py
). The handler class must implement the methodsadd_snuffling()
andremove_snuffling()
which are used as callbacks. The callbacks are utilized from the methodsload_if_needed()
andremove_snufflings()
which may be called from the handler class, when needed.