Python code to fetch Eta Carinae nebula FITS image and Display

In Astronomy, there will be needs to extract Images from FITS format file for further analysis or research, Below is the Two steps code for "getting image link" and "fetching & displaying image from the link" 

The code uses python libraries such as PYVO,  Astropy, Matplotlib

STEP 1-excute below code to get url of the astronomical object

import pyvo as vo

from astropy.coordinates import SkyCoord

from astropy.units import Quantity

pos = SkyCoord.from_name('Eta Carina') #Eta Carina Nebula

size = Quantity(0.5, unit="deg")

sia_service = vo.dal.SIAService("http://dc.zah.uni-heidelberg.de/hppunion/q/im/siap.xml")

sia_results = sia_service.search(pos=pos, size=size)


sia_results

 -------------- its will list all FITS format image from online repository------------

<Table length=8>
                                     accref                                      ...
                                                                                 ...
                                     object                                      ...
-------------------------------------------------------------------------------- ...
http://dc.zah.uni-heidelberg.de/getproduct/boydende/data/fits/HAR081_006454.fits ...
http://dc.zah.uni-heidelberg.de/getproduct/boydende/data/fits/HAR081_006478.fits ...
http://dc.zah.uni-heidelberg.de/getproduct/boydende/data/fits/HAR081_006507.fits ...
http://dc.zah.uni-heidelberg.de/getproduct/boydende/data/fits/HAR081_006510.fits ...
http://dc.zah.uni-heidelberg.de/getproduct/boydende/data/fits/HAR081_006523.fits ...
http://dc.zah.uni-heidelberg.de/getproduct/boydende/data/fits/HAR081_006481.fits ...
http://dc.zah.uni-heidelberg.de/getproduct/boydende/data/fits/HAR081_006498.fits ...
http://dc.zah.uni-heidelberg.de/getproduct/boydende/data/fits/HAR081_006479.fits ...

-----------------------------------------------------------------

STEP 2-select the image url which you want to display. copy past the url as shown below in bold part.

import matplotlib.pyplot as plt
from astropy.io import fits

# Open the FITS file
fits_file = 'http://dc.zah.uni-heidelberg.de/getproduct/boydende/data/fits/HAR081_006454.fits'  # Replace with your FITS file path
hdulist = fits.open(fits_file)

# Display the structure of the FITS file
hdulist.info()

# Get the image data from the primary HDU (Header Data Unit)
image_data = hdulist[0].data

# Close the FITS file
hdulist.close()

# Plot the image data using matplotlib
plt.imshow(image_data, cmap='gray')
plt.colorbar()
plt.title('FITS Image')
plt.show()

-----output----




Comments

Popular posts from this blog

Astronomy Python - Crab Nebula - Combine RGB channel images into One Image

Smart Telescopes - Interesting videos from Youtube.