Skip to content

Commit

Permalink
Merge branch 'main' into saanika/changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sblunt committed Jun 30, 2023
2 parents 62d86a3 + 3eefbce commit 8f0f17f
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 57 deletions.
8 changes: 8 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ User Guide:
Changelog:
++++++++++

**2.2.2 (2023-06-30)**

- tests now overwrite any generated text files (@sblunt)

**2.2.1 (2023-06-28)**

- tau_to_tp function now accepts array of after_date (@tomasstolker/@semaphoreP)

**2.2.0 (2023-06-21)**

- set up new CI system using GH actions (@sblunt)
Expand Down
2 changes: 1 addition & 1 deletion orbitize/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

__version__ = "2.2.0"
__version__ = "2.2.2"

# set Python env variable to keep track of example data dir
orbitize_dir = os.path.dirname(__file__)
Expand Down
4 changes: 2 additions & 2 deletions orbitize/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ def tau_to_tp(tau, ref_epoch, period, after_date=None):
tau (float or np.array): value of tau to convert
ref_epoch (float or np.array): date (in days, typically MJD) that tau is defined relative to
period (float or np.array): period (in years) that tau is noralized with
after_date (float): tp will be the first periastron after this date. If None, use ref_epoch.
after_date (float or np.array): tp will be the first periastron after this date. If None, use ref_epoch.
Returns:
float or np.array: corresponding t_p of the taus
Expand All @@ -1151,7 +1151,7 @@ def tau_to_tp(tau, ref_epoch, period, after_date=None):

if after_date is not None:
num_periods = (after_date - tp)/period_days
num_periods = int(np.ceil(num_periods))
num_periods = np.ceil(num_periods).astype(int)

tp += num_periods * period_days

Expand Down
60 changes: 37 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re

USE_C_KEPLER_MODULE = 1
if ("--disable-cython" in sys.argv):
if "--disable-cython" in sys.argv:
sys.argv.remove("--disable-cython")
USE_C_KEPLER_MODULE = 0
else:
Expand All @@ -13,44 +13,58 @@
print("Error: Importing cython build environment failed")
USE_C_KEPLER_MODULE = 0


# auto-updating version code stolen from RadVel
def get_property(prop, project):
result = re.search(r'{}\s*=\s*[\'"]([^\'"]*)[\'"]'.format(prop),
open(project + '/__init__.py').read())
result = re.search(
r'{}\s*=\s*[\'"]([^\'"]*)[\'"]'.format(prop),
open(project + "/__init__.py").read(),
)
return result.group(1)


def get_requires():
reqs = []
for line in open('requirements.txt', 'r').readlines():
for line in open("requirements.txt", "r").readlines():
reqs.append(line)
return reqs


def get_extensions():
extensions = []
if(USE_C_KEPLER_MODULE):
extensions = cythonize([Extension("orbitize._kepler", ["orbitize/_kepler.pyx"], include_dirs=[numpy.get_include()])])
if USE_C_KEPLER_MODULE:
extensions = cythonize(
[
Extension(
"orbitize._kepler",
["orbitize/_kepler.pyx"],
include_dirs=[numpy.get_include()],
)
]
)
return extensions


setup(
name='orbitize',
version=get_property('__version__', 'orbitize'),
description='orbitize! Turns imaging data into orbits',
url='https://github.com/sblunt/orbitize',
author='',
author_email='',
license='BSD',
name="orbitize",
version=get_property("__version__", "orbitize"),
description="orbitize! Turns imaging data into orbits",
url="https://github.com/sblunt/orbitize",
author="",
author_email="",
license="BSD",
packages=find_packages(),
package_data={"":["kernels/*.cu"]},
package_data={"": ["kernels/*.cu"]},
ext_modules=get_extensions(),
include_dirs=[numpy.get_include()],
include_package_data = True,
include_package_data=True,
zip_safe=False,
classifiers=[
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering :: Astronomy',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 3.6',
],
keywords='Orbits Astronomy Astrometry',
install_requires=get_requires()
)
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Astronomy",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3.6",
],
keywords="Orbits Astronomy Astrometry",
install_requires=get_requires(),
)
42 changes: 21 additions & 21 deletions tests/test_abs_astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import orbitize
from orbitize import kepler, read_input, system


