-
Notifications
You must be signed in to change notification settings - Fork 23
Add PixelResponseNonUniformity effect for fixed per-pixel gain variation (PRNU)
#886
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
Merged
+154
−1
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cae28b9
Implements a new `PixelResponseNonUniformity` effect in effeects/elec…
ShannonS00 acf6dae
Added default deviation of 0.01
ShannonS00 b44dde5
Addressed PR review:
ShannonS00 ec11007
Fix type error in PixelResponseNonUniformity for invalid prnu_std inp…
ShannonS00 be4928b
Updated PixelResponseNonUniformity docstring; updated test to conditi…
ShannonS00 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,73 @@ | ||
| from matplotlib import pyplot as plt | ||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from scopesim.detector import Detector | ||
| from scopesim.effects.electronic import PixelResponseNonUniformity | ||
| from scopesim.optics.image_plane_utils import header_from_list_of_xy | ||
|
|
||
| PLOTS = False | ||
|
|
||
| def make_detector(value=1000, size=10): | ||
| hdr = header_from_list_of_xy([-size/2, size/2], [-size/2, size/2], 1, "D") | ||
| dtcr = Detector(hdr) | ||
| dtcr._hdu.data[:] = value | ||
| return dtcr | ||
|
|
||
|
|
||
| class TestApplyTo: | ||
| def test_output_std_matches_prnu_std(self): | ||
| """Relative std of output should be close to prnu_std.""" | ||
| prnu_std = 0.05 | ||
| dtcr = make_detector(value=1000, size=100) | ||
| PixelResponseNonUniformity(prnu_std=prnu_std, prnu_seed=42).apply_to(dtcr) | ||
| rel_std = dtcr._hdu.data.std() / dtcr._hdu.data.mean() | ||
| assert abs(rel_std - prnu_std) < 0.01 | ||
|
|
||
| def test_gain_map_is_reused(self): | ||
| """Same map should be applied on repeated calls (fixed pattern).""" | ||
| dtcr1 = make_detector() | ||
| dtcr2 = make_detector() | ||
| prnu = PixelResponseNonUniformity(prnu_std=0.01, prnu_seed=42) | ||
| prnu.apply_to(dtcr1) | ||
| prnu.apply_to(dtcr2) | ||
| np.testing.assert_array_equal(dtcr1._hdu.data, dtcr2._hdu.data) | ||
|
|
||
| def test_dict_prnu_std(self): | ||
| """Dict mode: different amplitude per detector ID.""" | ||
| hdr = header_from_list_of_xy([-5, 5], [-5, 5], 1, "D") | ||
| dtcr = Detector(hdr) | ||
| dtcr.meta["id"] = "H2RG" | ||
| dtcr._hdu.data[:] = 1000 | ||
| prnu = PixelResponseNonUniformity( | ||
| prnu_std={"H2RG": 0.005, "GeoSnap": 0.020}, prnu_seed=42) | ||
| prnu.apply_to(dtcr) | ||
| assert dtcr._hdu.data.std() > 0 | ||
|
|
||
| def test_multiplicative_zero_signal(self): | ||
| """Zero signal should remain zero — confirms multiplicative (not additive).""" | ||
| dtcr = make_detector(value=0) | ||
| PixelResponseNonUniformity(prnu_std=0.01, prnu_seed=42).apply_to(dtcr) | ||
| assert dtcr._hdu.data.sum() == 0 | ||
|
|
||
| def test_non_detector_passthrough(self): | ||
| """Non-Detector objects should be returned unchanged.""" | ||
| prnu = PixelResponseNonUniformity(prnu_std=0.01) | ||
| result = prnu.apply_to("not a detector") | ||
| assert result == "not a detector" | ||
|
|
||
| def test_invalid_prnu_std_raises(self): | ||
| prnu = PixelResponseNonUniformity(prnu_std="not a number nor a dict") | ||
| with pytest.raises(TypeError): | ||
| prnu.apply_to(make_detector()) | ||
|
|
||
| def test_plot_raises_before_simulation(self): | ||
| prnu = PixelResponseNonUniformity(prnu_std=0.01) | ||
| with pytest.raises(RuntimeError): | ||
| prnu.plot() | ||
|
|
||
| def test_plot_returns_figure(self): | ||
| prnu = PixelResponseNonUniformity(prnu_std=0.01, prnu_seed=42) | ||
| prnu.apply_to(make_detector()) | ||
| if PLOTS: | ||
| assert isinstance(prnu.plot(), plt.Figure) |
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.
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.
Not sure it's a gain variation or rather a QE variation or a combination of both. But let's not split hairs.