Skip to main content

Software for performing silent substitution in Python.

Project description

Welcome to PySilentSubstitution!

DOI PyPI version Contributor Covenant PyPi license PyPI status

photoreceptor-characters

PySilSub is a Python software for performing the method of silent substitution with any multiprimary stimulation system for which accurate calibration data are available. Solutions are found with linear algebra and numerical optimisation via a flexible, intuitive interface:

# Example 1 - Target melanopsin with 100% contrast (no background 
# specified), whilst ignoring rods and minimizing cone contrast, 
# for a 42-year-old observer and field size of 10 degrees. Solved
# with numerical optimization.

from pysilsub.problems import SilentSubstitutionProblem as SSP
from pysilsub.observers import IndividualColorimetricObserver as ICO

problem = SSP.from_package_data('STLAB_1_York')  # Load example data
problem.observer = ICO(age=42, field_size=10)  # Assign custom observer model
problem.ignore = ['rh']  # Ignore rod photoreceptors
problem.minimize = ['sc', 'mc', 'lc']  # Minimise cone contrast
problem.modulate = ['mel']  # Target melanopsin
problem.target_contrast = 1.0  # With 100% contrast 
solution = problem.optim_solve()  # Solve with optimisation
fig = problem.plot_solution(solution.x)  # Plot the solution
Example 1

Another example:

# Example 2 - Target S-cones with 45% contrast against a specified 
# background spectrum (all primaries, half max) whilst ignoring rods 
# and minimizing contrast on L/M cones and melanopsin, assuming 
# 32-year-old observer and 10-degree field size. Solved with linear 
# algebra.

from pysilsub.problems import SilentSubstitutionProblem as SSP

problem = SSP.from_package_data('STLAB_1_York')  # Load example data
problem.background = [.5] * problem.nprimaries  # Specify background spectrum
problem.ignore = ['rh']  # Ignore rod photoreceptors
problem.minimize = ['sc', 'mc', 'lc']  # Minimise cone contrast
problem.modulate = ['mel']  # Target melanopsin
problem.target_contrast = .45  # With 45% contrast 
solution = problem.linalg_solve()  # Solve with optimisation
fig = problem.plot_solution(solution)  # Plot the solution
Example 2

There are many other features and use cases covered. The package also includes 6 example datasets for various multiprimary systems, so you can run the above code after a simple pip install:

pip install pysilsub

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

pysilsub-0.0.14.tar.gz (6.3 MB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page