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))
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))
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)
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))
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))