def test_approximation_one(self):
        bs = prepare_binary_system(PARAMS["eccentric"])

        phase_step = 1.0 / 120
        settings.configure(**APPROX_SETTINGS["approx_one"])
        settings.configure(**{"NUMBER_OF_PROCESSES": 4})
        o = Observer(passband=['Generic.Bessell.V'], system=bs)
        ap_res = o.lc(from_phase=-0.1, to_phase=1.1, phase_step=phase_step)
        ap_flux = normalize_lc_for_unittests(ap_res[1]["Generic.Bessell.V"])
        # ap_flux = ap_res[1]["Generic.Bessell.V"]

        settings.configure(**APPROX_SETTINGS["no_approx"])
        o = Observer(passband=['Generic.Bessell.V'], system=bs)
        ex_res = o.lc(from_phase=-0.1, to_phase=1.1, phase_step=phase_step)
        ex_flux = normalize_lc_for_unittests(ex_res[1]["Generic.Bessell.V"])
        # ex_flux = ex_res[1]["Generic.Bessell.V"]

        # import matplotlib.pyplot as plt
        # plt.plot(ex_res[0], ex_flux, label='exact')
        # plt.plot(ap_res[0], ap_flux, label='approx')
        # plt.plot(ap_res[0], ex_flux-ap_flux+1, label='diff')
        # plt.legend()
        # plt.show()

        self.assertTrue(np.all(ex_flux - ap_flux < 3e-3))
    def do_comparison(self, system, filename, f_tol, start_phs, stop_phs,
                      step):
        o = Observer(passband=['Generic.Bessell.V'], system=system)

        obtained = o.lc(from_phase=start_phs,
                        to_phase=stop_phs,
                        phase_step=step)
        obtained_phases = obtained[0]
        obtained_flux = normalize_lc_for_unittests(
            obtained[1]["Generic.Bessell.V"])

        expected = load_light_curve(filename)
        expected_phases = expected[0]
        expected_flux = normalize_lc_for_unittests(
            expected[1]["Generic.Bessell.V"])

        # import matplotlib.pyplot as plt
        # plt.plot(expected_phases, expected_flux, label='expected')
        # plt.plot(obtained_phases, obtained_flux, label='obtained')
        # plt.legend()
        # plt.plot()

        self.assertTrue(
            np.all(up.abs(obtained_phases - expected_phases) < TOL))
        self.assertTrue(np.all(up.abs(obtained_flux - expected_flux) < f_tol))
    def test_spotty_single_system(self):
        s = prepare_single_system(self.PARAMS['solar'],
                                  spots=self.SPOTS_META["standard"])
        o = Observer(passband=['Generic.Bessell.V'], system=s)

        start_phs, stop_phs, step = -0.2, 1.2, 0.1

        expected = load_light_curve("single.clear.v.json")
        expected_phases = expected[0]
        expected_flux = normalize_lc_for_unittests(
            expected[1]["Generic.Bessell.V"])

        obtained = o.lc(from_phase=start_phs,
                        to_phase=stop_phs,
                        phase_step=step)
        obtained_phases = obtained[0]
        obtained_flux = normalize_lc_for_unittests(
            obtained[1]["Generic.Bessell.V"])

        self.assertTrue(
            np.all(
                up.abs(
                    np.round(obtained_phases, 3) -
                    np.round(expected_phases, 3)) < TOL))
        self.assertTrue(
            np.all(
                up.abs(
                    np.round(obtained_flux, 3) -
                    np.round(expected_flux, 3)) < TOL))
    def do_comparison(self,
                      system,
                      start_phs=-0.2,
                      stop_phs=1.2,
                      step=0.1,
                      tol=1e-8):
        o = Observer(passband=['Generic.Bessell.V'], system=system)
        sp_res = o.lc(from_phase=start_phs, to_phase=stop_phs, phase_step=step)
        sp_flux = normalize_lc_for_unittests(sp_res[1]["Generic.Bessell.V"])\

        settings.configure(**{"NUMBER_OF_PROCESSES": 2})

        mp_res = o.lc(from_phase=start_phs, to_phase=stop_phs, phase_step=step)
        mp_flux = normalize_lc_for_unittests(mp_res[1]["Generic.Bessell.V"])

        # print(np.max(sp_flux - mp_flux))
        #
        # import matplotlib.pyplot as plt
        # plt.plot(sp_res[0], sp_flux, label='single')
        # plt.plot(mp_res[0], mp_flux, label='multi')
        # plt.legend()
        # plt.show()

        self.assertTrue(np.all(sp_flux - mp_flux < tol))