diff --git a/speclite/filters.py b/speclite/filters.py index 96eb0dc..1a6251e 100644 --- a/speclite/filters.py +++ b/speclite/filters.py @@ -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. diff --git a/speclite/tests/test_filters.py b/speclite/tests/test_filters.py index ec1cbe1..a8b039e 100644 --- a/speclite/tests/test_filters.py +++ b/speclite/tests/test_filters.py @@ -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') @@ -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 @@ -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 @@ -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