Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
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)
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
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)
Exemplo n.º 17
0
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)
Exemplo n.º 18
0
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)
Exemplo n.º 19
0
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)
Exemplo n.º 20
0
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)