Skip to content

Commit

Permalink
Quick fix for FWHM bug (#31)
Browse files Browse the repository at this point in the history
* Stop recalculating peak using interpolated transmission

* Fix use of Quantity with pytest.approx recursion issue

* Actually fix test errors.
  • Loading branch information
AnthonyHorton authored Apr 1, 2019
1 parent 6e77606 commit 3125eb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions gunagala/optical_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,15 @@ def _update_properties(self):
red_half_max_a = (wave1 + wave2) / 2
red_half_max_b = wave2 + (wave2 - wave1)

peak_results = minimize_scalar(lambda x: -self.transmission(x).value,
method='Bounded',
bounds=(blue_half_max_a.value, red_half_max_b.value))
peak_results = minimize_scalar(lambda x: -self.transmission(x).value,
method='Bounded',
bounds=(blue_half_max_a.value, red_half_max_b.value))

if not peak_results.success:
raise RuntimeError("Failed to find peak of filter transmission profile!")
if not peak_results.success:
raise RuntimeError("Failed to find peak of filter transmission profile!")

self._lambda_peak = peak_results.x * u.nm
self._peak = self.transmission(self._lambda_peak)
self._lambda_peak = peak_results.x * u.nm
self._peak = self.transmission(self._lambda_peak)

blue_half_max_results = brentq(lambda x: self.transmission(x).value - self._peak.value / 2,
blue_half_max_a.value,
Expand Down
4 changes: 2 additions & 2 deletions gunagala/tests/test_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ def test_n_pix(psf):


def test_n_pix_pix(pix_psf):
assert pix_psf.n_pix / u.pixel == pytest.approx(21.01351017)
assert pix_psf.n_pix.to(u.pixel).value == pytest.approx(21.01351017)


def test_peak(psf):
assert psf.peak == 0.7134084656751443 / u.pixel


def test_peak_pix(pix_psf):
assert pix_psf.peak * u.pixel == pytest.approx(0.08073066)
assert pix_psf.peak.to(1 / u.pixel).value == pytest.approx(0.08073066)


def test_shape(psf):
Expand Down

0 comments on commit 3125eb0

Please sign in to comment.