Beispiel #1
0
def test_optimizer_from_api2():
    """
    Here we test that granting only GD value will yield correct results.
    """
    g = Generator(
        1,
        3,
        2,
        500,
        GD=400,
        GDD=400,
        TOD=800,
        FOD=7000,
        QOD=70000,
        resolution=0.05,
        normalize=True,
    )
    g.generate_freq()

    cf = CosFitMethod(*g.data)
    cf.guess_GD(900)
    with patch.object(FitOptimizer, "update_plot") as patched_obj:
        res = cf.optimizer(2,
                           order=5,
                           initial_region_ratio=0.01,
                           extend_by=0.01)
        patched_obj.assert_called()
        np.testing.assert_array_almost_equal(res, [900, 400, 800, 7000, 70000])
Beispiel #2
0
def test_basic_parallel():
    g = Generator(
        1,
        3,
        2,
        3000,
        GDD=400,
        TOD=4000,
        FOD=4000,
        QOD=50000,
        pulse_width=5,
        resolution=0.01
    )

    g.generate()

    f = WFTMethod(*g.data)
    f.add_window_linspace(1.25, 2.75, 350, fwhm=0.017)

    d, _, _ = f.calculate(
        reference_point=2, order=5, fastmath=False, parallel=True, silent=True
    )

    np.testing.assert_array_almost_equal(
        d, [2999.16249, 399.94162, 3998.03069, 3991.45663, 49894.96710], decimal=1
    )
Beispiel #3
0
    def test_find_center3(self):
        g = Generator(1, 4, 3, 7000)
        g.generate_freq()

        a = FFTMethod(*g.data)
        a.ifft()

        x, y = find_roi(a.x, a.y)

        x_peak, _ = find_center(x, y, n_largest=4)

        assert 6950 < x_peak < 7050
Beispiel #4
0
def test_autorun(printing):
    g = Generator(1, 4, 3, 1000)
    g.generate()

    f = FFTMethod(*g.data)
    with pytest.raises(NotCalculatedException):
        f.get_pulse_shape_from_array(np.arange(10), np.arange(20))
    with unittest.mock.patch("matplotlib.pyplot.show") as mck:
        phase = f.autorun(enable_printing=printing)
        assert isinstance(phase, pysprint.core.phase.Phase)
        mck.assert_called()
        with pytest.raises(ValueError):
            f.get_pulse_shape_from_array(np.arange(10), np.arange(20))
Beispiel #5
0
 def test_ffts_advanced1(self):
     g = Generator(2,
                   2.8,
                   2.4,
                   delay=1500,
                   GD=200,
                   pulse_width=25,
                   resolution=0.01)
     g.generate_freq()
     a, b = g.data
     f = FFTMethod(a, b)
     f.ifft()
     f.window(1700, 3300, plot=False)
     f.apply_window()
     f.fft()
     d, _, _ = f.calculate(order=1, reference_point=2.4)
     np.testing.assert_array_almost_equal(d, [1699.99], decimal=2)
Beispiel #6
0
def test_optimizer_from_api(delay, GD, GDD):
    g = Generator(1,
                  3,
                  2,
                  delay,
                  GD=GD,
                  GDD=GDD,
                  resolution=0.05,
                  normalize=True)
    g.generate_freq()

    cf = CosFitMethod(*g.data)
    cf.guess_GD(GD + delay)
    cf.guess_GDD(GDD)
    with patch.object(FitOptimizer, "update_plot") as patched_obj:
        cf.optimizer(2, order=2, initial_region_ratio=0.01, extend_by=0.01)
        patched_obj.assert_called()
Beispiel #7
0
    def test_fwhm_detection(self):
        g = Generator(1, 4, 3, 1000)
        g.generate_freq()

        a = FFTMethod(*g.data)
        a.ifft()

        x, y = find_roi(a.x, a.y)

        cent, win_size, order = predict_fwhm(x,
                                             y,
                                             1000,
                                             10,
                                             prefer_high_order=True,
                                             tol=1e-3)
        assert cent > 1000
        assert win_size > 2000
Beispiel #8
0
 def test_ffts_advanced3(self):
     g = Generator(2,
                   2.8,
                   2.4,
                   delay=1500,
                   TOD=40000,
                   pulse_width=25,
                   resolution=0.01)
     g.generate_freq()
     a, b = g.data
     f = FFTMethod(a, b)
     f.ifft()
     f.window(2500, 4830, window_order=12, plot=False)
     f.apply_window()
     f.fft()
     d, _, _ = f.calculate(order=3, reference_point=2.4)
     np.testing.assert_array_almost_equal(d, [1500.03, 0.03, 39996.60],
                                          decimal=2)
Beispiel #9
0
 def test_ffts_advanced5(self):
     g = Generator(
         2,
         2.8,
         2.4,
         delay=1500,
         QOD=900000,
         pulse_width=25,
         resolution=0.01,
     )
     g.generate_freq()
     a, b = g.data
     f = FFTMethod(a, b)
     f.ifft()
     f.window(1600, 2950, window_order=12, plot=False)
     f.apply_window()
     f.fft()
     d, _, _ = f.calculate(order=5, reference_point=2.4)
     np.testing.assert_array_almost_equal(
         d, [1499.9646, -0.1429, 7.893, 16.075, 898919.85], decimal=1)
Beispiel #10
0
 def test_ffts_advanced4(self):
     g = Generator(
         2,
         2.8,
         2.4,
         delay=1500,
         GDD=2000,
         FOD=-100000,
         pulse_width=25,
         resolution=0.01,
     )
     g.generate_freq()
     a, b = g.data
     f = FFTMethod(a, b)
     f.ifft()
     f.window(1500, 1490, window_order=8, plot=False)
     f.apply_window()
     f.fft()
     d, _, _ = f.calculate(order=4, reference_point=2.4)
     np.testing.assert_array_almost_equal(
         d, [1500.00, 1999.95, -0.21, -99995.00], decimal=1)
Beispiel #11
0
 def test_Generator_from_API(self, mock_show):
     g = Generator_from_API(1, 3, 2, 100)
     g.generate_freq()
     g.phase_graph()
     mock_show.assert_called()
Beispiel #12
0
def test_lookup2():
    g = Generator(1, 3, 2, 400, GD=0, GDD=500, normalize=False)
    g.generate_freq()
    cf = CosFitMethod(*g.data)
    cf.GD_lookup(200, engine="normal", silent=True)
    assert cf.params[3] == 1
Beispiel #13
0
def test_lookup(delay):
    g = Generator(1, 3, 2, delay, GD=0, GDD=500, TOD=800, normalize=True)
    g.generate_freq()
    cf = CosFitMethod(*g.data)
    cf.GD_lookup(2, engine="normal", silent=True)
    assert delay * 0.95 <= cf.params[3] <= delay * 1.05