Repository navigation
Fix unit handling and restore deleted logic in ScreenGalHalo image methods - #56
Open
mandarmulherkar wants to merge 12 commits into
Open
mandarmulherkar wants to merge 12 commits into
mandarmulherkar wants to merge 12 commits into
Conversation
fake_image raised AttributeError on every call: it branched on self.lam_unit, an attribute removed in 949a0b6 when Halo migrated to astropy Quantities. Two further errors were masked behind it: self.lam was multiplied by u.angstrom despite already carrying a unit, and lmin/lmax were compared against unitless floats. self.lam carries its own unit, so the unit-string branching is unnecessary. Convert explicitly with the spectral equivalency instead, which handles any input unit rather than just two. Adds the first test coverage for fake_image.
time_delay documents alpha as a bare float in arcsec, but variable_profile passed self.theta, a Quantity, which broke the comparison in _is_small_angle. Convert at the call site. The intensity accumulator was a plain ndarray while the values written into it carry 1/arcsec^2, so give it norm_int's unit. Return type is now a Quantity; docstring updated to match.
Commit fe4c562 ("first try of remaking docstrings with claude") removed the line that computes var_profile, leaving the loop below referencing an undefined name. fake_variable_image raised NameError on every call. variable_profile already defaults tnow to time[-1], so the separate time_now block that commit also removed is unnecessary.
Same lam_unit branching as Halo.fake_image: the attribute was removed in 949a0b6 during the astropy Quantity migration, but the read survived here. self.lam carries its own unit, so convert with the spectral equivalency and strip to a plain array for the spline.
lmin and lmax are documented as bare floats in halo.lam units but were compared directly against self.lam, an astropy Quantity, raising UnitConversionError whenever either was passed. Give them lam's unit before comparing, as in Halo.fake_image.
Assert the linearity of variable_profile in lc, which the previous version computed but never checked. pytest.approx does not handle astropy Quantities, so compare .value.
This branch has not been deployed
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.
What is broken
ScreenGalHalo.fake_variable_image, ScreenGalHalo.variable_profile, and the module-level time_delay all raise on every call. Six distinct defects, from two unrelated causes:
From the astropy-Quantity migration (949a0b6, June 2022):
From a docstring-only commit (fe4c562, June 2026):
Why it went unnoticed
No test or notebook exercises any of these methods. 949a0b6 also deleted the only assertions that referenced lam_unit, so the suite stayed green while the attribute disappeared.
The fix
self.lam and self.theta carry their own units, so the unit-string branching is unnecessary. One .to(...) with the appropriate equivalency handles any input unit, and .value strips to a plain array where scipy needs one. lmin/lmax are given lam's unit before comparison. time_delay lets astropy do the kpc→s conversion instead of hand-rolling it. The var_profile line is restored; the time_now block deleted alongside it is not needed, since variable_profile already defaults tnow to time[-1].
variable_profile now returns a Quantity; its docstring is updated to match.
Tests
First coverage for all of these. 159 → 165 passing. Reverting any individual fix turns its corresponding test red. Verified one at a time, not just in aggregate.
Noticed but deliberately not addressed
Co-authored by Claude: Claude explained the physics and did the code reviews; I wrote the tests and code fixes.