def plot_summary(s, colour, title, ax=None): ax = ax if ax else plt.gca() mjd0 = int(s.mjd.min()) mjd = s.mjd - mjd0 ax.plot(mjd, s.flux, ls='None', marker='.', color='k', zorder=2) lims = (ax.get_xlim(), ax.get_ylim()) ax.errorbar(mjd, s.flux, s.std, ls='None', color=colour, alpha=0.5, zorder=1) ax.set_xlim(*lims[0]) ax.set_ylim(*lims[1]) ax.set(title=title)
def noisecharacterise(i, flux_limits, datadict, c='b', model=True, ax=None): '''Characterises the noise level of bright, non saturated stars from the output of sysrem as a function of number of bins''' ax = ax if ax is not None else plt.gca() tmid = datadict['time'] cadence = np.median(np.diff(tmid)) * 24 * 60 flux = datadict['flux'] binlow = 0.2 binhigh = 4.0 binstep = 0.1 binrange = [int(np.ceil(10.0 ** (x))) for x in np.arange(binlow, binhigh, binstep)] binrange = np.sort(np.array(list(set(binrange)))) binrange = binrange[binrange < len(flux[0]) / 3] minflux, maxflux = flux_limits[i] zero = 21.18135675 mag_min = zero - 2.512 * np.log10(maxflux) mag_max = zero - 2.512 * np.log10(minflux) rms_lim = 1e9 avflux = np.median(flux, axis=1) stdflux = np.std(flux, axis=1) rms = stdflux # Fractional rms in units of mmag rms = abs(1.0857 * 1000.0 * stdflux / avflux) sane_keys = ((rms > 0) & (avflux > 0) & (avflux < maxflux) & (avflux > minflux)) flux_sane = flux[sane_keys].copy() logger.info('Stats: av: %s, std: %s, rms: %s', avflux, stdflux, rms) logger.debug('nstars: %s, mag_min: %s, mag_max: %s, npoints: %s', len(flux_sane), mag_min, mag_max, len(flux_sane[0])) logger.debug('median flux range: %s to %s', min(np.median(flux_sane, axis=1)), max(np.median(flux_sane, axis=1))) median_list = [np.median(rms[sane_keys])] N_bin_list = [1] quartiles = [ [np.percentile(rms[sane_keys], 25), np.percentile(rms[sane_keys], 75)]] rms_error = [ (np.std(rms[sane_keys])) / np.sqrt(len(rms[sane_keys]) * 1000)] for N in binrange: logger.debug('bin size: %s', N) binned = binning(flux_sane, N) avflux = np.median(binned, axis=1) stdflux = np.std(binned, axis=1) rms = stdflux rms = abs(1.0857 * 1000.0 * stdflux / avflux) sanity = ((avflux < maxflux) & (avflux > minflux)) rmssane = rms[sanity] median_list += [np.median(rmssane)] quartiles += [[np.percentile(rmssane, 25), np.percentile(rmssane, 75)]] N_bin_list += [N] rms_error += [(np.std(rms[sanity])) / np.sqrt(rms[sanity].size)] # Get the limits of the median list prior = [median_list[0], median_list[-1]] # Convert to numpy arrays N_bin_list = np.array(N_bin_list) median_list = np.array(median_list) rms_error = np.array(rms_error) quartiles = np.array(quartiles) low_quart = quartiles[:, 0] high_quart = quartiles[:, 1] m = 15 output = leastsq( fitnoise, prior, args=(N_bin_list[:m], median_list[:m], rms_error[:m])) final = output[0] noise_curve = noisemodel(final, N_bin_list) white_curve = noisemodel([final[0], 0], N_bin_list) red_curve = noisemodel([0, final[1]], N_bin_list) return NoiseResult( cadence * N_bin_list, median_list, rms_error, white_curve)
def plot_breaks(s, ax=None): ax = ax if ax else plt.gca() for b in s.breaks: ax.axvline(b, ls='--', color='k', zorder=-10)
def plot_summary(s, colour, label='', ax=None): ax = ax if ax else plt.gca() ax.plot(s.mags, s.frms, ls='None', marker='.', color=colour, label=label)