# Set up some useful astronomy libraries:
import pyvo as vo, os, astropy
import astropy.coordinates as coord
import matplotlib.pyplot as plt
%matplotlib inline
from astropy.io import fits
import astropy.coordinates as coord
# Set up AWS access with the boto3 and associated libraries:
import boto3
from botocore import UNSIGNED
from botocore.client import Config
s3_client = boto3.client("s3", config=Config(signature_version=UNSIGNED))
import warnings
# There are a number of relatively unimportant warnings that show up, so for now, suppress them:
warnings.filterwarnings("ignore", module="astropy.io.votable.*")
warnings.filterwarnings("ignore", module="astropy.units.format.vounit")
warnings.filterwarnings("ignore", module="pyvo.utils.xml.*")
The first step is to find the HEASARC service that you can use to search for Chandra images:
chandra_services = vo.regsearch(servicetype='image',keywords=['chandra heasarc'])
chandra_services.to_table()['ivoid','short_name','res_title']
ivoid | short_name | res_title |
---|---|---|
object | object | object |
ivo://nasa.heasarc/chanmaster | Chandra | Chandra Observations |
Next, use Astropy to get the coordinates of your favorite source, in this case the Cas A supernova remnant. Then query the service for matching images.
coords = coord.SkyCoord.from_name("cas a")
im_table = chandra_services[0].search(pos=coords,size=0.1)
im_table.to_table()[0:5]
obsid | status | name | ra | dec | time | detector | grating | exposure | type | pi | public_date | datalink | t_min | t_resolution | t_max | t_exptime | em_res_power | s_region | s_ra | s_dec | s_resolution | access_estsize | s_fov | o_ucd | access_url | obs_publisher_did | obs_id | obs_collection | target_name | instrument_name | facility_name | pol_states | calib_level | access_format | dataproduct_type | em_min | em_max | SIA_title | SIA_scale | SIA_naxis | SIA_naxes | SIA_format | SIA_reference | SIA_ra | SIA_dec | SIA_instrument |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
degree | degree | mjd | s | mjd | d | s | d | s | deg | deg | deg | arcsec | kbyte | deg | m | m | ||||||||||||||||||||||||||||||
object | object | object | float64 | float64 | float64 | object | object | float64 | object | object | int32 | object | float64 | float64 | float64 | float64 | float64 | object | float64 | float64 | float32 | int32 | float64 | object | object | object | object | object | object | object | object | object | int32 | object | object | float64 | float64 | object | object | object | int32 | object | object | float64 | float64 | object |
1038 | archived | Cas A | 350.86604 | 58.81169 | 52171.2069 | HRC-S | NONE | 50400 | GTO | Murray | 52545 | 23379:chandra.obs.img | 52171.2068981481 | -- | 102571.2068981481 | 50400.0 | -- | 350.86604 | 58.81169 | -- | 432185 | -- | https://heasarc.gsfc.nasa.gov/FTP/chandra/data/byobsid/8/1038/primary/hrcf01038N005_cntr_img2.fits.gz | HEASARC | 1038 | CHANDRA HRC-S | Cas A | HRC-S | Chandra | 3 | image/fits | Image | 1.24e-10 | 1.24e-08 | hrcf01038N005_cntr_img2.fits | [-0.0013666666666667 0.0013666666666667] | [1024 1025] | 2 | image/fits | https://heasarc.gsfc.nasa.gov/FTP/chandra/data/byobsid/8/1038/primary/hrcf01038N005_cntr_img2.fits.gz | 350.86604 | 58.81169 | CHANDRA HRC-S | |||
1038 | archived | Cas A | 350.86604 | 58.81169 | 52171.2069 | HRC-S | NONE | 50400 | GTO | Murray | 52545 | 23379:chandra.obs.img | 52171.2068981481 | -- | 102571.2068981481 | 50400.0 | -- | 350.86604 | 58.81169 | -- | 945041 | -- | https://heasarc.gsfc.nasa.gov/FTP/chandra/data/byobsid/8/1038/primary/hrcf01038N005_cntr_img2.jpg | HEASARC | 1038 | CHANDRA HRC-S | Cas A | HRC-S | Chandra | 3 | image/jpeg | Image | 1.24e-10 | 1.24e-08 | hrcf01038N005_cntr_img2.jpg | [-0.0013666666666667 0.0013666666666667] | [1024 1025] | 2 | image/jpeg | https://heasarc.gsfc.nasa.gov/FTP/chandra/data/byobsid/8/1038/primary/hrcf01038N005_cntr_img2.jpg | 350.86604 | 58.81169 | CHANDRA HRC-S | |||
1857 | archived | CAS A | 350.86606 | 58.81169 | 51821.9464 | HRC-S | NONE | 48880 | GTO | Murray | 52214 | 23380:chandra.obs.img | 51821.9463888889 | -- | 100701.9463888889 | 48880.0 | -- | 350.86606 | 58.81169 | -- | 426096 | -- | https://heasarc.gsfc.nasa.gov/FTP/chandra/data/byobsid/7/1857/primary/hrcf01857N007_cntr_img2.fits.gz | HEASARC | 1857 | CHANDRA HRC-S | CAS A | HRC-S | Chandra | 3 | image/fits | Image | 1.24e-10 | 1.24e-08 | hrcf01857N007_cntr_img2.fits | [-0.0013666666666667 0.0013666666666667] | [1024 1024] | 2 | image/fits | https://heasarc.gsfc.nasa.gov/FTP/chandra/data/byobsid/7/1857/primary/hrcf01857N007_cntr_img2.fits.gz | 350.86606 | 58.81169 | CHANDRA HRC-S | |||
1857 | archived | CAS A | 350.86606 | 58.81169 | 51821.9464 | HRC-S | NONE | 48880 | GTO | Murray | 52214 | 23380:chandra.obs.img | 51821.9463888889 | -- | 100701.9463888889 | 48880.0 | -- | 350.86606 | 58.81169 | -- | 959340 | -- | https://heasarc.gsfc.nasa.gov/FTP/chandra/data/byobsid/7/1857/primary/hrcf01857N007_cntr_img2.jpg | HEASARC | 1857 | CHANDRA HRC-S | CAS A | HRC-S | Chandra | 3 | image/jpeg | Image | 1.24e-10 | 1.24e-08 | hrcf01857N007_cntr_img2.jpg | [-0.0013666666666667 0.0013666666666667] | [1024 1024] | 2 | image/jpeg | https://heasarc.gsfc.nasa.gov/FTP/chandra/data/byobsid/7/1857/primary/hrcf01857N007_cntr_img2.jpg | 350.86606 | 58.81169 | CHANDRA HRC-S | |||
26655 | archived | CXOU J232327.8+584842 | 350.86667 | 58.81178 | 59943.1372 | ACIS-S | NONE | 30100 | GO | Posselt | 60141 | 23381:chandra.obs.img | 59943.1372106482 | -- | 90043.1372106482 | 30100.0 | -- | 350.86667 | 58.81178 | -- | 244996 | -- | https://heasarc.gsfc.nasa.gov/FTP/chandra/data/byobsid/5/26655/primary/acisf26655N001_cntr_img2.fits.gz | HEASARC | 26655 | CHANDRA ACIS-S | CXOU J232327.8+584842 | ACIS-S | Chandra | 3 | image/fits | Image | 1.24e-10 | 1.24e-08 | acisf26655N001_cntr_img2.fits | [-0.0013666666666667 0.0013666666666667] | [1025 1025] | 2 | image/fits | https://heasarc.gsfc.nasa.gov/FTP/chandra/data/byobsid/5/26655/primary/acisf26655N001_cntr_img2.fits.gz | 350.86667 | 58.81178 | CHANDRA ACIS-S |
Select an image and fetch its URL:
url = im_table[0].getdataurl()
print(url)
https://heasarc.gsfc.nasa.gov/FTP/chandra/data/byobsid/8/1038/primary/hrcf01038N005_cntr_img2.fits.gz
Now convert that URL into an S3 bucket address and use boto3 to download the object to a local file:
key_name = url.replace("https://heasarc.gsfc.nasa.gov/FTP/","")
s3_client.download_file("nasa-heasarc", key_name, "chandra_casA.fits")
hdu_list = fits.open("chandra_casA.fits")
Now you're ready to analyze this Cas A Chandra image:
plt.imshow(hdu_list[0].data, cmap='hot', origin='lower',vmax=1)
<matplotlib.image.AxesImage at 0x116058430>
Note that in astropy>=5.2, you do not have to download the file locally to read it but can give the astropy.io.fits reader the S3 bucket URI directly. An example is shown below for WMAP. Obviously you cannot write to the file on the bucket.
The LAMBDA community generally needs full sky datasets, so browsing the products is something that can be done interactively on the LAMBDA data portal. Once a user has selected, for example, the WMAP DR5 smoothed polarization map for the K band, the portal shows the archive's URL of the dataset. To find the file on AWS is almost as straightforward as for HEASARC:
url = "https://lambda.gsfc.nasa.gov/data/map/dr5/skymaps/9yr/smoothed/wmap_band_smth_iqumap_r9_9yr_K_v5.fits"
## The "map" directory on LAMBDA has been renamed "wmap" on AWS to clarify that it refers to the mission:
s3_uri = url.replace("https://lambda.gsfc.nasa.gov/data/map/","s3://nasa-lambda/wmap/")
With astropy>=5.2, you can read the file directly out of the bucket. You must also install fsspec and s3fs. (Astropy will tell you this.) With these libraries, you can open the FITS file and even extract subsets of the data. For this case, we will just visualize the map of one of the columns:
try:
import fsspec, s3fs
except:
print("Please install fsspec and s3fs in order to use the cell below.")
if tuple(map(int, (astropy.__version__.split(".")))) < tuple(map(int, ("5.2".split(".")))):
print(f"You have astropoy v{astropy.__version__}. Please update astropy to >= 5.2")
hdul = fits.open(s3_uri, use_fsspec=True, fsspec_kwargs={"anon": True})
import healpy
healpy.mollview(hdul[1].data['Q_POLARISATION'],nest=True,min=-0.1,max=0.1)