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))
Пример #2
0
    def test_sun():
        _passband = ['Generic.Bessell.B', 'Generic.Bessell.V']
        TS = np.arange(3500, 50000, 500)

        #         for ld in ['logarithmic', 'square_root']:
        settings.configure(REFLECTION_EFFECT=False)
        reload(observer)
        reload(system)

        res = []

        for t in TS:
            try:
                system_blueprint["primary"]["t_eff"] = t
                bs = system.BinarySystem.from_json(system_blueprint)
                o = observer.Observer(passband=_passband, system=bs)
                lc = o.observe.lc(phases=[0.5])

                b_v = pogsons_formula(lc[1]['Generic.Bessell.B'][-1],
                                      lc[1]['Generic.Bessell.V'][-1])
                res.append([t, b_v])

            except Exception as e:
                print(e)

        x, y = np.array(res).T[1], np.array(res).T[0]

        with open(f"cosine.sun.dat", "a") as f:
            f.write(f"{repr(x)}\n")
            f.write(f"{repr(y)}\n")
        print()
 def test_cicular_spotty_asynchronous_detached_system(self):
     settings.configure(**{"MAX_SPOT_D_LONGITUDE": up.pi / 45.0})
     bs = prepare_binary_system(PARAMS["detached-async"],
                                spots_primary=SPOTS_META["primary"])
     self.do_comparison(bs,
                        "detached.circ.spotty.async.generic.bessel.v.json",
                        TOL, -0.2, 1.2, 0.2)
Пример #4
0
    def test_interpolate_on_ld_grid_log(self):
        settings.configure(
            **{
                "LIMB_DARKENING_LAW":
                "logarithmic",
                "LD_TABLES":
                os.path.join(self.base_path, "data", "light_curves",
                             "limbdarkening")
            })
        temperature = np.array([5500, 5561, 5582, 5932])
        log_g = np.array([4.2, 4.21, 4.223, 4.199]) - 2.0
        metallicity = 0.0
        passband = ["Generic.Bessell.V"]

        expected_xlog = np.round(
            np.array([0.776400, 0.772272, 0.770870, 0.747420]), 5)
        expected_ylog = np.round(
            np.array([0.204200, 0.211724, 0.214276, 0.251288]), 5)

        obtained = ld.interpolate_on_ld_grid(temperature, log_g, metallicity,
                                             passband)
        obtained_xlog = np.round(obtained["Generic.Bessell.V"].xlog.values, 5)
        obtained_ylog = np.round(obtained["Generic.Bessell.V"].ylog.values, 5)

        self.assertTrue(np.all(expected_ylog == obtained_ylog))
        self.assertTrue(np.all(expected_xlog == obtained_xlog))
Пример #5
0
    def test_orbital_position_container_is_indempotent(self):
        settings.configure(LD_TABLES=op.join(self.base_path, "data", "light_curves", "limbdarkening"))

        system = OrbitalPositionContainer.from_binary_system(self.s, Position(0, 1.0, 0.0, 0.0, 0.0))
        system.build(components_distance=1.0)
        flatt_1 = system.flatt_it()
        flatt_2 = system.flatt_it()
        self.assertTrue(len(flatt_1.primary.points) == len(flatt_2.primary.points))
Пример #6
0
 def setUp(self):
     super(TestObserver, self).setUp()
     self._data_path = pjoin(dirname(os.path.abspath(__file__)), "data",
                             "passband")
     self._passband = 'Generic.Bessell.V'
     self._bessel_v_df = pd.read_csv(
         pjoin(self._data_path, f'{self._passband}.csv'))
     settings.configure(**{"PASSBAND_TABLES": self._data_path})
Пример #7
0
 def test__update_atlas_to_base_dir(self):
     settings.configure(CK04_ATM_TABLES="x")
     settings._update_atlas_to_base_dir()
     ck_values = [
         v for k, v in settings.ATLAS_TO_BASE_DIR.items()
         if str(k).startswith("c")
     ]
     self.assertTrue(np.all(ck_values == ['x'] * len(ck_values)))
 def test_eccentric_system_approximation_two(self):
     settings.configure(**APPROX_SETTINGS["approx_two"])
     ec_params = PARAMS["eccentric"].copy()
     ec_params["argument_of_periastron"] = 90 * u.deg
     bs = prepare_binary_system(ec_params)
     self.do_comparison(
         bs, "detached.ecc.sync.generic.bessell.v.appx_two.json", TOL, -0.2,
         1.15, 0.05)
