Skip to content

Commit

Permalink
x.ptp() -> np.ptp(x)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-faria committed Jun 20, 2024
1 parent b78c1a3 commit 0cd40c7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/kima/pykima/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def aliases(P):
return alias_year, alias_solar_day, alias_sidereal_day

def FIP(results, oversampling=5, plot=True, adjust_oversampling=True):
Tobs = results.t.ptp()
Tobs = np.ptp(results.t)
Dw = 2 * np.pi / Tobs
a, b = results.priors['Pprior'].support()

Expand Down Expand Up @@ -341,7 +341,7 @@ def FIP_count_detections(results, alpha=0.05, Ptrue=None):
from interval import Interval
bins, fip = FIP(results, plot=False)
ftrue = 1 / Ptrue
Tobs = results.t.ptp()
Tobs = np.ptp(results.t)
ffip = 1 / bins[fip.argmin()]
return ftrue in Interval(ffip - 1 / Tobs, ffip + 1 / Tobs)

Expand Down Expand Up @@ -866,9 +866,9 @@ def detection_limits(results, star_mass: Union[float, Tuple] = 1.0,
kwargs = dict(ls='--', lw=2, alpha=0.5, zorder=-1, color='C5')
if isinstance(res, list):
for r in res:
ax.axvline(r.data.t.ptp(), 0.5, 1, **kwargs)
ax.axvline(np.ptp(r.data.t), 0.5, 1, **kwargs)
else:
ax.axvline(res.data.t.ptp(), 0.5, 1, **kwargs)
ax.axvline(np.ptp(res.data.t), 0.5, 1, **kwargs)

# ax.hlines(s.max, bins_start, bins_end, lw=2)
# ax.loglog(s99.bins, s99.max * mjup2mearth)
Expand Down
16 changes: 8 additions & 8 deletions src/kima/pykima/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def plot_posterior_period(res,
ax.axvline(x=year, color='r', label='1 year', **kwline)

if show_timespan: # mark the timespan of the data
ax.axvline(x=res.data.t.ptp(), color='k', label='time span', **kwline)
ax.axvline(x=np.ptp(res.data.t), color='k', label='time span', **kwline)

if show_aliases is not None: # mark daily and yearly aliases of top peak
from .analysis import aliases
Expand Down Expand Up @@ -452,7 +452,7 @@ def plot_PKE(res, mask=None, include_known_object=False, show_prior=False,
K = K.ravel()
E = E.ravel()

if K.size > 1 and K.ptp() > Khdr_threshold:
if K.size > 1 and np.ptp(K) > Khdr_threshold:
ax1.loglog(P, K, '.', **kw)
else:
ax1.semilogx(P, K, '.', **kw)
Expand All @@ -461,7 +461,7 @@ def plot_PKE(res, mask=None, include_known_object=False, show_prior=False,


else:
if K.size > 1 and K.ptp() > 30:
if K.size > 1 and np.ptp(K) > 30:
cm = ax1.hexbin(P[P != 0.0], K[P != 0.0], gridsize=gridsize, bins='log', xscale='log',
yscale='log', cmap=plt.get_cmap('coolwarm_r'))
else:
Expand Down Expand Up @@ -1198,7 +1198,7 @@ def corner_planet_parameters(res, fig=None, Np=None, true_values=None, period_ra

# # set the parameter ranges to include everything
# def r(x, over=0.2):
# return x.min() - over * x.ptp(), x.max() + over * x.ptp()
# return x.min() - over * np.ptp(x), x.max() + over * np.ptp(x)



Expand Down Expand Up @@ -2490,7 +2490,7 @@ def phase_plot(res,
axp = fig.add_subplot(gs[:, -1])
from astropy.timeseries import LombScargle
gls = LombScargle(res.data.t, residuals, res.data.e)
freq, power = gls.autopower(maximum_frequency=1.0, minimum_frequency=1/res.data.t.ptp())
freq, power = gls.autopower(maximum_frequency=1.0, minimum_frequency=1/np.ptp(res.data.t))
axp.semilogy(power, 1 / freq, 'k', alpha=0.6)

kwl = dict(color='k', alpha=0.2, ls='--')
Expand Down Expand Up @@ -2798,7 +2798,7 @@ def plot_random_samples_multiseries(res, ncurves=50, samples=None, over=0.1, ntt
t -= 24e5
M0_epoch -= 24e5

tt = np.linspace(t.min() - over * t.ptp(), t.max() + over * t.ptp(), ntt + int(100 * over))
tt = np.linspace(t.min() - over * np.ptp(t), t.max() + over * np.ptp(t), ntt + int(100 * over))

if res.has_gp:
# let's be more reasonable for the number of GP prediction points
Expand All @@ -2808,7 +2808,7 @@ def plot_random_samples_multiseries(res, ncurves=50, samples=None, over=0.1, ntt
kde = gaussian_kde(t)
ttGP = kde.resample(25000 + t.size * 3).reshape(-1)
# constrain ttGP within observed times, to not waste
ttGP = (ttGP + t[0]) % t.ptp() + t[0]
ttGP = (ttGP + t[0]) % np.ptp(t) + t[0]
ttGP = np.r_[ttGP, t]
ttGP.sort() # in-place

Expand Down Expand Up @@ -2933,7 +2933,7 @@ def plot_random_samples_multiseries(res, ncurves=50, samples=None, over=0.1, ntt
for iko in range(res.nKO):
KOpl = res.eval_model(samples[i], tt,
single_planet=-iko - 1)[0]
ax1.plot(tt, KOpl - y_offset + (iko + 1) * res.data.y.ptp(),
ax1.plot(tt, KOpl - y_offset + (iko + 1) * np.ptp(res.data.y),
color='g', alpha=alpha)

if res.has_gp:
Expand Down
10 changes: 5 additions & 5 deletions src/kima/pykima/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __repr__(self):

@property
def tmiddle(self):
return self.t.min() + 0.5 * self.t.ptp()
return self.t.min() + 0.5 * np.ptp(self.t)


@dataclass
Expand Down Expand Up @@ -1835,16 +1835,16 @@ def _get_tt(self, N=1000, over=0.1):
Create array for model prediction plots. This simply returns N
linearly-spaced times from t[0]-over*Tspan to t[-1]+over*Tspan.
"""
start = self.data.t.min() - over * self.data.t.ptp()
end = self.data.t.max() + over * self.data.t.ptp()
start = self.data.t.min() - over * np.ptp(self.data.t)
end = self.data.t.max() + over * np.ptp(self.data.t)
return np.linspace(start, end, N)

def _get_ttGP(self, N=1000, over=0.1):
""" Create array of times for GP prediction plots. """
kde = gaussian_kde(self.data.t)
ttGP = kde.resample(N - self.data.N).reshape(-1)
# constrain ttGP within observed times, to not waste
ttGP = (ttGP + self.data.t[0]) % self.data.t.ptp() + self.data.t[0]
ttGP = (ttGP + self.data.t[0]) % np.ptp(self.data.t) + self.data.t[0]
# add the observed times as well
ttGP = np.r_[ttGP, self.data.t]
ttGP.sort() # in-place
Expand Down Expand Up @@ -2623,7 +2623,7 @@ def _offset_times(self):
def data_properties(self):
t = self.data.t
prop = {
'time span': (t.ptp(), 'days', True),
'time span': (np.ptp(t), 'days', True),
'mean time gap': (np.ediff1d(t).mean(), 'days', True),
'median time gap': (np.median(np.ediff1d(t)), 'days', True),
'shortest time gap': (np.ediff1d(t).min(), 'days', True),
Expand Down
10 changes: 5 additions & 5 deletions src/kima/pykima/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,16 +597,16 @@ def priors_latex(results, title='Priors', label='tab:1'):
2 * np.pi: r'$2\pi$',
results.y.min(): r'$\min v$',
results.y.max(): r'$\max v$',
results.t.ptp(): r'$\Delta t$',
results.y.ptp(): r'$\Delta RV$',
-results.y.ptp(): r'$-\Delta RV$'
np.ptp(results.t): r'$\Delta t$',
np.ptp(results.y): r'$\Delta RV$',
-np.ptp(results.y): r'$-\Delta RV$'
}
if results.model == 'RVFWHMmodel':
translation.update({
results.y2.min(): r'$\min$ FWHM',
results.y2.max(): r'$\max$ FWHM',
results.y2.ptp(): r'$\Delta$ FWHM',
-results.y2.ptp(): r'$-\Delta$ FWHM'
np.ptp(results.y2): r'$\Delta$ FWHM',
-np.ptp(results.y2): r'$-\Delta$ FWHM'
})

def translate_value(value):
Expand Down

0 comments on commit 0cd40c7

Please sign in to comment.