From 4fdecc1aefcbd66906acc369355f2277669a2018 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 23 Jan 2024 09:50:42 -0500 Subject: [PATCH] update tests for changes to pytest (#820) * Fixing up all pytests The new pytest version raises an error instead of warning when tests return a value, and when assert is used incorrectly. All tests have been touched up to not have issues with the latest pytest. * Update f-string to be compatible with python 3.7 f-string format f'{var=}' has been introduced in python 3.8, and it caused the 3.7 tests to fail. This fixes that issue. --------- Co-authored-by: Andrej Prsa --- .../test_import.py | 58 ++--- tests/tests/test_blackbody/test_blackbody.py | 18 +- .../test_cached_bundles.py | 3 + tests/tests/test_cbs/test_cbs.py | 16 +- tests/tests/test_checks/test_checks.py | 38 +-- .../test_constraints/test_constraints.py | 82 +++--- .../test_constructors/test_constructors.py | 3 +- tests/tests/test_contacts/test_neck.py | 27 +- .../tests/test_contacts/test_omega_at_vol.py | 35 ++- tests/tests/test_contacts/test_vol.py | 29 +-- .../test_distortion_method_none.py | 7 +- tests/tests/test_dpdt/test_dpdt.py | 13 +- tests/tests/test_dperdt/test_dperdt.py | 12 +- tests/tests/test_dynamics/test_dynamics.py | 78 +++--- .../tests/test_dynamics/test_dynamics_grid.py | 80 +++--- tests/tests/test_ecc/test_ecc.py | 15 +- .../tests/test_extinction/text_extinction.py | 7 +- .../test_forbidden_parameters.py | 17 +- tests/tests/test_fti/test_fti.py | 11 +- tests/tests/test_gravb/test_gravb.py | 12 +- tests/tests/test_hierarchy/test_hierarchy.py | 6 +- .../test_interp_value/test_interp_value.py | 7 +- .../test_jktebop_agreement.py | 46 ++-- tests/tests/test_l3/test_l3.py | 20 +- tests/tests/test_latexrepr/test_latexrepr.py | 6 +- tests/tests/test_ld/test_ld.py | 35 +-- .../test_legacy_export_import.py | 29 +-- .../test_legacy_parser/test_legacy_parser.py | 130 +++++----- tests/tests/test_limits/test_limits.py | 14 +- .../test_line_profile/test_line_profile.py | 9 +- .../tests/test_mesh/test_marching_meshing.py | 239 ++++++++---------- tests/tests/test_mesh/test_mesh.py | 29 +-- .../tests/test_misaligned/test_misaligned.py | 8 +- .../test_misaligned_area_volume.py | 32 +-- tests/tests/test_mpi/test_mpi.py | 15 +- tests/tests/test_mpi/test_mpi_detach.py | 14 +- .../test_pblum_scale/test_pblum_scale.py | 8 +- .../tests/test_reflection/test_reflection.py | 52 ++-- tests/tests/test_rm/test_rm.py | 1 - tests/tests/test_rvgrav/test_rvgrav.py | 5 +- tests/tests/test_rvs/test_rvs.py | 20 +- tests/tests/test_single/test_single.py | 26 +- tests/tests/test_spots/test_spots.py | 13 +- tests/tests/test_sun_earth/test_sun_earth.py | 105 ++++---- tests/tests/test_t0s/test_t0s.py | 25 +- tests/travis/phoebe.config | 17 -- 46 files changed, 665 insertions(+), 807 deletions(-) delete mode 100644 tests/travis/phoebe.config diff --git a/tests/tests/test_backward_compatibility/test_import.py b/tests/tests/test_backward_compatibility/test_import.py index e3f2a7536..405dd9c52 100644 --- a/tests/tests/test_backward_compatibility/test_import.py +++ b/tests/tests/test_backward_compatibility/test_import.py @@ -17,16 +17,14 @@ def _export_21(filename, plot=False): be imported later """ - if parse(phoebe.__version__) >= parse("2.2"): - raise ImportError("script runs on PHOEBE 2.1.x") - exit() + raise ImportError("script runs on PHOEBE 2.1.x") b = phoebe.default_binary() # TESS:default was renamed to TESS:T in 2.2 - b.add_dataset('lc', times=np.linspace(0,1,11), passband='TESS:default') - b.add_dataset('rv', times=phoebe.linspace(0,1,4)) - b.add_dataset('lp', times=phoebe.linspace(0,1,4), wavelengths=np.linspace(500,510,51)) + b.add_dataset('lc', times=np.linspace(0, 1, 11), passband='TESS:default') + b.add_dataset('rv', times=phoebe.linspace(0, 1, 4)) + b.add_dataset('lp', times=phoebe.linspace(0, 1, 4), wavelengths=np.linspace(500, 510, 51)) b.add_dataset('mesh', times=[0]) b.run_compute() @@ -36,6 +34,7 @@ def _export_21(filename, plot=False): b.save(os.path.join(dir, filename)) + def _export_22(filename, plot=False): """ this isn't run during testing, but should be edited to run on certain versions @@ -43,16 +42,14 @@ def _export_22(filename, plot=False): be imported later """ - if parse(phoebe.__version__) >= parse("2.3"): - raise ImportError("script runs on PHOEBE 2.2.x") - exit() + raise ImportError("script runs on PHOEBE 2.2.x") b = phoebe.default_binary() - b.add_dataset('lc', times=np.linspace(0,1,11), passband='Johnson:V', Av=0.1) - b.add_dataset('lc', times=np.linspace(0,1,11), passband='Johnson:R', Av=0.2) - b.add_dataset('rv', times=phoebe.linspace(0,1,4)) - b.add_dataset('lp', times=phoebe.linspace(0,1,4), wavelengths=np.linspace(500,510,51)) + b.add_dataset('lc', times=np.linspace(0, 1, 11), passband='Johnson:V', Av=0.1) + b.add_dataset('lc', times=np.linspace(0, 1, 11), passband='Johnson:R', Av=0.2) + b.add_dataset('rv', times=phoebe.linspace(0, 1, 4)) + b.add_dataset('lp', times=phoebe.linspace(0, 1, 4), wavelengths=np.linspace(500, 510, 51)) b.add_dataset('mesh', times=[0]) b.run_compute() @@ -62,6 +59,7 @@ def _export_22(filename, plot=False): b.save(os.path.join(dir, filename)) + def _export_23(filename, plot=False): """ this isn't run during testing, but should be edited to run on certain versions @@ -69,16 +67,14 @@ def _export_23(filename, plot=False): be imported later """ - if parse(phoebe.__version__) >= parse("2.4"): - raise ImportError("script runs on PHOEBE 2.3.x") - exit() + raise ImportError("script runs on PHOEBE 2.3.x") b = phoebe.default_binary() - b.add_dataset('lc', times=np.linspace(0,1,11), passband='Johnson:V', Av=0.1) - b.add_dataset('lc', times=np.linspace(0,1,11), passband='Johnson:R', Av=0.2) - b.add_dataset('rv', times=phoebe.linspace(0,1,4)) - b.add_dataset('lp', times=phoebe.linspace(0,1,4), wavelengths=np.linspace(500,510,51)) + b.add_dataset('lc', times=np.linspace(0, 1, 11), passband='Johnson:V', Av=0.1) + b.add_dataset('lc', times=np.linspace(0, 1, 11), passband='Johnson:R', Av=0.2) + b.add_dataset('rv', times=phoebe.linspace(0, 1, 4)) + b.add_dataset('lp', times=phoebe.linspace(0, 1, 4), wavelengths=np.linspace(500, 510, 51)) b.add_dataset('mesh', times=[0]) b.run_compute() @@ -101,7 +97,6 @@ def test_21(verbose=False, plot=False): if plot: b.plot(show=True, time=0) - return b def test_22(verbose=False, plot=False): b = phoebe.load(os.path.join(dir, '22_export.phoebe')) @@ -110,7 +105,6 @@ def test_22(verbose=False, plot=False): if plot: b.plot(show=True, time=0) - return b def test_23(verbose=False, plot=False): b = phoebe.load(os.path.join(dir, '23_export.phoebe')) @@ -123,20 +117,20 @@ def test_23(verbose=False, plot=False): if plot: b.plot(show=True, time=0) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='WARNING') - # if parse(phoebe.__version__) >= parse("2.1.0") and parse(phoebe.__version__) < parse("2.2.0"): - # _export_21('21_export.phoebe') - # exit() - # if parse(phoebe.__version__) >= parse("2.2.0") and parse(phoebe.__version__) < parse("2.3.0"): - # _export_22('22_export.phoebe') - # exit() - # if parse(phoebe.__version__) >= parse("2.3.0") and parse(phoebe.__version__) < parse("2.4.0"): - # _export_23('23_export.phoebe') - # exit() + if False: + if parse(phoebe.__version__) >= parse("2.1.0") and parse(phoebe.__version__) < parse("2.2.0"): + _export_21('21_export.phoebe') + exit() + if parse(phoebe.__version__) >= parse("2.2.0") and parse(phoebe.__version__) < parse("2.3.0"): + _export_22('22_export.phoebe') + exit() + if parse(phoebe.__version__) >= parse("2.3.0") and parse(phoebe.__version__) < parse("2.4.0"): + _export_23('23_export.phoebe') + exit() b = test_21(verbose=True, plot=True) b = test_22(verbose=True, plot=True) diff --git a/tests/tests/test_blackbody/test_blackbody.py b/tests/tests/test_blackbody/test_blackbody.py index cb9b60ba0..8c7c0ad06 100644 --- a/tests/tests/test_blackbody/test_blackbody.py +++ b/tests/tests/test_blackbody/test_blackbody.py @@ -14,7 +14,7 @@ def test_binary(plot=False, gen_comp=False): b.set_value('sma', component='binary', value=100.) b.set_value('period', component='binary', value=81.955) - b.add_dataset('lc', times=np.linspace(0,100,21)) + b.add_dataset('lc', times=np.linspace(0, 100, 21)) b.add_compute('phoebe', compute='phoebe2') if gen_comp: b.add_compute('legacy', compute='phoebe1') @@ -31,31 +31,29 @@ def test_binary(plot=False, gen_comp=False): b.set_value_all('ld_func', 'linear') b.set_value_all('ld_coeffs', [0.0]) - #turn off albedos (legacy requirement) + # turn off albedos (legacy requirement): b.set_value_all('irrad_frac_refl_bol', 0.0) - if plot: print("running phoebe2 model...") + if plot: + print("running phoebe2 model...") b.run_compute(compute='phoebe2', irrad_method='none', model='phoebe2model') if gen_comp: - if plot: print("running phoebe1 model...") + if plot: + print("running phoebe1 model...") b.run_compute(compute='phoebe1', refl_num=0, model='phoebe1model') b.filter(model='phoebe1model').save('test_blackbody.comp.model') else: b.import_model(os.path.join(os.path.dirname(__file__), 'test_blackbody.comp.model'), model='phoebe1model') - phoebe2_val = b.get_value('fluxes@phoebe2model') phoebe1_val = b.get_value('fluxes@phoebe1model') if plot: b.plot(dataset='lc01', show=True) - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=1e-3, atol=0.)) + assert np.allclose(phoebe2_val, phoebe1_val, rtol=1e-3, atol=0.) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - - b = test_binary(plot=True, gen_comp=True) + test_binary(plot=True, gen_comp=True) diff --git a/tests/tests/test_cached_bundles/test_cached_bundles.py b/tests/tests/test_cached_bundles/test_cached_bundles.py index 6854580c3..1c9b840d0 100644 --- a/tests/tests/test_cached_bundles/test_cached_bundles.py +++ b/tests/tests/test_cached_bundles/test_cached_bundles.py @@ -7,18 +7,21 @@ def test_star(): # TODO: add comparison + def test_binary(): b1 = phoebe.default_binary(force_build=True) b2 = phoebe.default_binary() # TODO: add comparison + def test_contact_binary(): b1 = phoebe.default_binary(contact_binary=True, force_build=True) b2 = phoebe.default_binary(contact_binary=True) # TODO: add comparison + if __name__ == '__main__': logger = phoebe.logger(clevel='debug') diff --git a/tests/tests/test_cbs/test_cbs.py b/tests/tests/test_cbs/test_cbs.py index ec3950e74..150896473 100644 --- a/tests/tests/test_cbs/test_cbs.py +++ b/tests/tests/test_cbs/test_cbs.py @@ -4,7 +4,6 @@ def test_binary(plot=False, gen_comp=False): - cb = phoebe.Bundle.default_binary(contact_binary=True) cb.flip_constraint('pot', solve_for='requiv@primary') cb['pot@contact_envelope@component'] = 3.5 @@ -14,7 +13,7 @@ def test_binary(plot=False, gen_comp=False): # cb.set_value_all('incl',90.0) - times = cb.to_time(np.linspace(-.1,1.1,100)) + times = cb.to_time(np.linspace(-.1, 1.1, 100)) cb.add_dataset('lc', times=times, dataset='lc01') cb.add_dataset('rv', time=times, dataset='rv01') @@ -36,7 +35,7 @@ def test_binary(plot=False, gen_comp=False): cb.set_value_all('rv_grav', False) cb.set_value_all('ltte', False) - #turn off albedos (legacy requirement) + # turn off albedos (legacy requirement): cb.set_value_all('irrad_frac_refl_bol', 0.0) print("running phoebe2 model...") @@ -62,16 +61,15 @@ def test_binary(plot=False, gen_comp=False): cb.plot(dataset='lc01', legend=True, show=True) cb.plot(dataset='rv01', legend=True, show=True) - assert(np.allclose(phoebe2_val_lc, phoebe1_val_lc, rtol=7e-3, atol=0.)) + assert np.allclose(phoebe2_val_lc, phoebe1_val_lc, rtol=7e-3, atol=0.) # note we can't use relative tolerances because those blow up near 0, so # instead we'll fake a relative tolerance by using the amplitude of the RV curve. rv_ampl = np.max(np.abs(phoebe1_val_rv1)) rtol = 7e-3 - assert(np.allclose(phoebe2_val_rv1, phoebe1_val_rv1, rtol=0., atol=rtol*rv_ampl)) - assert(np.allclose(phoebe2_val_rv2, phoebe1_val_rv2, rtol=0., atol=rtol*rv_ampl)) - return cb + assert np.allclose(phoebe2_val_rv1, phoebe1_val_rv1, rtol=0., atol=rtol*rv_ampl) + assert np.allclose(phoebe2_val_rv2, phoebe1_val_rv2, rtol=0., atol=rtol*rv_ampl) + if __name__ == '__main__': logger = phoebe.logger(clevel='debug') - - cb = test_binary(plot=True, gen_comp=True) + test_binary(plot=True, gen_comp=True) diff --git a/tests/tests/test_checks/test_checks.py b/tests/tests/test_checks/test_checks.py index 4b4621f8f..496b414a7 100644 --- a/tests/tests/test_checks/test_checks.py +++ b/tests/tests/test_checks/test_checks.py @@ -3,74 +3,60 @@ import phoebe - phoebe.logger('DEBUG') + def test_checks(): b = phoebe.Bundle.default_binary() - - b.add_dataset('lc') # test overflow report = b.run_checks() - if not report.passed: - raise AssertionError(msg) + assert report.passed b.set_value('requiv', component='primary', value=9.0) report = b.run_checks() - if report.passed: - raise AssertionError + assert not report.passed b.set_value('requiv', component='primary', value=1.0) # TODO: test overlap scenario - # test ld_func vs ld_coeffs report = b.run_checks() - if not report.passed: - raise AssertionError(msg) + assert report.passed b.set_value_all('ld_mode_bol', 'manual') b.set_value('ld_coeffs_bol', component='primary', value=[0.]) report = b.run_checks() - if report.passed: - raise AssertionError - b.set_value('ld_coeffs_bol', component='primary', value=[0.5, 0.5]) + assert not report.passed + b.set_value('ld_coeffs_bol', component='primary', value=[0.5, 0.5]) b.set_value('ld_mode', component='primary', value='manual') b.set_value('ld_func', component='primary', value='logarithmic') b.set_value('ld_coeffs', component='primary', value=[0.]) report = b.run_checks() - if report.passed: - raise AssertionError + assert not report.passed + b.set_value('ld_coeffs', component='primary', value=[0., 0.]) b.set_value('ld_mode', component='primary', value='interp') # test ld_func vs atm report = b.run_checks() - if not report.passed: - raise AssertionError(msg) + assert report.passed b.set_value('atm', component='primary', value='blackbody') report = b.run_checks() - if report.passed: - raise AssertionError + assert not report.passed b.set_value('atm', component='primary', value='ck2004') - # test gravb vs teff warning b.set_value('teff', component='primary', value=6000) b.set_value('gravb_bol', component='primary', value=1.0) report = b.run_checks() - if not report.passed or not len(report.items): - raise AssertionError + assert report.passed and len(report.items) > 0 - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - - b = test_checks() + test_checks() diff --git a/tests/tests/test_constraints/test_constraints.py b/tests/tests/test_constraints/test_constraints.py index 0a2feac47..5658080a8 100644 --- a/tests/tests/test_constraints/test_constraints.py +++ b/tests/tests/test_constraints/test_constraints.py @@ -4,68 +4,80 @@ import phoebe import pytest + def test_esinw_ecosw(verbose=False): - if verbose: print("b=phoebe.default_binary()") + if verbose: + print("b = phoebe.default_binary()") b = phoebe.default_binary() - if verbose: print("b.set_value('ecc', 0.5)") + if verbose: + print("b.set_value('ecc', 0.5)") b.set_value('ecc', 0.5) - if verbose: print(b.filter(qualifier=['ecosw', 'esinw', 'ecc', 'per0'])) + if verbose: + print(b.filter(qualifier=['ecosw', 'esinw', 'ecc', 'per0'])) - assert(b.get_value('ecosw', context='component')==0.5) - assert(b.get_value('esinw', context='component')==0.0) - assert(b.run_checks().passed) + assert b.get_value('ecosw', context='component') == 0.5 + assert b.get_value('esinw', context='component') == 0.0 + assert b.run_checks().passed - if verbose: print("b.flip_constraint('esinw', solve_for='ecc')") + if verbose: + print("b.flip_constraint('esinw', solve_for='ecc')") b.flip_constraint('esinw', solve_for='ecc') - if verbose: print(b.filter(qualifier=['ecosw', 'esinw', 'ecc', 'per0'])) + if verbose: + print(b.filter(qualifier=['ecosw', 'esinw', 'ecc', 'per0'])) - assert(b.run_checks().passed==False) - with pytest.raises(ValueError) as e_info: + assert not b.run_checks().passed + with pytest.raises(ValueError): b.run_compute() - if verbose: print("b.set_value('per0', 10)") + if verbose: + print("b.set_value('per0', 10)") b.set_value('per0', 10) - if verbose: print(b.filter(qualifier=['ecosw', 'esinw', 'ecc', 'per0'])) - - assert(b.run_checks().passed) + if verbose: + print(b.filter(qualifier=['ecosw', 'esinw', 'ecc', 'per0'])) - assert(b.get_value('ecc', context='component')==0) + assert b.run_checks().passed + assert b.get_value('ecc', context='component') == 0 - if verbose: print(b.set_value('per0', 0.0)) + if verbose: + print(b.set_value('per0', 0.0)) b.set_value('per0', 0.0) - if verbose: print(b.filter(qualifier=['ecosw', 'esinw', 'ecc', 'per0'])) + if verbose: + print(b.filter(qualifier=['ecosw', 'esinw', 'ecc', 'per0'])) - assert(b.run_checks().passed==False) + assert not b.run_checks().passed - if verbose: print("b.flip_constraint('ecosw', solve_for='per0')") + if verbose: + print("b.flip_constraint('ecosw', solve_for='per0')") b.flip_constraint('ecosw', solve_for='per0') - if verbose: print(b.filter(qualifier=['ecosw', 'esinw', 'ecc', 'per0'])) + if verbose: + print(b.filter(qualifier=['ecosw', 'esinw', 'ecc', 'per0'])) - assert(b.run_checks().passed) - assert(b.get_value('ecc', context='component')==0.0) - assert(b.get_value('per0', context='component')==0.0) + assert b.run_checks().passed + assert b.get_value('ecc', context='component') == 0.0 + assert b.get_value('per0', context='component') == 0.0 - if verbose: print("b.set_value('ecosw', 0.5)") + if verbose: + print("b.set_value('ecosw', 0.5)") b.set_value('ecosw', 0.5) - assert(b.run_checks().passed) - - if verbose: print(b.filter(qualifier=['ecosw', 'esinw', 'ecc', 'per0'])) + assert b.run_checks().passed - assert(b.get_value('per0', context='component')==0.0) - assert(b.get_value('ecc', context='component')==0.5) + if verbose: + print(b.filter(qualifier=['ecosw', 'esinw', 'ecc', 'per0'])) + assert b.get_value('per0', context='component') == 0.0 + assert b.get_value('ecc', context='component') == 0.5 - return b def test_pot_filloutfactor(verbose=False): - if verbose: print("b=phoebe.default_binary(contact_binary=True)") + if verbose: + print("b=phoebe.default_binary(contact_binary=True)") b = phoebe.default_binary(contact_binary=True) b.flip_constraint('pot', solve_for='requiv@primary') @@ -74,11 +86,11 @@ def test_pot_filloutfactor(verbose=False): b.set_value('fillout_factor', 0.45) b.set_value('q', 0.25) - assert(b.run_checks().passed) + assert b.run_checks().passed + if __name__ == '__main__': logger = phoebe.logger(clevel='WARNING') - b = test_esinw_ecosw(verbose=True) - - b = test_pot_filloutfactor(verbose=True) + test_esinw_ecosw(verbose=True) + test_pot_filloutfactor(verbose=True) diff --git a/tests/tests/test_constructors/test_constructors.py b/tests/tests/test_constructors/test_constructors.py index a9d2882bc..1ab3025f6 100644 --- a/tests/tests/test_constructors/test_constructors.py +++ b/tests/tests/test_constructors/test_constructors.py @@ -3,6 +3,7 @@ import phoebe + def test_all(): print("phoebe.Bundle() ...") b = phoebe.Bundle() @@ -15,7 +16,7 @@ def test_all(): # b = phoebe.default_triple(inner_as_primary=True) # b = phoebe.default_triple(inner_as_primary=False) + if __name__ == '__main__': logger = phoebe.logger(clevel='WARNING') - test_all() diff --git a/tests/tests/test_contacts/test_neck.py b/tests/tests/test_contacts/test_neck.py index 312541fa8..c4af18daf 100644 --- a/tests/tests/test_contacts/test_neck.py +++ b/tests/tests/test_contacts/test_neck.py @@ -4,24 +4,25 @@ import numpy as np import libphoebe + def test_contact_neck(plot=False): - q=0.1 - d=1. - Omega0 = 1.9 + q = 0.1 + d = 1. + Omega0 = 1.9 - neck_xy = libphoebe.roche_contact_neck_min(0., q, d, Omega0) - neck_xz = libphoebe.roche_contact_neck_min(np.pi/2., q, d, Omega0) + neck_xy = libphoebe.roche_contact_neck_min(0., q, d, Omega0) + neck_xz = libphoebe.roche_contact_neck_min(np.pi/2., q, d, Omega0) - neck_xy0 = {'xmin': 0.742892957853368, 'rmin': 0.14601804638933566} - neck_xz0 = {'xmin': 0.7383492639142092, 'rmin': 0.13255145166593718} + neck_xy0 = {'xmin': 0.742892957853368, 'rmin': 0.14601804638933566} + neck_xz0 = {'xmin': 0.7383492639142092, 'rmin': 0.13255145166593718} - assert(abs(neck_xy['xmin'] - neck_xy0['xmin']) < 1e-12*neck_xy0['xmin']) - assert(abs(neck_xz['xmin'] - neck_xz0['xmin']) < 1e-12*neck_xz0['xmin']) + assert abs(neck_xy['xmin'] - neck_xy0['xmin']) < 1e-12*neck_xy0['xmin'] + assert abs(neck_xz['xmin'] - neck_xz0['xmin']) < 1e-12*neck_xz0['xmin'] - if plot: - print("neck_xy={}".format(neck_xy)) - print("neck_xz={}".format(neck_xz)) + if plot: + print("neck_xy={}".format(neck_xy)) + print("neck_xz={}".format(neck_xz)) -if __name__ == '__main__': +if __name__ == '__main__': test_contact_neck(plot=True) diff --git a/tests/tests/test_contacts/test_omega_at_vol.py b/tests/tests/test_contacts/test_omega_at_vol.py index ca321aec1..842f88d1f 100644 --- a/tests/tests/test_contacts/test_omega_at_vol.py +++ b/tests/tests/test_contacts/test_omega_at_vol.py @@ -5,31 +5,30 @@ import numpy as np import libphoebe + def test_contact_omega_at_vol(plot=False): - q = 0.1 - d = 1. - Omega0 = 1.9 - phi = np.pi/2 + q = 0.1 + d = 1. + Omega0 = 1.9 + phi = np.pi/2 - neck = libphoebe.roche_contact_neck_min(phi, q, d, Omega0) + neck = libphoebe.roche_contact_neck_min(phi, q, d, Omega0) - x = neck["xmin"] # where we cut it - choice = 0 # 0 for left and 1 for right + x = neck["xmin"] # where we cut it + choice = 0 # 0 for left and 1 for right - pvol = libphoebe.roche_contact_partial_area_volume(x, q, d, Omega0, choice=choice) + pvol = libphoebe.roche_contact_partial_area_volume(x, q, d, Omega0, choice=choice) + vol = pvol['lvolume'] - vol= pvol['lvolume'] + Omega1 = libphoebe.roche_contact_Omega_at_partial_vol(vol, phi, q, d, choice=choice) - Omega1 = libphoebe.roche_contact_Omega_at_partial_vol(vol, phi, q, d, choice=choice) + assert abs(Omega0 - Omega1) < 1e-12*Omega0 - assert(abs(Omega0 - Omega1) < 1e-12*Omega0) + if plot: + print("neck=", neck) + print("pvol=", pvol) + print("Omega0={}, Omega1={}".format(Omega0, Omega1)) - if plot: - print("neck=",neck) - print("pvol=", pvol) - print("Omega0={}, Omega1={}".format(Omega0, Omega1)) if __name__ == '__main__': - - test_contact_omega_at_vol(plot=True) - + test_contact_omega_at_vol(plot=True) diff --git a/tests/tests/test_contacts/test_vol.py b/tests/tests/test_contacts/test_vol.py index c2ea26aef..df88e94ee 100644 --- a/tests/tests/test_contacts/test_vol.py +++ b/tests/tests/test_contacts/test_vol.py @@ -3,26 +3,25 @@ """ import libphoebe -def test_contact_vol(plot=False): - x=0.7 # where we cut it - choice = 0 # 0 for left and 1 for right - q=0.1 - Omega0=1.9 - d=1. +def test_contact_vol(plot=False): + x = 0.7 # where we cut it + choice = 0 # 0 for left and 1 for right + q = 0.1 + Omega0 = 1.9 + d = 1. - res = libphoebe.roche_contact_partial_area_volume(x, q, d, Omega0, choice) + res = libphoebe.roche_contact_partial_area_volume(x, q, d, Omega0, choice) - larea0 = 4.587028506379938 - lvolume0 = 0.9331872042603445 + larea0 = 4.587028506379938 + lvolume0 = 0.9331872042603445 - assert(abs(res['larea'] - larea0) < 1e-10*larea0) - assert(abs(res['lvolume']- lvolume0) < 1e-10*lvolume0) + assert abs(res['larea'] - larea0) < 1e-10*larea0 + assert abs(res['lvolume'] - lvolume0) < 1e-10*lvolume0 - if plot: - print ("results={}".format(res)) + if plot: + print(f'res={res}') if __name__ == '__main__': - - test_contact_vol(plot=True) + test_contact_vol(plot=True) diff --git a/tests/tests/test_distortion_method_none/test_distortion_method_none.py b/tests/tests/test_distortion_method_none/test_distortion_method_none.py index 8d6232f17..d77293aa0 100644 --- a/tests/tests/test_distortion_method_none/test_distortion_method_none.py +++ b/tests/tests/test_distortion_method_none/test_distortion_method_none.py @@ -5,8 +5,6 @@ def test_binary(plot=False): - - b = phoebe.Bundle.default_binary() b.add_dataset('lc', times=[0]) b.add_dataset('lp', times=[0]) @@ -21,10 +19,7 @@ def test_binary(plot=False): b.run_compute() - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - - b = test_binary(plot=True) + test_binary(plot=True) diff --git a/tests/tests/test_dpdt/test_dpdt.py b/tests/tests/test_dpdt/test_dpdt.py index 310caab35..5b3a8f7cb 100644 --- a/tests/tests/test_dpdt/test_dpdt.py +++ b/tests/tests/test_dpdt/test_dpdt.py @@ -10,7 +10,7 @@ def test_binary(plot=False, gen_comp=False): b = phoebe.Bundle.default_binary() period = b.get_value('period@binary') - b.add_dataset('lc', times=np.linspace(0,period,21)) + b.add_dataset('lc', times=np.linspace(0, period, 21)) b.add_compute('phoebe', irrad_method='none', compute='phoebe2') b.add_compute('legacy', refl_num=0, compute='phoebe1') @@ -27,13 +27,12 @@ def test_binary(plot=False, gen_comp=False): b.set_value_all('ld_coeffs', [0.0]) # b.set_value_all('ecc', 0.2) - #turn off albedos (legacy requirement) + # turn off albedos (legacy requirement) b.set_value_all('irrad_frac_refl_bol', 0.0) for dpdt in [-0.5, -0.25, 0.25, 0.5]: b.set_value('dpdt', dpdt) - print("running phoebe2 model...") b.run_compute(compute='phoebe2', model='phoebe2model', overwrite=True) if gen_comp: @@ -48,15 +47,11 @@ def test_binary(plot=False, gen_comp=False): if plot: b.plot(dataset='lc01', show=True) - print("max (rel):", abs((phoebe2_val-phoebe1_val)/phoebe1_val).max()) - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=5e-3, atol=0.)) + assert np.allclose(phoebe2_val, phoebe1_val, rtol=5e-3, atol=0.) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - - b = test_binary(plot=True, gen_comp=True) + test_binary(plot=True, gen_comp=True) diff --git a/tests/tests/test_dperdt/test_dperdt.py b/tests/tests/test_dperdt/test_dperdt.py index cb7720fac..61b98ec4b 100644 --- a/tests/tests/test_dperdt/test_dperdt.py +++ b/tests/tests/test_dperdt/test_dperdt.py @@ -10,7 +10,7 @@ def test_binary(plot=False, gen_comp=False): b = phoebe.Bundle.default_binary() period = b.get_value('period@binary') - b.add_dataset('lc', times=np.linspace(0,period,21)) + b.add_dataset('lc', times=np.linspace(0, period, 21)) b.add_compute('phoebe', irrad_method='none', compute='phoebe2') if gen_comp: b.add_compute('legacy', refl_num=0, compute='phoebe1') @@ -28,7 +28,7 @@ def test_binary(plot=False, gen_comp=False): b.set_value_all('ld_coeffs', [0.0]) b.set_value_all('ecc', 0.2) - #turn off albedos (legacy requirement) + # turn off albedos (legacy requirement) b.set_value_all('irrad_frac_refl_bol', 0.0) for dperdt in [-0.5, -0.25, 0.25, 0.5]: @@ -48,15 +48,11 @@ def test_binary(plot=False, gen_comp=False): if plot: b.plot(dataset='lc01', show=True) - print("max (rel):", abs((phoebe2_val-phoebe1_val)/phoebe1_val).max()) - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=5e-3, atol=0.)) + assert np.allclose(phoebe2_val, phoebe1_val, rtol=5e-3, atol=0.) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - - b = test_binary(plot=True, gen_comp=True) + test_binary(plot=True, gen_comp=True) diff --git a/tests/tests/test_dynamics/test_dynamics.py b/tests/tests/test_dynamics/test_dynamics.py index d6eea256c..01621c2cd 100644 --- a/tests/tests/test_dynamics/test_dynamics.py +++ b/tests/tests/test_dynamics/test_dynamics.py @@ -7,7 +7,7 @@ try: import matplotlib.pyplot as plt PLOTTING_ENABLED = True -except: +except ImportError: PLOTTING_ENABLED = False @@ -25,7 +25,7 @@ def _keplerian_v_nbody(b, plot=False): nb_ts, nb_us, nb_vs, nb_ws, nb_vus, nb_vvs, nb_vws = phoebe.dynamics.nbody.dynamics_from_bundle(b, times, ltte=False) k_ts, k_us, k_vs, k_ws, k_vus, k_vvs, k_vws = phoebe.dynamics.keplerian.dynamics_from_bundle(b, times) - assert(np.allclose(nb_ts, k_ts, 1e-8)) + assert np.allclose(nb_ts, k_ts, 1e-8) for ci in range(len(b.hierarchy.get_stars())): # TODO: make atol lower (currently 1e-5 solRad which is awfully big, but 1e-6 currently fails!) if plot: @@ -36,12 +36,13 @@ def _keplerian_v_nbody(b, plot=False): print("max atol vys:", nb_vvs[ci] - k_vvs[ci]) print("max atol vzs:", nb_vws[ci] - k_vws[ci]) - assert(np.allclose(nb_us[ci], k_us[ci], atol=1e-5)) - assert(np.allclose(nb_vs[ci], k_vs[ci], atol=1e-5)) - assert(np.allclose(nb_ws[ci], k_ws[ci], atol=1e-5)) - assert(np.allclose(nb_vus[ci], k_vus[ci], atol=1e-4)) - assert(np.allclose(nb_vvs[ci], k_vvs[ci], atol=1e-4)) - assert(np.allclose(nb_vws[ci], k_vws[ci], atol=1e-4)) + assert np.allclose(nb_us[ci], k_us[ci], atol=1e-5) + assert np.allclose(nb_vs[ci], k_vs[ci], atol=1e-5) + assert np.allclose(nb_ws[ci], k_ws[ci], atol=1e-5) + assert np.allclose(nb_vus[ci], k_vus[ci], atol=1e-4) + assert np.allclose(nb_vvs[ci], k_vvs[ci], atol=1e-4) + assert np.allclose(nb_vws[ci], k_vws[ci], atol=1e-4) + def _phoebe_v_photodynam(b, plot=False): """ @@ -68,7 +69,6 @@ def _phoebe_v_photodynam(b, plot=False): # TODO: look into justification of flipping x and y for both dynamics (photodynam & phoebe) # TODO: why the small discrepancy (visible especially in y, still <1e-11) - possibly a difference in time0 or just a precision limit in the photodynam backend since loading from a file?? - if PLOTTING_ENABLED and plot: for k in ['us', 'vs', 'ws', 'vus', 'vvs', 'vws']: plt.cla() @@ -80,13 +80,14 @@ def _phoebe_v_photodynam(b, plot=False): plt.ylabel(k) plt.show() - assert(np.allclose(b.get_value('times', dataset='orb01', model='phoeberesults', component=comp, unit=u.d), b.get_value('times', dataset='orb01', model='pdresults', component=comp, unit=u.d), atol=1e-6)) - assert(np.allclose(b.get_value('us', dataset='orb01', model='phoeberesults', component=comp, unit=u.AU), b.get_value('us', dataset='orb01', model='pdresults', component=comp, unit=u.AU), atol=1e-6)) - assert(np.allclose(b.get_value('vs', dataset='orb01', model='phoeberesults', component=comp, unit=u.AU), b.get_value('vs', dataset='orb01', model='pdresults', component=comp, unit=u.AU), atol=1e-6)) - assert(np.allclose(b.get_value('ws', dataset='orb01', model='phoeberesults', component=comp, unit=u.AU), b.get_value('ws', dataset='orb01', model='pdresults', component=comp, unit=u.AU), atol=1e-6)) - assert(np.allclose(b.get_value('vus', dataset='orb01', model='phoeberesults', component=comp, unit=u.solRad/u.d), b.get_value('vus', dataset='orb01', model='pdresults', component=comp, unit=u.solRad/u.d), atol=1e-6)) - assert(np.allclose(b.get_value('vvs', dataset='orb01', model='phoeberesults', component=comp, unit=u.solRad/u.d), b.get_value('vvs', dataset='orb01', model='pdresults', component=comp, unit=u.solRad/u.d), atol=1e-6)) - assert(np.allclose(b.get_value('vws', dataset='orb01', model='phoeberesults', component=comp, unit=u.solRad/u.d), b.get_value('vws', dataset='orb01', model='pdresults', component=comp, unit=u.solRad/u.d), atol=1e-6)) + assert np.allclose(b.get_value('times', dataset='orb01', model='phoeberesults', component=comp, unit=u.d), b.get_value('times', dataset='orb01', model='pdresults', component=comp, unit=u.d), atol=1e-6) + assert np.allclose(b.get_value('us', dataset='orb01', model='phoeberesults', component=comp, unit=u.AU), b.get_value('us', dataset='orb01', model='pdresults', component=comp, unit=u.AU), atol=1e-6) + assert np.allclose(b.get_value('vs', dataset='orb01', model='phoeberesults', component=comp, unit=u.AU), b.get_value('vs', dataset='orb01', model='pdresults', component=comp, unit=u.AU), atol=1e-6) + assert np.allclose(b.get_value('ws', dataset='orb01', model='phoeberesults', component=comp, unit=u.AU), b.get_value('ws', dataset='orb01', model='pdresults', component=comp, unit=u.AU), atol=1e-6) + assert np.allclose(b.get_value('vus', dataset='orb01', model='phoeberesults', component=comp, unit=u.solRad/u.d), b.get_value('vus', dataset='orb01', model='pdresults', component=comp, unit=u.solRad/u.d), atol=1e-6) + assert np.allclose(b.get_value('vvs', dataset='orb01', model='phoeberesults', component=comp, unit=u.solRad/u.d), b.get_value('vvs', dataset='orb01', model='pdresults', component=comp, unit=u.solRad/u.d), atol=1e-6) + assert np.allclose(b.get_value('vws', dataset='orb01', model='phoeberesults', component=comp, unit=u.solRad/u.d), b.get_value('vws', dataset='orb01', model='pdresults', component=comp, unit=u.solRad/u.d), atol=1e-6) + def _frontend_v_backend(b, plot=False): """ @@ -109,46 +110,39 @@ def _frontend_v_backend(b, plot=False): # do frontend Nbody b.run_compute('nbody', model='nbodyresults') - - for ci,comp in enumerate(b.hierarchy.get_stars()): + for ci, comp in enumerate(b.hierarchy.get_stars()): # TODO: can we lower tolerance? - assert(np.allclose(b.get_value('times', dataset='orb01', model='nbodyresults', component=comp, unit=u.d), b_ts, atol=1e-6)) - assert(np.allclose(b.get_value('us', dataset='orb01', model='nbodyresults', component=comp, unit=u.solRad), b_us[ci], atol=1e-5)) - assert(np.allclose(b.get_value('vs', dataset='orb01', model='nbodyresults', component=comp, unit=u.solRad), b_vs[ci], atol=1e-5)) - assert(np.allclose(b.get_value('ws', dataset='orb01', model='nbodyresults', component=comp, unit=u.solRad), b_ws[ci], atol=1e-5)) - assert(np.allclose(b.get_value('vus', dataset='orb01', model='nbodyresults', component=comp, unit=u.solRad/u.d), b_vus[ci], atol=1e-4)) - assert(np.allclose(b.get_value('vvs', dataset='orb01', model='nbodyresults', component=comp, unit=u.solRad/u.d), b_vvs[ci], atol=1e-4)) - assert(np.allclose(b.get_value('vws', dataset='orb01', model='nbodyresults', component=comp, unit=u.solRad/u.d), b_vws[ci], atol=1e-4)) - - - + assert np.allclose(b.get_value('times', dataset='orb01', model='nbodyresults', component=comp, unit=u.d), b_ts, atol=1e-6) + assert np.allclose(b.get_value('us', dataset='orb01', model='nbodyresults', component=comp, unit=u.solRad), b_us[ci], atol=1e-5) + assert np.allclose(b.get_value('vs', dataset='orb01', model='nbodyresults', component=comp, unit=u.solRad), b_vs[ci], atol=1e-5) + assert np.allclose(b.get_value('ws', dataset='orb01', model='nbodyresults', component=comp, unit=u.solRad), b_ws[ci], atol=1e-5) + assert np.allclose(b.get_value('vus', dataset='orb01', model='nbodyresults', component=comp, unit=u.solRad/u.d), b_vus[ci], atol=1e-4) + assert np.allclose(b.get_value('vvs', dataset='orb01', model='nbodyresults', component=comp, unit=u.solRad/u.d), b_vvs[ci], atol=1e-4) + assert np.allclose(b.get_value('vws', dataset='orb01', model='nbodyresults', component=comp, unit=u.solRad/u.d), b_vws[ci], atol=1e-4) # KEPLERIAN # do backend keplerian b_ts, b_xs, b_ys, b_zs, b_vxs, b_vys, b_vzs = phoebe.dynamics.keplerian.dynamics_from_bundle(b, times, compute='keplerian') - # do frontend keplerian b.run_compute('keplerian', model='keplerianresults') - # TODO: loop over components and assert - for ci,comp in enumerate(b.hierarchy.get_stars()): + for ci, comp in enumerate(b.hierarchy.get_stars()): # TODO: can we lower tolerance? - assert(np.allclose(b.get_value('times', dataset='orb01', model='keplerianresults', component=comp, unit=u.d), b_ts, atol=1e-6)) - assert(np.allclose(b.get_value('us', dataset='orb01', model='keplerianresults', component=comp, unit=u.solRad), b_us[ci], atol=1e-5)) - assert(np.allclose(b.get_value('vs', dataset='orb01', model='keplerianresults', component=comp, unit=u.solRad), b_vs[ci], atol=1e-5)) - assert(np.allclose(b.get_value('ws', dataset='orb01', model='keplerianresults', component=comp, unit=u.solRad), b_ws[ci], atol=1e-5)) - assert(np.allclose(b.get_value('vus', dataset='orb01', model='keplerianresults', component=comp, unit=u.solRad/u.d), b_vus[ci], atol=1e-4)) - assert(np.allclose(b.get_value('vvs', dataset='orb01', model='keplerianresults', component=comp, unit=u.solRad/u.d), b_vvs[ci], atol=1e-4)) - assert(np.allclose(b.get_value('vws', dataset='orb01', model='keplerianresults', component=comp, unit=u.solRad/u.d), b_vws[ci], atol=1e-4)) - + assert np.allclose(b.get_value('times', dataset='orb01', model='keplerianresults', component=comp, unit=u.d), b_ts, atol=1e-6) + assert np.allclose(b.get_value('us', dataset='orb01', model='keplerianresults', component=comp, unit=u.solRad), b_us[ci], atol=1e-5) + assert np.allclose(b.get_value('vs', dataset='orb01', model='keplerianresults', component=comp, unit=u.solRad), b_vs[ci], atol=1e-5) + assert np.allclose(b.get_value('ws', dataset='orb01', model='keplerianresults', component=comp, unit=u.solRad), b_ws[ci], atol=1e-5) + assert np.allclose(b.get_value('vus', dataset='orb01', model='keplerianresults', component=comp, unit=u.solRad/u.d), b_vus[ci], atol=1e-4) + assert np.allclose(b.get_value('vvs', dataset='orb01', model='keplerianresults', component=comp, unit=u.solRad/u.d), b_vvs[ci], atol=1e-4) + assert np.allclose(b.get_value('vws', dataset='orb01', model='keplerianresults', component=comp, unit=u.solRad/u.d), b_vws[ci], atol=1e-4) def test_binary(plot=False): """ """ - phoebe.devel_on() # required for nbody dynamics + phoebe.devel_on() # required for nbody dynamics # TODO: grid over orbital parameters # TODO: once ps.copy is implemented, just send b.copy() to each of these @@ -165,13 +159,11 @@ def test_binary(plot=False): b.get_parameter('dynamics_method')._choices = ['keplerian', 'bs'] _frontend_v_backend(b, plot=plot) - phoebe.devel_off() # reset for future tests + phoebe.devel_off() # reset for future tests if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - test_binary(plot=True) # TODO: create tests for both triple configurations (A--B-C, A-B--C) - these should first be default bundles diff --git a/tests/tests/test_dynamics/test_dynamics_grid.py b/tests/tests/test_dynamics/test_dynamics_grid.py index d7bc2c5a0..0945e029b 100644 --- a/tests/tests/test_dynamics/test_dynamics_grid.py +++ b/tests/tests/test_dynamics/test_dynamics_grid.py @@ -7,7 +7,7 @@ try: import matplotlib.pyplot as plt PLOTTING_ENABLED = True -except: +except ImportError: PLOTTING_ENABLED = False @@ -24,18 +24,19 @@ def _keplerian_v_nbody(b, ltte, period, plot=False): nb_ts, nb_us, nb_vs, nb_ws, nb_vus, nb_vvs, nb_vws = phoebe.dynamics.nbody.dynamics_from_bundle(b, times, ltte=ltte) k_ts, k_us, k_vs, k_ws, k_vus, k_vvs, k_vws = phoebe.dynamics.keplerian.dynamics_from_bundle(b, times, ltte=ltte) - assert(np.allclose(nb_ts, k_ts, 1e-8)) + assert np.allclose(nb_ts, k_ts, 1e-8) for ci in range(len(b.hierarchy.get_stars())): # TODO: make rtol lower if possible - assert(np.allclose(nb_us[ci], k_us[ci], rtol=1e-5, atol=1e-2)) - assert(np.allclose(nb_vs[ci], k_vs[ci], rtol=1e-5, atol=1e-2)) - assert(np.allclose(nb_ws[ci], k_ws[ci], rtol=1e-5, atol=1e-2)) + assert np.allclose(nb_us[ci], k_us[ci], rtol=1e-5, atol=1e-2) + assert np.allclose(nb_vs[ci], k_vs[ci], rtol=1e-5, atol=1e-2) + assert np.allclose(nb_ws[ci], k_ws[ci], rtol=1e-5, atol=1e-2) # nbody ltte velocities are wrong so only check velocities if ltte off if not ltte: - assert(np.allclose(nb_vus[ci], k_vus[ci], rtol=1e-5, atol=1e-2)) - assert(np.allclose(nb_vvs[ci], k_vvs[ci], rtol=1e-5, atol=1e-2)) - assert(np.allclose(nb_vws[ci], k_vws[ci], rtol=1e-5, atol=1e-2)) + assert np.allclose(nb_vus[ci], k_vus[ci], rtol=1e-5, atol=1e-2) + assert np.allclose(nb_vvs[ci], k_vvs[ci], rtol=1e-5, atol=1e-2) + assert np.allclose(nb_vws[ci], k_vws[ci], rtol=1e-5, atol=1e-2) + def _phoebe_v_photodynam(b, period, plot=False): """ @@ -61,7 +62,6 @@ def _phoebe_v_photodynam(b, period, plot=False): # TODO: look into justification of flipping x and y for both dynamics (photodynam & phoebe) # TODO: why the small discrepancy (visible especially in y, still <1e-11) - possibly a difference in time0 or just a precision limit in the photodynam backend since loading from a file?? - if PLOTTING_ENABLED and plot: for k in ['us', 'vs', 'ws', 'vus', 'vvs', 'vws']: plt.cla() @@ -73,13 +73,14 @@ def _phoebe_v_photodynam(b, period, plot=False): plt.ylabel(k) plt.show() - assert(np.allclose(b.get_value('times', model='phoeberesults', component=comp, unit=u.d), b.get_value('times', model='pdresults', component=comp, unit=u.d), rtol=0, atol=1e-05)) - assert(np.allclose(b.get_value('us', model='phoeberesults', component=comp, unit=u.AU), b.get_value('us', model='pdresults', component=comp, unit=u.AU), rtol=0, atol=1e-05)) - assert(np.allclose(b.get_value('vs', model='phoeberesults', component=comp, unit=u.AU), b.get_value('vs', model='pdresults', component=comp, unit=u.AU), rtol=0, atol=1e-05)) - assert(np.allclose(b.get_value('ws', model='phoeberesults', component=comp, unit=u.AU), b.get_value('ws', model='pdresults', component=comp, unit=u.AU), rtol=0, atol=1e-05)) - #assert(np.allclose(b.get_value('vxs', model='phoeberesults', component=comp, unit=u.solRad/u.d), b.get_value('vxs', model='pdresults', component=comp, unit=u.solRad/u.d), rtol=0, atol=1e-05)) - #assert(np.allclose(b.get_value('vys', model='phoeberesults', component=comp, unit=u.solRad/u.d), b.get_value('vys', model='pdresults', component=comp, unit=u.solRad/u.d), rtol=0, atol=1e-05)) - #assert(np.allclose(b.get_value('vzs', model='phoeberesults', component=comp, unit=u.solRad/u.d), b.get_value('vzs', model='pdresults', component=comp, unit=u.solRad/u.d), rtol=0, atol=1e-05)) + assert np.allclose(b.get_value('times', model='phoeberesults', component=comp, unit=u.d), b.get_value('times', model='pdresults', component=comp, unit=u.d), rtol=0, atol=1e-05) + assert np.allclose(b.get_value('us', model='phoeberesults', component=comp, unit=u.AU), b.get_value('us', model='pdresults', component=comp, unit=u.AU), rtol=0, atol=1e-05) + assert np.allclose(b.get_value('vs', model='phoeberesults', component=comp, unit=u.AU), b.get_value('vs', model='pdresults', component=comp, unit=u.AU), rtol=0, atol=1e-05) + assert np.allclose(b.get_value('ws', model='phoeberesults', component=comp, unit=u.AU), b.get_value('ws', model='pdresults', component=comp, unit=u.AU), rtol=0, atol=1e-05) + # assert np.allclose(b.get_value('vxs', model='phoeberesults', component=comp, unit=u.solRad/u.d), b.get_value('vxs', model='pdresults', component=comp, unit=u.solRad/u.d), rtol=0, atol=1e-05) + # assert np.allclose(b.get_value('vys', model='phoeberesults', component=comp, unit=u.solRad/u.d), b.get_value('vys', model='pdresults', component=comp, unit=u.solRad/u.d), rtol=0, atol=1e-05) + # assert np.allclose(b.get_value('vzs', model='phoeberesults', component=comp, unit=u.solRad/u.d), b.get_value('vzs', model='pdresults', component=comp, unit=u.solRad/u.d), rtol=0, atol=1e-05) + def _frontend_v_backend(b, ltte, period, plot=False): """ @@ -96,8 +97,6 @@ def _frontend_v_backend(b, ltte, period, plot=False): b.add_compute('phoebe', dynamics_method='keplerian', compute='keplerian', ltte=ltte) - - # NBODY # do backend Nbody b_ts, b_us, b_vs, b_ws, b_vus, b_vvs, b_vws = phoebe.dynamics.nbody.dynamics_from_bundle(b, times, compute='nbody', ltte=ltte) @@ -105,17 +104,16 @@ def _frontend_v_backend(b, ltte, period, plot=False): # do frontend Nbody b.run_compute('nbody', model='nbodyresults') - - for ci,comp in enumerate(b.hierarchy.get_stars()): + for ci, comp in enumerate(b.hierarchy.get_stars()): # TODO: can we lower tolerance? - assert(np.allclose(b.get_value('times', model='nbodyresults', component=comp, unit=u.d), b_ts, rtol=0, atol=1e-6)) - assert(np.allclose(b.get_value('us', model='nbodyresults', component=comp, unit=u.solRad), b_us[ci], rtol=1e-7, atol=1e-4)) - assert(np.allclose(b.get_value('vs', model='nbodyresults', component=comp, unit=u.solRad), b_vs[ci], rtol=1e-7, atol=1e-4)) - assert(np.allclose(b.get_value('ws', model='nbodyresults', component=comp, unit=u.solRad), b_ws[ci], rtol=1e-7, atol=1e-4)) + assert np.allclose(b.get_value('times', model='nbodyresults', component=comp, unit=u.d), b_ts, rtol=0, atol=1e-6) + assert np.allclose(b.get_value('us', model='nbodyresults', component=comp, unit=u.solRad), b_us[ci], rtol=1e-7, atol=1e-4) + assert np.allclose(b.get_value('vs', model='nbodyresults', component=comp, unit=u.solRad), b_vs[ci], rtol=1e-7, atol=1e-4) + assert np.allclose(b.get_value('ws', model='nbodyresults', component=comp, unit=u.solRad), b_ws[ci], rtol=1e-7, atol=1e-4) if not ltte: - assert(np.allclose(b.get_value('vus', model='nbodyresults', component=comp, unit=u.solRad/u.d), b_vus[ci], rtol=1e-7, atol=1e-4)) - assert(np.allclose(b.get_value('vvs', model='nbodyresults', component=comp, unit=u.solRad/u.d), b_vvs[ci], rtol=1e-7, atol=1e-4)) - assert(np.allclose(b.get_value('vws', model='nbodyresults', component=comp, unit=u.solRad/u.d), b_vws[ci], rtol=1e-7, atol=1e-4)) + assert np.allclose(b.get_value('vus', model='nbodyresults', component=comp, unit=u.solRad/u.d), b_vus[ci], rtol=1e-7, atol=1e-4) + assert np.allclose(b.get_value('vvs', model='nbodyresults', component=comp, unit=u.solRad/u.d), b_vvs[ci], rtol=1e-7, atol=1e-4) + assert np.allclose(b.get_value('vws', model='nbodyresults', component=comp, unit=u.solRad/u.d), b_vws[ci], rtol=1e-7, atol=1e-4) # KEPLERIAN # do backend keplerian @@ -124,22 +122,21 @@ def _frontend_v_backend(b, ltte, period, plot=False): # do frontend keplerian b.run_compute('keplerian', model='keplerianresults') - for ci,comp in enumerate(b.hierarchy.get_stars()): + for ci, comp in enumerate(b.hierarchy.get_stars()): # TODO: can we lower tolerance? - assert(np.allclose(b.get_value('times', model='keplerianresults', component=comp, unit=u.d), b_ts, rtol=0, atol=1e-08)) - assert(np.allclose(b.get_value('us', model='keplerianresults', component=comp, unit=u.solRad), b_us[ci], rtol=0, atol=1e-08)) - assert(np.allclose(b.get_value('vs', model='keplerianresults', component=comp, unit=u.solRad), b_vs[ci], rtol=0, atol=1e-08)) - assert(np.allclose(b.get_value('ws', model='keplerianresults', component=comp, unit=u.solRad), b_ws[ci], rtol=0, atol=1e-08)) - assert(np.allclose(b.get_value('vus', model='keplerianresults', component=comp, unit=u.solRad/u.d), b_vus[ci], rtol=0, atol=1e-08)) - assert(np.allclose(b.get_value('vvs', model='keplerianresults', component=comp, unit=u.solRad/u.d), b_vvs[ci], rtol=0, atol=1e-08)) - assert(np.allclose(b.get_value('vws', model='keplerianresults', component=comp, unit=u.solRad/u.d), b_vws[ci], rtol=0, atol=1e-08)) - + assert np.allclose(b.get_value('times', model='keplerianresults', component=comp, unit=u.d), b_ts, rtol=0, atol=1e-08) + assert np.allclose(b.get_value('us', model='keplerianresults', component=comp, unit=u.solRad), b_us[ci], rtol=0, atol=1e-08) + assert np.allclose(b.get_value('vs', model='keplerianresults', component=comp, unit=u.solRad), b_vs[ci], rtol=0, atol=1e-08) + assert np.allclose(b.get_value('ws', model='keplerianresults', component=comp, unit=u.solRad), b_ws[ci], rtol=0, atol=1e-08) + assert np.allclose(b.get_value('vus', model='keplerianresults', component=comp, unit=u.solRad/u.d), b_vus[ci], rtol=0, atol=1e-08) + assert np.allclose(b.get_value('vvs', model='keplerianresults', component=comp, unit=u.solRad/u.d), b_vvs[ci], rtol=0, atol=1e-08) + assert np.allclose(b.get_value('vws', model='keplerianresults', component=comp, unit=u.solRad/u.d), b_vws[ci], rtol=0, atol=1e-08) def test_binary(plot=False): """ """ - phoebe.devel_on() # required for nbody dynamics + phoebe.devel_on() # required for nbody dynamics # TODO: once ps.copy is implemented, just send b.copy() to each of these @@ -148,8 +145,8 @@ def test_binary(plot=False): system2 = [1., 257.5] system3 = [40., 65000.] - for system in [system1,system2,system3]: - for q in [0.5,1.]: + for system in [system1, system2, system3]: + for q in [0.5, 1.]: for ltte in [True, False]: print("test_dynamics_grid: sma={}, period={}, q={}, ltte={}".format(system[0], system[1], q, ltte)) b = phoebe.default_binary() @@ -158,7 +155,7 @@ def test_binary(plot=False): b.set_default_unit_all('sma', u.AU) b.set_default_unit_all('period', u.d) - b.set_value('sma@binary',system[0]) + b.set_value('sma@binary', system[0]) b.set_value('period@binary', system[1]) b.set_value('q', q) @@ -167,10 +164,9 @@ def test_binary(plot=False): phoebe.devel_off() # reset for future tests + if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - test_binary(plot=True) # TODO: create tests for both triple configurations (A--B-C, A-B--C) - these should first be default bundles diff --git a/tests/tests/test_ecc/test_ecc.py b/tests/tests/test_ecc/test_ecc.py index 17b900680..f43ee04b9 100644 --- a/tests/tests/test_ecc/test_ecc.py +++ b/tests/tests/test_ecc/test_ecc.py @@ -5,11 +5,12 @@ import numpy as np import os + def test_binary(plot=False, gen_comp=False): b = phoebe.default_binary() period = b.get_value('period@binary') - b.add_dataset('lc', times=np.linspace(0,period,21)) + b.add_dataset('lc', times=np.linspace(0, period, 21)) b.add_compute('phoebe', irrad_method='none', compute='phoebe2') if gen_comp: b.add_compute('legacy', refl_num=0, compute='phoebe1') @@ -26,10 +27,9 @@ def test_binary(plot=False, gen_comp=False): b.set_value_all('ld_func', 'linear') b.set_value_all('ld_coeffs', [0.0]) - #turn off albedos (legacy requirement) + # turn off albedos (legacy requirement) b.set_value_all('irrad_frac_refl_bol', 0.0) - # 0.51 starts to overlap for ecc in [0.3, 0.505]: b.set_value('ecc', ecc) @@ -50,16 +50,13 @@ def test_binary(plot=False, gen_comp=False): phoebe1_val = b.get_value('fluxes@phoebe1model') if plot: - print("ecc: {} per0:: {} max (rel): {}".format(ecc , per0, abs((phoebe2_val-phoebe1_val)/phoebe1_val).max())) + print("ecc: {} per0:: {} max (rel): {}".format(ecc, per0, abs((phoebe2_val-phoebe1_val)/phoebe1_val).max())) b.plot(dataset='lc01', show=True) - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=1e-3 if ecc < 0.5 else 5e-3, atol=0.)) + assert np.allclose(phoebe2_val, phoebe1_val, rtol=1e-3 if ecc < 0.5 else 5e-3, atol=0.) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='DEBUG') - - - b = test_binary(plot=True, gen_comp=True) + test_binary(plot=True, gen_comp=True) diff --git a/tests/tests/test_extinction/text_extinction.py b/tests/tests/test_extinction/text_extinction.py index e260159f2..475e6624d 100644 --- a/tests/tests/test_extinction/text_extinction.py +++ b/tests/tests/test_extinction/text_extinction.py @@ -7,7 +7,7 @@ def test_binary(plot=False): b = phoebe.Bundle.default_binary() - b.add_dataset('lc', times=phoebe.linspace(0,1,21)) + b.add_dataset('lc', times=phoebe.linspace(0, 1, 21)) b.set_value('Av', 0.2) b.flip_constraint('ebv', solve_for='Av') @@ -16,10 +16,7 @@ def test_binary(plot=False): # enable and implement assertions once extinction tables are available # b.run_compute(irrad_method='none') - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - - b = test_binary(plot=True) + test_binary(plot=True) diff --git a/tests/tests/test_forbidden_labels/test_forbidden_parameters.py b/tests/tests/test_forbidden_labels/test_forbidden_parameters.py index 71b1215a3..710f99bb1 100644 --- a/tests/tests/test_forbidden_labels/test_forbidden_parameters.py +++ b/tests/tests/test_forbidden_labels/test_forbidden_parameters.py @@ -3,8 +3,8 @@ import phoebe -def test_forbidden(verbose=False): +def test_forbidden(verbose=False): phoebe.devel_on() b = phoebe.default_binary(contact_binary=True) @@ -37,20 +37,19 @@ def test_forbidden(verbose=False): b.add_server('remoteslurm') - # TODO: include constraint_func? Shouldn't matter since they're not in twigs should_be_forbidden = b.qualifiers + b.contexts + b.kinds + [c.split('@')[0] for c in b.get_parameter(qualifier='columns').choices] if verbose: - for l in should_be_forbidden: - if l not in phoebe.parameters.parameters._forbidden_labels: - print(l) + for label in should_be_forbidden: + if label not in phoebe.parameters.parameters._forbidden_labels: + print(label) - for l in should_be_forbidden: - assert(l in phoebe.parameters.parameters._forbidden_labels) + for label in should_be_forbidden: + assert label in phoebe.parameters.parameters._forbidden_labels phoebe.reset_settings() - return b + if __name__ == '__main__': - b = test_forbidden(verbose=True) + test_forbidden(verbose=True) diff --git a/tests/tests/test_fti/test_fti.py b/tests/tests/test_fti/test_fti.py index 63f0308d3..4f4f285f5 100644 --- a/tests/tests/test_fti/test_fti.py +++ b/tests/tests/test_fti/test_fti.py @@ -2,13 +2,12 @@ """ import phoebe -from phoebe import u import numpy as np import os try: import matplotlib.pyplot as plt PLOTTING_ENABLED = True -except: +except ImportError: PLOTTING_ENABLED = False @@ -34,7 +33,7 @@ def test_binary(plot=False): print(abs(fluxes_legacy-fluxes).max()) plt.plot(times, fluxes_legacy, 'k-') b.plot(show=True) - assert(np.allclose(fluxes, fluxes_legacy, rtol=0, atol=1e-3)) + assert np.allclose(fluxes, fluxes_legacy, rtol=0, atol=1e-3) b.run_compute(kind='phoebe', fti_method='oversample', fti_oversample=10) fluxes_legacy = np.loadtxt(os.path.join(dir, 'kic12004834.fti.data'), unpack=True, usecols=(1,)) @@ -45,11 +44,9 @@ def test_binary(plot=False): print(abs(fluxes_legacy-fluxes).max()) plt.plot(times, fluxes_legacy, 'k-') b.plot(show=True) - assert(np.allclose(fluxes, fluxes_legacy, rtol=0, atol=1e-3)) + assert np.allclose(fluxes, fluxes_legacy, rtol=0, atol=1e-3) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - b = test_binary(plot=True) + test_binary(plot=True) diff --git a/tests/tests/test_gravb/test_gravb.py b/tests/tests/test_gravb/test_gravb.py index d35888459..dc93be961 100644 --- a/tests/tests/test_gravb/test_gravb.py +++ b/tests/tests/test_gravb/test_gravb.py @@ -10,7 +10,7 @@ def test_binary(plot=False, gen_comp=False): b = phoebe.Bundle.default_binary() period = b.get_value('period@binary') - b.add_dataset('lc', times=np.linspace(0,period,21)) + b.add_dataset('lc', times=np.linspace(0, period, 21)) b.add_compute('phoebe', irrad_method='none', compute='phoebe2') if gen_comp: b.add_compute('legacy', refl_num=0, compute='phoebe1') @@ -27,13 +27,12 @@ def test_binary(plot=False, gen_comp=False): b.set_value_all('ld_func', 'linear') b.set_value_all('ld_coeffs', [0.0]) - #turn off albedos (legacy requirement) + # turn off albedos (legacy requirement) b.set_value_all('irrad_frac_refl_bol', 0.0) for gravb in [0.1, 0.9]: b.set_value('gravb_bol', component='primary', value=gravb) - print("running phoebe2 model...") b.run_compute(compute='phoebe2', irrad_method='none', model='phoebe2model', overwrite=True) if gen_comp: @@ -54,12 +53,9 @@ def test_binary(plot=False, gen_comp=False): # 0.0: 0.0007 # 0.5: 0.0007 # 1.0: 0.0007 - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=1e-3, atol=0.)) + assert np.allclose(phoebe2_val, phoebe1_val, rtol=1e-3, atol=0.) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - - b = test_binary(plot=True, gen_comp=True) + test_binary(plot=True, gen_comp=True) diff --git a/tests/tests/test_hierarchy/test_hierarchy.py b/tests/tests/test_hierarchy/test_hierarchy.py index 14f56c7df..1004ddf8e 100644 --- a/tests/tests/test_hierarchy/test_hierarchy.py +++ b/tests/tests/test_hierarchy/test_hierarchy.py @@ -3,16 +3,14 @@ import phoebe + def test_binary(): b = phoebe.Bundle.default_binary() b.set_hierarchy() - b.set_hierarchy('orbit:binary(star:secondary, star:primary)') - return b if __name__ == '__main__': logger = phoebe.logger(clevel='DEBUG') - - b = test_binary() + test_binary() diff --git a/tests/tests/test_interp_value/test_interp_value.py b/tests/tests/test_interp_value/test_interp_value.py index 7514f8292..e4457a884 100644 --- a/tests/tests/test_interp_value/test_interp_value.py +++ b/tests/tests/test_interp_value/test_interp_value.py @@ -6,14 +6,13 @@ def test_interp_value(): b = phoebe.default_binary() b.add_dataset('lc', times=[0, 1], fluxes=[0.8, 0.7]) - assert(abs(b.get_parameter('fluxes').interp_value(times=0.5)-0.75) < 1e-12) + assert abs(b.get_parameter('fluxes').interp_value(times=0.5)-0.75) < 1e-12 times_in_s = (0.5*u.d).to(u.s) - assert(abs(b.get_parameter('fluxes').interp_value(times=times_in_s)-0.75) < 1e-12) + assert abs(b.get_parameter('fluxes').interp_value(times=times_in_s)-0.75) < 1e-12 + assert abs(b.get_parameter('fluxes').interp_quantity(times=times_in_s).value-0.75) < 1e-12 - assert(abs(b.get_parameter('fluxes').interp_quantity(times=times_in_s).value-0.75) < 1e-12) if __name__ == '__main__': logger = phoebe.logger(clevel='debug') - test_interp_value() diff --git a/tests/tests/test_jktebop_agreement/test_jktebop_agreement.py b/tests/tests/test_jktebop_agreement/test_jktebop_agreement.py index a724be47e..31a9eeac2 100644 --- a/tests/tests/test_jktebop_agreement/test_jktebop_agreement.py +++ b/tests/tests/test_jktebop_agreement/test_jktebop_agreement.py @@ -6,13 +6,12 @@ try: import matplotlib.pyplot as plt PLOTTING_ENABLED = True -except: +except ImportError: PLOTTING_ENABLED = False import os def _jktebop_ext_vs_phoebe2(case, plot=False, gen_comp=False): - b = phoebe.default_binary() b.add_compute( 'jktebop', @@ -49,7 +48,6 @@ def _jktebop_ext_vs_phoebe2(case, plot=False, gen_comp=False): jktebop_rv2 = np.loadtxt(os.path.join(os.path.dirname(__file__), 'jktebop2.rv2.out')).T atol = 3e-5 - elif case == 3: b['ecc@binary@component'] = 0.5 b['sma@binary@component'] = 100 @@ -65,14 +63,12 @@ def _jktebop_ext_vs_phoebe2(case, plot=False, gen_comp=False): jktebop_rv2 = np.loadtxt(os.path.join(os.path.dirname(__file__), 'jktebop3.rv2.out')).T atol = 2e-3 - times = np.linspace(0, b['period@binary@component'].get_value(), 100) - rv = np.zeros_like(times) - errs = np.ones_like(times)*0.001 + # rv = np.zeros_like(times) + # errs = np.ones_like(times)*0.001 # b.add_dataset('rv', times={'primary': times}, rvs={'primary': rv}, sigmas={'primary': errs}, dataset='rv01') b.add_dataset('rv', times=times, dataset='rv01') - b.set_value_all('ld_mode', value='manual') b.run_compute('jktebop1', model='jktebop_model1') b.run_compute('phoebe1', model='phoebe_model1') @@ -85,17 +81,17 @@ def _jktebop_ext_vs_phoebe2(case, plot=False, gen_comp=False): if plot and PLOTTING_ENABLED: fig, axs = plt.subplots(2, 1, sharex=True, gridspec_kw={'height_ratios': [2, 1]}, figsize=(6, 4)) - axs[0].plot(b['times@jktebop_model1@primary'].get_value(), b['rvs@jktebop_model1@primary'].get_value(), '+', c = 'k', label = 'jktebop backend primary') - axs[0].plot(b['times@jktebop_model1@secondary'].get_value(), b['rvs@jktebop_model1@secondary'].get_value(), 'x', c = 'k', label = 'jktebop backend secondary') + axs[0].plot(b['times@jktebop_model1@primary'].get_value(), b['rvs@jktebop_model1@primary'].get_value(), '+', c='k', label='jktebop backend primary') + axs[0].plot(b['times@jktebop_model1@secondary'].get_value(), b['rvs@jktebop_model1@secondary'].get_value(), 'x', c='k', label='jktebop backend secondary') - axs[0].plot(jktebop_rv1[0], jktebop_rv1[4], '-', c = 'r', label = 'jktebop ext. primary') - axs[0].plot(jktebop_rv2[0], jktebop_rv2[4], '--', c = 'r', label = 'jktebop ext. secondary') + axs[0].plot(jktebop_rv1[0], jktebop_rv1[4], '-', c='r', label='jktebop ext. primary') + axs[0].plot(jktebop_rv2[0], jktebop_rv2[4], '--', c='r', label='jktebop ext. secondary') axs[0].legend(loc='best') axs[0].set_ylabel('RV (km/s)') - axs[1].plot(b['times@jktebop_model1@primary'].get_value(), b['rvs@jktebop_model1@primary'].get_value() - jktebop_rv1[4], 'o', c = 'b', label = 'jktebop primary') - axs[1].plot(b['times@jktebop_model1@secondary'].get_value(), b['rvs@jktebop_model1@secondary'].get_value() - jktebop_rv2[4], 'o', c = 'g', label = 'jktebop primary') + axs[1].plot(b['times@jktebop_model1@primary'].get_value(), b['rvs@jktebop_model1@primary'].get_value() - jktebop_rv1[4], 'o', c='b', label='jktebop primary') + axs[1].plot(b['times@jktebop_model1@secondary'].get_value(), b['rvs@jktebop_model1@secondary'].get_value() - jktebop_rv2[4], 'o', c='g', label='jktebop primary') axs[1].set_ylabel('Residuals (km/s)') axs[0].set_ylabel('Time') @@ -103,32 +99,30 @@ def _jktebop_ext_vs_phoebe2(case, plot=False, gen_comp=False): if plot and PLOTTING_ENABLED: fig, axs = plt.subplots(2, 1, sharex=True, gridspec_kw={'height_ratios': [2, 1]}, figsize=(6, 4)) - axs[0].plot(b['times@phoebe_model1@primary'].get_value(), b['rvs@phoebe_model1@primary'].get_value(), '+', c = 'k', label = 'phoebe primary') - axs[0].plot(b['times@phoebe_model1@secondary'].get_value(), b['rvs@phoebe_model1@secondary'].get_value(), 'x', c = 'k', label = 'phoebe secondary') + axs[0].plot(b['times@phoebe_model1@primary'].get_value(), b['rvs@phoebe_model1@primary'].get_value(), '+', c='k', label='phoebe primary') + axs[0].plot(b['times@phoebe_model1@secondary'].get_value(), b['rvs@phoebe_model1@secondary'].get_value(), 'x', c='k', label='phoebe secondary') - axs[0].plot(jktebop_rv1[0], jktebop_rv1[4], '-', c = 'r', label = 'jktebop ext. primary') - axs[0].plot(jktebop_rv2[0], jktebop_rv2[4], '--', c = 'r', label = 'jktebop ext. secondary') + axs[0].plot(jktebop_rv1[0], jktebop_rv1[4], '-', c='r', label='jktebop ext. primary') + axs[0].plot(jktebop_rv2[0], jktebop_rv2[4], '--', c='r', label='jktebop ext. secondary') axs[0].legend(loc='best') axs[0].set_ylabel('RV (km/s)') - axs[1].plot(b['times@phoebe_model1@primary'].get_value(), b['rvs@phoebe_model1@primary'].get_value() - jktebop_rv1[4], 'o', c = 'b', label = 'jktebop primary') - axs[1].plot(b['times@phoebe_model1@secondary'].get_value(), b['rvs@phoebe_model1@secondary'].get_value() - jktebop_rv2[4], 'o', c = 'g', label = 'jktebop primary') + axs[1].plot(b['times@phoebe_model1@primary'].get_value(), b['rvs@phoebe_model1@primary'].get_value() - jktebop_rv1[4], 'o', c='b', label='jktebop primary') + axs[1].plot(b['times@phoebe_model1@secondary'].get_value(), b['rvs@phoebe_model1@secondary'].get_value() - jktebop_rv2[4], 'o', c='g', label='jktebop primary') axs[1].set_ylabel('Residuals (km/s)') axs[0].set_ylabel('Time') plt.show() - - assert(np.allclose(b['rvs@phoebe_model1@primary'].get_value(), jktebop_rv1[4], rtol=0., atol=atol)) - assert(np.allclose(b['rvs@phoebe_model1@secondary'].get_value(), jktebop_rv2[4], rtol=0., atol=atol)) - assert(np.allclose(b['rvs@jktebop_model1@primary'].get_value(), jktebop_rv1[4], rtol=0., atol=1e-8)) - assert(np.allclose(b['rvs@jktebop_model1@secondary'].get_value(), jktebop_rv2[4], rtol=0., atol=1e-8)) + assert np.allclose(b['rvs@phoebe_model1@primary'].get_value(), jktebop_rv1[4], rtol=0., atol=atol) + assert np.allclose(b['rvs@phoebe_model1@secondary'].get_value(), jktebop_rv2[4], rtol=0., atol=atol) + assert np.allclose(b['rvs@jktebop_model1@primary'].get_value(), jktebop_rv1[4], rtol=0., atol=1e-8) + assert np.allclose(b['rvs@jktebop_model1@secondary'].get_value(), jktebop_rv2[4], rtol=0., atol=1e-8) def test_jktebop(plot=False, gen_comp=False): - - for case in range(1,4): + for case in range(1, 4): _jktebop_ext_vs_phoebe2(case, plot=plot, gen_comp=gen_comp) diff --git a/tests/tests/test_l3/test_l3.py b/tests/tests/test_l3/test_l3.py index 8d3805c50..626847a0a 100644 --- a/tests/tests/test_l3/test_l3.py +++ b/tests/tests/test_l3/test_l3.py @@ -9,7 +9,7 @@ def test_binary(plot=False, gen_comp=False): b = phoebe.Bundle.default_binary() - b.add_dataset('lc', times=phoebe.linspace(0,1,21)) + b.add_dataset('lc', times=phoebe.linspace(0, 1, 21)) b.add_compute('phoebe', irrad_method='none', compute='phoebe2') if gen_comp: b.add_compute('legacy', refl_num=0, compute='phoebe1') @@ -27,20 +27,23 @@ def test_binary(plot=False, gen_comp=False): b.set_value_all('ld_coeffs', [0.0]) # b.set_value_all('ecc', 0.2) - #turn off albedos (legacy requirement) + # turn off albedos (legacy requirement) b.set_value_all('irrad_frac_refl_bol', 0.0) b.set_value('l3', 0.5) b.set_value('l3_frac', 0.2, check_visible=False) for l3_mode in ['flux', 'fraction']: - if plot: print("l3_mode={}".format(l3_mode)) + if plot: + print("l3_mode={}".format(l3_mode)) b.set_value('l3_mode', l3_mode) - if plot: print("running phoebe2 model...") + if plot: + print("running phoebe2 model...") b.run_compute(compute='phoebe2', model='phoebe2model', overwrite=True) if gen_comp: - if plot: print("running phoebe1 model...") + if plot: + print("running phoebe1 model...") b.run_compute(compute='phoebe1', model='phoebe1model', overwrite=True) b.filter(model='phoebe1model').save('test_l3_{}.comp.model'.format(l3_mode)) else: @@ -54,12 +57,9 @@ def test_binary(plot=False, gen_comp=False): print("max (rel):", abs((phoebe2_val-phoebe1_val)/phoebe1_val).max()) - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=5e-3, atol=0.)) + assert np.allclose(phoebe2_val, phoebe1_val, rtol=5e-3, atol=0.) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - - b = test_binary(plot=True, gen_comp=True) + test_binary(plot=True, gen_comp=True) diff --git a/tests/tests/test_latexrepr/test_latexrepr.py b/tests/tests/test_latexrepr/test_latexrepr.py index 05b11c6cd..84bb93dee 100644 --- a/tests/tests/test_latexrepr/test_latexrepr.py +++ b/tests/tests/test_latexrepr/test_latexrepr.py @@ -3,9 +3,8 @@ import phoebe -def test_latexrepr(verbose=False): - +def test_latexrepr(verbose=False): b = phoebe.default_binary(contact_binary=True) b.add_dataset('lc') b.add_dataset('rv') @@ -32,7 +31,6 @@ def test_latexrepr(verbose=False): print("param: {}".format(param.twig)) param.latextwig - return b if __name__ == '__main__': - b = test_latexrepr(verbose=True) + test_latexrepr(verbose=True) diff --git a/tests/tests/test_ld/test_ld.py b/tests/tests/test_ld/test_ld.py index 1e1b0ae6b..28fdf32ab 100644 --- a/tests/tests/test_ld/test_ld.py +++ b/tests/tests/test_ld/test_ld.py @@ -5,6 +5,7 @@ import numpy as np import os + def _get_ld_coeffs(ld_coeff, ld_func, ld_mode='manual'): # length of ld_coeffs depends on ld_func if ld_coeff is None: @@ -22,17 +23,16 @@ def _get_ld_coeffs(ld_coeff, ld_func, ld_mode='manual'): return ld_coeffs + def test_binary(plot=False, gen_comp=False): b = phoebe.Bundle.default_binary() - period = b.get_value('period@binary') - b.add_dataset('lc', times=np.linspace(0,period,21)) + b.add_dataset('lc', times=np.linspace(0, period, 21)) b.add_compute('phoebe', irrad_method='none', compute='phoebe2') if gen_comp: b.add_compute('legacy', refl_num=0, compute='phoebe1') - # set matching limb-darkening for bolometric b.set_value_all('ld_mode_bol', 'manual') b.set_value_all('ld_func_bol', 'linear') @@ -42,7 +42,7 @@ def test_binary(plot=False, gen_comp=False): b.set_value_all('ld_func', 'linear') b.set_value_all('ld_coeffs', [0.]) - #turn off albedos (legacy requirement) + # turn off albedos (legacy requirement) b.set_value_all('irrad_frac_refl_bol', 0.0) for ld_func in b.get('ld_func', component='primary').choices + ['interp']: @@ -50,10 +50,9 @@ def test_binary(plot=False, gen_comp=False): # exact comparisons, so we'll get close and leave a really lose # tolerance. - ld_coeff_loop = [None] if ld_func=='interp' else [0.2, 'ck2004'] + ld_coeff_loop = [None] if ld_func == 'interp' else [0.2, 'ck2004'] for ld_coeff in ld_coeff_loop: - if isinstance(ld_coeff, str): ld_coeffs = None ld_coeffs_source = ld_coeff @@ -61,22 +60,18 @@ def test_binary(plot=False, gen_comp=False): ld_coeffs = _get_ld_coeffs(ld_coeff, ld_func) ld_coeffs_source = 'none' - - if ld_func=='interp': + if ld_func == 'interp': atm = 'ck2004' atm_ph1 = 'extern_atmx' exact_comparison = False - else: atm = 'extern_atmx' atm_ph1 = 'extern_atmx' exact_comparison = True - # some ld_funcs aren't supported by legacy. So let's fall back # on logarthmic at least to make sure there isn't a large offset if ld_func in ['logarithmic', 'linear', 'square_root']: - # TODO: add linear and square_root once bugs 111 and 112 are fixed ld_func_ph1 = ld_func ld_coeffs_ph1 = ld_coeffs exact_comparison = exact_comparison @@ -91,7 +86,6 @@ def test_binary(plot=False, gen_comp=False): if plot: print("running phoebe2 model atm={}, ld_func={}, ld_coeffs={} ld_coeffs_source={}...".format(atm, ld_func, ld_coeffs, ld_coeffs_source)) - b.set_value_all('atm@phoebe2', atm) if ld_func == 'interp': b.set_value_all('ld_mode', 'interp') @@ -133,14 +127,14 @@ def test_binary(plot=False, gen_comp=False): if plot: b.plot(dataset='lc01', show=True) - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=5e-3 if exact_comparison else 0.3, atol=0.)) - + assert np.allclose(phoebe2_val, phoebe1_val, rtol=5e-3 if exact_comparison else 0.3, atol=0.) b.set_value_all('ld_mode', 'manual') + for atm in ['ck2004', 'blackbody']: # don't need much time-resolution at all since we're just using median # to compare - b.set_value('times@dataset', np.linspace(0,3,11)) + b.set_value('times@dataset', np.linspace(0, 3, 11)) b.set_value_all('atm@phoebe2', atm) for ld_func in b.get_parameter('ld_func', component='primary').choices: @@ -151,7 +145,6 @@ def test_binary(plot=False, gen_comp=False): # vs legacy (quadratic, power), but also important to run all # with blackbody. - b.set_value_all('ld_func', ld_func, check_visible=False) med_fluxes = [] @@ -163,7 +156,6 @@ def test_binary(plot=False, gen_comp=False): ld_coeff_loop = [0.0, 0.3, 'ck2004'] for ld_coeff in ld_coeff_loop: - if isinstance(ld_coeff, str): ld_coeffs = None ld_coeffs_source = ld_coeff @@ -192,14 +184,9 @@ def test_binary(plot=False, gen_comp=False): if plot: b.show() - assert(diff_med_fluxes < 0.035) + assert diff_med_fluxes < 0.035 - - return b - if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - - b = test_binary(plot=False, gen_comp=True) + test_binary(plot=False, gen_comp=True) diff --git a/tests/tests/test_legacy_parser/test_legacy_export_import.py b/tests/tests/test_legacy_parser/test_legacy_export_import.py index 64f703650..2d1b45752 100644 --- a/tests/tests/test_legacy_parser/test_legacy_export_import.py +++ b/tests/tests/test_legacy_parser/test_legacy_export_import.py @@ -1,10 +1,8 @@ import phoebe as phb2 import numpy as np -def test_reimport(filename=None): - -#import data +def test_reimport(filename=None): if filename: b = phb2.from_legacy(filename) else: @@ -14,42 +12,29 @@ def test_reimport(filename=None): b.export_legacy('test.legacy') b2 = phb2.from_legacy('test.legacy') -# compare data - -# check to see if datasets are attached and the right number + # check to see if datasets are attached and the right number Nlcs = len(b.get_dataset(kind='lc').datasets) Nlcs2 = len(b2.get_dataset(kind='lc').datasets) Nrvs = len(b.get_dataset(kind='rv').datasets) Nrvs2 = len(b2.get_dataset(kind='rv').datasets) # must be equal - assert(Nlcs==Nlcs2) - assert(2*Nrvs==Nrvs2) - -# check to make sure parameters are the same + assert Nlcs == Nlcs2 + assert 2*Nrvs == Nrvs2 + # check to make sure parameters are the same pars = b.filter() pars2 = b.filter() - #checking parameters + # checking parameters for x in range(len(pars)): val1 = pars[x].value val2 = pars2[x].value if pars[x].qualifier not in ['times', 'fluxes', 'sigmas', 'rvs']: - - try: - assert(val1==val2) - except: - assert(all(val1==val2)) - - - + assert np.all(val1 == val2) if __name__ == '__main__': -# logger= phb2.logger() filename = 'default.phoebe' - #for default binary test_reimport() - #for more complex phoebe1 system test_reimport(filename) diff --git a/tests/tests/test_legacy_parser/test_legacy_parser.py b/tests/tests/test_legacy_parser/test_legacy_parser.py index 72f49173f..30cf5b4cf 100644 --- a/tests/tests/test_legacy_parser/test_legacy_parser.py +++ b/tests/tests/test_legacy_parser/test_legacy_parser.py @@ -15,21 +15,19 @@ import os - def _legacy_test(filename='default.phoebe', verbose=True): - #locate file + # locate file dir = os.path.dirname(os.path.realpath(__file__)) - #load in phoebe parameter file - params = np.loadtxt(os.path.join(dir, filename), dtype='str', delimiter = '=', - converters = {0: lambda s: s.strip(), 1: lambda s: s.strip()}) + # load in phoebe parameter file + params = np.loadtxt( + os.path.join(dir, filename), dtype='str', delimiter='=', + converters={0: lambda s: s.strip(), 1: lambda s: s.strip()}) lcno = int(params[:,1][list(params[:,0]).index('phoebe_lcno')]) rvno = int(params[:,1][list(params[:,0]).index('phoebe_rvno')]) - - - #load phoebe2 file + # load phoebe2 file if verbose: print(dir) print(os.path.join(dir, filename)) @@ -40,14 +38,12 @@ def _legacy_test(filename='default.phoebe', verbose=True): lcs = b.get_dataset(kind='lc').datasets rvs = b.get_dataset(kind='rv').datasets - lc_id = [] rv_id = [] fluxes = [] vels = [] vels2 = [] - for x in range(lcno): # load file lc_add = '['+str(x+1)+']' @@ -56,9 +52,10 @@ def _legacy_test(filename='default.phoebe', verbose=True): datafile = params[:,1][list(params[:,0]).index('phoebe_lc_filename'+lc_add)].strip('"') - if verbose: print(id) - #load data file + if verbose: + print(id) + # load data file: time_phb1, flux_phb1, err_phb1 = np.loadtxt(os.path.join(dir, datafile), unpack=True) # get third column type @@ -69,30 +66,32 @@ def _legacy_test(filename='default.phoebe', verbose=True): flux = b.filter(dataset=id, qualifier='fluxes').get_value() sigma = b.filter(dataset=id, qualifier='sigmas').get_value() - #compare to datafile - if verbose: print("x={}, datafile={}, lcs[x]={}".format(x, datafile, lcs[x])) - assert(np.all(time==time_phb1)) - if verbose: print("checking flux in "+str(lcs[x])) - if verbose: print("x={}, datafile={}, lcs[x]={}".format(x, datafile, lcs[x])) - assert(np.all(flux==flux_phb1)) - if verbose: print("checking sigma in "+str(lcs[x])) + # compare to datafile + if verbose: + print("x={}, datafile={}, lcs[x]={}".format(x, datafile, lcs[x])) + assert np.all(time == time_phb1) + if verbose: + print("checking flux in "+str(lcs[x])) + print("x={}, datafile={}, lcs[x]={}".format(x, datafile, lcs[x])) + assert np.all(flux == flux_phb1) + if verbose: + print("checking sigma in "+str(lcs[x])) if err_val == 'Standard deviation': - assert(np.all(sigma==err_phb1)) + assert np.all(sigma == err_phb1) else: val = np.sqrt(1/err_phb1) - assert(np.allclose(sigma, val, atol=1e-7)) + assert np.allclose(sigma, val, atol=1e-7) - #grab legacy ld_coeffs + # grab legacy ld_coeffs ld1x1 = params[:,1][list(params[:,0]).index('phoebe_ld_lcx1'+lc_add+'.VAL')] ld1y1 = params[:,1][list(params[:,0]).index('phoebe_ld_lcy1'+lc_add)] - ld1x2 = params[:,1][list(params[:,0]).index('phoebe_ld_lcx2'+lc_add+'.VAL')] ld1y2 = params[:,1][list(params[:,0]).index('phoebe_ld_lcy2'+lc_add)] ld_coeffs1 = [float(ld1x1), float(ld1y1), float(ld1x2), float(ld1y2)] - #grab phoebe2 ld_coeffs + # grab phoebe2 ld_coeffs ldx1, ldy1 = b.filter(dataset=lcs[x], qualifier='ld_coeffs', component='cow').get_value() ldx1, ldy1 = b.filter(dataset=id, qualifier='ld_coeffs', component='cow').get_value() ldx2, ldy2 = b.filter(dataset=id, qualifier='ld_coeffs', component='pig').get_value() @@ -101,21 +100,24 @@ def _legacy_test(filename='default.phoebe', verbose=True): print("ld_coeffs1", ld_coeffs1) print("ld_coeffs2", ld_coeffs2) - #compare - if verbose: print("checking ld coeffs in "+str(lcs[x])) - assert(np.all(ld_coeffs1==ld_coeffs2)) - #calculate lc + # compare + if verbose: + print("checking ld coeffs in "+str(lcs[x])) + assert np.all(ld_coeffs1 == ld_coeffs2) + # calculate lc fluxes.append(flux_phb1) prim = 0 sec = 0 for x in range(rvno): - if verbose: print(x, rvno) + if verbose: + print(x, rvno) rv_add = '['+str(x+1)+']' - if verbose: print('rvs') + if verbose: + print('rvs') err_val = params[:,1][list(params[:,0]).index('phoebe_rv_indweight'+rv_add)].strip('"') id = params[:,1][list(params[:,0]).index('phoebe_rv_id'+rv_add)].strip('"') @@ -125,37 +127,40 @@ def _legacy_test(filename='default.phoebe', verbose=True): if verbose: print("id", id) - print("comp",comp) + print("comp", comp) if comp == 'primary': comp_name = 'cow' elif comp == 'secondary': comp_name = 'pig' a = int(x/2.) - if verbose: print("loop iteration", a) - + if verbose: + print("loop iteration", a) datafile = params[:,1][list(params[:,0]).index('phoebe_rv_filename'+rv_add)].strip('"') - time_phb1, rv_phb1, err_phb1 = np.loadtxt(os.path.join(dir, datafile), unpack=True) time = b.filter(dataset=id, qualifier='times', component=comp_name).get_value() rv = b.filter(dataset=id, qualifier='rvs', component=comp_name).get_value() sigma = b.filter(dataset=id, qualifier='sigmas', component=comp_name).get_value() - if verbose: print("checking time in "+str(rvs[a])) - assert(np.all(time==time_phb1)) - if verbose: print("checking rv in "+str(rvs[a])) - if verbose: print("a={}, datafile={}, rvs[a]={}".format(a, datafile, rvs[a])) - assert(np.all(rv==rv_phb1)) + if verbose: + print("checking time in "+str(rvs[a])) + assert np.all(time == time_phb1) + if verbose: + print("checking rv in "+str(rvs[a])) + if verbose: + print("a={}, datafile={}, rvs[a]={}".format(a, datafile, rvs[a])) + assert np.all(rv == rv_phb1) sigma = b.filter(dataset=id, qualifier='sigmas', component=comp_name).get_value() - if verbose: print("checking sigma in "+str(rvs[a])) + if verbose: + print("checking sigma in "+str(rvs[a])) if err_val == 'Standard deviation': - assert(np.all(sigma==err_phb1)) + assert np.all(sigma == err_phb1) else: val = np.sqrt(1/err_phb1) - assert(np.allclose(sigma, val, atol=1e-7)) + assert np.allclose(sigma, val, atol=1e-7) if comp_name == 'cow': rv_comp = '['+str(prim+1)+']' @@ -174,7 +179,7 @@ def _legacy_test(filename='default.phoebe', verbose=True): ld_coeffs2 = [ldx1, ldy1, ldx2, ldy2] if verbose: print("checking ld coeffs in primary "+str(rvs[a])) - assert(np.all(ld_coeffs1==ld_coeffs2)) + assert np.all(ld_coeffs1 == ld_coeffs2) prim = prim+1 else: @@ -194,7 +199,7 @@ def _legacy_test(filename='default.phoebe', verbose=True): ld_coeffs2 = [ldx1, ldy1, ldx2, ldy2] if verbose: print("checking ld coeffs in secondary "+str(rvs[a])) - assert(np.all(ld_coeffs1==ld_coeffs2)) + assert np.all(ld_coeffs1 == ld_coeffs2) sec = sec+1 if _has_phb1: @@ -203,19 +208,22 @@ def _legacy_test(filename='default.phoebe', verbose=True): for x in range(len(lcs)): lc2 = b.filter('fluxes', context='model', dataset=lc_id[x]).get_value() time = b.filter('times', context='model', dataset=lc_id[x]).get_value() - if verbose: print("comparing lightcurve "+str(lcs[x])) + if verbose: + print("comparing lightcurve "+str(lcs[x])) - assert(np.allclose(fluxes[x], lc2, atol=1e-5)) + assert np.allclose(fluxes[x], lc2, atol=1e-5) for x in range(rvno): rv_add = '['+str(x+1)+']' - if verbose: print(x, rvno) + if verbose: + print(x, rvno) prim = 0 sec = 0 comp = params[:,1][list(params[:,0]).index('phoebe_rv_dep'+rv_add)].strip('"').split(' ')[0].lower() - if verbose: print('comp', comp) + if verbose: + print('comp', comp) if comp == 'primary': comp_name = 'cow' @@ -226,21 +234,23 @@ def _legacy_test(filename='default.phoebe', verbose=True): time = b.filter('times', component=comp_name, context='model').get_value() a = int(x/2.) - if verbose: print("comp name", comp_name) + if verbose: + print("comp name", comp_name) if comp_name == 'cow': if verbose: print("trying primary rv at "+str(rvs[a])) - assert(np.allclose(vels[prim], rv2, atol=1e-5)) - prim= prim+1 + assert np.allclose(vels[prim], rv2, atol=1e-5) + prim = prim+1 else: if verbose: print("trying secondary rv at "+str(rvs[a])) - assert(np.allclose(vels2[sec], rv2, atol=1e-5)) + assert np.allclose(vels2[sec], rv2, atol=1e-5) sec = sec+1 - if verbose: print("comparing bolometric ld coeffs") + if verbose: + print("comparing bolometric ld coeffs") ldxbol1 = params[:,1][list(params[:,0]).index('phoebe_ld_xbol1')] ldybol1 = params[:,1][list(params[:,0]).index('phoebe_ld_ybol1')] @@ -255,20 +265,16 @@ def _legacy_test(filename='default.phoebe', verbose=True): ldx2, ldy2 = b.filter(qualifier='ld_coeffs_bol', component='pig').get_value() ld_coeffs2 = [ldx1, ldy1, ldx2, ldy2] - assert(np.all(ld_coeffs1==ld_coeffs2)) - - - - return - - + assert np.all(ld_coeffs1 == ld_coeffs2) def test_default(verbose=False): return _legacy_test('default.phoebe', verbose=verbose) -#def test_weighted(verbose=False): -# return _legacy_test('weight.phoebe', verbose=verbose) + +# def test_weighted(verbose=False): +# return _legacy_test('weight.phoebe', verbose=verbose) + def test_contact(verbose=False): return _legacy_test('contact.phoebe', verbose=verbose) diff --git a/tests/tests/test_limits/test_limits.py b/tests/tests/test_limits/test_limits.py index bb63d23e3..e5579becb 100644 --- a/tests/tests/test_limits/test_limits.py +++ b/tests/tests/test_limits/test_limits.py @@ -7,24 +7,20 @@ phoebe.logger('DEBUG') + def test_limits(): b = phoebe.Bundle.default_binary() - with pytest.raises(ValueError) as e_info: + with pytest.raises(ValueError): b.set_value('teff@primary', -10) - # NOTE: celsius not supported for all supported astropy versions (not 1.0) - #assert_raises(ValueError, b.set_value, 'teff@primary', -10*u.Celsius) - with pytest.raises(ValueError) as e_info: + with pytest.raises(ValueError): b.set_value('requiv@primary', -10*u.km) - with pytest.raises(ValueError) as e_info: + with pytest.raises(ValueError): b.set_value('ecc@binary', 1.0) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - - b = test_limits() + test_limits() diff --git a/tests/tests/test_line_profile/test_line_profile.py b/tests/tests/test_line_profile/test_line_profile.py index b7b06ff82..135c4100f 100644 --- a/tests/tests/test_line_profile/test_line_profile.py +++ b/tests/tests/test_line_profile/test_line_profile.py @@ -34,13 +34,11 @@ def test_interp(plot=False): interp_fluxes = b['value@flux_densities@interp@model'] diffs = np.abs(interp_fluxes-np.interp(interp_wavelengths, wavelengths, fluxes)) - assert (np.all(diffs < 0.004)) + assert np.all(diffs < 0.004) if plot: b.plot(show=True) - return b - def test_multi_lp(): """ @@ -64,11 +62,10 @@ def test_multi_lp(): assert (np.allclose(b['values@00.000000@flux_densities@model'], b['values@01.000000@flux_densities@model'], rtol=1e-6, atol=1e-6)) assert (np.allclose(b['values@01.000000@flux_densities@model'], b['values@02.000000@flux_densities@model'], rtol=1e-6, atol=1e-6)) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - b = test_interp() - b = test_multi_lp() + test_interp() + test_multi_lp() diff --git a/tests/tests/test_mesh/test_marching_meshing.py b/tests/tests/test_mesh/test_marching_meshing.py index 8111f1a43..6333fbdc0 100644 --- a/tests/tests/test_mesh/test_marching_meshing.py +++ b/tests/tests/test_mesh/test_marching_meshing.py @@ -7,140 +7,121 @@ from numpy import linalg as la import libphoebe + def potential_roche(r, q, F, d): - r1 = np.array([r[0]- d, r[1], r[2]]); - return 1/la.norm(r) + q*(1/la.norm(r1) - r[0]/d**2) + F**2*(1+q)*(r[0]**2 + r[1]**2)/2 + r1 = np.array([r[0] - d, r[1], r[2]]) + return 1/la.norm(r) + q*(1/la.norm(r1) - r[0]/d**2) + F**2*(1+q)*(r[0]**2 + r[1]**2)/2 + def test_roche_detached(plot=False): - - #print "roche detached" - - q = 1 - F = 1 - d = 1 - Omega0 = 10 - choice = 0 - - # determine area and volume - r_av = libphoebe.roche_area_volume(q, F, d, Omega0, choice, larea=True, lvolume=True) - - #print r_av - - # calculate delta - ntriangles=1000 - delta = np.sqrt(r_av["larea"]/(np.sqrt(3)*ntriangles/4)) - - max_triangles = int(1.5*ntriangles) - - # generate mesh - r_mesh = libphoebe.roche_marching_mesh(q, F, d, Omega0, delta, choice, max_triangles, - vertices=True, vnormals=True, triangles=True, - tnormals=True, areas=True, area=True, volume=True, full=True) - - # check the number of triagles of the mesh - #print len(r_mesh["triangles"]) - assert(0.75*ntriangles < len(r_mesh["triangles"]) < 1.35*ntriangles) - - # check is the vertices are really on isosurface - #print np.max(np.abs([potential_roche(r, q, F, d) - Omega0 for r in r_mesh["vertices"]])) - assert(np.max(np.abs([potential_roche(r, q, F, d) - Omega0 for r in r_mesh["vertices"]])) < 1e-12) - - # check the area -0.00551862428183 - #print (r_mesh["area"]-r_av["larea"])/r_av["larea"] - assert (np.abs(r_mesh["area"]-r_av["larea"])/r_av["larea"] < 1e-2) - - # check the volume -0.0100753493075 - #print (r_mesh["volume"]- r_av["lvolume"])/r_av["lvolume"] - assert (np.abs(r_mesh["volume"]- r_av["lvolume"])/r_av["lvolume"] < 2e-2) + q = 1 + F = 1 + d = 1 + Omega0 = 10 + choice = 0 + + # determine area and volume + r_av = libphoebe.roche_area_volume(q, F, d, Omega0, choice, larea=True, lvolume=True) + + # calculate delta + ntriangles = 1000 + delta = np.sqrt(r_av["larea"]/(np.sqrt(3)*ntriangles/4)) + + max_triangles = int(1.5*ntriangles) + + # generate mesh + r_mesh = libphoebe.roche_marching_mesh( + q, F, d, Omega0, delta, choice, max_triangles, + vertices=True, vnormals=True, triangles=True, + tnormals=True, areas=True, area=True, volume=True, full=True) + + # check the number of triagles of the mesh + assert 0.75*ntriangles < len(r_mesh["triangles"]) < 1.35*ntriangles + + # check is the vertices are really on isosurface + assert np.max(np.abs([potential_roche(r, q, F, d) - Omega0 for r in r_mesh["vertices"]])) < 1e-12 + + # check the area -0.00551862428183 + assert np.abs(r_mesh["area"]-r_av["larea"])/r_av["larea"] < 1e-2 + + # check the volume -0.0100753493075 + assert np.abs(r_mesh["volume"] - r_av["lvolume"])/r_av["lvolume"] < 2e-2 + def test_roche_contact(plot=False): - #print "roche contact" - - q = 0.5 - F = 0.5 - d = 1 - Omega0 = 2.65 - choice = 2 - - # determine area and volume - r_av = libphoebe.roche_area_volume(q, F, d, Omega0, choice, larea=True, lvolume=True) - - #print r_av - - # calculate delta - ntriangles=2000 - delta = np.sqrt(r_av["larea"]/(np.sqrt(3)*ntriangles/4)) - - max_triangles = int(1.5*ntriangles) - - # generate mesh - r_mesh = libphoebe.roche_marching_mesh(q, F, d, Omega0, delta, choice, max_triangles, - vertices=True, vnormals=True, triangles=True, - tnormals=True, areas=True, area=True, volume=True, full=True) - - # check the number of triagles of the mesh - #print len(r_mesh["triangles"]) - assert(0.75*ntriangles < len(r_mesh["triangles"]) < 1.35*ntriangles) - - # check is the vertices are really on isosurface - #print np.max(np.abs([potential_roche(r, q, F, d) - Omega0 for r in r_mesh["vertices"]])) - assert(np.max(np.abs([potential_roche(r, q, F, d) - Omega0 for r in r_mesh["vertices"]])) < 1e-12) - - # check the area - #print (r_mesh["area"]-r_av["larea"])/r_av["larea"] - assert (np.abs(r_mesh["area"]-r_av["larea"])/r_av["larea"] < 1e-2) - - # check the volume - #print (r_mesh["volume"]- r_av["lvolume"])/r_av["lvolume"] - assert (np.abs(r_mesh["volume"]- r_av["lvolume"])/r_av["lvolume"] < 1e-2) + q = 0.5 + F = 0.5 + d = 1 + Omega0 = 2.65 + choice = 2 + + # determine area and volume + r_av = libphoebe.roche_area_volume(q, F, d, Omega0, choice, larea=True, lvolume=True) + + # calculate delta + ntriangles = 2000 + delta = np.sqrt(r_av["larea"]/(np.sqrt(3)*ntriangles/4)) + + max_triangles = int(1.5*ntriangles) + + # generate mesh + r_mesh = libphoebe.roche_marching_mesh( + q, F, d, Omega0, delta, choice, max_triangles, + vertices=True, vnormals=True, triangles=True, + tnormals=True, areas=True, area=True, volume=True, full=True) + + # check the number of triagles of the mesh + assert 0.75*ntriangles < len(r_mesh["triangles"]) < 1.35*ntriangles + + # check is the vertices are really on isosurface + assert np.max(np.abs([potential_roche(r, q, F, d) - Omega0 for r in r_mesh["vertices"]])) < 1e-12 + + # check the area + assert np.abs(r_mesh["area"]-r_av["larea"])/r_av["larea"] < 1e-2 + + # check the volume + assert np.abs(r_mesh["volume"] - r_av["lvolume"])/r_av["lvolume"] < 1e-2 + def test_roche_semidetached(plot=False): - - #print "roche semi-detached" - - q = 1 - F = 1 - d = 1 - - r_crit = libphoebe.roche_critical_potential(q, F, d, L1 = True, L2 = False, L3 = False) - - Omega0 = r_crit["L1"] - choice = 0 - - # determine area and volume - r_av = libphoebe.roche_area_volume(q, F, d, Omega0, choice, larea=True, lvolume=True) - - #print r_av - - # calculate delta - ntriangles=1000 - delta = np.sqrt(r_av["larea"]/(np.sqrt(3)*ntriangles/4)) - - max_triangles = int(1.5*ntriangles) - - # generate mesh - r_mesh = libphoebe.roche_marching_mesh(q, F, d, Omega0, delta, choice, max_triangles, - vertices=True, vnormals=True, triangles=True, - tnormals=True, areas=True, area=True, volume=True, full=True) - - # check the number of triagles of the mesh - #print len(r_mesh["triangles"]) - assert(0.75*ntriangles < len(r_mesh["triangles"]) < 1.35*ntriangles) - - # check is the vertices are really on isosurface - #print np.max(np.abs([potential_roche(r, q, F, d) - Omega0 for r in r_mesh["vertices"]])) - assert(np.max(np.abs([potential_roche(r, q, F, d) - Omega0 for r in r_mesh["vertices"]])) < 1e-12) - - # check the area -0.00524575234831 - #print (r_mesh["area"]-r_av["larea"])/r_av["larea"] - assert (np.abs(r_mesh["area"]-r_av["larea"])/r_av["larea"] < 1e-2) - - # check the volume -0.00985875277254 - #print (r_mesh["volume"]- r_av["lvolume"])/r_av["lvolume"] - assert (np.abs(r_mesh["volume"]- r_av["lvolume"])/r_av["lvolume"] < 2e-2) - - + q = 1 + F = 1 + d = 1 + + r_crit = libphoebe.roche_critical_potential(q, F, d, L1=True, L2=False, L3=False) + + Omega0 = r_crit["L1"] + choice = 0 + + # determine area and volume + r_av = libphoebe.roche_area_volume(q, F, d, Omega0, choice, larea=True, lvolume=True) + + # calculate delta + ntriangles = 1000 + delta = np.sqrt(r_av["larea"]/(np.sqrt(3)*ntriangles/4)) + + max_triangles = int(1.5*ntriangles) + + # generate mesh + r_mesh = libphoebe.roche_marching_mesh( + q, F, d, Omega0, delta, choice, max_triangles, + vertices=True, vnormals=True, triangles=True, + tnormals=True, areas=True, area=True, volume=True, full=True) + + # check the number of triagles of the mesh + assert 0.75*ntriangles < len(r_mesh["triangles"]) < 1.35*ntriangles + + # check is the vertices are really on isosurface + assert np.max(np.abs([potential_roche(r, q, F, d) - Omega0 for r in r_mesh["vertices"]])) < 1e-12 + + # check the area -0.00524575234831 + assert np.abs(r_mesh["area"]-r_av["larea"])/r_av["larea"] < 1e-2 + + # check the volume -0.00985875277254 + assert np.abs(r_mesh["volume"] - r_av["lvolume"])/r_av["lvolume"] < 2e-2 + + if __name__ == '__main__': - test_roche_detached(plot=True) - test_roche_contact(plot=True) - test_roche_semidetached(plot=True) + test_roche_detached(plot=True) + test_roche_contact(plot=True) + test_roche_semidetached(plot=True) diff --git a/tests/tests/test_mesh/test_mesh.py b/tests/tests/test_mesh/test_mesh.py index 66ba7a029..db7f8ed4d 100644 --- a/tests/tests/test_mesh/test_mesh.py +++ b/tests/tests/test_mesh/test_mesh.py @@ -2,13 +2,12 @@ """ import phoebe -from phoebe import u import numpy as np import os try: import matplotlib.pyplot as plt PLOTTING_ENABLED = True -except: +except ImportError: PLOTTING_ENABLED = False @@ -33,7 +32,7 @@ def _phoebe_v_legacy_lc_protomesh(b, gridsize=10, plot=False, gen_comp=False): # TODO: also compare phoebe1:kurucz to phoebe:extern_atmx b.set_value_all('atm', 'extern_planckint') - #turn off albedos (legacy requirement) + # turn off albedos (legacy requirement) b.set_value_all('irrad_frac_refl_bol', 0.0) if gen_comp: @@ -43,7 +42,6 @@ def _phoebe_v_legacy_lc_protomesh(b, gridsize=10, plot=False, gen_comp=False): b.import_model(os.path.join(os.path.dirname(__file__), 'test_mesh.comp.model'), model='phoebe1model') b.run_compute('phoebe2', model='phoebe2model', irrad_method='none') - compares = [] # compares += [{'qualifier': 'us', 'dataset': 'mesh01', 'atol': 1e-10}] # compares += [{'qualifier': 'vs', 'dataset': 'mesh01', 'atol': 1e-12}] @@ -58,28 +56,24 @@ def _phoebe_v_legacy_lc_protomesh(b, gridsize=10, plot=False, gen_comp=False): compares += [{'qualifier': 'loggs', 'dataset': 'mesh01', 'atol': 2e-4}] compares += [{'qualifier': 'teffs', 'dataset': 'mesh01', 'atol': 1e-5}] - compares += [{'qualifier': 'abs_normal_intensities', 'dataset': 'lc01', 'atol': 0, 'rtol': 1e-8}] # NOTE: these values are of order 1E14 - + compares += [{'qualifier': 'abs_normal_intensities', 'dataset': 'lc01', 'atol': 0, 'rtol': 1e-8}] # NOTE: these values are of order 1E14 for c in compares: qualifier = c['qualifier'] dataset = c.get('dataset', 'protomesh') for component in b.hierarchy.get_stars(): - - phoebe1_val = b.get_value(section='model', model='phoebe1model', component=component, dataset=dataset, qualifier=qualifier) phoebe2_val = b.get_value(section='model', model='phoebe2model', component=component, dataset=dataset, qualifier=qualifier) - # phoebe2 wd-style mesh duplicates each trapezoid into two # triangles, so we only need every other. It also handles # duplicating quadrants per-element, whereas the phoebe1 # wrapper duplicates per-quadrant. So we also need to reshape. # TODO: move this into the order that these are actually # exposed by PHOEBE to the user - phoebe2_val = phoebe2_val[::2].reshape(-1,4).flatten(order='F') + phoebe2_val = phoebe2_val[::2].reshape(-1, 4).flatten(order='F') - if component=='secondary': + if component == 'secondary': # TODO: this logic should /REALLY/ be moved into the legacy backend wrapper if qualifier in ['xs']: # the secondary star from phoebe 1 is at (d=1, 0, 0) @@ -93,7 +87,7 @@ def _phoebe_v_legacy_lc_protomesh(b, gridsize=10, plot=False, gen_comp=False): x1 = b.get_value(section='model', model='phoebe1model', component=component, dataset='mesh01', qualifier='xs') # x2 = b.get_value(section='model', model='phoebe2model', component=component, dataset='mesh01', qualifier='xs')[::2] - fig, (ax1, ax2) = plt.subplots(1,2) + fig, (ax1, ax2) = plt.subplots(1, 2) ax1.plot(x1, phoebe1_val, 'bo') ax1.plot(x1, phoebe2_val, 'r.') @@ -108,16 +102,14 @@ def _phoebe_v_legacy_lc_protomesh(b, gridsize=10, plot=False, gen_comp=False): plt.show() plt.close(fig) - assert(np.allclose(phoebe1_val, phoebe2_val, atol=c.get('atol', 1e-7), rtol=c.get('rtol', 0.0))) - - + assert np.allclose(phoebe1_val, phoebe2_val, atol=c.get('atol', 1e-7), rtol=c.get('rtol', 0.0)) def test_binary(plot=False, gen_comp=False): """ """ - phoebe.devel_on() # required for wd meshing + phoebe.devel_on() # required for wd meshing # TODO: try an eccentric orbit over multiple phases (will need to wait for non-protomesh support from the legacy wrapper) # TODO: once ps.copy is implemented, just send b.copy() to each of these @@ -125,10 +117,9 @@ def test_binary(plot=False, gen_comp=False): b = phoebe.Bundle.default_binary() _phoebe_v_legacy_lc_protomesh(b, plot=plot, gen_comp=gen_comp) - phoebe.devel_off() # reset for future tests + phoebe.devel_off() # reset for future tests + if __name__ == '__main__': logger = phoebe.logger('debug') - - test_binary(plot=True, gen_comp=True) diff --git a/tests/tests/test_misaligned/test_misaligned.py b/tests/tests/test_misaligned/test_misaligned.py index ca7503f7e..103841fc3 100644 --- a/tests/tests/test_misaligned/test_misaligned.py +++ b/tests/tests/test_misaligned/test_misaligned.py @@ -3,6 +3,7 @@ import phoebe import numpy as np + def test_binary(plot=False): b = phoebe.Bundle.default_binary() @@ -14,17 +15,14 @@ def test_binary(plot=False): b['distortion_method@secondary'] = 'rotstar' - b.add_dataset('lc', times=np.linspace(0,1,21)) - + b.add_dataset('lc', times=np.linspace(0, 1, 21)) b.run_compute(irrad_method='none') # TODO: add comparisons???? if plot: b.plot(show=True) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - b = test_binary(plot=True) + test_binary(plot=True) diff --git a/tests/tests/test_misaligned/test_misaligned_area_volume.py b/tests/tests/test_misaligned/test_misaligned_area_volume.py index de17797ca..6801fdd33 100644 --- a/tests/tests/test_misaligned/test_misaligned_area_volume.py +++ b/tests/tests/test_misaligned/test_misaligned_area_volume.py @@ -5,23 +5,23 @@ import libphoebe as ph import math as m + def test_area_volume(): - - # detacted case (only meaningful) - choice = 0 - q = 1 - F = 1 - d = 1 - Omega0 = 10 - theta = 0.9 - area0 = 0.1554255703973858 - volume0 = 5.7617852701434746e-03 + # detacted case (only meaningful) + choice = 0 + q = 1 + F = 1 + d = 1 + Omega0 = 10 + theta = 0.9 + area0 = 0.1554255703973858 + volume0 = 5.7617852701434746e-03 + + av = ph.roche_misaligned_area_volume(q, F, d, theta, Omega0, choice, larea=True, lvolume=True) + + assert m.fabs(av["larea"] - area0) < 1e-8*area0 + assert m.fabs(av["lvolume"] - volume0) < 1e-8*volume0 - av = ph.roche_misaligned_area_volume(q, F, d, theta, Omega0, choice, larea=True, lvolume=True) - - assert(m.fabs(av["larea"] - area0) < 1e-8*area0) - assert(m.fabs(av["lvolume"] - volume0) < 1e-8*volume0) if __name__ == '__main__': - - test_area_volume() + test_area_volume() diff --git a/tests/tests/test_mpi/test_mpi.py b/tests/tests/test_mpi/test_mpi.py index fb5886a94..815f1f378 100644 --- a/tests/tests/test_mpi/test_mpi.py +++ b/tests/tests/test_mpi/test_mpi.py @@ -3,7 +3,6 @@ """ import phoebe import numpy as np -import sys def test_mpi(verbose=False, plot=False, npoints=8, turn_mpi_off_after=True): @@ -12,11 +11,13 @@ def test_mpi(verbose=False, plot=False, npoints=8, turn_mpi_off_after=True): b = phoebe.Bundle.default_binary() - b.add_dataset('lc', times=np.linspace(0,1,npoints)) + b.add_dataset('lc', times=np.linspace(0, 1, npoints)) - if verbose: print("calling compute") + if verbose: + print("calling compute") b.run_compute(irrad_method='none', model='phoebe2model') - if verbose: print("model received") + if verbose: + print("model received") if plot: b.plot(show=True) @@ -28,17 +29,15 @@ def test_mpi(verbose=False, plot=False, npoints=8, turn_mpi_off_after=True): # workers or they'll just pickup all the previous tasks phoebe.mpi_off() - return b # disable testing within nosetests/Travis test_mpi.__test__ = False + if __name__ == '__main__': # for fair timing comparisons, let's disable checking for online passbands import os os.environ['PHOEBE_ENABLE_ONLINE_PASSBANDS'] = 'FALSE' - logger = phoebe.logger(clevel='INFO') - - b = test_mpi(verbose=True, plot=False, npoints=101, turn_mpi_off_after=False) + test_mpi(verbose=True, plot=False, npoints=101, turn_mpi_off_after=False) diff --git a/tests/tests/test_mpi/test_mpi_detach.py b/tests/tests/test_mpi/test_mpi_detach.py index 09e4d7178..e7f21bccb 100644 --- a/tests/tests/test_mpi/test_mpi_detach.py +++ b/tests/tests/test_mpi/test_mpi_detach.py @@ -5,7 +5,7 @@ import phoebe import numpy as np -import sys + def test_mpi(verbose=False, plot=False, npoints=8, turn_mpi_off_after=True): phoebe.reset_settings() @@ -13,16 +13,18 @@ def test_mpi(verbose=False, plot=False, npoints=8, turn_mpi_off_after=True): b = phoebe.Bundle.default_binary() - b.add_dataset('lc', times=np.linspace(0,1,npoints)) + b.add_dataset('lc', times=np.linspace(0, 1, npoints)) - if verbose: print("calling compute") + if verbose: + print("calling compute") b.run_compute(irrad_method='none', ntriangles=1000, detach=True) if verbose: print("attaching to model") print(b['model'].status) b['model'].attach() - if verbose: print("model received") + if verbose: + print("model received") if plot: b.plot(show=True) @@ -34,11 +36,11 @@ def test_mpi(verbose=False, plot=False, npoints=8, turn_mpi_off_after=True): # workers or they'll just pickup all the previous tasks phoebe.mpi_off() - return b # disable testing within nosetests/Travis test_mpi.__test__ = False + if __name__ == '__main__': # for fair timing comparisons, let's disable checking for online passbands import os @@ -46,4 +48,4 @@ def test_mpi(verbose=False, plot=False, npoints=8, turn_mpi_off_after=True): logger = phoebe.logger(clevel='INFO') - b = test_mpi(verbose=True, plot=False, npoints=101, turn_mpi_off_after=False) + test_mpi(verbose=True, plot=False, npoints=101, turn_mpi_off_after=False) diff --git a/tests/tests/test_pblum_scale/test_pblum_scale.py b/tests/tests/test_pblum_scale/test_pblum_scale.py index 083e1f973..ac8c7fa9d 100644 --- a/tests/tests/test_pblum_scale/test_pblum_scale.py +++ b/tests/tests/test_pblum_scale/test_pblum_scale.py @@ -5,11 +5,10 @@ import numpy as np - def test_dataset_scaled(verbose=False, plot=False): b = phoebe.Bundle.default_binary() - times = np.linspace(0,1,11) + times = np.linspace(0, 1, 11) fluxes = np.random.random(11) b.add_dataset('lc', times=times, fluxes=fluxes, pblum_mode='dataset-scaled') b.add_dataset('lc', times=times, fluxes=fluxes, pblum_mode='dataset-scaled') @@ -17,10 +16,7 @@ def test_dataset_scaled(verbose=False, plot=False): b.run_compute(irrad_method='none') - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - - b = test_dataset_scaled(verbose=True, plot=True) + test_dataset_scaled(verbose=True, plot=True) diff --git a/tests/tests/test_reflection/test_reflection.py b/tests/tests/test_reflection/test_reflection.py index 78b224ae2..0c6beedb4 100644 --- a/tests/tests/test_reflection/test_reflection.py +++ b/tests/tests/test_reflection/test_reflection.py @@ -5,6 +5,7 @@ import numpy as np import os + def test_binary(plot=False, gen_comp=False): b = phoebe.Bundle.default_binary() @@ -17,7 +18,7 @@ def test_binary(plot=False, gen_comp=False): b.set_value('incl', component='binary', value=45.0) period = b.get_value('period@binary') - b.add_dataset('lc', times=np.linspace(0,period,21)) + b.add_dataset('lc', times=np.linspace(0, period, 21)) if plot: b.add_dataset('mesh', times=[0.0]) b.add_compute('phoebe', compute='phoebe2', irrad_method='wilson') @@ -37,13 +38,16 @@ def test_binary(plot=False, gen_comp=False): b.set_value_all('ld_coeffs', [0.0, 0.0]) for alb in [1.0, 0.5, 0.0]: - if plot: print("alb = {}".format(alb)) + if plot: + print("alb = {}".format(alb)) b.set_value_all('irrad_frac_refl_bol', alb) - if plot: print("running phoebe2 model...") + if plot: + print("running phoebe2 model...") b.run_compute(compute='phoebe2', ntriangles=1000, model='phoebe2model', overwrite=True) if gen_comp: - if plot: print("running phoebe1 model...") + if plot: + print("running phoebe1 model...") b.run_compute(compute='phoebe1', gridsize=30, model='phoebe1model', overwrite=True) b.filter(model='phoebe1model').save('test_reflection_binary_{}.comp.model'.format(alb)) else: @@ -59,9 +63,8 @@ def test_binary(plot=False, gen_comp=False): b.plot(dataset='lc01', ylim=(1.96, 2.02), legend=True, show=True) - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=1e-3, atol=0.)) + assert np.allclose(phoebe2_val, phoebe1_val, rtol=1e-3, atol=0.) - return b def test_binary_ecc(plot=False, gen_comp=False): b = phoebe.Bundle.default_binary() @@ -74,7 +77,7 @@ def test_binary_ecc(plot=False, gen_comp=False): b.set_value('ecc', value=0.1) period = b.get_value('period@binary') - b.add_dataset('lc', times=np.linspace(0,period,21)) + b.add_dataset('lc', times=np.linspace(0, period, 21)) if plot: b.add_dataset('mesh', times=[0.0]) b.add_compute('phoebe', compute='phoebe2', irrad_method='wilson') @@ -94,13 +97,16 @@ def test_binary_ecc(plot=False, gen_comp=False): b.set_value_all('ld_coeffs', [0.0, 0.0]) for alb in [0.5]: - if plot: print("alb = {}".format(alb)) + if plot: + print("alb = {}".format(alb)) b.set_value_all('irrad_frac_refl_bol', alb) - if plot: print("running phoebe2 model...") + if plot: + print("running phoebe2 model...") b.run_compute(compute='phoebe2', ntriangles=1000, model='phoebe2model', overwrite=True) if gen_comp: - if plot: print("running phoebe1 model...") + if plot: + print("running phoebe1 model...") b.run_compute(compute='phoebe1', gridsize=30, model='phoebe1model', overwrite=True) b.filter(model='phoebe1model').save('test_reflection_ecc_{}.comp.model'.format(alb)) else: @@ -116,12 +122,10 @@ def test_binary_ecc(plot=False, gen_comp=False): b.plot(dataset='lc01', ylim=(1.96, 2.02), legend=True, show=True) - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=1e-3, atol=0.)) + assert np.allclose(phoebe2_val, phoebe1_val, rtol=1e-3, atol=0.) - return b def test_contact(plot=False, gen_comp=False): - b = phoebe.default_binary(contact_binary=True) b.set_value('incl', component='binary', value=45.0) @@ -131,12 +135,12 @@ def test_contact(plot=False, gen_comp=False): b['teff@primary'] = 10000. b['teff@secondary'] = 5000. - b.add_dataset('lc', times=np.linspace(0,3,21)) + b.add_dataset('lc', times=np.linspace(0, 3, 21)) if plot: b.add_dataset('mesh', times=[0.0]) b.add_compute('phoebe', compute='phoebe2', irrad_method='wilson') if gen_comp: - b.add_compute('legacy', compute='phoebe1', refl_num=5, morphology = 'Overcontact binary not in thermal contact') + b.add_compute('legacy', compute='phoebe1', refl_num=5, morphology='Overcontact binary not in thermal contact') # set matching atmospheres b.set_value_all('atm', 'extern_planckint') @@ -151,13 +155,16 @@ def test_contact(plot=False, gen_comp=False): b.set_value_all('ld_coeffs', [0.0, 0.0]) for alb in [0, 0.5, 1.0]: - if plot: print("alb = {}".format(alb)) + if plot: + print("alb = {}".format(alb)) b.set_value_all('irrad_frac_refl_bol', alb) - if plot: print("running phoebe2 model...") + if plot: + print("running phoebe2 model...") b.run_compute(compute='phoebe2', ntriangles=1000, model='phoebe2model', overwrite=True) if gen_comp: - if plot: print("running phoebe1 model...") + if plot: + print("running phoebe1 model...") b.run_compute(compute='phoebe1', gridsize=30, model='phoebe1model', overwrite=True) b.filter(model='phoebe1model').save('test_reflection_contact_{}.comp.model'.format(alb)) else: @@ -176,13 +183,12 @@ def test_contact(plot=False, gen_comp=False): # this is quite a low rtol, but our reflection is more robust because # each "half" of the envelope can reflect with itself, whereas WD # only allows reflection between the two halves - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=1e-2, atol=0.)) + assert np.allclose(phoebe2_val, phoebe1_val, rtol=1e-2, atol=0.) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - b = test_binary(plot=True, gen_comp=True) - b = test_binary_ecc(plot=True, gen_comp=True) - b = test_contact(plot=True, gen_comp=True) + test_binary(plot=True, gen_comp=True) + test_binary_ecc(plot=True, gen_comp=True) + test_contact(plot=True, gen_comp=True) diff --git a/tests/tests/test_rm/test_rm.py b/tests/tests/test_rm/test_rm.py index ece92d872..bb839e538 100644 --- a/tests/tests/test_rm/test_rm.py +++ b/tests/tests/test_rm/test_rm.py @@ -31,7 +31,6 @@ def _beta_vs_legacy(b, syncpar, plot=False, gen_comp=False): def test_binary(plot=False, gen_comp=False): - b = phoebe.default_binary() # set equivalent radius of the secondary to be different from the primary to avoid diff --git a/tests/tests/test_rvgrav/test_rvgrav.py b/tests/tests/test_rvgrav/test_rvgrav.py index f36380357..5fedae12b 100644 --- a/tests/tests/test_rvgrav/test_rvgrav.py +++ b/tests/tests/test_rvgrav/test_rvgrav.py @@ -1,6 +1,6 @@ # Test gravitational redshift for the Sun. The theoretically # predicted value from GTR is ~633 m/s. -# +# # The Sun-Jupiter system # expected RV semi-amplitude of the Sun is 12.5 m/s. @@ -8,7 +8,6 @@ import phoebe from phoebe import u, c -# import libphoebe def initiate_sun_jupiter_system(): @@ -25,7 +24,7 @@ def initiate_sun_jupiter_system(): b['teff@secondary'] = (500, 'K') b['requiv@secondary'] = 1.*c.R_jup b['atm@secondary'] = 'blackbody' - + b['ld_mode_bol@secondary'] = 'manual' b['ld_func_bol@secondary'] = 'linear' b['ld_coeffs_bol@secondary'] = [0.5] diff --git a/tests/tests/test_rvs/test_rvs.py b/tests/tests/test_rvs/test_rvs.py index 4e0dfc90e..4b6f420e7 100644 --- a/tests/tests/test_rvs/test_rvs.py +++ b/tests/tests/test_rvs/test_rvs.py @@ -9,20 +9,19 @@ def _beta_vs_legacy(b, ind, plot=False, gen_comp=False): period = b.get_value('period@orbit') - times = np.linspace(-0.2,1.2*period,51) + times = np.linspace(-0.2, 1.2*period, 51) b.set_value('vgamma', 50) - #turn off albedos (legacy requirement) + # turn off albedos (legacy requirement) b.set_value_all('irrad_frac_refl_bol', 0.0) - b.add_dataset('rv', times=times, dataset='rv01', ld_mode='manual', ld_func='logarithmic', ld_coeffs=[0.5,0.5]) + b.add_dataset('rv', times=times, dataset='rv01', ld_mode='manual', ld_func='logarithmic', ld_coeffs=[0.5, 0.5]) b.add_compute('phoebe', compute='phnum', ltte=False, atm='extern_planckint', rv_method='flux-weighted', irrad_method='none') if gen_comp: b.add_compute('legacy', compute='legnum', ltte=False, atm='extern_planckint', rv_method='flux-weighted', refl_num=0) - b.run_compute('phnum', model='phnumresults') if gen_comp: b.run_compute('legnum', model='legnumresults') @@ -38,30 +37,31 @@ def _beta_vs_legacy(b, ind, plot=False, gen_comp=False): phoebe1_val = b.get_value('rvs@primary@legnumresults@legnum') if plot: print("rv@primary max rel diff: {}".format(max(np.abs((phoebe1_val-phoebe2_val)/phoebe2_val)))) - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=1e-1, atol=0.)) + + assert np.allclose(phoebe2_val, phoebe1_val, rtol=1e-1, atol=0.) phoebe2_val = b.get_value('rvs@secondary@phnumresults@phnum') phoebe1_val = b.get_value('rvs@secondary@legnumresults@legnum') if plot: print("rv@secondary max rel diff: {}".format(max(np.abs((phoebe1_val-phoebe2_val)/phoebe2_val)))) - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=1e-1, atol=0.)) + assert np.allclose(phoebe2_val, phoebe1_val, rtol=1e-1, atol=0.) -def test_binary(plot=False, gen_comp=False): - ## system = [sma (solRad), period (d)] +def test_binary(plot=False, gen_comp=False): + # system = [sma (solRad), period (d)] system1 = [11, 2.575] system2 = [215., 257.5] system3 = [8600., 65000.] ind = 0 - for q in [0.5,1.]: + for q in [0.5, 1.]: for system in [system1, system2, system3]: ind += 1 b = phoebe.Bundle.default_binary() - b.set_value('sma@binary',system[0]) + b.set_value('sma@binary', system[0]) b.set_value('period@binary', system[1]) b.set_value('q', q) diff --git a/tests/tests/test_single/test_single.py b/tests/tests/test_single/test_single.py index 86de99bce..3eedd3a89 100644 --- a/tests/tests/test_single/test_single.py +++ b/tests/tests/test_single/test_single.py @@ -5,6 +5,7 @@ from phoebe import u import numpy as np + def test_sun(plot=False): b = phoebe.default_star(starA='sun') @@ -16,32 +17,29 @@ def test_sun(plot=False): b.set_value('incl', 23.5*u.deg) b.set_value('distance', 1.0*u.AU) - assert(b.get_value('teff', u.K)==5772) - assert(b.get_value('requiv', u.solRad)==1.0) - assert(b.get_value('mass', u.solMass)==1.0) - assert(b.get_value('period', u.d)==24.47) - assert(b.get_value('incl', u.deg)==23.5) - assert(b.get_value('distance', u.m)==1.0*u.AU.to(u.m)) + assert b.get_value('teff', u.K) == 5772 + assert b.get_value('requiv', u.solRad) == 1.0 + assert b.get_value('mass', u.solMass) == 1.0 + assert b.get_value('period', u.d) == 24.47 + assert b.get_value('incl', u.deg) == 23.5 + assert b.get_value('distance', u.m) == 1.0*u.AU.to(u.m) b.add_dataset('lc', pblum=1*u.solLum) b.add_dataset('mesh', times=[0], columns=['teffs', 'areas', 'volume'], dataset='mesh01') b.run_compute(irrad_method='none', distortion_method='rotstar') - #print abs(b.get_value('teffs', dataset='pbmesh').mean()-b.get_value('teff', context='component')) + # print abs(b.get_value('teffs', dataset='pbmesh').mean()-b.get_value('teff', context='component')) - assert(abs(np.average(b.get_value('teffs', dataset='mesh01'), weights=b.get_value('areas', dataset='mesh01')) - b.get_value('teff', context='component')) < 1e-6) - assert(abs(b.get_value('volume', dataset='mesh01')-4./3*np.pi*b.get_value('requiv', context='component')**3) < 1e-6) + assert abs(np.average(b.get_value('teffs', dataset='mesh01'), weights=b.get_value('areas', dataset='mesh01')) - b.get_value('teff', context='component')) < 1e-6 + assert abs(b.get_value('volume', dataset='mesh01')-4./3*np.pi*b.get_value('requiv', context='component')**3) < 1e-6 - #print abs(b.get_value('fluxes@model')[0]-1357.12228578) + # print abs(b.get_value('fluxes@model')[0]-1357.12228578) if plot: axs, artists = b['mesh01'].plot(facecolor='teffs', show=True) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - - b = test_sun(plot=True) + test_sun(plot=True) diff --git a/tests/tests/test_spots/test_spots.py b/tests/tests/test_spots/test_spots.py index b8be5499c..5640d4f29 100644 --- a/tests/tests/test_spots/test_spots.py +++ b/tests/tests/test_spots/test_spots.py @@ -5,12 +5,13 @@ import numpy as np import os + def test_binary(plot=False, gen_comp=False): b = phoebe.Bundle.default_binary() b.add_spot(component='primary', relteff=0.9, radius=20, colat=45, long=90, feature='spot01') - b.add_dataset('lc', times=np.linspace(0,1,26)) + b.add_dataset('lc', times=np.linspace(0, 1, 26)) b.add_dataset('mesh', times=[0], columns=['teffs']) b.add_compute('phoebe', compute='phoebe2') if gen_comp: @@ -28,8 +29,7 @@ def test_binary(plot=False, gen_comp=False): b.set_value_all('ld_func', 'logarithmic') b.set_value_all('ld_coeffs', [0.0, 0.0]) - - #turn off albedos (legacy requirement) + # turn off albedos (legacy requirement) b.set_value_all('irrad_frac_refl_bol', 0.0) print("running phoebe2 model...") @@ -52,12 +52,9 @@ def test_binary(plot=False, gen_comp=False): b.plot(dataset='lc01', legend=True, show=True) - assert(np.allclose(phoebe2_val, phoebe1_val, rtol=2e-3, atol=5e-4)) + assert np.allclose(phoebe2_val, phoebe1_val, rtol=2e-3, atol=5e-4) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='DEBUG') - - - b = test_binary(plot=True, gen_comp=True) + test_binary(plot=True, gen_comp=True) diff --git a/tests/tests/test_sun_earth/test_sun_earth.py b/tests/tests/test_sun_earth/test_sun_earth.py index 44a0c79cd..f37b465b8 100644 --- a/tests/tests/test_sun_earth/test_sun_earth.py +++ b/tests/tests/test_sun_earth/test_sun_earth.py @@ -20,7 +20,7 @@ def initiate_sun_earth_system(pb_str): b.add_dataset('lc', times=[0.75,], dataset='lc01', passband=pb_str) b.add_dataset('mesh', times=[0.0], columns=['areas', 'mus', 'visibilities', 'abs_intensities@lc01'], dataset='mesh01') - b['pblum@primary'] = 1.*u.solLum #* 0.99 # 0.99 is bolometric correction + b['pblum@primary'] = 1.*u.solLum # * 0.99 # 0.99 is bolometric correction b['teff@primary'] = 1.*u.solTeff b['requiv@primary'] = 1.*u.solRad b['syncpar@primary'] = 14.61 @@ -51,14 +51,14 @@ def initiate_sun_earth_system(pb_str): return b -def integrated_flux(b, pb): - r = b['value@abs_intensities@primary'] - r *= b['areas@primary@mesh01'].get_value(unit=u.m**2) - r *= b['value@mus@primary@mesh01'] - r *= b['value@visibilities@primary@mesh01'] +def integrated_flux(b, pb): + r = b['value@abs_intensities@primary'] + r *= b['areas@primary@mesh01'].get_value(unit=u.m**2) + r *= b['value@mus@primary@mesh01'] + r *= b['value@visibilities@primary@mesh01'] - return np.nansum(r)*pb.ptf_area/b['value@distance@system']**2 + return np.nansum(r)*pb.ptf_area/b['value@distance@system']**2 def _planck(lam, Teff): @@ -66,71 +66,70 @@ def _planck(lam, Teff): def sun_earth_result(): + pb_str = 'Bolometric:900-40000' + mypb = phoebe.atmospheres.passbands.get_passband(pb_str) - pb_str = 'Bolometric:900-40000' - mypb = phoebe.atmospheres.passbands.get_passband(pb_str) + # theoretical result: Planck formula + passband, no limb-darkening + sedptf = lambda w: _planck(w, c.T_sun.si.value)*mypb.ptf(w) + sb_flux = np.pi*integrate.quad(sedptf, mypb.ptf_table['wl'][0], mypb.ptf_table['wl'][-1])[0] # Stefan-Boltzmann flux - # theoretical result: Planck formula + passband, no limb-darkening - sedptf = lambda w: _planck(w, c.T_sun.si.value)*mypb.ptf(w) - sb_flux = np.pi*integrate.quad(sedptf, mypb.ptf_table['wl'][0], mypb.ptf_table['wl'][-1])[0] # Stefan-Boltzmann flux + # fixed point observer + # xi = ((1*u.solRad).si.value/c.au.si.value)**2 + # iflux0 = sb_flux*xi*2/(1 + np.sqrt(1 - xi)) - # fixed point observer - #~ xi = ((1*u.solRad).si.value/c.au.si.value)**2 - #~ iflux0 = sb_flux*xi*2/(1 + np.sqrt(1 - xi)) + # fixed direction of observation + # xi = (1*u.solRad).si.value/c.au.si.value + # iflux0 = sb_flux*(xi**2)*(1 + 4*xi/3 + xi**2) - # fixed direction of observation - #~ xi = (1*u.solRad).si.value/c.au.si.value - #~ iflux0 = sb_flux*(xi**2)*(1 + 4*xi/3 + xi**2) + # naive fixed direction of observation + xi = (1*u.solRad).si.value/c.au.si.value + iflux0 = sb_flux*(xi**2) - # naive fixed direction of observation - xi = (1*u.solRad).si.value/c.au.si.value - iflux0 = sb_flux*(xi**2) + # phoebe result for different mesh sizes + b = initiate_sun_earth_system(pb_str) - # phoebe result for different mesh sizes - b = initiate_sun_earth_system(pb_str) + res = [] + for Nt in [5000, 10000, 20000]: + b['ntriangles@primary'] = Nt + b['ntriangles@secondary'] = Nt - res=[] - for Nt in [5000, 10000, 20000]: - b['ntriangles@primary'] = Nt - b['ntriangles@secondary'] = Nt + # we're not actually computing light curves so don't care about + # the failing check that the earth is smaller than triangles on + # the sun + b.run_compute(skip_checks=True, eclipse_method='only_horizon') - # we're not actually computing light curves so don't care about - # the failing check that the earth is smaller than triangles on - # the sun - b.run_compute(skip_checks=True, eclipse_method='only_horizon') + q = b['value@q@orbit'] + F = b['value@syncpar@primary'] + spin = np.array([0., 0., 1.]) + req = b['value@requiv@primary']/b['value@sma@orbit'] + V = 4*np.pi*req**3/3 - q = b['value@q@orbit'] - F = b['value@syncpar@primary'] - spin = np.array([0.,0.,1.]) - req = b['value@requiv@primary']/b['value@sma@orbit'] - V = 4*np.pi*req**3/3 + Omega0 = libphoebe.roche_misaligned_Omega_at_vol(V, q, F, 1., spin) - Omega0 = libphoebe.roche_misaligned_Omega_at_vol(V, q, F, 1., spin) + area0 = libphoebe.roche_misaligned_area_volume(q, F, 1., spin, Omega0, larea=True)['larea'] + area0 *= b['value@sma@orbit']**2 - area0 = libphoebe.roche_misaligned_area_volume(q, F, 1., spin, Omega0, larea=True)['larea'] - area0 *= b['value@sma@orbit']**2 + area = np.sum(b['value@areas@primary@mesh01']) + iflux = integrated_flux(b, mypb) - area = np.sum(b['value@areas@primary@mesh01']) - iflux = integrated_flux(b, mypb) + res.append([Nt, area/area0-1, iflux/iflux0-1]) - res.append([Nt, area/area0-1, iflux/iflux0-1]) + return np.array(res) - return np.array(res) +def test_sun_earth(print_results=False, save_results=False): + res = sun_earth_result() -def test_sun_earth(print_results = False, save_results = False): - res = sun_earth_result() + if print_results: + print(res) - if print_results: - print(res) + if save_results: + np.savetxt("res.txt", res) - if save_results: - np.savetxt("res.txt", res) + assert np.abs(res[:,1]).max() < 1e-14 + assert np.abs(res[:,2]).max() < 1e-3 - assert(np.abs(res[:,1]).max() < 1e-14) - assert(np.abs(res[:,2]).max() < 1e-3) if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - res = test_sun_earth(print_results = True, save_results = True) + test_sun_earth(print_results=True, save_results=True) diff --git a/tests/tests/test_t0s/test_t0s.py b/tests/tests/test_t0s/test_t0s.py index 2ee5950df..f98e18e59 100644 --- a/tests/tests/test_t0s/test_t0s.py +++ b/tests/tests/test_t0s/test_t0s.py @@ -6,6 +6,7 @@ phoebe.interactive_on() + def test_binary(verbose=False): def assert_t0s(p1_t0_ref, p1_t0_supconj, p1_t0_perpass, tol=1e-4): # b.run_delayed_constraints() @@ -17,9 +18,9 @@ def assert_t0s(p1_t0_ref, p1_t0_supconj, p1_t0_perpass, tol=1e-4): if verbose: print("{}=={}, {}=={}, {}=={}".format(p1_t0_ref, p2_t0_ref, p1_t0_supconj, p2_t0_supconj, p1_t0_perpass, p2_t0_perpass)) - assert(abs(p2_t0_ref-p1_t0_ref) < tol) - assert(abs(p2_t0_supconj-p1_t0_supconj) < tol) - assert(abs(p2_t0_perpass-p1_t0_perpass) < tol) + assert abs(p2_t0_ref-p1_t0_ref) < tol + assert abs(p2_t0_supconj-p1_t0_supconj) < tol + assert abs(p2_t0_perpass-p1_t0_perpass) < tol b = phoebe.Bundle.default_binary() @@ -27,19 +28,19 @@ def assert_t0s(p1_t0_ref, p1_t0_supconj, p1_t0_perpass, tol=1e-4): # ecc = 0, per0 = 0 # compare against values in PHOEBE 1 by manually setting the HJD0 in PHOEBE 1 # so that supconj matches the prescribed 0.0 - p1_ref = 0.0 # SET + p1_ref = 0.0 # SET p1_supconj = 0.0 p1_perpass = -0.25 assert_t0s(p1_ref, p1_supconj, p1_perpass) b['ecc'] = 0.2 - p1_ref = 0.063235 # SET + p1_ref = 0.063235 # SET p1_supconj = 0.0 p1_perpass = -0.186765 assert_t0s(p1_ref, p1_supconj, p1_perpass) b['per0'] = 90 - p1_ref = 0.0 # SET + p1_ref = 0.0 # SET p1_supconj = 0.0 p1_perpass = 0.0 assert_t0s(p1_ref, p1_supconj, p1_perpass) @@ -50,20 +51,20 @@ def assert_t0s(p1_t0_ref, p1_t0_supconj, p1_t0_perpass, tol=1e-4): b['t0_ref@component'] = 0.0 b['per0'] = 180 - p1_ref = 0.0 # SET + p1_ref = 0.0 # SET p1_supconj = 0.063235 p1_perpass = 0.25 assert_t0s(p1_ref, p1_supconj, p1_perpass) b['t0_ref@component'] = 0.3 b['per0'] = 45 - p1_ref = 0.3 # SET + p1_ref = 0.3 # SET p1_supconj = 0.259489 p1_perpass = 0.17500 assert_t0s(p1_ref, p1_supconj, p1_perpass) # cannot flip both constraints to solve for t0_supconj - with pytest.raises(ValueError) as e_info: + with pytest.raises(ValueError): b.flip_constraint('t0_perpass', solve_for='t0_supconj') b.flip_constraint('t0_supconj', solve_for='t0_ref') @@ -76,14 +77,12 @@ def assert_t0s(p1_t0_ref, p1_t0_supconj, p1_t0_perpass, tol=1e-4): b['ecc'] = 0.3 b['per0'] = 0.123, 'rad' # set p1 HJD0 = +0.691272 - p1_ref = 0.691272 # SET + p1_ref = 0.691272 # SET p1_supconj = 0.418709 p1_perpass = 0.0 assert_t0s(p1_ref, p1_supconj, p1_perpass) - return b if __name__ == '__main__': logger = phoebe.logger(clevel='INFO') - - b = test_binary(verbose=True) + test_binary(verbose=True) diff --git a/tests/travis/phoebe.config b/tests/travis/phoebe.config deleted file mode 100644 index 182235607..000000000 --- a/tests/travis/phoebe.config +++ /dev/null @@ -1,17 +0,0 @@ -GUI_CONFIRM_ON_OVERWRITE = 1 -GUI_BEEP_AFTER_PLOT_AND_FIT = 0 -GUI_ANGLE_UNITS = Radians -PHOEBE_BASE_DIR = /usr/local/share/phoebe -PHOEBE_DEFAULTS_DIR = /usr/local/share/phoebe -PHOEBE_TEMP_DIR = /tmp -PHOEBE_DATA_DIR = /usr/local/share/phoebe -PHOEBE_PTF_DIR = /usr/local/share/phoebe/ptf -PHOEBE_LD_SWITCH = 0 -PHOEBE_LD_INTERN = 0 -PHOEBE_LD_DIR = /usr/local/share/phoebe -PHOEBE_LD_VH_DIR = /usr/local/share/phoebe -PHOEBE_KURUCZ_SWITCH = 0 -PHOEBE_KURUCZ_DIR = /usr/local/share/phoebe/kurucz -PHOEBE_PLUGINS_DIR = /usr/local/lib/phoebe/plugins -LOAD_ATM_TO_MEMORY = 1 -DUMP_LCOUT_FILES = 1