Пример #9
0
 def setUp(self):
     super(IndempotenceTestCase, self).setUp()
     self.s = testutils.prepare_binary_system(testutils.BINARY_SYSTEM_PARAMS['detached-physical'],
                                              testutils.SPOTS_META["primary"])
     self.s.primary.discretization_factor = up.radians(10)
     self.single = testutils.prepare_single_system(testutils.SINGLE_SYSTEM_PARAMS['spherical'],
                                                   testutils.SPOTS_META["primary"])
     self.base_path = op.dirname(op.abspath(__file__))
     settings.configure(LD_TABLES=op.join(self.base_path, "data", "light_curves", "limbdarkening"))
Пример #10
0
 def setUp(self):
     super(CompareApproxVsExact, self).setUp()
     self.lc_base_path = op.join(op.dirname(op.abspath(__file__)), "data",
                                 "light_curves")
     settings.configure(
         **{
             "LD_TABLES": op.join(self.lc_base_path, "limbdarkening"),
             "CK04_ATM_TABLES": op.join(self.lc_base_path, "atmosphere")
         })
Пример #11
0
 def setUp(self):
     super(BinaryRadialCurvesConsistencyTestCase, self).setUp()
     self.lc_base_path = op.join(op.dirname(op.abspath(__file__)), "data",
                                 "light_curves")
     settings.configure(
         **{
             "LD_TABLES": op.join(self.lc_base_path, "limbdarkening"),
             "CK04_ATM_TABLES": op.join(self.lc_base_path, "atmosphere")
         })
Пример #12
0
    def test_eccentric_system_approximation_three(self):
        settings.configure(**APPROX_SETTINGS["approx_three"])

        with open(self.CONFIG_FILE, "a") as f:
            f.write(
                f"[computational]"
                f"\npoints_on_ecc_orbit={settings.POINTS_ON_ECC_ORBIT}"
                f"\nmax_relative_d_r_point={settings.MAX_RELATIVE_D_R_POINT}")
        bs = prepare_binary_system(PARAMS["eccentric"])
        self.do_comparison(bs, 0.0, 0.01, 0.002, tol=1e-4)
Пример #13
0
 def test_ATLAS_TO_BASE_DIR(self):
     settings.configure(**{
         "CK04_ATM_TABLES": os.path.join(os.path.dirname(os.path.abspath(__file__)), 'ck04'),
         "K93_ATM_TABLES": os.path.join(os.path.dirname(os.path.abspath(__file__)), 'k93')
     })
     supplied = ["castelli", "castelli-kurucz", "ck", "ck04", "kurucz", "k93", "k"]
     expected = [os.path.join(os.path.dirname(os.path.abspath(__file__)), 'ck04')] * 4 + \
                [os.path.join(os.path.dirname(os.path.abspath(__file__)), 'k93')] * 3
     obtained = [settings.ATLAS_TO_BASE_DIR[s] for s in supplied]
     assert_array_equal(obtained, expected)
Пример #14
0
 def test_eccentric_system_approximation_two(self):
     settings.configure(**APPROX_SETTINGS["approx_two"])
     ec_params = PARAMS["eccentric"].copy()
     ec_params["argument_of_periastron"] = 90 * u.deg
     bs = prepare_binary_system(ec_params)
     self.do_comparison(bs,
                        "detached.ecc.appx_two.json",
                        start_phs=-0.2,
                        stop_phs=1.2,
                        step=0.05)
 def setUp(self):
     super(BuildSpottyTemperatureTestCase, self).setUp()
     settings.configure(
         **{
             "LIMB_DARKENING_LAW":
             "linear",
             "LD_TABLES":
             op.join(op.dirname(op.abspath(__file__)), "data",
                     "light_curves", "limbdarkening")
         })
Пример #16
0
 def test_resolve_object_geometry_update(self):
     settings.configure(**{"MAX_RELATIVE_D_R_POINT": 0.1})
     rel_d_radii = np.array(
         [[0.05, 0.04, 0.02, 0.01, 0.1, 1.1, 98, 0.00001],
          [0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.12]])
     expected = np.array(
         [True, False, False, True, False, True, True, True, True],
         dtype=bool)
     obtained = dynamic.resolve_object_geometry_update(
         False, rel_d_radii.shape[1] + 1, rel_d_radii)
     self.assertTrue(np.all(expected == obtained))
