Skip to content

Commit

Permalink
Small fixes to the uniform model.
Browse files Browse the repository at this point in the history
  • Loading branch information
hpparvi committed Feb 3, 2024
1 parent 3d5f9a4 commit 7390451
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 41 deletions.
84 changes: 44 additions & 40 deletions pytransit/models/numba/ma_uniform_nb.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
from numpy import pi, sqrt, arccos, abs, zeros_like, sign, sin, cos, abs, atleast_2d, zeros, atleast_1d, isnan, inf, \
nan, copysign, fmax, floor

from meepmeep.xy.position import pd_t15sc, solve_xy_p5s, xyd_t15s
from meepmeep.xy.derivatives import pd_with_derivatives_s, xy_derivative_coeffs, pd_derivatives_s

from ...orbits import d_from_pkaiews
from ...orbits.taylor_z import vajs_from_paiew, z_taylor_st, vajs_from_paiew_eclipse, t14

TWO_PI = 2.0 * pi
Expand Down Expand Up @@ -142,46 +146,46 @@ def dfdz(z, r1, r2):
return (t1 + t2 - t3) / pi


@njit
def xuniform_model_v(times, k, t0, p, a, i, e, w, with_derivatives):
npt = times.size
flux = zeros(npt)
dflux = zeros((6, npt)) if with_derivatives else None
ds = zeros(6)

if a <= 1.0 or e >= 0.99:
flux[:] = nan
return flux, dflux

half_window_width = 0.025 + 0.5 * d_from_pkaiews(p, k, a, i, e, w, 1.)

# ---------------------------------------------------------------------
# Solve the Taylor series coefficients for the planet's (x, y) location
# and its derivatives if they're requested.
# ---------------------------------------------------------------------
cf = solve_xy_p5s(0.0, p, a, i, e, w)
if with_derivatives:
dcf = xy_derivative_coeffs(diffs(p, a, i, e, w, 1e-4), 1e-4, cf)
else:
dcf = None

# -----------------------------------------------
# Calculate the transit model and its derivatives
# -----------------------------------------------
for j in range(npt):
t = folded_time(times[j], t0, p)
if fabs(t) > half_window_width:
flux[j] = 1.0
else:
x, y, d = xyd_t15s(t, cf)
if d <= 1.0 + k:
flux[j] += uniform_z_s(d, k, 1.0)
if with_derivatives:
ds = pd_derivatives_s(t, x, y, dcf, ds)
dflux[:, j] += -dfdz(d, k, 1.0) * ds
else:
flux[j] += 1.
return flux, dflux
# @njit
# def xuniform_model_v(times, k, t0, p, a, i, e, w, with_derivatives):
# npt = times.size
# flux = zeros(npt)
# dflux = zeros((6, npt)) if with_derivatives else None
# ds = zeros(6)
#
# if a <= 1.0 or e >= 0.99:
# flux[:] = nan
# return flux, dflux
#
# half_window_width = 0.025 + 0.5 * d_from_pkaiews(p, k, a, i, e, w, 1.)
#
# # ---------------------------------------------------------------------
# # Solve the Taylor series coefficients for the planet's (x, y) location
# # and its derivatives if they're requested.
# # ---------------------------------------------------------------------
# cf = solve_xy_p5s(0.0, p, a, i, e, w)
# if with_derivatives:
# dcf = xy_derivative_coeffs(diffs(p, a, i, e, w, 1e-4), 1e-4, cf)
# else:
# dcf = None
#
# # -----------------------------------------------
# # Calculate the transit model and its derivatives
# # -----------------------------------------------
# for j in range(npt):
# t = folded_time(times[j], t0, p)
# if fabs(t) > half_window_width:
# flux[j] = 1.0
# else:
# x, y, d = xyd_t15s(t, cf)
# if d <= 1.0 + k:
# flux[j] += uniform_z_s(d, k, 1.0)
# if with_derivatives:
# ds = pd_derivatives_s(t, x, y, dcf, ds)
# dflux[:, j] += -dfdz(d, k, 1.0) * ds
# else:
# flux[j] += 1.
# return flux, dflux


@njit(parallel=True, fastmath=False)
Expand Down
3 changes: 2 additions & 1 deletion pytransit/models/numba/udmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def uniform_model_simple(times, k, t0, p, a, i, e, w, with_derivatives):
# ---------------------------------------------------------------------
cf = solve_xy_p5s(0.0, p, a, i, e, w)
if with_derivatives:
dcf = xy_derivative_coeffs(diffs(p, a, i, e, w, 1e-4), 1e-4, cf)
raise NotImplementedError
#dcf = xy_derivative_coeffs(diffs(p, a, i, e, w, 1e-4), 1e-4, cf)
else:
dcf = None

Expand Down

0 comments on commit 7390451

Please sign in to comment.