Skip to content

Commit

Permalink
add test and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
semaphoreP committed Feb 5, 2024
1 parent e36dce4 commit 08c86a2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
29 changes: 29 additions & 0 deletions tests/test_predictions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Testing the prediciton tool
"""
import subprocess
import numpy as np
import whereistheplanet.whereistheplanet as witp

def test_all_predictions():
"""
Test all predictions to make sure the posteriors exist.
Checks the values produced are not nan
"""
labels = witp.post_dict.keys()

for name in labels:
print(name)
ra_args, dec_args, sep_args, pa_args = witp.predict_planet(name)
assert np.all(~np.isnan(ra_args))
assert np.all(~np.isnan(pa_args))

def test_cmd_line():
"""
Test command line script
"""
subprocess.run(['whereistheplanet', 'betpicb', '-t', '2022-01-01'])

if __name__ == "__main__":
test_all_predictions()

18 changes: 13 additions & 5 deletions whereistheplanet/whereistheplanet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from astropy.time import Time

import orbitize.kepler as kepler
import orbitize.results as results

moduledir = os.path.dirname(__file__)
basedir = os.path.dirname(moduledir) # up one leve
Expand Down Expand Up @@ -68,7 +69,7 @@
"hr5362b" : ("binary_HR5362B.hdf5", "GRAVITY Binary"),
"kap01sclb" : ("binary_kap01SclB.hdf5", "GRAVITY Binary"),
"hd30003b" : ("binary_HD30003B.hdf5", "GRAVITY Binary"),
"hd1663b" : ("binary_wds00209+1059.hdf5", "Nowak et al. 2024"),
"hd1663b" : ("binary_wdsj00209+1059.hdf5", "Nowak et al. 2024"),
"lam01sclb" : ("binary_wdsj00427-3828.hdf5", "Nowak et al. 2024"),
"hd25535b" : ("binary_wdsj04021-3429.hdf5", "Nowak et al. 2024"),
"hd32642b" : ("binary_wdsj05055+1948.hdf5", "Nowak et al. 2024"),
Expand Down Expand Up @@ -258,10 +259,17 @@ def get_chains(planet_name):

filename, reference = post_dict[planet_name]
filepath = os.path.join(datadir, filename)
with h5py.File(filepath,'r') as hf: # Opens file for reading
post = np.array(hf.get('post'))
tau_ref_epoch = float(hf.attrs['tau_ref_epoch'])

try:
res = results.Results()
res.load_results(filepath)
post = res.post
tau_ref_epoch = res.tau_ref_epoch
except KeyError:
with h5py.File(filepath,'r') as hf: # Opens file for reading
post = np.array(hf.get('post'))
tau_ref_epoch = float(hf.attrs['tau_ref_epoch'])
post = np.array(post, dtype=float)

return post, tau_ref_epoch

def get_reference(planet_name):
Expand Down

0 comments on commit 08c86a2

Please sign in to comment.