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):
        settings.configure(**{"NUMBER_OF_PROCESSES": -1})

        o = Observer(system=system)

        sp_res = o.rv(from_phase=start_phs,
                      to_phase=stop_phs,
                      phase_step=step,
                      method='radiometric')
        sp_p = np.array(sp_res[1]['primary'])
        sp_s = np.array(sp_res[1]['secondary'])
        sp_p = sp_p[~np.isnan(sp_p)]
        sp_s = sp_s[~np.isnan(sp_s)]

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

        mp_res = o.rv(from_phase=start_phs,
                      to_phase=stop_phs,
                      phase_step=step,
                      method='radiometric')
        mp_p = np.array(mp_res[1]['primary'])
        mp_s = np.array(mp_res[1]['secondary'])
        mp_p = mp_p[~np.isnan(mp_p)]
        mp_s = mp_s[~np.isnan(mp_s)]

        self.assertTrue(
            np.all((up.abs(sp_p - mp_p) / np.abs(np.max(sp_p))) < tol))
        self.assertTrue(
            np.all((up.abs(sp_s - mp_s) / np.abs(np.max(sp_s))) < tol))
Esempio n. 4
0
    def test_BinarySystem_phase_interval_reduce_has_pulsation(self):
        s1 = SingleSystemMock(p=True, s=True)
        s2 = SingleSystemMock(p=True, s=False)
        o1 = Observer(self._passband, s1)
        o2 = Observer(self._passband, s2)
        o1._system_cls = SingleSystem
        o2._system_cls = SingleSystem

        phases = np.array([
            -0.1, 0.0, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2,
            3.5
        ])
        obtained_ph1, obtained_ri1 = o1.phase_interval_reduce(phases)
        obtained_ph2, obtained_ri2 = o2.phase_interval_reduce(phases)

        expected_ph = phases
        expected_ri = up.arange(0, 14, 1)

        assert_array_equal(np.round(expected_ph, 2), np.round(obtained_ph1, 2))
        assert_array_equal(np.round(expected_ph, 2), np.round(obtained_ph2, 2))
        assert_array_equal(expected_ri, obtained_ri1)
        assert_array_equal(expected_ri, obtained_ri2)

        expected_phases = np.array(phases)
        obtained_phases1 = obtained_ph1[obtained_ri1]
        obtained_phases2 = obtained_ph2[obtained_ri2]

        assert_array_equal(np.round(expected_phases, 2),
                           np.round(obtained_phases1, 2))
        assert_array_equal(np.round(expected_phases, 2),
                           np.round(obtained_phases2, 2))
Esempio n. 5
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 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)
Esempio n. 7
0
 def test_setup_bandwidth(self):
     passbands = ['Generic.Bessell.V', 'SLOAN.SDSS.g']
     s = BinarySystemMock()
     o = Observer(passbands, s)
     expected = [3700.0, 7500.0]
     obtained = [o.left_bandwidth, o.right_bandwidth]
     assert_array_equal(expected, obtained)
Esempio n. 8
0
 def test_setup_bandwidth_bolometric_in(self):
     passbands = ['Generic.Bessell.V', 'SLOAN.SDSS.g', 'bolometric']
     s = BinarySystemMock()
     o = Observer(passbands, s)
     expected = [0.0, sys.float_info.max]
     obtained = [o.left_bandwidth, o.right_bandwidth]
     assert_array_equal(expected, obtained)
Esempio n. 9
0
 def test_init_passband_has_table(self):
     s = BinarySystemMock()
     o = Observer(self._passband, s)
     expected = self._bessel_v_df
     obtained = o.passband[self._passband].table
     obtained[settings.PASSBAND_DATAFRAME_WAVE] = obtained[
         settings.PASSBAND_DATAFRAME_WAVE] / 10.0
     assert_frame_equal(expected, obtained)
    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_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_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

        laws = settings.LD_LAW_TO_FILE_PREFIX.keys()

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

        for cpu_core in [-1, 2]:
            for law in laws:
                settings.configure(
                    **{
                        "NUMBER_OF_PROCESSES": cpu_core,
                        "LIMB_DARKENING_LAW": law,
                        "LD_TABLES": op.join(self.lc_base_path,
                                             "limbdarkening"),
                        "CK04_ATM_TABLES": op.join(self.lc_base_path,
                                                   "atmosphere"),
                        "ATM_ATLAS": "ck04"
                    })
                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, cpu=cpu_core))

                o = Observer(system=bs)
                o.rv(from_phase=start_phs,
                     to_phase=stop_phs,
                     phase_step=step,
                     method='radiometric')

                if op.isfile(self.CONFIG_FILE):
                    os.remove(self.CONFIG_FILE)
