-
Notifications
You must be signed in to change notification settings - Fork 0
Testing, and some streamlining, of LUT calibration (& CLI) #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JorisVincent
wants to merge
15
commits into
master
Choose a base branch
from
dev/lut_calibration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b1e82ce
test: mock photometer object, to simulated luminance readings
JorisVincent 8cc4906
fix: flipping screen should be done by draw function, not measurement
JorisVincent 5911f6a
refactor: measure can handle no input device connected
JorisVincent 9d1dd7a
fix: example LUTs properly defined
JorisVincent cadae73
test: `measure_lut`
JorisVincent 628c102
refactor: `measure_lut` does (optional) filewriting itself
JorisVincent 9727e30
test: regenerate test fixtures
JorisVincent 63f33bd
test: integration using created LUT, and regressions to known ground …
JorisVincent dafda9d
refactor(util): more robust filewriting, including CLI args
JorisVincent 7e63819
refactor(util): `out_file` as CLI arg to `lut measure`
JorisVincent 8b32a8b
test(util): `lut measure` CLI command
JorisVincent a5dbea6
test(util): CLI integration
JorisVincent dba336a
test(util): `verify` CLI command
JorisVincent d3c9ee8
test: fix gamma_correct to use proper LUT format
JorisVincent 089256a
fix: flip in calibration stimulus draw function
JorisVincent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| """Mock photometer (for testing) using a lookup table to simulate luminance readings. | ||
|
|
||
| Simulated photometer object that adheres to the same interface as the real photometer, | ||
| but returns simulated luminance values (based on a LUT) instead of reading from a physical device. | ||
|
|
||
| The challenge with mocking a photometer is that it has no knowledge of what | ||
| intensity is currently being displayed -- that information travels through the | ||
| physical path (screen → photons → sensor). | ||
|
|
||
| MockPhotometer solves this by holding ``current_intensity`` as a direct attribute, | ||
| which a stimulus draw function should update before ``readLuminance`` is called. | ||
|
|
||
| Typical usage:: | ||
|
|
||
| ihrl.photometer = MockPhotometer(lut) | ||
|
|
||
| def mock_draw(ihrl, intensity): | ||
| ihrl.photometer.current_intensity = intensity | ||
| # draw_uniform_square(ihrl, intensity) | ||
|
|
||
| measure_lut(ihrl, stim_draw_func=mock_draw, ...) | ||
| """ | ||
|
|
||
| import numpy as np | ||
|
|
||
| from .photometer import Photometer | ||
|
|
||
|
|
||
| class MockPhotometer(Photometer): | ||
| """Photometer that returns simulated luminance values from a LUT. | ||
|
|
||
| The currently displayed intensity is tracked via the ``current_intensity`` | ||
| attribute, which must be updated by the stimulus drawing code before each | ||
| call to ``readLuminance``. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| lut : array-like or callable | ||
| Defines the intensity to luminance mapping. | ||
|
|
||
| - **array**: shape ``(N, 2)`` or ``(N, 3)``. Column 0 is intensity | ||
| (input), the *last* column is luminance (cd/m²). Values are | ||
| linearly interpolated. | ||
| - **callable**: ``lut(intensity: float) -> float`` returning cd/m². | ||
| noise : float, optional | ||
| Standard deviation of zero-mean Gaussian noise added to each reading, | ||
| in cd/m², by default 0.0 (noiseless). | ||
| rng : numpy.random.Generator or int or None, optional | ||
| Random number generator (or seed) used for noise. Pass an integer | ||
| for reproducible results. By default None (unseeded). | ||
|
|
||
| Attributes | ||
| ---------- | ||
| current_intensity : float | ||
| The intensity value (in [0, 1]) most recently drawn to the screen. | ||
| Update this before calling ``readLuminance``. | ||
| """ | ||
|
|
||
| def __init__(self, lut, noise=0.0, rng=None): | ||
| super().__init__() | ||
| self.current_intensity = 0.0 | ||
| self.noise = noise | ||
| self.rng = np.random.default_rng(rng) | ||
|
|
||
| if callable(lut): | ||
| self._lut_func = lut | ||
| else: | ||
| lut = np.asarray(lut) | ||
| if lut.shape[1] == 3: | ||
| # Full 3-column LUT (intensity_in, intensity_out, luminance): | ||
| # use intensity_out (col 1) as the physical intensity axis. | ||
| intensities = lut[:, 1] | ||
| else: | ||
| intensities = lut[:, 0] | ||
| luminances = lut[:, -1] | ||
| self._lut_func = lambda x: float(np.interp(x, intensities, luminances)) | ||
|
|
||
| def readLuminance(self, n=3, slp=None): | ||
| """Return simulated luminance for the currently displayed intensity. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| n : int | ||
| Number of samples to average (mirrors the real photometer API). | ||
| slp : int | ||
| Sleep time between samples in ms (ignored in mock). | ||
|
|
||
| Returns | ||
| ------- | ||
| float | ||
| Simulated luminance in cd/m², averaged over ``n`` samples. | ||
| """ | ||
| base_lum = self._lut_func(self.current_intensity) | ||
| if self.noise > 0.0: | ||
| samples = base_lum + self.rng.normal(0.0, self.noise, size=n) | ||
| return float(np.mean(samples)) | ||
| return base_lum | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that we can introduce a mock photometer, so be able to test the whole pipeline. But I am not sure about this design decision, to have a LUT as input.
I think it is cleaner to have a gamma value as input (or 3 gamma values in the case of color), and a default range of luminances. Then the mock photometer calculates luminance using a standard gamma function.
I say this because conceptually, an LUT file is the result of the calibration pipeline, not the input. So it can be confusing what is the Photometer actually mocking