Skip to content

Instantly share code, notes, and snippets.

@barentsen
Created December 10, 2015 23:27
Show Gist options
  • Save barentsen/239c0a9983522a2736ff to your computer and use it in GitHub Desktop.
Save barentsen/239c0a9983522a2736ff to your computer and use it in GitHub Desktop.
Creates a plot of a K2 target's centroids, with and without mid-campaign offset.
"""Creates a plot of a K2 target's centroids, with and without mid-campaign offset.
"""
import numpy as np
import matplotlib.pyplot as pl
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
import seaborn
from astropy.io import fits
def plot_centroids(ax, col, row, xlim, ylim, title=""):
sc = ax.scatter(col, row, c=range(len(col)), s=4, lw=0, cmap="viridis")
cbar = fig.colorbar(sc, ax=ax, orientation="horizontal")
cbar.set_label('Cadence')
ax.grid(True)
ax.xaxis.set_major_locator(MultipleLocator(1))
ax.yaxis.set_major_locator(MultipleLocator(1))
ax.xaxis.set_minor_locator(MultipleLocator(0.1))
ax.yaxis.set_minor_locator(MultipleLocator(0.1))
ax.xaxis.set_major_formatter(FormatStrFormatter('%.0f'))
ax.yaxis.set_major_formatter(FormatStrFormatter('%.0f'))
ax.set_xlim(xlim)
ax.set_ylim(ylim)
ax.set_xlabel("Column (pixels)")
ax.set_ylabel("Row (pixels)")
ax.text(0.05, 0.9, title, ha="left", transform=ax.transAxes, fontsize=24)
if __name__ == "__main__":
EPIC = "212126314-c05"
# Load centroid positions
fts = fits.open("ktwo{}_llc.fits".format(EPIC))
col = fts[1].data["MOM_CENTR1"]
row = fts[1].data["MOM_CENTR2"]
mean_col, mean_row = np.nanmean(col), np.nanmean(row)
xlim = [mean_col-1.5, mean_col+1.5]
ylim = [mean_row-1.5, mean_row+1.5]
# Simulate C9
col_c9, row_c9 = col.copy(), row.copy()
row_c9[int(len(row)/2):] -= 0.5
# Make the plot pretty
seaborn.set(context="notebook", style="ticks", font_scale=2)
seaborn.set_palette("RdBu")
fig = pl.figure(figsize=(16, 9))
ax1 = fig.add_subplot(1, 2, 1)
plot_centroids(ax1, col, row, xlim, ylim, title="Nominal")
ax2 = fig.add_subplot(1, 2, 2)
plot_centroids(ax2, col_c9, row_c9, xlim, ylim, title="With mid-campaign offset")
fig.tight_layout()
output_fn = "epic-{}.png".format(EPIC)
fig.savefig(output_fn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment