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 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, 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_light_curve_pass_on_all_ld_law(self):
        """
        no assert here, it just has to pass without error
        """
        bs = prepare_binary_system(PARAMS["detached"])
        start_phs, stop_phs, step = -0.2, 1.2, 0.1

        # idea is to update configuration content for problematic values in default configuration file
        content_tempalte = "[physics]limb_darkening_law={ld_law}"

        for law in settings.LD_LAW_TO_FILE_PREFIX.keys():
            settings.configure(**{"LIMB_DARKENING_LAW": law})
            self.write_default_support(ld_tables=settings.LD_TABLES,
                                       atm_tables=settings.CK04_ATM_TABLES)
            with open(self.CONFIG_FILE, "a") as f:
                f.write(content_tempalte.format(ld_law=law))

            o = Observer(passband=['Generic.Bessell.V'], system=bs)
            o.lc(from_phase=start_phs, to_phase=stop_phs, phase_step=step)
    def test_solar_constant(self):
        s = prepare_single_system(SOLAR_MODEL)
        o = Observer(passband=['bolometric'], system=s)

        start_phs, stop_phs, step = 0.0, 0.1, 0.1

        expected = 1361.0

        obtained = o.lc(from_phase=start_phs,
                        to_phase=stop_phs,
                        phase_step=step)
        obtained_flux = obtained[1]["bolometric"][0] / np.power(c.AU, 2)

        np.testing.assert_almost_equal(obtained_flux, expected, decimal=0)
Пример #6
0
def get_data(data, phs):
    binary = system.BinarySystem.from_json(data)
    o = Observer(
        passband=[  # defining passbands at which calculate a light curve
            # 'Generic.Bessell.U',
            'Generic.Bessell.B',
            'Generic.Bessell.V',
            'Generic.Bessell.R',
            # 'Generic.Bessell.I',
        ],
        system=binary
    )  # specifying the binary system to use in light curve synthesis

    _ = o.lc(phases=phs)
    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))
Пример #8
0
                       # 'Generic.Bessell.B',
                       # 'Generic.Bessell.U',
                       # 'Generic.Bessell.R',
                       # 'Generic.Bessell.I',
                       ],
             system=bs)

start_phs = -0.6
stop_phs = 0.6
step = 0.005
settings.POINTS_ON_ECC_ORBIT = 50

start_time = time()
for _ in range(N):
    curves_approx1 = o.lc(from_phase=start_phs,
                          to_phase=stop_phs,
                          phase_step=step,
                          )
interp_time = (time() - start_time) / N
print('Elapsed time for approx one LC gen: {:.6f}'.format(interp_time))

settings.POINTS_ON_ECC_ORBIT = 9999
settings.MAX_RELATIVE_D_R_POINT = 0.005
start_time = time()

for _ in range(N):
    curves_approx2 = o.lc(from_phase=start_phs,
                          to_phase=stop_phs,
                          phase_step=step,
                          )
sim_geom_time = (time() - start_time) / N
print('Elapsed time for approx two LC gen: {:.6f}'.format(sim_geom_time))
Пример #9
0
    # 'Generic.Bessell.U',
    # 'Generic.Bessell.B',
    # 'Generic.Bessell.V',
    'Generic.Bessell.R',
    # 'Generic.Bessell.I',
    ]
lc_kwargs = {"from_phase": -0.6,
             "to_phase": 0.6,
             "phase_step": 0.005,
             "normalize": True}

o = Observer(passband=filters,
             system=bs)

# light curve of clear system
phases, clr_curve = o.lc(**lc_kwargs)

bs.primary.spots = simple_spot
bs.init()
o = Observer(passband=filters,
             system=bs)

# light curve with simple spot
_, simple_curve = o.lc(**lc_kwargs)

composite_curves = []
for ii, r in enumerate(radius):
    bs.primary.spots = composite_spots[ii]
    bs.init()
    o = Observer(passband=filters,
                 system=bs)
Пример #10
0
    binary = system.BinarySystem.from_json(data)

    o = Observer(
        passband=[  # defining passbands at which calculate a light curve
            # 'Generic.Bessell.U',
            # 'Generic.Bessell.B',
            'Generic.Bessell.V',
            # 'Generic.Bessell.R',
            # 'Generic.Bessell.I',
        ],
        system=binary
    )  # specifying the binary system to use in light curve synthesis
    phases, curves[ii] = o.lc(
        from_phase=-0.5,
        to_phase=0.5,
        phase_step=0.005,
        # phase_step=0.01,
        # normalize=True,
    )
    curves[ii] = curves[ii]['Generic.Bessell.V']

    y_data = curves[ii] / np.mean(curves[ii])
    mean = np.sqrt(np.mean(np.power(y_data - 1, 2)))
    print(f'factor: {alpha}, mean noise: {mean}')
    plt.plot(phases,
             y_data,
             label='factor: {0}, mean noise: {1:.2E}'.format(alpha, mean))

    position = binary.calculate_orbital_motion(0.0)[0]
    container = OrbitalPositionContainer.from_binary_system(binary, position)
    container.build()