Beispiel #1
0
def main(inf, outf, config):
	with open(inf, "r", newline="") as f:
		times, fluxs = utils.csv_column_read(f, FIELDS, casts=CASTS, start=config.start, end=config.end)

	fx, fy = utils.lombscargle_amplitude(times, fluxs, mult=config.mult, upper=config.upper)

	# Output the FFT.
	utils.csv_column_write(outf, [fx, fy], ["frequency", "amplitude"])
Beispiel #2
0
def plot_lc(config, fig, ifile):
	# Get the cadence information.
	with open(ifile, "r", newline="") as f:
		times, fluxs = utils.csv_column_read(f, FIELDS, casts=CASTS, start=config.start, end=config.end)

	# Times and fluxes.
	xs = times
	ys = fluxs

	# Convert flux to ppm.
	#ys = ys / ys.mean() - 1
	#ys *= 1e6

	# Figure out time-related offsets.
	offset = np.min(times)
	xs -= offset
	if config.timestamp is not None:
		config.timestamp -= offset

	if config.fft:
		fx, fy = utils.lombscargle_amplitude(xs, ys, upper=config.high_freq)

		if config.fftout:
			with open(config.fftout, "w", newline="") as f:
				utils.csv_column_write(f, [fx, fy], ["frequency", "amplitude"])

		fx, fy = utils.raw_to_psd(fx, fy, fluxs.var())

	if config.lc:
		if config.period is not None:
			# TODO: We should allow for showing more than one phase.
			xs = (xs % config.period) / config.period
			xs = (xs + config.phase) % 1.0

		# Bin the folded phase plot by taking the average of ranges.
		if config.bins is not None:
			size = 1.0 / config.bins
			nys = np.zeros(config.bins)

			for i in range(config.bins):
				rnge = (i*size <= xs) & (xs < (i+1)*size)
				nys[i] = np.median(ys[rnge])

			ys = nys
			xs = np.arange(config.bins) * size

		# Replication.
		xs = np.tile(xs, config.width) + np.repeat(np.arange(config.width), xs.shape[0])
		ys = np.tile(ys, config.width)

	if config.fft and config.lc:
		ax1 = utils.latexify(fig.add_subplot(211))
	else:
		ax1 = utils.latexify(fig.add_subplot(111))

	if config.lc:
		if not (config.period or config.bins):
			ax1.plot(xs, ys, color="0.5", linestyle="-", marker="None")
			#ax1.plot(xs, ys, color="k", linestyle="None", marker="+", label=r"Kepler/K2 Halo Photometry")
			ax1.set_xlabel("Time ($d$)")
		else:
			# TODO: We should overlay a binned version.
			if config.timestamp is not None:
				predicted = (config.timestamp % config.period) / config.period
				predicted = (predicted + config.phase) % 1.0
				ax1.xaxis.set_ticks(predicted + np.arange(config.width), minor=True)
				ax1.xaxis.grid(True, which="minor", color="r", linestyle="--", linewidth=2)
			ax1.plot(xs, ys, color="0.5", linestyle="None", marker="o", label=r"Kepler/K2 Halo Photometry")
			ax1.set_xlabel("Phase")
		ax1.set_ylabel(r"Intensity (ppm)")

	if config.lc and config.title:
		ax1.set_title(r"Light Curve [%s] # %s" % (description(config), config.comment or ""))

	if config.fft:
		if config.lc:
			ax2 = utils.latexify(fig.add_subplot(212))
		else:
			ax2 = ax1
		ax2.plot(fx, fy, color="k", linestyle="-", marker="None")
		#ax2.xaxis.set_ticks(np.arange(*ax2.get_xlim(), step=1))
		#ax2.xaxis.set_ticks(np.arange(*ax2.get_xlim(), step=0.25), minor=True)
		#ax2.xaxis.grid(True, which="major", color="k", linestyle="--")
		#ax2.xaxis.grid(True, which="minor", color="k", linestyle=":")
		ax2.set_axisbelow(True)
		#ax2.set_xlabel("Frequency ($d^{-1}$)")
		ax2.set_xlabel("Frequency ($\mu$Hz)")
		#ax2.set_ylabel("Amplitude (ppm)")
		ax2.set_ylabel("PDF (ppm$^2$ $\mu$Hz$^{-1}$)")
		if config.maxx > config.minx:
			ax2.set_xlim([config.minx, config.maxx])
		if config.maxy > config.miny:
			ax2.set_ylim([config.miny, config.maxy])

	plt.legend()
	fig.tight_layout()