Example Usage¶
The SkyScene object is designed to give you access to many PRFs to make up a field of stars. This will rely on you having gaiaoffline installed and the database for gaiaoffline downloaded and in the right place.
!!! note "You must ensure you have gaiaoffline database installed"
You should follow the [`gaiaoffline` documentation](https://christinahedges.github.io/gaiaoffline/) to ensure your database is installed correctly. This database is 30gb, and you should download the approved one from Zenodo or obtain it from a team member.
To create a SkyScene we three things:
- The PRF: You should load the PRF you want to be used in the scene. You obtain the
PRFfrompandoraaperture - The WCS: The world coordinate system that we are using. This is determined by where we are pointing. You can obtain the WCS from
pandoraref - The time: Because stars have proper motion we also need the time, to ensure the catalog has the stars in the right position. You should update the time based on when you're observing with Pandora.
We have convenience methods to load PRFs and WCS using from_pointing which will take an RA, Dec, and theta for the boresight of the telescope and will then load the right reference products.
import pandoraaperture as pa
import matplotlib.pyplot as plt
import pandoraref as pr
import numpy as np
from astropy.time import Time
# coordinates for Kepler-10
ra, dec, theta = (285.6794224553767, 50.24130600481639, 85.1230985)
The first kind of SkyScene is the base class and is mostly useful for modeling VISDA full frame images.
scene = pa.SkyScene.from_pointing(ra, dec, theta, time=Time.now())
scene
SkyScene
Let's plot the scene. This models the scene using all the flux values in the catalog.
scene.plot();
/Users/chedges/Pandora/repos/pandora-aperture/src/pandoraaperture/scene.py:210: FutureWarning: Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
cat.phot_bp_mean_flux.fillna(0).values
This looks good, let's take a look at a different kind of SkyScene.
ROISkyScene is for ROIs on the VISDA. The ROIs are specified using their own corners and sizes.
rR, rC = np.mgrid[-500:500:3j, -500:500:3j]
ROI_corners = [(r + 1024 - 25, c + 1024 - 25) for r, c in zip(rR.ravel(), rC.ravel())]
nROIs = len(ROI_corners)
ROI_size = (50, 50)
scene = pa.ROISkyScene.from_pointing(ra, dec, theta, time=Time.now(), nROIs=nROIs, ROI_size=ROI_size, ROI_corners=ROI_corners)
scene.plot(vmax=1000);
/Users/chedges/Pandora/repos/pandora-aperture/src/pandoraaperture/scene.py:210: FutureWarning: Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
cat.phot_bp_mean_flux.fillna(0).values
This looks good too.
Let's look at the last kind of scene which is the DispersedSkyScene. This is primarily for working with NIRDA data.
scene = pa.DispersedSkyScene.from_pointing(ra, dec, theta, time=Time.now())
/Users/chedges/Pandora/repos/pandora-aperture/src/pandoraaperture/scene.py:219: FutureWarning: Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
return cat.j_flux.fillna(0).values * 1 * u.electron / u.second
scene.plot(vmax=1000);
/Users/chedges/Pandora/repos/pandora-aperture/src/pandoraaperture/scene.py:219: FutureWarning: Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
return cat.j_flux.fillna(0).values * 1 * u.electron / u.second
All SkyScene objects use a PRF, WCS and a catalog of sources to make scenes. Each of these items should be loaded for you by the SkyScene object.
scene.prf
DispersedPRF [836 elements]
scene.wcs
WCS Keywords Number of WCS axes: 2 CTYPE : 'RA---TAN-SIP' 'DEC--TAN-SIP' CRVAL : 285.6794224553767 50.24130600481639 CRPIX : 2008.0 1024.0 PC1_1 PC1_2 : 0.08501524470486811 -0.9963796506190656 PC2_1 PC2_2 : 0.9963796506190656 0.08501524470486811 CDELT : -0.00033055555555555 0.00033055555555556 NAXIS : 0 0
scene.cat
| RA | Dec | source_id | phot_g_mean_flux | phot_bp_mean_flux | phot_rp_mean_flux | j_flux | h_flux | k_flux | teff_gspphot | row | column | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 285.633757 | 50.231231 | 2132155154538128768 | 56236.210944 | 31355.100882 | 35614.164609 | 1540.991844 | 1572.679262 | 985.916266 | 5941.9517 | 932.076534 | 1984.175847 |
| 1 | 285.641148 | 50.233379 | 2132155085818652928 | 203377.545737 | 116295.538335 | 125442.543287 | 5250.496097 | 5448.0384 | 3137.90674 | 6142.2866 | 946.977434 | 1989.423785 |
| 2 | 285.647999 | 50.232175 | 2132155085818653184 | 42743.629051 | 17197.44932 | 36317.625121 | 2351.799751 | 3380.960991 | 2080.846441 | 4535.444 | 959.92687 | 1984.663413 |
| 3 | 285.679214 | 50.241604 | 2132155017099178624 | 807113.660182 | 430541.476911 | 539327.990865 | 24603.695303 | 27405.653344 | 16559.225946 | 5595.7837 | 1022.675063 | 2007.933868 |
| 4 | 285.742462 | 50.244746 | 2133655472513199360 | 44080.19357 | 24707.747994 | 27664.001865 | 1191.791655 | 1314.135538 | 776.676262 | 6050.1006 | 1144.778271 | 2007.053045 |
| 5 | 285.742767 | 50.260734 | 2133655571295536896 | 35732.399589 | 14461.998394 | 30473.324992 | 1927.526422 | 2763.377136 | 1794.072677 | 4520.6436 | 1149.299699 | 2055.215998 |
| 6 | 285.753612 | 50.237074 | 2133655403793722752 | 32228.636685 | 16795.400158 | 22203.38556 | 1128.756697 | 1296.104922 | 826.875325 | 5807.1235 | 1164.094135 | 1982.099503 |
| 7 | 285.764802 | 50.242807 | 2133655506872938752 | 3783886.782239 | 2558851.50372 | 1839476.5443 | 58748.981246 | 50008.077622 | 30105.097079 | 9376.287 | 1186.870348 | 1997.569689 |
| 8 | 285.786348 | 50.264355 | 2133655713031373184 | 119057.057927 | 67003.067235 | 74566.519233 | 3169.569944 | 3421.686056 | 1981.709686 | 6014.1904 | 1233.070374 | 2059.074925 |
| 9 | 285.815075 | 50.241934 | 2133655266354774528 | 47226.165502 | 25787.084681 | 30479.605866 | 1368.359904 | 1514.398462 | 890.922715 | 5815.2905 | 1281.980343 | 1986.80266 |
The object works by creating a design matrix for you.
This design matrix is a Sparse3D object which contains one image per source. When you dot it with the flux values of each source, you get the scene image.
scene.A(delta_pos=(0, 0))
<(400, 80, 10) Sparse3D array of type float64>
Each SkyScene has an evaluate method which will return the image of the scene.
r, c, im = scene.evaluate()
/Users/chedges/Pandora/repos/pandora-aperture/src/pandoraaperture/scene.py:219: FutureWarning: Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
return cat.j_flux.fillna(0).values * 1 * u.electron / u.second
You can move this scene around with the delta_pos argument to shift it by a number of pixels. You should only do this for small shifts.
SkyScene objects enable you to build FITS files containing the information you may need for that scene. You can obtain the following files
Catalog extension¶
This extension shows what targets are likely to fall on a pixel
hdu = scene.get_catalog_hdu()
hdu.data
FITS_rec([(285.63375724, 50.23123125, '2132155154538128768', 56236.21094419, 31355.10088213, 35614.16460896, 1540.99184352, 1572.67926186, 985.91626641, 5941.9517, 932.07653438, 1984.17584713, 0, 0),
(285.64114848, 50.23337892, '2132155085818652928', 203377.54573736, 116295.53833483, 125442.5432872 , 5250.49609725, 5448.03839999, 3137.90673989, 6142.2866, 946.97743365, 1989.42378521, 0, 0),
(285.64799859, 50.23217547, '2132155085818653184', 42743.62905105, 17197.44932034, 36317.625121 , 2351.79975073, 3380.96099121, 2080.8464409 , 4535.444 , 959.9268703 , 1984.66341253, 0, 0),
(285.67921404, 50.24160444, '2132155017099178624', 807113.66018202, 430541.47691061, 539327.99086458, 24603.69530318, 27405.6533437 , 16559.22594555, 5595.7837, 1022.67506268, 2007.93386828, 0, 0),
(285.74246182, 50.24474633, '2133655472513199360', 44080.1935701 , 24707.74799427, 27664.00186461, 1191.79165461, 1314.13553792, 776.67626242, 6050.1006, 1144.77827079, 2007.05304495, 0, 0),
(285.74276729, 50.26073441, '2133655571295536896', 35732.39958896, 14461.99839408, 30473.32499193, 1927.52642221, 2763.37713634, 1794.0726765 , 4520.6436, 1149.29969872, 2055.21599811, 0, 0),
(285.75361156, 50.23707355, '2133655403793722752', 32228.63668549, 16795.40015799, 22203.38555981, 1128.75669692, 1296.10492239, 826.87532456, 5807.1235, 1164.09413491, 1982.09950322, 0, 0),
(285.76480193, 50.24280658, '2133655506872938752', 3783886.78223853, 2558851.50371957, 1839476.5442999 , 58748.9812463 , 50008.07762171, 30105.09707888, 9376.287 , 1186.87034804, 1997.56968904, 0, 0),
(285.78634785, 50.26435453, '2133655713031373184', 119057.05792735, 67003.06723471, 74566.51923251, 3169.56994443, 3421.68605625, 1981.70968561, 6014.1904, 1233.07037366, 2059.07492471, 0, 0),
(285.8150753 , 50.24193411, '2133655266354774528', 47226.16550153, 25787.08468124, 30479.60586578, 1368.35990431, 1514.39846237, 890.92271528, 5815.2905, 1281.98034252, 1986.80265976, 0, 0)],
dtype=(numpy.record, [('RA', '<f8'), ('Dec', '<f8'), ('source_id', 'S19'), ('phot_g_mean_flux', '<f8'), ('phot_bp_mean_flux', '<f8'), ('phot_rp_mean_flux', '<f8'), ('j_flux', '<f8'), ('h_flux', '<f8'), ('k_flux', '<f8'), ('teff_gspphot', '<f8'), ('row', '<f8'), ('column', '<f8'), ('row0', '<i8'), ('column0', '<i8')]))
Aperture extension¶
This extension shows the apertures for a given target. You will need to input the target number to obtain the aperture. You can either use the target index in the catalog, or a SkyCoord to use the target closest to that coordinate.
scene.get_aperture_hdu(1)
/Users/chedges/Pandora/repos/pandora-aperture/src/pandoraaperture/scene.py:219: FutureWarning: Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
return cat.j_flux.fillna(0).values * 1 * u.electron / u.second
<astropy.io.fits.hdu.compressed.compressed.CompImageHDU at 0x14f713af0>
from astropy.coordinates import SkyCoord
scene.get_aperture_hdu(SkyCoord(ra, dec, unit='deg'))
<astropy.io.fits.hdu.compressed.compressed.CompImageHDU at 0x16e943700>
PRF extension¶
This extension gives you a FITS extension of the PRFs of each source. When combined with the catalog PRF, this gives you all of the information you strictly need for PRF photometry. This does not require a specific target to be input as it gives all PRFs for all possible targets.
scene.get_prf_hdu()
<astropy.io.fits.hdu.compressed.compressed.CompImageHDU at 0x16e94c5b0>
Model extension¶
This extension models the whole scene and returns it as an image.
scene.get_model_hdu()
<astropy.io.fits.hdu.compressed.compressed.CompImageHDU at 0x16e97dc40>