Esempio n. 13
0
    def test_SingleSystem_phase_interval_reduce_with_spots_no_pulsation(self):
        s = SingleSystemMock(p=False, s=True)
        o = Observer(self._passband, s)
        o._system_cls = SingleSystem

        phases = np.array([
            -0.1, 0.0, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2,
            3.5
        ])
        obtained_ph, obtained_ri = o.phase_interval_reduce(phases)

        expected_ph = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
        expected_ri = [9, 0, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 5]

        assert_array_equal(np.round(expected_ph, 2), np.round(obtained_ph, 2))
        assert_array_equal(expected_ri, obtained_ri)

        expected_phases = np.array(phases) % 1
        obtained_phases = obtained_ph[obtained_ri]

        assert_array_equal(np.round(expected_phases, 2),
                           np.round(obtained_phases, 2))
Esempio n. 14
0
    def test_SingleSystem_phase_interval_on_clear_surface(self):
        s = SingleSystemMock(p=False, s=False)
        o = Observer(self._passband, s)
        o._system_cls = SingleSystem

        phases = np.array([
            -0.1, 0.0, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2,
            3.5
        ])
        obtained_ph, obtained_ri = o.phase_interval_reduce(phases)

        expected_ph = [0.0]
        expected_ri = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        assert_array_equal(np.round(expected_ph, 2), np.round(obtained_ph, 2))
        assert_array_equal(expected_ri, obtained_ri)

        expected_phases = np.zeros(phases.shape)
        obtained_phases = obtained_ph[obtained_ri]

        assert_array_equal(np.round(expected_phases, 2),
                           np.round(obtained_phases, 2))
    def do_comparison(self,
                      bs,
                      rv_file,
                      start_phs=-0.2,
                      stop_phs=1.2,
                      step=0.1):
        o = Observer(system=bs)

        obtained = o.rv(from_phase=start_phs,
                        to_phase=stop_phs,
                        phase_step=step,
                        method='radiometric')
        obt_phs = obtained[0]
        obt_p = np.array(obtained[1]['primary'])
        obt_s = np.array(obtained[1]['secondary'])
        obt_p = obt_p[~np.isnan(obt_p)]
        obt_s = obt_s[~np.isnan(obt_s)]

        expected = load_radial_curve(rv_file)
        exp_phs = expected['phases']
        exp_p = np.array(expected['primary'])
        exp_s = np.array(expected['secondary'])
        exp_p = exp_p[~np.isnan(exp_p)]
        exp_s = exp_s[~np.isnan(exp_s)]

        # from matplotlib import pyplot as plt
        # # plt.plot(obt_phs, (obt_p-exp_p)/obt_p.max(), c='r')
        # plt.plot(obt_phs, obt_p, c='r')
        # plt.plot(exp_phs, exp_p, c='r', linestyle='dashed')
        # # plt.plot(obt_phs, (obt_s-exp_s)/obt_p.max(), c='b')
        # plt.plot(obt_phs, obt_s, c='b')
        # plt.plot(exp_phs, exp_s, c='b', linestyle='dashed')
        # plt.show()

        self.assertTrue(np.all(up.abs(obt_phs - np.round(exp_phs, 3)) < TOL))
        self.assertTrue(
            np.all((up.abs(obt_p - exp_p) / np.abs(np.max(obt_p))) < TOL))
        self.assertTrue(
            np.all((up.abs(obt_s - exp_s) / np.abs(np.max(obt_s))) < TOL))
    def check_consistency(binary_kwargs,
                          desired_delta,
                          spots_primary=None,
                          spots_secondary=None,
                          phases=None):
        system = prepare_binary_system(binary_kwargs,
                                       spots_primary=spots_primary,
                                       spots_secondary=spots_secondary)

        o = Observer(system=system)
        _, rvdict1 = o.rv(phases=phases, method='radiometric')
        _, rvdict2 = o.rv(phases=phases, method='point_mass')

        rvdict1['primary'], rvdict1['secondary'] = normalize_lv_for_unittests(
            rvdict1['primary'], rvdict1['secondary'])
        rvdict2['primary'], rvdict2['secondary'] = normalize_lv_for_unittests(
            rvdict2['primary'], rvdict2['secondary'])

        assert_array_less(np.abs(rvdict1['primary'] - rvdict2['primary']),
                          desired_delta * np.ones(phases.shape))
        assert_array_less(np.abs(rvdict2['secondary'] - rvdict2['secondary']),
                          desired_delta * np.ones(phases.shape))
Esempio n. 17
0
    def test_BinarySystem_phase_interval_reduce_has_pulsation_and_no_spots(
            self):
        s = BinarySystemMock(pp=False, sp=True)
        o = Observer(self._passband, s)
        o._system_cls = BinarySystem

        phases = np.array([
            -0.1, 0.0, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2,
            3.5
        ])
        obtained_ph, obtained_ri = o.phase_interval_reduce(phases)

        expected_ph = phases
        expected_ri = up.arange(0, 14, 1)

        assert_array_equal(np.round(expected_ph, 2), np.round(obtained_ph, 2))
        assert_array_equal(expected_ri, obtained_ri)

        expected_phases = np.array(phases)
        obtained_phases = obtained_ph[obtained_ri]

        assert_array_equal(np.round(expected_phases, 2),
                           np.round(obtained_phases, 2))
    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))
