Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flip the movie frames when RA or DEC are inverted #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion k2mosaic/movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from astropy import visualization
import fitsio
from astropy.wcs import WCS
import imageio
import numpy as np

Expand All @@ -23,6 +24,29 @@ class KeplerMosaicMovieFrame(object):
def __init__(self, fits_filename):
self.fits_filename = fits_filename

def flip_frame(self, image, wcs):
"""Flips the image if the RA or DEC axes are inverted

Parameters
----------
image : array
Frame to be shown in the output movie.

wcs : WCS
Object containing information about the WCS transformation and
distortion. The header keywords are copied from the available K2
FFI's.
"""
ra_0, dec_0 = wcs.all_pix2world(0, 0, 0)
ra_1, dec_1 = wcs.all_pix2world(*(image.shape+(0,)))
if ra_0 < ra_1:
# Reverse the array in RA
image = image[:,::-1]
if dec_1 < dec_0:
# Reverse the array in DEC
image = image[::-1,:]
return image

def to_fig(self, rowrange, colrange, extension=1, cmap='Greys_r', cut=None, dpi=50):
"""Turns a fits file into a cropped and contrast-stretched matplotlib figure."""
fts = fitsio.FITS(self.fits_filename)
Expand All @@ -35,13 +59,16 @@ def to_fig(self, rowrange, colrange, extension=1, cmap='Greys_r', cut=None, dpi=
image_scaled = visualization.scale_image(image, scale="log",
min_cut=cut[0], max_cut=cut[1]) #min_percent=0.5, max_percent=99.5)

wcs = WCS(fts[extension].header)

px_per_kepler_px = 20
dimensions = [image.shape[0] * px_per_kepler_px, image.shape[1] * px_per_kepler_px]
figsize = [dimensions[1]/dpi, dimensions[0]/dpi]
dpi = 440 / float(figsize[0])
fig = pl.figure(figsize=figsize, dpi=dpi)
ax = fig.add_subplot(1, 1, 1, axisbg='green')
ax.matshow(image_scaled, aspect='auto',
ax.matshow(self.flip_frame(image_scaled, wcs),
aspect='auto',
cmap=cmap, origin='lower',
interpolation='nearest')
ax.set_xticks([])
Expand Down