Comments (5)
I took a stab at this and I'm pretty happy with the aesthetics of the result. There are probably more clever ways to do some of this. I will note that these pixels don't appear dead-on position when I compare to where the flux is distributed in the TPFs. Perhaps I've been a bit careless in the translation from RA,Dec to image location, or perhaps get_coordinates()
has limited accuracy.
import numpy as np
import matplotlib.pyplot as plt
from lightkurve import KeplerTargetPixelFile
from astroquery.skyview import SkyView
from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy.wcs import WCS
from astropy.visualization import ImageNormalize,PercentileInterval,SqrtStretch
#What to inspect?
kic = 11090674
quarter = 4
tpf = KeplerTargetPixelFile.from_archive(kic, quarter=quarter)
#Requires some wcs projection for the axis
#I get one from the image header that I want to plot pixel locations over
c = SkyCoord(ra=tpf.ra*u.degree, dec=tpf.dec*u.degree, frame='icrs')
images = SkyView.get_images(position=c, survey=['2MASS-J'], radius=1.*u.arcmin)
wcs = WCS(images[0][0].header)
#Get median RA,Dec for each pixel
pixra = np.median(tpf.get_coordinates()[0],axis=0)
pixdec = np.median(tpf.get_coordinates()[1],axis=0)
#Convert RA,DEC to pixel coordinates in image frame
pixels = wcs.wcs_world2pix(pixra*u.degree,pixdec*u.degree,1)
#Reshape for plotting
xy = np.reshape(pixels,(2,pixels[0].size)).T
npixels = len(xy)
#Spacing between pixels is also spacing between corners of pixels
dx = np.median(np.diff(pixels)[0])
dy = np.median(np.diff(pixels)[1])
#Define locations of corners relative to pixel centers
corners = np.array([[1.,1.],[1.,-1.],[-1.,-1.],[-1.,1],[1.,1.]])
offsetmatrix = np.array(((dx,-dy), (dy, dx)))/2.
#There must be a more elegant way to do this...
for i in range(len(corners)):
corners[i] = np.cross(offsetmatrix,corners[i])
#Which pixels have data or are in mask
# 0 = no data; 1 = data, 2 = mask
d = np.zeros(npixels,dtype=int)
d[np.isfinite(tpf.flux[0]).flatten()] += 1
d[tpf.pipeline_mask.flatten()] += 1
colors = ['None','lightblue','red']
lws = [0,1,2]
zorders = [0,1,2]
#Plot reference image
f = plt.figure(figsize=(4.2,4))
ax = plt.subplot(projection=wcs)
norm = ImageNormalize(images[0][0].data, interval=PercentileInterval(99.9),
stretch=SqrtStretch())
ax.imshow(images[0][0].data,origin='lower',norm=norm,cmap='gray_r')
#Plot boundaries of each pixel
for i in range(npixels):
ccoords = xy[i]+corners
ax.plot(ccoords[:,0],ccoords[:,1],c=colors[d[i]],lw=lws[d[i]],zorder=zorders[d[i]])
ax.set_title('KIC'+str(kic)+', Q'+str(quarter),size=14,pad=15)
ax.set_xlabel('Right Ascension',size=12)
ax.set_ylabel('Declination',size=12)
ax.set_aspect(1)
plt.tight_layout(rect=[.22,-.3,1,1.3]) #matplotlib problem
plt.show()
Let me know if you'd like me to proceed to implement an KeplerTargetPixelFile.overlay_on_sky()
function like this.
from lightkurve.
This would be nice, I was just about to add an issue saying we need to add the WCS solution for each target pixel file. (Some gotchas include note all TPFs having WCS in them). This would allow us to make the above function, right?
from lightkurve.
I've been dreaming about a tpf.get_wcs()
function that returns an AstroPy WCS object, which is somewhat non-trivial to instantiate otherwise. Here is the code I'm talking about: https://gist.github.com/barentsen/46a4b44223ae05377702
Not sure this is exactly what we need to enable an astropy wcsaxis
to overlay the image, I'd have to be reminded how that all works. What'd you think, @chedges?
from lightkurve.
Many thanks @keatonb! I expect it will take us a bit of time to look carefully at your code because of other activities this and next week, but this is great input!!
from lightkurve.
So, any suggestions on how or whether to implement this?
Has anyone quantified the accuracy of the get_coordinates()
function? Is this affected by the same systematic offsets of up to 10 pixels described in KeplerGO/K2fov#15? Unless we could provide ~sub-pixel accuracy with get_coordinates()
, I would be hesitant to provide this overlay functionality.
from lightkurve.
Related Issues (20)
- Typo in "Searching & downloading Kepler, K2, and TESS data" tutorial HOT 5
- LightCurve.to_fits extra_data keyword not working? HOT 2
- lc.to_fits() + lk.io.read() does not preserve correct FLUX_ORIGIN meta data for SAP_FLUX data HOT 1
- Type error on stitch() HOT 4
- Attempts to download from lightkurve results in a KeyError: 'dataURL' HOT 14
- branch v2.4.x and main is of of sync that could cause merge headache
- Unable to download a lightcurve HOT 1
- showing key error "data URL" while trying to download a targetpixelfile HOT 3
- SearchResult no longer ordered chronologically, it could break user expectation HOT 4
- Having Trouble with lc.download for various stars trying to download TESS-SPOC data HOT 3
- Enhance `TargetPixelFile.interact()` to let user access the selected pixels mask directly in Jupyter notebooks
- Potential memory leak using `lightkurve.read` HOT 3
- Support changes in QLP lightcurves in sectors 56+ (renaming of detrended flux columns, etc.) HOT 1
- Using lightkurve for data other than Tess or Kepler HOT 3
- `search_lightcurve(cadence="short")` includes FFI-based data for TESS sector 56+ / Cycle 5+ HOT 4
- `df_sso=lc.query_solar_system_objects(cadence_mask='all')` Query Fail HOT 5
- `FoldedLightCurve.cycle` failed with `TypeError` when folded without `epoch_time`
- `centroid_quadratic()` incorrectly failed in a boundary case, when `mask` is specified and fluxes are all negative HOT 3
- The dependency 'astropy.config' doesn't work in lightkurve. HOT 5
- tpf.get_coordinates() keyword argument name should be frame, not cadence.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightkurve.