pyTomoAO.dm_fitting.fitting¶
- class pyTomoAO.dm_fitting.fitting(dmParams, logger=<Logger pyTomoAO.dm_fitting (INFO)>)[source]¶
Bases:
objectA class for handling deformable mirror fitting operations with influence function computation.
This class provides methods for computing influence functions, generating fitting matrices, and fitting optical path difference (OPD) maps for deformable mirror control. The class supports both single and double Gaussian influence functions, and can handle different grid resolutions and actuator geometries. The class forwards attribute access to dmParams when appropriate.
- Parameters:
dmParams (
object) – An instance of a class containing DM geometry parameterslogger (
logging.Logger, optional) – Logger object for logging messages (default is the module-level logger)
- Returns:
None– Initializes the fitting object with the specified parameters.
Notes
The class maintains several internal attributes:
- modesnumpy.ndarray
Array containing influence function modes
- resolutionint
Resolution of the grid for influence function computation
- _fitting_matrixnumpy.ndarray
Matrix used for fitting OPD maps to actuator commands
- _influence_functionsnumpy.ndarray
Matrix of influence functions for each actuator
- actuator_coordinateslist
List of (y, x) coordinate tuples for all actuators
- property F¶
Get the fitting matrix.
- Returns:
numpy.ndarray– The fitting matrix for OPD map to actuator command conversion
- property fitting_matrix¶
Get the fitting matrix (alias for F property).
- Returns:
numpy.ndarray– The fitting matrix for OPD map to actuator command conversion
- property IF¶
Get the influence functions matrix.
- Returns:
numpy.ndarray– The influence functions matrix
- property influence_functions¶
Get the influence functions matrix (alias for IF property).
- Returns:
numpy.ndarray– The influence functions matrix
- fit(opd_map)[source]¶
Multiply the OPD map by the fitting matrix to obtain the command vector.
- Parameters:
opd_map (
numpy.ndarray) – The Optical Path Difference (OPD) map to be fitted- Returns:
numpy.ndarray– The command vector to send to the DM- Raises:
ValueError – If the fitting matrix is not set
- double_gaussian_influence(x, y, center_x=0, center_y=0, w1=2, w2=-1, sigma1=0.54, sigma2=0.85)[source]¶
Compute the double Gaussian influence function for a deformable mirror.
This function allows placement of a double Gaussian influence function at any position on a grid of any dimensions.
- Parameters:
x (
floatornumpy.ndarray) – Coordinates at which to evaluate the influence functiony (
floatornumpy.ndarray) – Coordinates at which to evaluate the influence functioncenter_x (
float) – Center coordinates of the double Gaussian functioncenter_y (
float) – Center coordinates of the double Gaussian functionw1 (
float) – Weights of the two Gaussian componentsw2 (
float) – Weights of the two Gaussian componentssigma1 (
float) – Standard deviations of the two Gaussian componentssigma2 (
float) – Standard deviations of the two Gaussian components
- Returns:
floatornumpy.ndarray– Influence function value at the given coordinates
- create_influence_grid(grid_shape, actuator_pos, w1=2, w2=-1, sigma1=0.5, sigma2=0.85)[source]¶
Create a grid of the specified shape with a double Gaussian placed at the given position.
- Parameters:
grid_shape (
tuple) – Shape of the grid (height, width)actuator_pos (
tuple) – Position (y, x) where the center of the double Gaussian should be placedw1 (
float) – Weights of the two Gaussian componentsw2 (
float) – Weights of the two Gaussian componentssigma1 (
float) – Standard deviations of the two Gaussian componentssigma2 (
float) – Standard deviations of the two Gaussian components
- Returns:
numpy.ndarray– 2D grid with the double Gaussian influence function
- extract_actuator_coordinates(valid_actuator_map)[source]¶
Extract the (y, x) coordinates of all actuators from the map.
- Parameters:
valid_actuator_map (
numpy.ndarray) – Binary array where 1s indicate valid actuator positions- Returns:
list– List of (y, x) coordinate tuples for all actuators
- map_actuators_to_new_grid(actuator_coords, original_shape, new_shape, stretch_factor=1.03)[source]¶
Map actuator coordinates from original grid to a new grid size.
Maintains relative positions and stretches beyond [-1, 1] by the stretch factor.
- Parameters:
actuator_coords (
list) – List of (y, x) coordinate tuples in the original gridoriginal_shape (
tuple) – Shape of the original grid (height, width)new_shape (
tuple) – Shape of the new grid (height, width)stretch_factor (
float, optional) – Factor to stretch the normalized coordinates (default: 1.03)
- Returns:
list– List of (y, x) coordinate tuples in the new grid, normalized and stretched
- map_actuators_to_new_grid_old(actuator_coords, original_shape, new_shape)[source]¶
Map actuator coordinates from original grid to a new grid size (legacy method).
Maintains relative positions using direct scaling.
- set_influence_function(dmParams=None, resolution=None, display=False, w1=2, w2=-1, sigma1=1.0, sigma2=1.7, stretch_factor=1.03)[source]¶
Generate a deformable mirror influence function based on the provided parameters.
This method computes the influence functions for each actuator in the DM and stores them in the class.
- Parameters:
dmParams (
object, optional) – Contains deformable mirror parameters. If None, uses the associated dmParams.resolution (
int, optional) – Resolution of the output influence function grid. If None, uses the class default resolution.display (
bool, optional) – Whether to display plots of the influence functions.w1 (
float, optional) – Weights for the double Gaussian function.w2 (
float, optional) – Weights for the double Gaussian function.sigma1 (
float, optional) – Standard deviations for the double Gaussian function.sigma2 (
float, optional) – Standard deviations for the double Gaussian function.stretch_factor (
float, optional) – Factor to stretch the normalized coordinates (default: 1.03)
- Returns:
numpy.ndarray– 2D array representing the influence function for each actuator.