Skip to content

Commit

Permalink
work with copy of wavelength
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Aug 2, 2024
1 parent d114acd commit abc1372
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion speclite/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,9 @@ def __init__(self, response, wavelength,
self._response = load_filter(response)
else:
self._response = response
self._wavelength = validate_wavelength_array(wavelength, min_length=2)
# Work with a copy of the wavelength array,
# see https://github.com/desihub/speclite/issues/34
self._wavelength = validate_wavelength_array(wavelength, min_length=2).copy()
self.num_wavelength = len(self._wavelength)

# Check if extrapolation would be required.
Expand Down
16 changes: 16 additions & 0 deletions speclite/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def test_response_convolve_with_function():
with pytest.raises(ValueError):
filt.convolve_with_function(lambda wlen: 1. * u.m, units=u.erg)


def test_response_mag():
wlen = [1, 2, 3]
meta = dict(group_name='g', band_name='b')
Expand All @@ -239,6 +240,19 @@ def test_response_mag():
[1, 3] * default_wavelength_unit)


def test_get_ab_maggies_modify_wavelength():
"""This is a regression test for
https://github.com/desihub/speclite/issues/34
"""
filters = load_filters('gaiadr2-BP', 'gaiadr2-RP', 'gaiadr2-G')
waves = np.arange(3000, 11000, 0.11)
waves0 = waves.copy()
flux = waves * 1.
filters[0].get_ab_magnitude(flux, waves)
assert (waves == waves0).all()
# print(np.nonzero(waves != waves0), waves[2249], waves0[2249], waves[40932], waves0[40932])


def test_mag_wavelength_units():
# Check that non-default wavelength units are handled correctly.
wlen = [1, 2, 3] * u.Angstrom
Expand All @@ -254,6 +268,7 @@ def test_mag_wavelength_units():
m2 = r.get_ab_maggies(flux, wlen)
assert m1 == m2


def test_wavelength_property():
# Check that the wavelength property is working
wlen = [1, 2, 3] * u.Angstrom
Expand All @@ -262,6 +277,7 @@ def test_wavelength_property():
assert np.allclose(r.wavelength, r._wavelength)
assert np.allclose(r.wavelength, validate_wavelength_array(wlen))


def test_mag_flux_units():
# Check that non-default flux units are handled correctly.
wlen = [1, 2, 3] * u.Angstrom
Expand Down

0 comments on commit abc1372

Please sign in to comment.