ScopeFoundry package¶
Submodules¶
ScopeFoundry.base_app module¶
Created on Jul 23, 2014
Modified by Ed Barnard UI enhancements by Ed Barnard, Alan Buckley
-
class
ScopeFoundry.base_app.
BaseApp
(argv=[])[source]¶ Bases:
PyQt4.QtCore.QObject
-
settings_load_ini_ask
(dir=None)[source]¶ Opens a Load dialogue asking the user which .ini file to load into our app settings. Loads settings from an .ini file.
-
settings_save_ini_ask
(dir=None, save_ro=True)[source]¶ Opens a Save dialogue asking the user to select a save destination and give the save file a filename. Saves settings to an .ini file.
-
setup_console_widget
(kernel=None)[source]¶ Create and return console QWidget. If Jupyter / IPython is installed this widget will be a full-featured IPython console. If Jupyter is unavailable it will fallback to a pyqtgraph.console.ConsoleWidget.
If the app is started in an Jupyter notebook, the console will be connected to the notebook’s IPython kernel.
the returned console_widget will also be accessible as self.console_widget
In order to see the console widget, remember to insert it into an existing window or call self.console_widget.show() to create a new window
-
-
class
ScopeFoundry.base_app.
BaseMicroscopeApp
(argv=[])[source]¶ Bases:
ScopeFoundry.base_app.BaseApp
-
add_hardware
(hw)[source]¶ Loads a HardwareComponent object into the app. After calling this, the HW appears in the Hardware tree.
If hw is a class, rather an instance, create an instance and add it to self.hardware
-
add_measurement
(measure)[source]¶ Loads a Measurement object into the app. After calling this, the measurement appears in the Measurement tree.
If measure is a class, rather an instance, create an instance and add it to self.measurements
-
cascade_layout
()[source]¶ Cascades subwindows in user interface. Specifically in the Multi Document Interface.
-
hardware_components
¶
-
logged_quantities
¶
-
lq_path
(path)[source]¶ returns the lq based on path string of the form ‘domain/[component/]setting’ domain = “measurement”, “hardware” or “app”
-
mdi
= True¶ Multiple Document Interface flag. Tells the app whether to include an MDI widget in the app.
-
measurement_components
¶
-
name
= 'ScopeFoundry'¶ The name of the microscope app, default is ScopeFoundry.
-
settings_auto_save_ini
()[source]¶ Saves the ini file to the pre-defined directory with a time stamp in the filename.
-
settings_load_h5
(fname)[source]¶ Loads h5 settings given a filename.
Arguments: Type: Description: fname str relative path to the filename of the h5 file.
-
settings_load_ini
(fname)[source]¶ Arguments: Type: Description: fname str relative path to the filename of the ini file.
-
settings_save_h5
(fname)[source]¶ Saves h5 file to a file.
Arguments: Type: Description: fname str relative path to the filename of the h5 file.
-
-
class
ScopeFoundry.base_app.
LoggingQTextEditHandler
(textEdit, level=0)[source]¶ Bases:
logging.Handler
,PyQt4.QtCore.QObject
-
emit
(record)[source]¶ Do whatever it takes to actually log the specified logging record.
This version is intended to be implemented by subclasses and so raises a NotImplementedError.
-
format
(record)[source]¶ Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter for the module.
-
level_styles
= {'CRITICAL': 'color: red;', 'DEBUG': 'color: green;', 'ERROR': 'color: red;', 'INFO': 'color: green;', 'NOTSET': '', 'WARNING': 'color: orange;'}¶
-
new_log_signal
¶
-
ScopeFoundry.data_browser module¶
-
class
ScopeFoundry.data_browser.
DataBrowser
(argv)[source]¶ Bases:
ScopeFoundry.base_app.BaseApp
-
name
= 'DataBrowser'¶
-
-
class
ScopeFoundry.data_browser.
DataBrowserView
(databrowser)[source]¶ Bases:
PyQt4.QtCore.QObject
Abstract class for DataBrowser Views
-
class
ScopeFoundry.data_browser.
FileInfoView
(databrowser)[source]¶ Bases:
ScopeFoundry.data_browser.DataBrowserView
-
name
= 'file_info'¶
-
-
class
ScopeFoundry.data_browser.
HyperSpectralBaseView
(databrowser)[source]¶ Bases:
ScopeFoundry.data_browser.DataBrowserView
-
load_data
(fname)[source]¶ override to set hyperspectral dataset and the display image need to define:
- self.hyperspec_data (shape Ny, Nx, Nspec)
- self.display_image (shape Ny, Nx)
- self.spec_x_array (shape Nspec)
-
name
= 'HyperSpectralBaseView'¶
-
ScopeFoundry.h5_io module¶
-
ScopeFoundry.h5_io.
h5_create_emd_dataset
(name, h5parent, shape=None, data=None, maxshape=None, dim_arrays=None, dim_names=None, dim_units=None, **kwargs)[source]¶ create an EMD dataset v0.2 inside h5parent returns an h5 group emd_grp
to access N-dim dataset: emd_grp[‘data’] to access a specific dimension array: emd_grp[‘dim1’]
- h5parent
- name [emd_grp] (<–returned)
- emd_group_type = 1
D data [shape = shape] D dim1 [shape = shape[0]]
- name
- units
… D dimN [shape = shape[-1]]
h5parent : parent HDF5 group
shape : Dataset shape of N dimensions. Required if “data” isn’t provided.
- data : Provide data to initialize the dataset. If used, you can omit
- shape and dtype arguments.
Keyword Args:
- dtype : Numpy dtype or string. If omitted, dtype(‘f’) will be used.
- Required if “data” isn’t provided; otherwise, overrides data array’s dtype.
dim_arrays : optional, a list of N dimension arrays
dim_names : optional, a list of N strings naming the dataset dimensions
dim_units : optional, a list of N strings specifying units of dataset dimensions
Other keyword arguments follow from h5py.File.create_dataset
emd_grp : h5 group containing dataset and dimension arrays, see hierarchy below
ScopeFoundry.hardware module¶
-
class
ScopeFoundry.hardware.
HardwareComponent
(app, debug=False, name=None)[source]¶ Bases:
PyQt4.QtCore.QObject
Base class for ScopeFoundry Hardware objects
to subclass, implement
setup()
,connect()
anddisconnect()
-
add_operation
(name, op_func)[source]¶ Create an operation for the HardwareComponent.
op_func is a function that will be called upon operation activation
operations are typically exposed in the default ScopeFoundry gui via a pushButton
-
connect
()[source]¶ Opens a connection to hardware and connects
LoggedQuantity
settings to related hardware functions and parameters
-
connection_failed
¶
-
connection_succeeded
¶
-
gui
¶
-
ScopeFoundry.helper_funcs module¶
-
class
ScopeFoundry.helper_funcs.
ConfirmCloseEventEater
(title='Close ScopeFoundry?', message='Do you wish to shut down ScopeFoundry?', func_on_close=None)[source]¶ Bases:
PyQt4.QtCore.QObject
Tells the Qt to confirm the closing of the app by the user with a pop-up confirmation dialog.
-
class
ScopeFoundry.helper_funcs.
IgnoreCloseEventEater
[source]¶ Bases:
PyQt4.QtCore.QObject
This class is utilized to prevent the closing of important subwindows and prevent the deletion of related python objects. Tells the Qt event manager to ignore calls to close the subwindow when user hits [x] on the subwindow.
-
ScopeFoundry.helper_funcs.
confirm_on_close
(widget, title='Close ScopeFoundry?', message='Do you wish to shut down ScopeFoundry?', func_on_close=None)[source]¶ Calls the
ConfirmCloseEventEater
class which asks for user confirmation in a pop-up dialog upon closing the ScopeFoundry app.
-
ScopeFoundry.helper_funcs.
get_logger_from_class
(obj)[source]¶ returns a named Logger from the logging package using the full name of the class of the object (obj) as the log name
-
ScopeFoundry.helper_funcs.
ignore_on_close
(widget)[source]¶ Calls the
IgnoreCloseEventEater
class which intercepts the QtCore.QEvent.Close signal and prevents the deletion of subwindows and their associated objects.
-
ScopeFoundry.helper_funcs.
load_qt_ui_file
(ui_filename)[source]¶ Loads a QT user interface file (files ending in .ui). This function is typically called from
Measurement
level modules.
-
ScopeFoundry.helper_funcs.
replace_widget_in_layout
(old_widget, new_widget, retain_font=True, retain_sizePolicy=True, retain_size=True)[source]¶ Replace a widget with a new widget instance in an existing layout.
returns new_widget
Useful for replacing placeholder widgets created with QtCreator with custom widgets Note: currently works for widgets in QGridLayouts only
inspiration from: – http://stackoverflow.com/questions/4625102/how-to-replace-a-widget-with-another-using-qt – http://stackoverflow.com/questions/24189202/how-to-get-the-row-column-location-of-a-widget-in-a-qgridlayout
ScopeFoundry.logged_quantity module¶
-
class
ScopeFoundry.logged_quantity.
ArrayLQ
(name, dtype=<class 'float'>, hardware_read_func=None, hardware_set_func=None, initial=[], fmt='%g', si=True, ro=False, unit=None, vmin=-1000000000000.0, vmax=1000000000000.0, choices=None)[source]¶ Bases:
ScopeFoundry.logged_quantity.LoggedQuantity
-
array_tableView
¶
-
coerce_to_type
(x)[source]¶ Force x to dtype of the LQ
Arguments Description x value of type str, bool, int, etc. Returns: Same value, x of the same type as its respective logged quantity
-
connect_element_follower_lq
(lq, index, bidir=True)[source]¶ connects an LQ to follow the changes of the array and display a specific element
-
new_default_widget
()[source]¶ returns the approriate QWidget for the datatype of the LQ. automatically connects widget
-
same_values
(v1, v2)[source]¶ Compares two values of the LQ type, used in update_value
Arguments Description v1 value 1 v2 value 2 Returns: Boolean value (True or False)
-
send_display_updates
(force=False)[source]¶ Emit updated_value signals if value has changed.
Arguments Description force will emit signals regardless of value change. Returns: None
-
updated_shape
¶
-
-
class
ScopeFoundry.logged_quantity.
FileLQ
(name, default_dir=None, is_dir=False, **kwargs)[source]¶ Bases:
ScopeFoundry.logged_quantity.LoggedQuantity
Specialized str type
LoggedQuantity
that handles a filename (or directory) and associated file.
-
class
ScopeFoundry.logged_quantity.
LQCircularNetwork
(lq_dict)[source]¶ Bases:
PyQt4.QtCore.QObject
LQCircularNetwork is collection of logged quantities Helper class if a network of lqs with circular structures are present Use update_values_synchronously method if the specified lqs should be updated at once. The internal lock-flag prevents infinite loops.
-
update_values_synchronously
(**kwargs)[source]¶ kwargs is dict containing lq_key and new_vals Note: lq_key is not necessarily the name of the lq but key of lq_dict
as specified at initialization
-
updated_values
¶
-
-
class
ScopeFoundry.logged_quantity.
LQCollection
[source]¶ Bases:
object
LQCollection is a smart dictionary of LoggedQuantity objects.
attribute access such as lqcoll.x1 will return full LoggedQuantity object
dictionary-style access lqcoll[‘x1’] allows direct reading and writing of the LQ’s value, handling the signals automatically
New LQ’s can be created with
New()
LQRange objects can be created with
New_Range()
and will be stored in :attr:ranges-
Add
(lq)[source]¶ Add an existing LoggedQuantity to the Collection Examples of usefulness: add hardware lq to measurement settings
-
-
class
ScopeFoundry.logged_quantity.
LQRange
(min_lq, max_lq, step_lq, num_lq, center_lq=None, span_lq=None)[source]¶ Bases:
ScopeFoundry.logged_quantity.LQCircularNetwork
LQRange is a collection of logged quantities that describe a numpy.linspace array inputs. Four (or six) LQ’s are defined, min, max, num, step (center, span) and are connected by signals/slots that keep the quantities in sync. LQRange.array is the linspace array and is kept upto date with changes to the 4 (or 6) LQ’s
-
array
¶
-
-
class
ScopeFoundry.logged_quantity.
LoggedQuantity
(name, dtype=<class 'float'>, hardware_read_func=None, hardware_set_func=None, initial=0, fmt='%g', si=False, ro=False, unit=None, spinbox_decimals=2, spinbox_step=0.1, vmin=-1000000000000.0, vmax=1000000000000.0, choices=None, reread_from_hardware_after_write=False, description=None)[source]¶ Bases:
PyQt4.QtCore.QObject
LoggedQuantity objects are containers that wrap settings. These settings may be a number (integer or float) or a string and occasionally small arrays of them.
These objects emit signals when changed and can be connected bidirectionally to Qt Widgets.
In ScopeFoundry we represent the values in an object called a LoggedQuantity. A
LoggedQuantity
is a class that contains a value, a bool, float, int, str etc that is part of an application’s state. In the case of microscope and equipment control, these also can represent the state of a piece of hardware. These are very useful objects because the are the central location of the value contained within. All graphical interface views will be guaranteed to be consistent with the LQ state. The data of these quantities will also be saved in datafiles created by ScopeFoundry.-
add_listener
(func, argtype=(), **kwargs)[source]¶ Connect ‘func’ as a listener (Qt Slot) for the updated_value signal. By default ‘func’ should take no arguments, but argtype can define the data type that it should accept. but should be limited to those supported by LoggedQuantity (i.e. int, float, str) **kwargs are passed to the connect function appends the ‘func’ to the ‘listeners’ list
-
coerce_to_type
(x)[source]¶ Force x to dtype of the LQ
Arguments Description x value of type str, bool, int, etc. Returns: Same value, x of the same type as its respective logged quantity
-
connect_lq_math
(lqs, func, reverse_func=None)[source]¶ Links LQ to other LQs using math functions
takes a func that takes a set of logged quantities new_val = f(lq1, lq2, …)
when any of the lqs change, the value of this derived LQ will be updated based on func
reverse_func allows changes to this LQ to update lqs via reverse func
new_lq1_val, new_lq2_val, … = g(new_val, old_lqs_values) or new_lq1_val, new_lq2_val, … = g(new_val)
-
connect_to_widget
(widget)[source]¶ Creates Qt signal-slot connections between LQ and the QtWidget widget
connects updated_value signal to the appropriate slot depending on the type of widget
Makes a bidirectional connection to a QT widget, ie when LQ is updated, widget gets a signal and when widget is updated, the LQ receives a signal and update_value() slot is called.
- Handles many types of widgets:
- QDoubleSpinBox
- QCheckBox
- QLineEdit
- QComboBox
- pyqtgraph.widgets.SpinBox.SpinBox
Arguments Description widget The name of the Qt GUI Object, examples of which are listed above. For example, if you have a QDoubleSpinBox in the gui which you renamed int_value_doubleSpinBox in the Qt Designer Object Inspector, use self.ui.int_value_doubleSpinBox Returns: None
-
is_connected_to_hardware
()[source]¶ Returns: True if either self.hardware_read_func or self.hardware_set_func are defined. False if None.
-
new_default_widget
()[source]¶ returns the approriate QWidget for the datatype of the LQ. automatically connects widget
-
same_values
(v1, v2)[source]¶ Compares two values of the LQ type, used in update_value
Arguments Description v1 value 1 v2 value 2 Returns: Boolean value (True or False)
-
send_display_updates
(force=False)[source]¶ Emit updated_value signals if value has changed.
Arguments Description force will emit signals regardless of value change. Returns: None
-
update_value
(new_val=None, update_hardware=True, send_signal=True, reread_hardware=None)[source]¶ Update stored value with new_val
Change value of LQ and emit signals to inform listeners of change
if update_hardware is true: call connected hardware write function
Arguments: Description: new_val New value for the LoggedQuantity to store update_hardware calls hardware_set_func if defined (default True) send_signal sends out QT signals on upon change (default True) reread_hardware read from hardware after writing to hardware to ensure change (defaults to self.reread_from_hardware_after_write) Returns: None
-
updated_choice_index_value
¶
-
updated_min_max
¶
-
updated_readonly
¶
-
updated_text_value
¶
-
updated_value
¶
-
value
¶ return stored value
-
ScopeFoundry.measurement module¶
Created on Tue Apr 1 09:25:48 2014 @author: esbarnard
-
class
ScopeFoundry.measurement.
Measurement
(app, name=None)[source]¶ Bases:
PyQt4.QtCore.QObject
Base class for ScopeFoundry Hardware objects
to subclass, implement
setup()
,run()
for measurements with graphical interfaces, subclass and additionally implement
setup_figure()
,update_display()
-
add_logged_quantity
(name, **kwargs)[source]¶ Create a new
LoggedQuantity
and adds it to the measurement’ssettings
(LQCollection
)
-
add_operation
(name, op_func)[source]¶ Used to create a logged quantity connection between a button in the Measurement tree and a function.
type name: type op_func: str QtCore.Slot
-
add_widgets_to_tree
(tree)[source]¶ Adds Measurement items and their controls to Measurements tree in the user interface.
-
gui
¶
-
interrupt
()[source]¶ Kindly ask the measurement to stop.
This raises the
interrupt_measurement_called
flag To actually stop, the threadedrun()
method must check for this flag and exit
-
load_ui
(ui_fname=None)[source]¶ Loads and shows user interface.
Arguments: ui_fname filename of user interface file (usually made with Qt Designer)
-
measurement_interrupted
¶ signal sent when measurement is complete due to an interruption
-
measurement_sucessfully_completed
¶ signal sent when full measurement is complete
-
post_run
()[source]¶ Override this method to enable main-thread finalization after to measurement thread completes
-
pre_run
()[source]¶ Override this method to enable main-thread initialization prior to measurement thread start
-
run
()[source]¶ run method runs in an separate thread and is used for data acquisition
No GUI updates should occur within the run function, any Qt related GUI work should occur in
update_display()
-
set_progress
(pct)[source]¶ This function updates the logged quantity progress which is used for the display of progress bars in the UI.
Arguments: pct The percentage of progress given by a measurement module
-
setup
()[source]¶ Override this to set up logged quantities and gui connections Runs during __init__, before the hardware connection is established Should generate desired LoggedQuantities
-
setup_figure
()[source]¶ Overide setup_figure to build graphical interfaces. This function is run on ScopeFoundry startup.
-
start_nested_measure_and_wait
(measure, nested_interrupt=True, polling_func=None, polling_time=0.1)[source]¶ Start another nested measurement measure and wait until completion.
Optionally it can call a polling function polling_func with no arguments at an interval polling_time in seconds.
if nested_interrupt is True then interrupting the nested measure will also interrupt the outer measurement. nested_interrupt defaults to True
-
start_stop
(start)[source]¶ Use boolean start to either start (True) or interrupt (False) measurement. Test.
-
ScopeFoundry.ndarray_interactive module¶
-
class
ScopeFoundry.ndarray_interactive.
ArrayLQ_QTableModel
(lq, col_names=None, row_names=None, parent=None, **kwargs)[source]¶