Skip to content

Commit 68693e5

Browse files
authored
Merge pull request #925 from rzellem/develop
v1.9.0: update to centroiding and lightcurve plotter
2 parents 5330a0a + 2ef2337 commit 68693e5

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

exotic/api/elca.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def time_bin(time, flux, dt=1./(60*24)):
123123
if mask.sum() > 0:
124124
bflux[i] = np.nanmean(flux[mask])
125125
btime[i] = np.nanmean(time[mask])
126-
bstds[i] = np.nanstd(flux[mask])/(1+mask.sum())**0.5
126+
bstds[i] = np.nanstd(flux[mask])/(mask.sum()**0.5)
127127
zmask = (bflux==0) | (btime==0) | np.isnan(bflux) | np.isnan(btime)
128128
return btime[~zmask], bflux[~zmask], bstds[~zmask]
129129

@@ -223,10 +223,12 @@ def lc2min_airmass(pars):
223223
def create_fit_variables(self):
224224
self.phase = get_phase(self.time, self.parameters['per'], self.parameters['tmid'])
225225
self.transit = transit(self.time, self.parameters)
226+
self.time_upsample = np.linspace(min(self.time), max(self.time),1000)
227+
self.transit_upsample = transit(self.time_upsample, self.parameters)
228+
self.phase_upsample = get_phase(self.time_upsample, self.parameters['per'], self.parameters['tmid'])
226229
if self.mode == "ns":
227230
self.parameters['a1'], self.errors['a1'] = mc_a1(self.parameters.get('a2',0), self.errors.get('a2',1e-6),
228231
self.transit, self.airmass, self.data)
229-
230232
if np.ndim(self.airmass) == 2:
231233
detrended = self.data/self.transit
232234
self.wf = weightedflux(detrended, self.gw, self.nearest)
@@ -409,7 +411,9 @@ def plot_bestfit(self, title="", bin_dt=30./(60*24), zoom=False, phase=True):
409411
si = np.argsort(self.phase)
410412
bt2, bf2, bs = time_bin(self.phase[si]*self.parameters['per'], self.detrended[si], bin_dt)
411413
axs[0].errorbar(bt2/self.parameters['per'],bf2,yerr=bs,alpha=1,zorder=2,color='blue',ls='none',marker='s')
412-
axs[0].plot(self.phase[si], self.transit[si], 'r-', zorder=3, label=lclabel)
414+
#axs[0].plot(self.phase[si], self.transit[si], 'r-', zorder=3, label=lclabel)
415+
sii = np.argsort(self.phase_upsample)
416+
axs[0].plot(self.phase_upsample[sii], self.transit_upsample[sii], 'r-', zorder=3, label=lclabel)
413417
axs[0].set_xlim([min(self.phase), max(self.phase)])
414418
axs[0].set_xlabel("Phase ", fontsize=14)
415419
else:
@@ -421,8 +425,9 @@ def plot_bestfit(self, title="", bin_dt=30./(60*24), zoom=False, phase=True):
421425

422426
bt, bf, bs = time_bin(self.time, self.detrended, bin_dt)
423427
si = np.argsort(self.time)
428+
sii = np.argsort(self.time_upsample)
424429
axs[0].errorbar(bt,bf,yerr=bs,alpha=1,zorder=2,color='blue',ls='none',marker='s')
425-
axs[0].plot(self.time[si], self.transit[si], 'r-', zorder=3, label=lclabel)
430+
axs[0].plot(self.time_upsample[sii], self.transit_upsample[sii], 'r-', zorder=3, label=lclabel)
426431
axs[0].set_xlim([min(self.time), max(self.time)])
427432
axs[0].set_xlabel("Time [day]", fontsize=14)
428433

exotic/exotic.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -900,28 +900,34 @@ def gaussian_psf(x, y, x0, y0, a, sigx, sigy, rot, b):
900900
return a * gausx * gausy + b
901901

902902

903-
def mesh_box(pos, box):
903+
def mesh_box(pos, box, maxx=0, maxy=0):
904904
pos = [int(np.round(pos[0])), int(np.round(pos[1]))]
905-
x = np.arange(pos[0] - box, pos[0] + box + 1)
906-
y = np.arange(pos[1] - box, pos[1] + box + 1)
905+
if maxx:
906+
x = np.arange(max(0,pos[0] - box), min(maxx, pos[0] + box + 1))
907+
else:
908+
x = np.arange(max(0,pos[0] - box), pos[0] + box + 1)
909+
if maxy:
910+
y = np.arange(max(0,pos[1] - box), min(maxy, pos[1] + box + 1))
911+
else:
912+
y = np.arange(max(0,pos[1] - box), pos[1] + box + 1)
907913
xv, yv = np.meshgrid(x, y)
908914
return xv.astype(int), yv.astype(int)
909915

910916

911917
# Method fits a 2D gaussian function that matches the star_psf to the star image and returns its pixel coordinates
912918
def fit_centroid(data, pos, psf_function=gaussian_psf, box=10):
913919
# get sub field in image
914-
xv, yv = mesh_box(pos, box)
915-
916-
init = [np.nanmax(data[yv, xv]) - np.nanmin(data[yv, xv]), 1, 1, 0, np.nanmin(data[yv, xv])]
917-
920+
xv, yv = mesh_box(pos, box, maxx=data.shape[1], maxy=data.shape[0])
921+
subarray = data[yv, xv]
922+
init = [np.nanmax(subarray) - np.nanmin(subarray), 1, 1, 0, np.nanmin(subarray)]
923+
918924
# lower bound: [xc, yc, amp, sigx, sigy, rotation, bg]
919-
lo = [pos[0] - box * 0.5, pos[1] - box * 0.5, 0, 0.5, 0.5, -np.pi / 4, np.nanmin(data[yv, xv]) - 1]
920-
up = [pos[0] + box * 0.5, pos[1] + box * 0.5, 1e7, 20, 20, np.pi / 4, np.nanmax(data[yv, xv]) + 1]
925+
lo = [pos[0] - box * 0.5, pos[1] - box * 0.5, 0, 0.5, 0.5, -np.pi / 4, np.nanmin(subarray) - 1]
926+
up = [pos[0] + box * 0.5, pos[1] + box * 0.5, 1e7, 20, 20, np.pi / 4, np.nanmax(subarray) + 1]
921927

922928
def fcn2min(pars):
923929
model = psf_function(xv, yv, *pars)
924-
return (data[yv, xv] - model).flatten()
930+
return (subarray - model).flatten()
925931

926932
try:
927933
res = least_squares(fcn2min, x0=[*pos, *init], bounds=[lo, up], jac='3-point', xtol=None, method='trf')

exotic/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.8.4"
1+
__version__ = "1.9.0"

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ astroalign~=2.4
77
astropy>=4.3
88
astroquery~=0.4
99
barycorrpy~=0.4
10-
cython~=0.29.24 ; platform_system != "Windows"
10+
cython~=0.29.25 ; platform_system != "Windows"
1111
dynesty~=1.1 ; platform_system == "Windows"
1212
holoviews~=1.14
1313
LDTk~=1.7

0 commit comments

Comments
 (0)