Package for processing polarised images to measure stress in granular media
Project description
photoelastimetry
Package for processing polarised images to measure stress in granular media
Installation
To install the package, run the following command in the terminal:
pip install photoelastimetry
Documentation
Full documentation is available here.
Usage
After installation, two command line scripts are available:
image-to-stress
Converts photoelastic images to stress maps using the stress-optic law and polarisation analysis.
image-to-stress <json_filename> [--output OUTPUT]
Arguments:
json_filename: Path to the JSON5 parameter file containing configuration (required)--output: Path to save the output stress map image (optional)
Example:
image-to-stress params.json5 --output stress_map.png
The JSON5 parameter file should contain:
folderName: Path to folder containing raw photoelastic imagesC: Stress-optic coefficient in 1/Pathickness: Sample thickness in meterswavelengths: List of wavelengths in nanometersS_i_hat: Incoming normalised Stokes vector [S1_hat, S2_hat, S3_hat] representing polarisation statecrop(optional): Crop region as [y1, y2, x1, x2]debug(optional): If true, display all channels for debuggingseeding(optional): Controls phase-decomposed seeding (enabled,n_max,sigma_max)knot_spacing,spline_degree,boundary_mask_file,boundary_values_files,boundary_weight,regularisation_weight(regularization_weightalias),regularisation_order,external_potential_file,external_potential_gradient,max_iterations,tolerance,verbose,debug(optional): Optimise solver settings
stress-to-image
Converts stress field data to photoelastic fringe pattern images.
stress-to-image <json_filename>
Arguments:
json_filename: Path to the JSON5 parameter file containing configuration (required)
Example:
stress-to-image params.json5
The JSON5 parameter file should contain:
stress_filename: Path to the stress field data file (or legacys_filename)thickness(or legacyt): Thickness of the photoelastic materialwavelengths(nm or m) or legacylambda_light: Illumination wavelengthsC: Stress-optic coefficient(s), scalar or one per wavelengthS_i_hat(optional): Incoming normalised Stokes vector[S1_hat, S2_hat, S3_hat]stress_order(optional):xx_yy_xy(default) or legacyxy_yy_xxscattering(optional): Gaussian filter sigma for scattering simulationoutput_filename(optional):.tiff/.tif/.npy/.raw: saves full synthetic stack[H, W, n_wavelengths, 4].png/.jpg/.jpeg: saves a 2-panel fringe/isoclinic plot (default:output.png)
demosaic-raw
De-mosaics a raw polarimetric image from a camera with a 4x4 superpixel pattern into separate colour and polarisation channels.
demosaic-raw <input_file> [--width WIDTH] [--height HEIGHT] [--dtype DTYPE] [--output-prefix PREFIX] [--format FORMAT] [--all]
Arguments:
input_file: Path to the raw image file, or directory when using--all(required)--width: Image width in pixels (default: 4096)--height: Image height in pixels (default: 3000)--dtype: Data type, either 'uint8' or 'uint16' (auto-detected if not specified)--output-prefix: Prefix for output files (default: input filename without extension)--format: Output format, either 'tiff' or 'png' (default: 'tiff')--all: Recursively process all .raw files in the input directory and subdirectories
Examples:
# Save as a single TIFF stack
demosaic-raw image.raw --width 2448 --height 2048 --dtype uint16 --format tiff
# Save as four separate PNG files (one per polarisation angle)
demosaic-raw image.raw --width 2448 --height 2048 --format png --output-prefix output
# Process all raw files in a directory recursively
demosaic-raw images/ --format png --all
Output formats:
tiff: Creates a single TIFF file with shape [H/4, W/4, 4, 4] containing all colour channels (R, G1, G2, B) and polarisation angles (0°, 45°, 90°, 135°)png: Creates 4 PNG files (one per polarisation angle), each containing all colour channels as a composite image
Development
To set up the development environment, clone the repository and install the package in editable mode with development dependencies:
git clone https://github.com/benjym/photoelastimetry.git
cd photoelastimetry
pip install -e ".[dev]"
# Set up pre-commit hooks
pre-commit install
Running Tests
The project uses pytest for testing with comprehensive coverage analysis:
# Run all tests
pytest
# Run tests with coverage report
pytest --cov=photoelastimetry --cov-report=html
# Run specific test file
pytest tests/test_optimise.py -v
# Run tests in parallel (faster)
pytest -n auto
Code Coverage
View the coverage report by opening htmlcov/index.html in your browser after running tests with coverage enabled.
Current test coverage includes:
- Optimise solver: mean-stress recovery with equilibrium constraints
- Disk simulations: synthetic photoelastic data generation
- Image processing: retardance, principal angle, and Mueller matrix calculations
Code Quality
The project uses black for code formatting and flake8 for linting:
# Format code
black photoelastimetry tests
# Check code style
flake8 photoelastimetry
Continuous Integration
GitHub Actions automatically runs tests on:
- Python 3.9, 3.10, 3.11, and 3.12
- Multiple operating systems (Ubuntu)
- Every push and pull request
Test coverage is automatically uploaded to Codecov for tracking.
Authors
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file photoelastimetry-0.5.0.tar.gz.
File metadata
- Download URL: photoelastimetry-0.5.0.tar.gz
- Upload date:
- Size: 74.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2c82cb57cb1098ca2b00f8b5c7fb1733028313a2f881003db43089194701243
|
|
| MD5 |
da898259c309f67c1d0502b15c654e58
|
|
| BLAKE2b-256 |
e06e61c6989112670f60bb4c07dcdc267a5336d20802f4437b54c28b51649822
|
Provenance
The following attestation bundles were made for photoelastimetry-0.5.0.tar.gz:
Publisher:
pypi.yml on benjym/photoelastimetry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
photoelastimetry-0.5.0.tar.gz -
Subject digest:
f2c82cb57cb1098ca2b00f8b5c7fb1733028313a2f881003db43089194701243 - Sigstore transparency entry: 947300419
- Sigstore integration time:
-
Permalink:
benjym/photoelastimetry@b9364d8422b39a8e08df6c4ee3510bc1586a2885 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/benjym
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@b9364d8422b39a8e08df6c4ee3510bc1586a2885 -
Trigger Event:
release
-
Statement type:
File details
Details for the file photoelastimetry-0.5.0-py3-none-any.whl.
File metadata
- Download URL: photoelastimetry-0.5.0-py3-none-any.whl
- Upload date:
- Size: 56.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3de672d0c296cfe81537112d17a2e3607065b08640ecc0dd9d586c1c41d35cc9
|
|
| MD5 |
b23084f877bff997123302a49c1090eb
|
|
| BLAKE2b-256 |
73f42380d2a05ac701d932c30ebd6428c4ba429fc8bcf8b58f01c01a69ff0c09
|
Provenance
The following attestation bundles were made for photoelastimetry-0.5.0-py3-none-any.whl:
Publisher:
pypi.yml on benjym/photoelastimetry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
photoelastimetry-0.5.0-py3-none-any.whl -
Subject digest:
3de672d0c296cfe81537112d17a2e3607065b08640ecc0dd9d586c1c41d35cc9 - Sigstore transparency entry: 947300420
- Sigstore integration time:
-
Permalink:
benjym/photoelastimetry@b9364d8422b39a8e08df6c4ee3510bc1586a2885 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/benjym
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@b9364d8422b39a8e08df6c4ee3510bc1586a2885 -
Trigger Event:
release
-
Statement type: