Add golden-value colorimetry tests - #20
Merged
Merged
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #20 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 431 452 +21
=========================================
+ Hits 431 452 +21
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Most of the test suite asserts only types and shapes, so it would pass even if the colors produced were completely wrong. This PR adds tests that assert published colorimetric values, completing the work started in #17, which added the peak of the luminous efficiency function, the out-of-range values, and the D65 white point.
New tests
test_XYZcie1931_from_spd_equal_energy: a flat, equal-energy spectrum is CIE standard illuminant E, which sits at the center of the chromaticity diagram. The computed chromaticity isx = 0.333315,y = 0.333288against the exact1/3. Because the CIE 1931 color matching functions are normalized to have equal integrals, the tristimulus values also come out equal to each other and to the standard value of about 106.857, which the test asserts as well. This is a direct check that the tabulated data added in Use the tabulated CIE 1931 color matching functions #17 is correctly scaled.test_sRGB_white_point: sRGB is defined against the D65 white point, so those tristimulus values must map to pure white. The result is(1.0000055, 0.99999031, 1.00007973).test_sRGB_monochromatic: monochromatic sources at 450, 550, and 610 nm must be dominated by the blue, green, and red channel respectively. These check the color space conversions directly rather than throughrgb(), which remaps its input onto the visible range and so would not test the absolute wavelength-to-color relationship.test_xyY_from_XYZ_cie_roundtrip: converting to the xyY color space and back must be the identity. The observed error is 4.4e-16.These tests were checked against deliberate mutations, since an assertion that cannot fail is worth nothing:
One sharp edge found while writing these, not changed here.
xyY_from_XYZ_cie()cannot accept tristimulus values that carry a unit, becausexandyare dimensionless ratios whileYkeeps the unit of the input, and the three cannot be stacked into one array. This means the natural pipeline of passing a dimensionless spectrum throughXYZcie1931_from_spd()and then intoxyY_from_XYZ_cie()raises aUnitConversionError, since the tristimulus values pick up the unit of the wavelength. Giving the spectrum a per-wavelength unit, as this test does, makes the tristimulus values dimensionless and avoids it. That is arguably the physically correct way to specify a spectral power distribution, so this may be acceptable as is, but the failure mode is not obvious from the error message.🤖 Generated with Claude Code