Skip to content

Fix unit handling in Halo.fake_image - #55

Open
mandarmulherkar wants to merge 2 commits into
eblur:mainfrom
mandarmulherkar:fix-fake-image-lam-unit
Open

mandarmulherkar wants to merge 2 commits into
eblur:mainfrom
mandarmulherkar:fix-fake-image-lam-unit

Conversation

@mandarmulherkar

Copy link
Copy Markdown

What is broken

  • fake_image raised AttributeError on every call; two further errors were masked behind it.
  • Root cause: self.lam_unit was removed in 949a0b6 (June 2022) during the astropy-Quantity migration; two reads of it survived in halo.py and galhalo.py. That commit also deleted the only tests/assertions referencing it, so nothing caught it.
  • Why it went unnoticed: no test or notebook touches these methods.

Fix

  • lam carries its own unit, so the unit-string branching is unnecessary. One .to(u.keV, equivalencies=u.spectral()) handles any input unit. lmin/lmax get lam's unit before comparison.

Tests

  • First coverage for fake_image; each fails without its corresponding fix.
  • Test count: 159 → 161 tests passing
  • Reverting either fix independently turns the corresponding test red

Follow-ups (not addressed here)

  • fake_variable_image in galhalo.py has the same lam_unit pattern, plus an undefined var_profile caused by commit fe4c562 ("remaking docstrings") deleting the line that computes it, and time_delay raises UnitConversionError for all inputs because d_cm is a bare float. Happy to follow up in a separate PR.
  • iend = max(...) looks like it drops the bin at lmax; noted but deliberately left alone.

Co-authored by Claude: Claude explained the physics and checked my work; I added tests and code fixes.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant