Wavefront Corrector
In pyRTC, one of the core components is the wavefront corrector object. It typically finishes the AO chain by continously waiting for new corrections and applying them. This object is a consumer of the wfc shared memory object and a producer of the wfc2D shared memory objects which contain the current correction vector and the 2D representation of the curent correction respectively. This class required you to properly lay out the 2D actuator layout as well as define the correction basis.
Soft-RTC Example
The following is an example of how to initialize a WavefrontCorrector component in pyRTC.
Here we are in the soft-RTC mode of pyRTC, which holds all components in the same python process. See below for how to launch a hard-RTC equivalent.
"""
First we import the relevant wavefront corrector class. Typically, this will be a
specific hardware class which has been defined to work with the SDK of your corrector.
As an example (see hardware/ALPAODM.py):
from pyRTC.hardware import ALPAODM
Here, I will just initialize the Wavefront Sensor Superclass as an example
"""
#%% Run in interactive python or jupyter notebook to keep process alive
from pyRTC.WavefrontCorrector import WavefrontCorrector
import matplotlib.pyplot as plt
from pyRTC.utils import read_yaml_file
confWFC = {
"name": "example",
"numActuators": 97,
"numModes": 50,
"m2cFile": "", #Here you put the path to your basis ([nAct,nMode]) ./EXAMPLE/calib/wfcShape.npy"
"saveFile": "", #Here you put where the WFC will save its corrections ./EXAMPLE/calib/wfcShape.npy"
"affinity": 2,
"functions": ["sendToHardware"]
}
"""
Alternatively, read the config from a file
conf = read_yaml_file("./EXAMPLE/config.yaml")["wfs"]
"""
#Initialize the WFS object
wfc = WavefrontCorrector(confWFC)
#Start the functions regiserted to the loop (i.e, expose)
wfc.start()
wfc.flatten()
Hard-RTC Example
The following is an example of how to initialize a WavefrontCorrector component in pyRTC.
Here we are in the hard-RTC mode of pyRTC, which holds all components in the separate python processes. This circumvents the python Global Interpreter Lock.
See above for how to launch a soft-RTC equivalent.
from pyRTC.Pipeline import hardwareLauncher
"""
For the Hard-RTC, you will need to set-up a config before hand and store it in a yaml file.
It should look something like:
wfc:
name: "ALPAO"
serial: "BAX118"
numActuators: 97
numModes: 94
flatFile: "./examples/sharp_lab/calib/wfcShape.npy"
saveFile: "./examples/sharp_lab/calib/wfcShape.npy"
m2cFile: "./examples/sharp_lab/calib/m2c_kl.npy"
affinity: 5
commandCap: 0.8
hardwareDelay: 0.001 #seconds
frameDelay: 0
functions:
- sendToHardware
"""
config = 'path/to/config.yaml'
port = 3000
#Initialize the hardware launcher for your WFS child hardware class
wfc = hardwareLauncher('path/to/pyRTC/hardware/ALPAODM.py',config,port)
"""
Launch the process.
This will run the hardware file, which should establish a connection with the current process.
This is accomplished with the Listener class (see hardware folder for examples).
The functions registered in the config to the real-time loop will automatically be started.
"""
wfc.launch()
"""
Once the connection has been made successfully, you can run any function in the hardware class
using the run function. You can also get and set properties of the hardware using getProperty()
and setProperty() respectively.
"""
wfc.run("flatten")
wfc.setProperty("commandCap", 0.6)
print(wfc.getProperty("commandCap"))
Parameters
- class pyRTC.WavefrontCorrector.WavefrontCorrector(conf)[source]
Bases:
pyRTCComponentBase class for deformable mirrors and other wavefront-correction devices.
WavefrontCorrectoris responsible for the control-plane machinery around command generation: SHM output, flat shapes, mode-to-command transforms, floating actuator handling, and delayed command buffers. Subclasses are left to implement the device-specific transport insendToHardware.Config
- namestr
Name of the wavefront corrector.
- numActuatorsint
Number of actuators. Required.
- numModesint
Number of modes. Required.
- affinitystr
Affinity setting.
- m2cFilestr
Path to the mode-to-command file.
- floatingInfluenceRadiusint, optional
Radius for floating influence. Default is 1.
- frameDelayint, optional
Frame delay. Default is 0.
- saveFilestr, optional
File to save the shape. Default is “wfcShape.npy”.
Attributes
- namestr
Name of the wavefront corrector.
- numActuatorsint
Number of actuators.
- numModesint
Number of modes.
- affinitystr
Affinity setting.
- m2cFilestr
Path to the mode-to-command file.
- correctionVectorImageSHM
Correction vector.
- correctionVector2DImageSHM or None
2D correction vector for display.
- flatnumpy.ndarray
Initial flat shape.
- flatModalnumpy.ndarray
Flat shape in modal basis.
- currentShapenumpy.ndarray
Current shape.
- actuatorStatusnumpy.ndarray
Status of each actuator.
- index_mapnumpy.ndarray or None
Index map for actuators.
- floatingInfluenceRadiusint
Radius for floating influence.
- floatMatrixnumpy.ndarray
Floating actuator matrix.
- frameDelayint
Frame delay.
- saveFilestr
File to save the shape.
- layoutnumpy.ndarray or None
Layout of the actuators.
- M2Cnumpy.ndarray
Mode-to-command matrix.
- f_M2Cnumpy.ndarray
Floating mode-to-command matrix.
- C2Mnumpy.ndarray
Command-to-mode matrix.
- currentCorrectionnumpy.ndarray
Current correction vector.
- shapeBuffernumpy.ndarray
Buffer for shapes with frame delay.
- correctionVector2D_templatenumpy.ndarray
Template for the 2D correction vector.
- deactivateActuators(actuators)[source]
Deactivate specified actuators. Actuators are assumed to be floating
Parameters
- actuatorslist of int
List of actuator indices to deactivate.
- flatten()[source]
Flatten the wavefront corrector.
- loadFlat(filename='')[source]
Loads the Flat from a file.
Parameters
- filenamestr, optional
Filename to load the dark frame from. If not specified, uses the dark file path from the configuration.
- plot(addFlat=False)[source]
Plot the current correction.
Parameters
- removeFlatbool, optional
If True, removes the flat shape from the current correction before plotting. Default is False.
- push(mode, amp)[source]
Push a specific mode with a given amplitude.
Parameters
- modeint
Mode index to push.
- ampfloat
Amplitude to push the mode with.
- reactivateActuators(actuators)[source]
Reactivate specified actuators.
Parameters
- actuatorslist of int
List of actuator indices to reactivate.
- read(block=False)[source]
Read the current correction vector.
Returns
- numpy.ndarray
Current correction vector.
- readM2C(filename='')[source]
Read the mode-to-command matrix from a file.
Parameters
- filenamestr, optional
File to read the mode-to-command matrix from. If not specified, uses the configured m2cFile.
- saveShape(filename='')[source]
Save the current shape to a file.
Parameters
- filenamestr, optional
File to save the shape to. If not specified, uses the configured saveFile.
- sendToHardware()[source]
Send the current correction to the hardware. Nominally, this function is overwritten by the child hardware class and registered to the real-time loop from the config.
- setDelay(delay)[source]
Sets an artificial frame delay. Used for testing, nominally the delay should always be zero.
Parameters
- delayint
Frame delay to set.
- setLayout(layout)[source]
Set the layout of the actuators.
Parameters
- layoutnumpy.ndarray or None
Layout of the actuators. Is converted to boolean if not already.
- setM2C(M2C)[source]
Set the mode-to-command matrix. This is the basis for correction.
Parameters
- M2Cnumpy.ndarray or None
Mode-to-command matrix to set. Axes are [numActuators, numModes]
- start()
Start the registered real-time functions.
- stop()
Stops the registered real-time functions.