Esempio n. 19
0
    def test_rvs_from_binary_system_instance_are_same(self):
        s = prepare_binary_system(BINARY_SYSTEM_PARAMS["detached.ecc"])
        s.inclination = 1.1
        s.init()
        std_rvdict = rv.com_radial_velocity(s, position_method=s.calculate_orbital_motion, phases=self.phases)

        asini = np.float64((s.semi_major_axis * np.sin(s.inclination) * u.m).to(u.solRad))

        rv_system = RadialVelocitySystem(eccentricity=s.eccentricity,
                                         argument_of_periastron=np.degrees(s.argument_of_periastron),
                                         period=s.period,
                                         mass_ratio=s.mass_ratio,
                                         asini=asini,
                                         gamma=s.gamma)
        o = Observer(passband='bolometric', system=rv_system)

        phases, com_rv_dict = o.observe.rv(phases=self.phases, method='point_mass')

        self.assertTrue(np.all(np.abs(std_rvdict['primary'] - com_rv_dict['primary']) < TOL))
        self.assertTrue(np.all(np.abs(std_rvdict['secondary'] - com_rv_dict['secondary']) < TOL))
    def test_approximation_two(self):
        bs = prepare_binary_system(PARAMS["eccentric"])

        settings.configure(**APPROX_SETTINGS["approx_two"])
        settings.configure(**{"NUMBER_OF_PROCESSES": 4})
        o = Observer(system=bs)
        ap_res = o.rv(from_phase=-0.1,
                      to_phase=1.1,
                      phase_step=0.01,
                      method='radiometric')
        ap_p = np.array(ap_res[1]['primary'])
        ap_s = np.array(ap_res[1]['secondary'])
        ap_p = ap_p[~np.isnan(ap_p)]
        ap_s = ap_s[~np.isnan(ap_s)]

        settings.configure(**APPROX_SETTINGS["no_approx"])
        o = Observer(system=bs)
        ex_res = o.rv(from_phase=-0.1,
                      to_phase=1.1,
                      phase_step=0.01,
                      method='radiometric')
        ex_p = np.array(ex_res[1]['primary'])
        ex_s = np.array(ex_res[1]['secondary'])
        ex_p = ex_p[~np.isnan(ex_p)]
        ex_s = ex_s[~np.isnan(ex_s)]

        # import matplotlib.pyplot as plt
        # plt.plot(ex_res[0], ex_p / ex_s.max())
        # plt.plot(ex_res[0], ap_p / ex_s.max())
        # plt.plot(ex_res[0], ex_s / ex_s.max())
        # plt.plot(ex_res[0], ap_s / ex_s.max())
        # plt.plot(ex_res[0], (ex_p - ap_p) / ex_s.max(), label='primary')
        # plt.plot(ex_res[0], (ex_s - ap_s) / ex_s.max(), label='secondary')
        # plt.legend()
        # plt.show()

        self.assertTrue(
            np.all((up.abs(ex_p - ap_p) / np.abs(np.max(ex_s))) < 3e-3))
        self.assertTrue(
            np.all((up.abs(ex_s - ap_s) / np.abs(np.max(ex_s))) < 3e-3))
Esempio n. 21
0
                  gamma=-41.7 * u.km / u.s,
                  period=0.7949859 * u.d,
                  eccentricity=0.25,
                  # eccentricity=0,
                  inclination=85 * u.deg,
                  primary_minimum_time=2440862.60793 * u.d,
                  phase_shift=0.0,
                  )

print('Elapsed time during system build: {:.6f}'.format(time() - star_time))


o = Observer(passband=['Generic.Bessell.V',
                       # '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,
                          )
Esempio n. 22
0

data = get_params('data/wide_binary.json')
surface_discredizations = [10, 7, 5, 3]

curves = [None for _ in surface_discredizations]
phases = None
for ii, alpha in enumerate(surface_discredizations):
    data['primary']['discretization_factor'] = alpha
    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)))
Esempio n. 23
0
)

# pick only one
filters = [
    # '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]
Esempio n. 24
0
 def test_init_passband_str_vs_list(self):
     s = BinarySystemMock()
     o_str = Observer(self._passband, s)
     o_lst = Observer([self._passband], s)
     self.assertEqual(len(o_str.passband), len(o_lst.passband))
Esempio n. 25
0
 def test__systemc_cls(self):
     s = BinarySystemMock()
     o = Observer(self._passband, s)
     self.assertEqual(o._system_cls, BinarySystemMock)
Esempio n. 26
0
 def test_get_passband_df(self):
     obtained = Observer.get_passband_df(self._passband)
     obtained[settings.PASSBAND_DATAFRAME_WAVE] = obtained[
         settings.PASSBAND_DATAFRAME_WAVE] / 10.0
     assert_frame_equal(obtained, self._bessel_v_df)