def test_calculate_bin_widths_raises_not_1d(): """ Test we get a ValueError with a non-1D array. """ a = np.arange(20).reshape((4, 5)) binning.calculate_bin_widths(a)
def test_calculate_bin_widths_raises_1_val(): """ Test we get a ValueError with a single value array. """ a = np.array([5]) binning.calculate_bin_widths(a)
def test_calculate_bin_widths_two_val(): """ Test the edge case where there is only one bin. """ edges = [1, 2] widths = [1] np.testing.assert_array_equal(binning.calculate_bin_widths(edges), widths)
def test_obmag2(): ob = units.OBMag() wave = refs._default_waveset flux = np.ones_like(wave) delta_wave = \ binning.calculate_bin_widths(binning.calculate_bin_edges(wave)) ref = 10.0**(-0.4 * flux) / (delta_wave * refs.PRIMARY_AREA) test = ob.ToPhotlam(wave, flux) np.testing.assert_allclose(ref, test)
def test_counts2(): counts = units.Counts() wave = refs._default_waveset flux = np.ones_like(wave) delta_wave = \ binning.calculate_bin_widths(binning.calculate_bin_edges(wave)) ref = flux / (delta_wave * refs.PRIMARY_AREA) test = counts.ToPhotlam(wave, flux) np.testing.assert_allclose(ref, test)
def test_obmag1(): area = 1.0 ob = units.OBMag() wave = refs._default_waveset flux = np.ones_like(wave) delta_wave = \ binning.calculate_bin_widths(binning.calculate_bin_edges(wave)) ref = 10.0**(-0.4 * flux) / delta_wave test = ob.ToPhotlam(wave, flux, area=area) np.testing.assert_allclose(ref, test)
def test_counts1(): area = 1.0 counts = units.Counts() wave = refs._default_waveset flux = np.ones_like(wave) delta_wave = \ binning.calculate_bin_widths(binning.calculate_bin_edges(wave)) ref = flux / delta_wave test = counts.ToPhotlam(wave, flux, area=area) np.testing.assert_allclose(ref, test)
def test_flat_spectrum(): f = FlatSpectrum(1, fluxunits='photlam') f.convert('counts') delta_wave = \ binning.calculate_bin_widths(binning.calculate_bin_edges(f.wave)) ref = delta_wave * refs.PRIMARY_AREA test = f.sample(f.wave) np.testing.assert_allclose(ref, test) f.primary_area = 100.0 ref = delta_wave * 100 test = f.sample(f.wave) np.testing.assert_allclose(ref, test)
def test_photlam2(): p = units.Photlam() wave = refs._default_waveset flux = np.ones_like(wave) delta_wave = \ binning.calculate_bin_widths(binning.calculate_bin_edges(wave)) ref = -1.085736 * np.log(flux * delta_wave * refs.PRIMARY_AREA) test = p.ToOBMag(wave, flux) np.testing.assert_allclose(ref, test) ref = flux * delta_wave * refs.PRIMARY_AREA test = p.ToCounts(wave, flux) np.testing.assert_allclose(ref, test)
def test_calculate_bin_widths(): edges = [1, 2, 4, 10, 20] widths = [1, 2, 6, 10] np.testing.assert_array_equal(binning.calculate_bin_widths(edges), widths)