PYME.Acquire.microscope module¶
- class PYME.Acquire.microscope.Microscope¶
Bases:
object- Attributes
- frameWranglerPYME.Acquire.frameWrangler.FrameWrangler
Initialized in between hardware initializations and gui initializations.
- AddVoxelSizeSetting(name, x, y)¶
Adds a new voxel size setting.
The reason for multiple settings is to easily support switching between different cameras and/or optical configurations such as tube lenses, splitters, etc …
- Parameters
- namestring
The name to use for the new setting
- xfloat
the pixelsize along the x axis in um
- yfloat
the pixelsize along the y axis in um
- EnableJoystick(enable=True)¶
- GenStartMetadata(mdh)¶
Collects the metadata we want to record at the start of a sequence
- Parameters
- mdhobject derived from PYME.IO.MetaDataHandler.MDHandlerBase
The metadata handler to which we should write our metadata
- GetActiveCameraName()¶
Get the name / key of the currently active camera
- GetPixelSize(cam=None)¶
Get the (sample space) pixel size for the current camera
- Returns
- pixelsizetuple
the pixel size in the x and y axes, in um
- GetPos()¶
- GetPosRange()¶
- PanCamera(dx, dy)¶
Moves / pans the stage my a given offset, in pixels relative to the camera, correcting for any differences in rotation and mirroring between camera and stage axes.
TODO: fix to use state based position setting
- SetPos(**kwargs)¶
- SetVoxelSize(voxelsizename, camName=None)¶
Set the camera voxel size, from a pre-existing voxel size seting.
- Parameters
- voxelsizenamestring
The name of the voxelsize setting to use. This should have been created using the AddVoxelSize function.
- camNamestring
The name of the camera to ascociate the setting with. If None, then the currently selected camera is used.
- centre_roi_on(x, y)¶
Convenience function to center the ROI on a given location
- genStatus()¶
Generate a status message. TODO - move this to the GUI?
- get_roi_centre()¶
Convenience function to get the centre of the ROI
exists to allow both automatically and manually specified actions to use the same code
- get_roi_offset()¶
Stage (positioning) coordinates are referenced to the (0,0) pixel of the primary camera. Return the offset to the centre of the current ROI. Used when, e.g. moving the stage to centre the current view on a given set of coordinates.
- Returns
- roi_offset_x, roi_offset_yfloat
offsets in um
- initialize(init_script_name, locals={})¶
- property initialized¶
Checks if the initialisation thread has run (replaces check of initDone flag which needed to be manually set in initialisation script). Semantics are slightly different in that this returns true even if there is an error whist the old way of checking would get forever stuck at the splash screen.
- Returns
- True if the initialisation script has run, False otherwise
- property pa¶
property to catch access of what was previously called the scope.frameWrangler (the PreviewAcquisator)
- register_camera(cam, name, port='', rotate=False, flipx=False, flipy=False)¶
Register a camera with the microscope
- Parameters
- camThe camera object
- nameA human-readable name
- portWhich sideport the camera is attached to (used to automatically select the right camera when changing
sideports & vice versa, but currently only works on the Nikon Ti stand)
- rotateIs this camera rotated with respect to the cardinal camera (used for multi-camera support)
- flipxIs this camera flipped in x w.r.t. the cardinal camera (used for multi-camera support)
- flipyIs this camera flipped in y w.r.t. the cardinal camera (used for multi-camera support)
Notes
The optional port, rotate, flipx, and flipy parameters all relate to multiple camera support and should be defined with respect to the principle camera (not stages etc which should be in the frame of the principle camera). The support for these parameters is currently pretty limited - they work when panning the sample using the mouse, but are generally ignored in other parts of the code.
- register_piezo(piezo, axis_name, multiplier=1, needCamRestart=False, channel=0)¶
Register a piezo with the microscope object
- Parameters
- piezoPYME.Acquire.Hardware.Piezos.base_piezo.PiezoBase instance
the piezo to register
- axis_namestring
the axis name, e.g. ‘x’, ‘y’, ‘z’
- multiplierfloat, typically either 1 or -1
what to multiply the positions by to match the directionality in the displayed image and make panning etc work.
- needCamRestartbool
whether to restart the camera after changing the position (mostly for simulation and fake piezos)
Notes
The ‘x’ and ‘y’ axes should be defined in terms of the axes of the principle camera (i.e. if a stage moves the image on the camera left and right it is the ‘x’ stage, regardless of the physical motion of the sample). Likewise, the multipliers should be set so that a positive movement of the x stage moves the image right, and a positive movement of the y stage moves the image down.
- satCheck(source, **kwargs)¶
Check to see if the current frame is saturated and stop the camera/ close the shutter if necessary
TODO: could use a rewrite / new inspection.
- property settingsDB¶
- startFrameWrangler(event_loop=None)¶
Start the frame wrangler. Gets called during post-init phase of aquiremainframe.
- turnAllLasersOff()¶
Turn all attached lasers off.
TODO - does this fit with the new state based paradigm?
- wait_for_init()¶
- class PYME.Acquire.microscope.StateHandler(key, getFcn=None, setFcn=None, needCamRestart=False)¶
Bases:
objectDefine a state-change handler for a give state key, based on supplied get and set functions which interact with the underlying hardware.
This wrapper class serves two functions - a) allowing the get and set methods to be stored under a single dictionary key in the StateManager, and b) making sure a signal is fired when the state changes.
- Parameters
- keystring
The hardware key - e.g. “Positioning.x”, or “Lasers.405.Power”. This will also be how the hardware state is recorder in the metadata.
- getFcnfunction
The function to call to get the value of the parameter. Should take one parameter which is the value to get
- setFcnfunction
The function to call to set the value of the parameter. Should take one parameter which is the value to set. Not providing a setFcn results in a read-only property.
- needCamRestartbool
Does this absolutely need a camera restart (e.g. we are changing which camera we are using). Will override other preferences.
- setValue(value, force=False)¶
Set the state of the controlled hardware to the given value and fire a signal. The underlying function will not be called if old and new values are the same unless force=True.
- class PYME.Acquire.microscope.StateManager(scope, handlers={})¶
Bases:
objectManages object (microscope) state by calling an appropriate state-handler for a given key.
Looks and behaves like a dictionary to the user, with individual pieces of hardware registering themselves to handle individual keys.
- get(key, default=None)¶
- keys()¶
- registerChangeListener(key, callback)¶
Registers a function to be called when the state of a particular key changes.
The key and value are provided as keyword arguments to the callback the callback should accept have the signature callback(**kwargs), or callback(key, value, **kwargs). Other keyword arguments might also be given.
- registerHandler(key, getFcn=None, setFcn=None, needCamRestart=False)¶
Register a harware key and the ascociated handlers
- Parameters
- keystring
The hardware key - e.g. “Positioning.x”, or “Lasers.405.Power”. This will also be how the hardware state is recorded in the metadata.
- getFcnfunction
The function to call to get the value of the parameter. Should take one parameter which is the value to get
- setFcnfunction
The function to call to set the value of the parameter. Should take one parameter which is the value to set. Not providing a setFcn results in a read-only property.
- needCamRestartbool
Does this absolutely need a camera restart (e.g. we are changing which camera we are using). Will override other preferences.
Notes
There are a few conventions and special key names which should be observed as this is how the camera will find hardware.
Keys should be hierachial, separated by dots
Piezos and stages should start with “Positioning.”, followed by an axis name, and use um as a unit.
Lasers should start with “Laser.” and define both “<lasername>.Power” and “<lasername>.On” (this is to allow lasers with external switches/shutters as well as )
- setItem(key, value, stopCamera=False, force=False)¶
Set the value of one of our hardware components
- Parameters
- keystring
The parameter identifier - e.g. “Positioning.x”
- valueobject
The value to set. This can be anything the registered handler understands but designing the handlers to accept something which is easily converted to text for the Metadata (see PYME.IO.MetaDataHandler) is advised.
- stopCamerabool
Should we stop the camera before setting the value and restart afterwards. Useful for things like integration time which might not be able to be changed on the fly, but also potentially as a way of achieving hardware synchronization.
- forcebool
Whether we should call the set method even if the current state is already the desired state.
- setItems(stateDict, stopCamera=False, force=False, ignoreMissing=False)¶
Set multiple items at once - see setItem for details.
- Parameters
- stateDictdictionary (or dictionary like object)
a dictionary of key : value pairs for each piece of hardware which wants to be updated.
- stopCamerabool
Should we stop the camera before setting the values and restart afterwards? Useful for things like integration time which might not be able to be changed on the fly, but also potentially as a way of achieving hardware synchronization.
- forcebool
Whether we should call the set method even if the current state is already the desired state.
- ignoreMissingbool
Should we silently ignore keys that we don’t have handlers for. Used when setting state from e.g. sequence metadata which might have other irrelevent info.
- update(state)¶
Update state from a dictionary
- Parameters
- statedict
A dictionary containing the new state