Пример #17
0
    def test_rv_consistency_eccentric_approx_zero(self):
        # reload_modules()
        settings.configure(**{
            "POINTS_ON_ECC_ORBIT": -1,
            "MAX_RELATIVE_D_R_POINT": 0.0
        })

        phases = np.array([0.15, 0.2, 0.25, 0.3, 0.4, 0.7, 0.75, 0.8, 0.85])
        binary_kwargs = copy(BINARY_SYSTEM_PARAMS["detached-physical"])
        binary_kwargs['inclination'] = 70.0 * u.deg
        binary_kwargs['eccentricity'] = 0.3
        self.check_consistency(binary_kwargs, 0.005, phases=phases)
Пример #18
0
    def test_circulcar_spotty_async_lc(self):
        settings.configure(**{"MAX_SPOT_D_LONGITUDE": up.pi / 45.0})

        # write config for stupid windows multiprocessing
        with open(self.CONFIG_FILE, "a") as f:
            f.write(f"[computational]"
                    f"\nmax_spot_d_longitude={settings.MAX_SPOT_D_LONGITUDE}"
                    f"\n")

        bs = prepare_binary_system(PARAMS["detached-async"],
                                   spots_primary=SPOTS_META["primary"])
        self.do_comparison(bs)
Пример #19
0
    def setUp(self):
        super(CompareSingleVsMultiprocess, self).setUp()
        self.lc_base_path = op.join(op.dirname(op.abspath(__file__)), "data",
                                    "light_curves")

        settings.configure(
            **{
                "LD_TABLES": op.join(self.lc_base_path, "limbdarkening"),
                "CK04_ATM_TABLES": op.join(self.lc_base_path, "atmosphere")
            })
        self.write_default_support(ld_tables=settings.LD_TABLES,
                                   atm_tables=settings.CK04_ATM_TABLES)
Пример #20
0
    def setUp(self):
        super(ComputeLightCurvesTestCase, self).setUp()
        self.base_path = op.join(op.dirname(op.abspath(__file__)), "data",
                                 "light_curves")

        settings.configure(
            **{
                "LD_TABLES": op.join(self.base_path, "limbdarkening"),
                "CK04_ATM_TABLES": op.join(self.base_path, "atmosphere"),
                "ATM_ATLAS": "ck04",
                "LIMB_DARKENING_LAW": "linear"
            })
Пример #21
0
    def test_eccentric_system_approximation_two(self):
        settings.configure(**APPROX_SETTINGS["approx_two"])
        settings.configure(**{"MAX_RELATIVE_D_R_POINT": 0.0})

        with open(self.CONFIG_FILE, "a") as f:
            f.write(
                f"[computational]"
                f"\nmax_supplementar_d_distance={settings.MAX_SUPPLEMENTAR_D_DISTANCE}"
                f"\npoints_on_ecc_orbit={settings.POINTS_ON_ECC_ORBIT}"
                f"\nmax_relative_d_r_point={settings.MAX_RELATIVE_D_R_POINT}"
                f"\n")
        bs = prepare_binary_system(PARAMS["eccentric"])
        self.do_comparison(bs, start_phs=-0.2, stop_phs=1.2, step=0.1)
Пример #22
0
    def test_get_ld_table_by_name(self):
        settings.configure(
            **{"LD_TABLES": os.path.join(self.base_path, "data", "vh93")})
        filenames = ["lin.Generic.Bessell.B.m02.csv", "log.Kepler.m40.csv"]

        expected = self.expected_ld_tables()
        obtained = [ld.get_ld_table_by_name(file) for file in filenames]

        for e, o in zip(expected, obtained):
            assert_frame_equal(e,
                               o,
                               check_less_precise=True,
                               check_dtype=False,
                               check_exact=True)
Пример #23
0
    def test_get_ld_table_by_name_same_as_get_ld_table(self):
        settings.configure(
            **{"LD_TABLES": os.path.join(self.base_path, "data", "vh93")})
        params = [
            dict(passband="Generic.Bessell.B", metallicity=-0.2, law="cosine"),
            dict(passband="Kepler", metallicity=-4, law="logarithmic")
        ]
        filenames = ["lin.Generic.Bessell.B.m02.csv", "log.Kepler.m40.csv"]

        obtained_by_params = [ld.get_ld_table(**param) for param in params]
        obtained_by_filename = [
            ld.get_ld_table_by_name(file) for file in filenames
        ]

        for o1, o2 in zip(obtained_by_filename, obtained_by_params):
            assert_frame_equal(o1, o2)
