Slopes Process
The slopes process is responsible for converting images from the wavefront sensor into a measurement consumable by the AO loop. This object is the producer of the signal and signal2D shared memory objects which contain the vectorized and 2D mapped images of the slopes respectively. It is a consumer of the wfs shared memory object which contains the image stream from the wavefront sensor. The images are then be processed to compute the intermediate data product used for wavefront reconstruction.
Soft-RTC Example
The following is an example of how to initialize a SlopesProcess 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 class.
Here I will give an example for a Pyramid Wavefront Sensor
"""
#%% Run in interactive python or jupyter notebook to keep process alive
from pyRTC.SlopesProcess import SlopesProcess
import matplotlib.pyplot as plt
from pyRTC.utils import read_yaml_file
confWFS = {
"width": 256,
"height": 256,
}
confSlopes = {
"type": "SHWFS",
"signalType": "slopes",
"refSlopesFile": "", #"/home/whetstone/pyRTC/examples/sharp_lab/calib/ref.npy",
"validSubApsFile": "", #"/home/whetstone/pyRTC/examples/sharp_lab/calib/validSubAps.npy",
"subApSpacing": 16,
"subApOffsetX": 0,
"subApOffsetY": 0,
"imageNoise": 0.5,
"contrast": 20,
"affinity": 4,
"functions": ["computeSignal"],
}
conf = {"wfs": confWFS, "slopes": confSlopes}
"""
Alternatively, read the config from a file
conf = read_yaml_file("./EXAMPLE/config.yaml")
"""
#Initialize the WFS object
slopes = SlopesProcess(conf)
#Start the functions regiserted to the loop (i.e, expose)
slopes.start()
signal = slopes.read(block=False)
plt.plot(signal)
plt.show()
"""
Monitor the SHM in realtime by running the viewer command in a terminal
pyrtc-view signal2D &
"""
Hard-RTC Example
The following is an example of how to initialize a SlopesProcess 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:
slopes:
type: SHWFS
signalType: slopes
refSlopesFile: "/home/whetstone/pyRTC/examples/sharp_lab/calib/ref.npy"
validSubApsFile: "/home/whetstone/pyRTC/examples/sharp_lab/calib/validSubAps.npy"
subApSpacing: 16
subApOffsetX: 8
subApOffsetY: 4
imageNoise: 0.5
contrast: 20
affinity: 4
functions:
- computeSignal
"""
config = 'path/to/config.yaml'
port = 3005
#Initialize the hardware launcher for your WFS child hardware class
slopes = hardwareLauncher('path/to/pyRTC/SlopesProcess.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.
"""
slopes.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.
"""
slopes.run("loadValidSubAps")
slopes.setProperty("refSlopesFile", "test123")
print(slopes.getProperty("refSlopesFile"))
Parameters
- class pyRTC.SlopesProcess.SlopesProcess(conf)[source]
Bases:
pyRTCComponentA class to handle real-time slope computation for wavefront sensors.
Config
- typestr
Type of the WFS (“PYWFS” or “SHWFS”).
- signalTypestr
Type of signal (“slopes”).
- imageNoisefloat, optional
Image noise. Default is 0.0.
- centralObscurationRatiofloat, optional
Central obscuration ratio. Default is 0.0.
- flatNormfloat, optional
Normalization factor for the flat. Required for “PYWFS” with “slopes” signalType.
- pupilslist of str, optional
List of pupil locations in “x,y” format. Required for “PYWFS”.
- pupilsRadiusint, optional
Radius of the pupils. Required for “PYWFS”.
- contrastfloat, optional
Contrast for “SHWFS”. Default is 0.
- subApSpacingfloat, optional
Sub-aperture spacing for “SHWFS”.
- subApOffsetXfloat, optional
Sub-aperture offset in X direction for “SHWFS”.
- subApOffsetYfloat, optional
Sub-aperture offset in Y direction for “SHWFS”.
- refSlopeCountint, optional
Number of reference slopes for averaging. Default is 1000.
- validSubApsFilestr, optional
File containing valid sub-aperture mask. Default is “”.
- refSlopesFilestr, optional
File containing reference slopes. Default is “”.
Attributes
- confWFSdict
Wavefront sensor configuration.
- namestr
Name of the process.
- imageShapetuple
Shape of the WFS image.
- confdict
Slopes configuration.
- wfsMetanumpy.ndarray
Metadata of the WFS image.
- imageDTypetype
Data type of the WFS image.
- wfsShmImageSHM
Shared memory object for the WFS image.
- signalDTypetype
Data type of the signal.
- imageNoisefloat
Image noise.
- centralObscurationRatiofloat
Central obscuration ratio.
- wfsTypestr
Type of the WFS.
- signalTypestr
Type of signal.
- validSubApsnumpy.ndarray or None
Valid sub-aperture mask.
- shwfsContrastfloat
Contrast for “SHWFS”.
- subApSpacingfloat
Sub-aperture spacing for “SHWFS”.
- numRegionsint
Number of regions for “SHWFS”.
- offsetXfloat
Sub-aperture offset in X direction for “SHWFS”.
- offsetYfloat
Sub-aperture offset in Y direction for “SHWFS”.
- refSlopeCountint
Number of reference slopes for averaging.
- signal2DSizeint
Size of the 2D signal.
- signal2DShapetuple
Shape of the 2D signal.
- validSubApsFilestr
File containing valid sub-aperture mask.
- signalSizeint
Size of the signal.
- signalShapetuple
Shape of the signal.
- signalImageSHM
Shared memory object for the signal.
- signal2DImageSHM
Shared memory object for the 2D signal.
- refSlopesFilestr
File containing reference slopes.
- refSlopesnumpy.ndarray
Reference slopes.
- gpuDevicestr
Default device if using GPU
- flatNormfloat
Normalization factor for the flat.
- pupilLocslist of tuple
List of pupil locations.
- pupilRadiusint
Radius of the pupils.
- pupilMasknumpy.ndarray
Mask of the pupils.
- p1masknumpy.ndarray
Mask for pupil 1.
- p2masknumpy.ndarray
Mask for pupil 2.
- p3masknumpy.ndarray
Mask for pupil 3.
- p4masknumpy.ndarray
Mask for pupil 4.
- computeImageNoise()[source]
Compute the image noise. Useful to set a good SNR cutoff for SHWFS
- computePupilsMask()[source]
Compute the mask for the pupils. Assumes circular aperture with obstruction ratio set by the centralObscurationRatio parameter.
- computeSignal()[source]
Compute the signal from the WFS image.
- computeSignal2D(signal, validSubAps=None)[source]
Compute the 2D signal from the valid sub-aperture mask.
Parameters
- signalnumpy.ndarray
Signal to process.
- validSubApsnumpy.ndarray, optional
Valid sub-aperture mask. If not provided, uses the current valid sub-aperture mask.
Returns
- numpy.ndarray
2D signal.
- loadRefSlopes(filename='')[source]
Load the reference slopes from a file.
Parameters
- filenamestr, optional
File to load the reference slopes from. If not specified, uses the configured refSlopesFile.
- loadValidSubAps(filename='')[source]
Load the valid sub-aperture mask from a file.
Parameters
- filenamestr, optional
File to load the valid sub-aperture mask from. If not specified, uses the configured validSubApsFile.
- plotPupils()[source]
Plot the pupil mask to see if its right.
- read(block=True, SAFE=True, GPU=False)[source]
Read the current signal.
Returns
- numpy.ndarray
Current signal.
- readImage(SAFE=True, GPU=False, block=True)[source]
Read the current WFS image.
Returns
- numpy.ndarray
Current WFS image.
- saveRefSlopes(filename='')[source]
Save the reference slopes to a file.
Parameters
- filenamestr, optional
File to save the reference slopes to. If not specified, uses the configured refSlopesFile.
- saveValidSubAps(filename='')[source]
Save the valid sub-aperture mask to a file.
Parameters
- filenamestr, optional
File to save the valid sub-aperture mask to. If not specified, uses the configured validSubApsFile.
- setPupils(pupilLocs, pupilRadius)[source]
Set the pupils’ locations and radius. First computes a Pupil Mask, then generates slope mask and sets up SHMS of the correct sizes.
Parameters
- pupilLocslist of tuple
List of pupil locations.
- pupilRadiusint
Radius of the pupils.
- setRefSlopes(refSlopes)[source]
Set the reference slopes.
Parameters
- refSlopesnumpy.ndarray
Reference slopes.
- setValidSubAps(validSubAps)[source]
Set the valid sub-aperture mask. Converts to boolean if not already
Parameters
- validSubApsnumpy.ndarray
Valid sub-aperture mask.
- start()
Start the registered real-time functions.
- stop()
Stops the registered real-time functions.
- takeRefSlopes()[source]
Take reference slopes by averaging multiple slope measurements. Number of measurements set by refSlopeCount variable.