Exemple #1
0
def test_spectrum_bandwidth():
    e, c = __generate_spectrum()

    spectrum = Spectrum(e, c)

    emin, emax = spectrum.get_emin_eV(), spectrum.get_emax_eV()

    assert emin == pytest.approx(11840, abs=2)
    assert emax == pytest.approx(11876, abs=2)
Exemple #2
0
def test_spectrum_weighted_mean_variance():

    p = 11900.0
    h = 10000.0
    w = 5.0

    e, c = __generate_simple(p, h, w)

    spectrum = Spectrum(e, c)

    mean = spectrum.get_weighted_energy_eV()
    variance = spectrum.get_weighted_energy_variance()

    assert mean == pytest.approx(p, abs=1e-3)
    assert variance == pytest.approx(w * w, abs=1e-3)
Exemple #3
0
  def get_spectrum(self, index=0):
    ENERGY_CONV = 12398.419739640716
    img_prefix = self._header_dictionary["PREFIX"]
    idx = int(img_prefix[-6:])
    SS = spectrum_simulation()#common_data = common_data)
    SS.select(image=idx%100000)
    iterator = SS.generate_recast_renormalized_image(image=idx%100000,energy=7120.,total_flux=1e12)
    if False: SS.plot_recast_image(image=idx%100000, energy=7120.) # for debugging
    wavlen, flux, wavelength_A = next(iterator)
    energies = ENERGY_CONV/wavlen

    return Spectrum(energies, flux)
Exemple #4
0
def test_spectrum():
    mean_ev_1 = factor_ev_angstrom  # 1.0Å
    wavelengths = 2 / 3, 1, 3 / 2

    for wavelength in wavelengths:
        mean_ev = mean_ev_1 / wavelength
        spectrum = Spectrum(
            flex.double([mean_ev - 50, mean_ev, mean_ev + 50]),
            flex.double([0.5, 1.0, 0.5]),
        )
        assert spectrum.get_weighted_energy_eV() == pytest.approx(mean_ev)
        assert spectrum.get_weighted_wavelength() == pytest.approx(wavelength)

        spectrum = Spectrum.from_dict(spectrum.to_dict())
        assert spectrum.get_weighted_energy_eV() == pytest.approx(mean_ev)
        assert spectrum.get_weighted_wavelength() == pytest.approx(wavelength)