Пример #24
0
    def test_visible_indices_when_darkside_filter_apply(self):
        settings.configure(
            **{
                "LD_TABLES": op.join(self.lc_base_path, "limbdarkening"),
                "CK04_ATM_TABLES": op.join(self.lc_base_path, "atmosphere")
            })

        bs = prepare_binary_system(BINARY_SYSTEM_PARAMS['detached-physical'])
        from_this = dict(binary_system=bs,
                         position=const.Position(0, 1.0, 0.0, 0.0, 0.0))
        system = OrbitalPositionContainer.from_binary_system(**from_this)
        system.build(components_distance=1.0)
        system.calculate_face_angles(line_of_sight=const.LINE_OF_SIGHT)
        system.apply_darkside_filter()
        self.assertTrue((not is_empty(system.primary.indices))
                        and (not is_empty(system.secondary.indices)))
    def generator_test_temperatures(self, key, allowed_range=None):

        settings.configure(
            **{
                "LIMB_DARKENING_LAW":
                "linear",
                "LD_TABLES":
                op.join(op.dirname(op.abspath(__file__)), "data",
                        "light_curves", "limbdarkening")
            })

        s = testutils.prepare_binary_system(
            testutils.BINARY_SYSTEM_PARAMS[key])
        s.primary.discretization_factor = up.radians(10)
        s.secondary.discretization_factor = up.radians(10)
        orbital_position_container = testutils.prepare_orbital_position_container(
            s)
        orbital_position_container.build_mesh(components_distance=1.0)
        orbital_position_container.build_faces(components_distance=1.0)
        orbital_position_container.build_surface_areas()
        orbital_position_container.build_surface_gravity(
            components_distance=1.0)
        orbital_position_container.build_faces_orientation(
            components_distance=1.0)
        orbital_position_container.build_temperature_distribution(
            components_distance=1.0)

        print()
        i = np.argsort(orbital_position_container.secondary.temperatures)
        print(orbital_position_container.secondary.points[
            orbital_position_container.secondary.faces[i[:10]]])

        print()
        if allowed_range:
            obtained_primary = [
                np.min(orbital_position_container.primary.temperatures),
                np.max(orbital_position_container.primary.temperatures)
            ]
            obtained_secondary = [
                np.min(orbital_position_container.secondary.temperatures),
                np.max(orbital_position_container.secondary.temperatures)
            ]

            self.assertTrue((obtained_primary[0] >= allowed_range[0][0])
                            & (obtained_primary[1] <= allowed_range[0][1]))
            self.assertTrue((obtained_secondary[0] >= allowed_range[1][0])
                            & (obtained_secondary[1] <= allowed_range[1][1]))
Пример #26
0
    def test_get_ld_table(self):
        settings.configure(
            LD_TABLES=os.path.join(self.base_path, "data", "vh93"))
        params = [
            dict(passband="Generic.Bessell.B", metallicity=-0.2, law="cosine"),
            dict(passband="Kepler", metallicity=-4, law="logarithmic")
        ]

        expected = self.expected_ld_tables()
        obtained = [ld.get_ld_table(**param) for param in params]

        for e, o in zip(expected, obtained):
            assert_frame_equal(e,
                               o,
                               check_less_precise=True,
                               check_dtype=False,
                               check_exact=True)
Пример #27
0
    def test_resolve_spots_geometry_update():
        settings.configure(**{"MAX_SPOT_D_LONGITUDE": 0.06})
        spots_longitudes = {
            'primary': {
                0: np.array([0.5, 0.55, 0.6, 0.75, 0.76, 0.77]),
                1: np.array([0.5, 0.55, 0.6, 0.75, 0.76, 0.77]) - 0.1
            },
            'secondary': {}
        }

        pulsation_tests = {'primary': False, 'secondary': False}
        obtained = np.array(dynamic.resolve_spots_geometry_update(
            spots_longitudes, 6, pulsation_tests),
                            dtype=bool)
        expected = np.array(
            [[True, False, True, True, False, False], [True] + [False] * 5],
            dtype=bool)
        assert_array_equal(expected, obtained)
Пример #28
0
    def test_interpolate_on_ld_grid_lin(self):
        settings.configure(
            **{
                "LIMB_DARKENING_LAW": "cosine",
                "LD_TABLES": os.path.join(self.base_path, "data", "ld_grid")
            })
        temperature = np.array([5500, 5561, 5582, 5932])
        log_g = np.array([4.2, 4.21, 4.223, 4.199]) - 2.0
        metallicity = -0.1
        passband = ["Generic.Bessell.B"]

        expected = np.array([0.7732, 0.76364, 0.76032, 0.70833])

        obtained = ld.interpolate_on_ld_grid(temperature, log_g, metallicity,
                                             passband)
        obtained = np.round(obtained["Generic.Bessell.B"].xlin.values, 5)

        self.assertTrue(np.all(obtained - expected) < 1e-5)
Пример #29
0
    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)
Пример #30
0
    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))