optimiser.stokes¶
Stokes-based pixel-wise stress inversion.
This module implements stress field recovery using normalized Stokes components computed from polarimetric measurements. This is the primary and recommended method for most photoelastic analysis tasks.
Key Functions¶
compute_stokes_components()- Calculate Stokes parameters from intensity measurementscompute_normalized_stokes()- Normalize Stokes components for analysisrecover_stress_map_stokes()- Main function for stress field recoverypredict_stokes()- Forward model for validation
stokes
¶
Local stress measurement using polarimetric imaging.
This module implements the local stress measurement algorithm using Mueller matrix calculus and multi-wavelength polarimetry to recover the full 2D stress tensor at each pixel from polarimetric images.
Functions¶
predict_stokes(sigma_xx, sigma_yy, sigma_xy, C, nu, L, wavelength, S_i_hat)
¶
Predict normalized Stokes vector components from stress tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma_xx
|
float
|
Normal stress component in x direction (Pa). |
required |
sigma_yy
|
float
|
Normal stress component in y direction (Pa). |
required |
sigma_xy
|
float
|
Shear stress component (Pa). |
required |
C
|
float
|
Stress-optic coefficient (1/Pa). |
required |
nu
|
float
|
Solid fraction (use 1.0 for solid samples). |
required |
L
|
float
|
Sample thickness (m). |
required |
wavelength
|
float
|
Wavelength of light (m). |
required |
S_i_hat
|
array - like
|
Incoming normalized Stokes vector [S1_hat, S2_hat] or [S1_hat, S2_hat, S3_hat]. If 2 elements, S3_hat is assumed to be 0 (no circular polarization). If 3 elements, S3_hat represents circular polarization component. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
S_p_hat |
ndarray
|
Predicted normalized Stokes components [S1_hat, S2_hat]. |
Source code in photoelastimetry/optimiser/stokes.py
compute_residual(stress_params, S_m_hat, wavelengths, C_values, nu, L, S_i_hat)
¶
Compute residual between measured and predicted Stokes components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stress_params
|
array - like
|
Stress tensor components [sigma_xx, sigma_yy, sigma_xy]. |
required |
S_m_hat
|
ndarray
|
Measured normalized Stokes components, shape (3, 2) for RGB channels. |
required |
wavelengths
|
array - like
|
Wavelengths for R, G, B channels (m). |
required |
C_values
|
array - like
|
Stress-optic coefficients for R, G, B channels (1/Pa). |
required |
nu
|
float
|
Solid fraction (use 1.0 for solid samples). |
required |
L
|
float
|
Sample thickness (m). |
required |
S_i_hat
|
array - like
|
Incoming normalized Stokes vector [S1_hat, S2_hat] or [S1_hat, S2_hat, S3_hat]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
residual |
float
|
Sum of squared residuals across all colour channels. |
Source code in photoelastimetry/optimiser/stokes.py
recover_stress_tensor(S_m_hat, wavelengths, C_values, nu, L, S_i_hat, initial_guess=None, track_history=False, max_fringes=6)
¶
Recover stress tensor components by minimizing residual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S_m_hat
|
ndarray
|
Measured normalized Stokes components, shape (3, 2) for RGB channels. Each row is [S1_hat, S2_hat] for a colour channel. |
required |
wavelengths
|
array - like
|
Wavelengths for R, G, B channels (m). |
required |
C_values
|
array - like
|
Stress-optic coefficients for R, G, B channels (1/Pa). |
required |
nu
|
float
|
Solid fraction (use 1.0 for solid samples). |
required |
L
|
float
|
Sample thickness (m). |
required |
S_i_hat
|
array - like
|
Incoming normalized Stokes vector [S1_hat, S2_hat] or [S1_hat, S2_hat, S3_hat]. |
required |
initial_guess
|
array - like
|
Initial guess for stress tensor [sigma_xx, sigma_yy, sigma_xy]. Default is [1, 1, 1]. |
None
|
track_history
|
bool
|
If True, track optimization history for debugging plots. Default is False. |
False
|
max_fringes
|
float
|
Maximum expected fringe order. Used to set bounds on stress components. Default is 6 fringes, which corresponds to ~1.7 MPa for typical materials. |
6
|
Returns:
| Name | Type | Description |
|---|---|---|
stress_tensor |
ndarray
|
Recovered stress tensor components [sigma_xx, sigma_yy, sigma_xy]. |
success |
bool
|
Whether optimization was successful. |
history |
(dict, optional)
|
Only returned if track_history=True. Contains: - 'all_paths': list of dicts, each containing the optimization path from a start point - 'best_path_index': index of the path that led to the best solution |
Source code in photoelastimetry/optimiser/stokes.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
recover_stress_tensor_live(S_m_hat, wavelengths, C_values, nu, L, S_i_hat, initial_guess=None, update_interval=5, max_fringes=6)
¶
Recover stress tensor with live plotting of optimization progress.
This function is useful for debugging and understanding the optimization process for a single pixel. It creates a live-updating plot that shows how the stress components and predicted Stokes parameters evolve during optimization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S_m_hat
|
ndarray
|
Measured normalized Stokes components, shape (3, 2) for RGB channels. |
required |
wavelengths
|
array - like
|
Wavelengths for R, G, B channels (m). |
required |
C_values
|
array - like
|
Stress-optic coefficients for R, G, B channels (1/Pa). |
required |
nu
|
float
|
Solid fraction (use 1.0 for solid samples). |
required |
L
|
float
|
Sample thickness (m). |
required |
S_i_hat
|
array - like
|
Incoming normalized Stokes vector [S1_hat, S2_hat] or [S1_hat, S2_hat, S3_hat]. |
required |
initial_guess
|
array - like
|
Initial guess for stress tensor [sigma_xx, sigma_yy, sigma_xy]. |
None
|
update_interval
|
int
|
Update plot every N iterations. Default is 5. |
5
|
max_fringes
|
float
|
Maximum expected fringe order for setting bounds. Default is 6. |
6
|
Returns:
| Name | Type | Description |
|---|---|---|
stress_tensor |
ndarray
|
Recovered stress tensor components [sigma_xx, sigma_yy, sigma_xy]. |
success |
bool
|
Whether optimization was successful. |
history |
dict
|
Optimization history for further analysis. |
fig |
Figure
|
The figure object (will be kept open). |
Source code in photoelastimetry/optimiser/stokes.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
compute_solid_fraction(S0, S_ref, mu, L)
¶
Compute solid fraction from intensity using Beer-Lambert law.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S0
|
array - like
|
Measured intensity (from colour channel with absorptive dye). |
required |
S_ref
|
float
|
Reference light intensity before passing through sample. |
required |
mu
|
float
|
Absorption coefficient for the colour channel (calibrated parameter). |
required |
L
|
float
|
Sample thickness (m). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
nu |
array - like
|
Solid fraction values. |
Source code in photoelastimetry/optimiser/stokes.py
recover_stress_map_stokes(image_stack, wavelengths, C_values, nu, L, S_i_hat, initial_guess_map=None, n_jobs=-1)
¶
Recover full 2D stress tensor map from polarimetric image stack using Stokes method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_stack
|
ndarray
|
Image stack of shape [H, W, 3, 4] where: - H, W are image dimensions - 3 colour channels (R, G, B) - 4 polarisation angles (0, 45, 90, 135 degrees) |
required |
wavelengths
|
array - like
|
Wavelengths for R, G, B channels (m). |
required |
C_values
|
array - like
|
Stress-optic coefficients for R, G, B channels (1/Pa). |
required |
nu
|
float or ndarray
|
Solid fraction. Use 1.0 for solid samples. Can be scalar or array matching image dimensions. |
required |
L
|
float
|
Sample thickness (m). |
required |
S_i_hat
|
array - like
|
Incoming normalized Stokes vector [S1_hat, S2_hat] or [S1_hat, S2_hat, S3_hat]. |
required |
initial_guess_map
|
ndarray
|
Initial guess stress map [H, W, 3]. |
None
|
n_jobs
|
int
|
Number of parallel jobs. -1 uses all available cores (default: -1). |
-1
|
Returns:
| Name | Type | Description |
|---|---|---|
stress_map |
ndarray
|
Array of shape [H, W, 3] containing [sigma_xx, sigma_yy, sigma_xy] in Pa. |