def test_1planet():
"""
Check that for the 2-body case, the primary orbit around the barycenter
Expand All @@ -26,51 +27,50 @@ def test_1planet():
mass_b = 100 * mjup
mtot = mass_b + m0

epochs = np.linspace(0, 300, 100) + tau_ref_epoch # nearly the full period, MJD
epochs = np.linspace(0, 300, 100) + tau_ref_epoch # nearly the full period, MJD

ra_model, dec_model, _ = kepler.calc_orbit(
epochs, sma, ecc, inc, aop, pan, tau, plx, mtot,
tau_ref_epoch=tau_ref_epoch
epochs, sma, ecc, inc, aop, pan, tau, plx, mtot, tau_ref_epoch=tau_ref_epoch
)

# generate some fake measurements to feed into system.py to test bookkeeping
t = table.Table(
[
epochs,
np.ones(epochs.shape, dtype=int),
ra_model,
np.zeros(ra_model.shape),
dec_model,
np.zeros(dec_model.shape)
],
names=["epoch", "object" ,"raoff", "raoff_err","decoff","decoff_err"]
epochs,
np.ones(epochs.shape, dtype=int),
ra_model,
np.zeros(ra_model.shape),
dec_model,
np.zeros(dec_model.shape),
],
names=["epoch", "object", "raoff", "raoff_err", "decoff", "decoff_err"],
)
filename = os.path.join(orbitize.DATADIR, "rebound_1planet.csv")
t.write(filename)
t.write(filename, overwrite=True)

# create the orbitize system and generate model predictions using ground truth
astrom_dat = read_input.read_file(filename)

sys = system.System(
1, astrom_dat, m0, plx, tau_ref_epoch=tau_ref_epoch,
fit_secondary_mass=True
1, astrom_dat, m0, plx, tau_ref_epoch=tau_ref_epoch, fit_secondary_mass=True
)
sys.track_planet_perturbs = True

params = np.array([sma, ecc, inc, aop, pan, tau, plx, mass_b, m0])
ra, dec, _ = sys.compute_all_orbits(params)

# the planet and stellar orbit should just be scaled versions of one another
planet_ra = ra[:,1,:]
planet_dec = dec[:,1,:]
star_ra = ra[:,0,:]
star_dec = dec[:,0,:]
planet_ra = ra[:, 1, :]
planet_dec = dec[:, 1, :]
star_ra = ra[:, 0, :]
star_dec = dec[:, 0, :]

assert np.all(np.abs(star_ra + (mass_b / mtot) * planet_ra) < 1e-16)
assert np.all(np.abs(star_dec + (mass_b / mtot) * planet_dec) < 1e-16)

# remove the created csv file to clean up
os.system('rm {}'.format(filename))
os.system("rm {}".format(filename))


if __name__ == '__main__':
test_1planet()
if __name__ == "__main__":
test_1planet()
4 changes: 4 additions & 0 deletions tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def test_tau_tp_conversion():
tp = basis.tau_to_tp(tau, ref_epoch, period, after_date=47000)
assert tp == pytest.approx(51000 - 9 * 365.25, rel=1e-7)

tps = basis.tau_to_tp(tau, ref_epoch, period, after_date=np.array([47000, 51000]))
assert tps[0] == pytest.approx(51000 - 9 * 365.25, rel=1e-7)
assert tps[1] == pytest.approx(51000 + 365.25, rel=1e-7)

tau3 = basis.tp_to_tau(tp, ref_epoch, period)
assert tau == pytest.approx(tau3, rel=1e-7)

Expand Down
20 changes: 10 additions & 10 deletions tests/test_multiplanet_rebound.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_1planet():
names=["epoch", "object", "raoff", "raoff_err", "decoff", "decoff_err"],
)
filename = os.path.join(orbitize.DATADIR, "rebound_1planet.csv")
t.write(filename)
t.write(filename, overwrite=True)

# create the orbitize system and generate model predictions using the ground truth
astrom_dat = read_input.read_file(filename)
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_1planet():
assert np.all(np.abs(diff_dec) < 1e-9)

# clean up
os.system("rm {}".format(filename))
# os.system("rm {}".format(filename))


def test_2planet_massive():
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_2planet_massive():
names=["epoch", "object", "raoff", "raoff_err", "decoff", "decoff_err"],
)
filename = os.path.join(orbitize.DATADIR, "rebound_2planet_outer.csv")
t.write(filename)
t.write(filename, overwrite=True)

# TEST THE OUTER PLANET

Expand Down Expand Up @@ -292,7 +292,7 @@ def test_2planet_massive():
assert np.all(np.abs(diff_dec) / (params[0]) < 1e-3)

# clean up
os.system("rm {}".format(filename))
# os.system("rm {}".format(filename))

# NOW TEST THE INNER PLANET

Expand All @@ -310,7 +310,7 @@ def test_2planet_massive():
names=["epoch", "object", "raoff", "raoff_err", "decoff", "decoff_err"],
)
filename = os.path.join(orbitize.DATADIR, "rebound_2planet_inner.csv")
t.write(filename)
t.write(filename, overwrite=True)

# create the orbitize system and generate model predictions using the ground truth
astrom_dat = read_input.read_file(filename)
Expand Down Expand Up @@ -385,7 +385,7 @@ def test_2planet_massive():
assert np.all(np.abs(diff_dec) / (params[0]) < 3e-3)

# clean up
os.system("rm {}".format(filename))
# os.system("rm {}".format(filename))


def test_2planet_massive_reverse_order():
Expand Down Expand Up @@ -454,7 +454,7 @@ def test_2planet_massive_reverse_order():
names=["epoch", "object", "raoff", "raoff_err", "decoff", "decoff_err"],
)
filename = os.path.join(orbitize.DATADIR, "rebound_2planet_swapped_outer.csv")
t.write(filename)
t.write(filename, overwrite=True)

# TEST THE OUTER PLANET ####

Expand Down Expand Up @@ -543,7 +543,7 @@ def test_2planet_massive_reverse_order():
assert np.all(np.abs(diff_dec) / (params[6]) < 1e-3)

# clean up
os.system("rm {}".format(filename))
# os.system("rm {}".format(filename))


def test_2planet_nomass():
Expand Down Expand Up @@ -611,7 +611,7 @@ def test_2planet_nomass():
names=["epoch", "object", "raoff", "raoff_err", "decoff", "decoff_err"],
)
filename = os.path.join(orbitize.DATADIR, "rebound_2planet.csv")
t.write(filename)
t.write(filename, overwrite=True)

# create the orbitize system and generate model predictions using the ground truth
astrom_dat = read_input.read_file(filename)
Expand Down Expand Up @@ -693,7 +693,7 @@ def test_2planet_nomass():
assert np.all(np.abs(diff_dec) / (params[0] * params[6 * 2]) < 1e-9)

# clean up
os.system("rm {}".format(filename))
# os.system("rm {}".format(filename))


if __name__ == "__main__":
Expand Down

0 comments on commit 8f0f17f

Please sign in to comment.