def get_transit_mask(self, lc, period, epoch, duration_hours): """ """ tmask = get_transit_mask(lc.time, period=period, t0=epoch, dur=duration_hours / 24) return tmask
def get_transit_mask(self, lc, period, epoch, duration_hours): """ """ tmask = get_transit_mask(lc, period=period, epoch=epoch, duration_hours=duration_hours) return tmask
def get_flat_lc( self, lc=None, period=None, epoch=None, duration=None, window_length=None, method="biweight", sigma_upper=None, sigma_lower=None, return_trend=False, ): """ """ lc = self.lc if lc is None else lc period = self.period if period is None else period epoch = self.epoch if epoch is None else epoch duration = self.duration if duration is None else duration duration_hours = duration * 24 if duration_hours < 1: raise ValueError("Duration should be in hours.") if window_length is None: window_length = 0.5 if duration is None else duration * 3 if self.verbose: print( f"Using {method} filter with window_length={window_length:.2f} day" ) if (period is not None) & (epoch is not None) & (duration is not None): tmask = get_transit_mask(lc.time, period=period, t0=epoch, dur=duration_hours / 24) else: tmask = np.zeros_like(lc.time, dtype=bool) # dummy holder flat, trend = lc.flatten(return_trend=True) # flatten using wotan wflat, wtrend = flatten( lc.time, lc.flux, method=method, window_length=window_length, mask=tmask, return_trend=True, ) # overwrite flat.flux = wflat trend.flux = wtrend # clean lc sigma_upper = 5 if sigma_upper is None else sigma_upper sigma_lower = 10 if sigma_lower is None else sigma_lower flat = ( flat.remove_nans() ) # .remove_outliers(sigma_upper=sigma_upper, sigma_lower=sigma_lower) if return_trend: return flat, trend else: return flat
def get_transit_mask(self, lc, period=None, epoch=None, duration=None): """ """ period = self.toi_period if period is None else period epoch = self.toi_epoch - TESS_TIME_OFFSET if epoch is None else epoch duration = self.toi_duration if duration is None else duration tmask = get_transit_mask(lc, period=period, epoch=epoch, duration_hours=duration) return tmask
def _get_flat_lc( self, lc, period=None, epoch=None, duration=None, window_length=None, method="biweight", return_trend=False, **wotan_kwargs, ): """ TODO: migrate self in class method; See plot_hrd in cluster.py """ period = self.toi_period if period is None else period epoch = self.toi_epoch - TESS_TIME_OFFSET if epoch is None else epoch duration = self.toi_duration if duration is None else duration if duration is not None: if duration < 1: print("Duration should be in hours.") if window_length is None: window_length = 0.5 if duration is None else duration / 24 * 3 if self.verbose: print( f"Using {method} filter with window_length={window_length:.2f} day." ) if (period is not None) & (epoch is not None) & (duration is not None): tmask = get_transit_mask(lc.time, period=period, t0=epoch, dur=duration / 24) else: tmask = np.zeros_like(lc.time, dtype=bool) # dummy holder flat, trend = lc.flatten(return_trend=True) # flatten using wotan # import pdb; pdb.set_trace() wflat, wtrend = flatten( lc.time, lc.flux, method=method, mask=tmask, window_length=window_length, return_trend=True, **wotan_kwargs, ) # overwrite flat.flux = wflat trend.flux = wtrend if return_trend: return flat, trend else: return flat
def get_transit_mask(self, lc, period, epoch, duration_hours): """ """ period = self.period if period is None else period epoch = self.epoch if epoch is None else epoch duration_hours = (self.duration * 24 if duration_hours is None else duration_hours) if duration_hours < 1: raise ValueError("Duration should be in hours.") tmask = get_transit_mask(lc.time, period=period, t0=epoch, dur=duration_hours / 24) return tmask
def plot_trend_flat_lcs(self, lc, period=None, epoch=None, duration=None, binsize=10, **kwargs): """ plot trend and flat lightcurves (uses TOI ephemeris by default) TODO: migrate self in class method; See plot_hrd in cluster.py """ period = self.toi_period if period is None else period epoch = self.toi_epoch - TESS_TIME_OFFSET if epoch is None else epoch duration = self.toi_duration if duration is None else duration if duration is not None: if duration < 1: print("Duration should be in hours.") fig, axs = pl.subplots(2, 1, figsize=(12, 10), constrained_layout=True, sharex=True) if (period is not None) & (epoch is not None) & (duration is not None): if self.verbose: print( f"Using period={period:.4f} d, epoch={epoch:.2f} BTJD, duration={duration:.2f} hr" ) tmask = get_transit_mask(lc, period=period, epoch=epoch, duration_hours=duration) else: tmask = np.zeros_like(lc.time, dtype=bool) ax = axs.flatten() flat, trend = self.get_flat_lc( lc, period=period, epoch=epoch, duration=duration, return_trend=True, **kwargs, ) lc[tmask].scatter(ax=ax[0], zorder=5, c="r", label="transit") if np.any(tmask): lc[~tmask].scatter(ax=ax[0], c="k", alpha=0.5, label="_nolegend_") ax[0].set_title(f"{self.target_name} (sector {lc.sector})") ax[0].set_xlabel("") trend.plot(ax=ax[0], c="b", lw=2, label="trend") if (period is not None) & (epoch is not None) & (duration is not None): tmask2 = get_transit_mask(flat, period=period, epoch=epoch, duration_hours=duration) else: tmask2 = np.zeros_like(lc.time, dtype=bool) flat.scatter(ax=ax[1], c="k", alpha=0.5, label="flat") if np.any(tmask2): flat[tmask2].scatter(ax=ax[1], zorder=5, c="r", s=10, label="transit") flat.bin(binsize).scatter(ax=ax[1], s=10, c="C1", label=f"bin ({binsize})") fig.subplots_adjust(hspace=0) return fig
def plot_trend_flat_lcs(self, lc, period, epoch, duration, binsize=10, **kwargs): """ plot trend and falt lightcurves (uses TOI ephemeris by default) """ if duration < 1: print("Duration should be in hours.") assert ((period is not None) & (epoch is not None) & (duration is not None)) if self.verbose: print( f"Using period={period:.4f} d, epoch={epoch:.2f} BTJD, duration={duration:.2f} hr" ) fig, axs = pl.subplots(2, 1, figsize=(12, 10), constrained_layout=True, sharex=True) if (period is not None) & (epoch is not None) & (duration is not None): tmask = get_transit_mask(lc.time, period=period, t0=epoch, dur=duration / 24) else: tmask = np.zeros_like(lc.time, dtype=bool) ax = axs.flatten() flat, trend = self.get_flat_lc(lc, period=period, duration=duration, return_trend=True, **kwargs) lc[tmask].scatter(ax=ax[0], c="r", zorder=5, label="transit") if np.any(tmask): lc[~tmask].scatter(ax=ax[0], c="k", alpha=0.5, label="_nolegend_") ax[0].set_title(f"{self.target_name} (campaign {lc.campaign})") ax[0].set_xlabel("") trend.plot(ax=ax[0], c="b", lw=2, label="trend") if (period is not None) & (epoch is not None) & (duration is not None): tmask2 = get_transit_mask(flat.time, period=period, t0=epoch, dur=duration / 24) else: tmask2 = np.zeros_like(lc.time, dtype=bool) flat.scatter(ax=ax[1], c="k", alpha=0.5, label="flat") if np.any(tmask2): flat[tmask2].scatter(ax=ax[1], zorder=5, c="r", s=10, label="transit") flat.bin(binsize).scatter(ax=ax[1], s=10, c="C1", label=f"bin ({binsize})") fig.subplots_adjust(hspace=0) return fig