4.6 - Multi-spectrum visualisation

In [60]:
#imports if needed
from astropy.io import fits
import astropy.units as u
import astropy.wcs as fitswcs
from specutils import Spectrum1D
import matplotlib.pyplot as plt

#list of path files
spec_list = ["dataset/GamCas_20201104T204413.fit",
            "dataset/GamCas_20201104T204413-2.fit",
            "dataset/GamCas_20201104T204937.fit",
            "dataset/GamCas_20201104T204937-2.fit"] 

#list of spectrum1D
spec1D_list = []

#modify offset for change visualization preferences
offset = 0.3

#parse and create plot for each spectrum in progress
for sip in spec_list :
    sip_file = fits.open(sip)
    sip_data = sip_file[0].data
    sip_header = sip_file[0].header

    #create WCS object for each spectrum in progress
    sip_wcs = fitswcs.WCS(header={'CDELT1': sip_header['CDELT1'], 'CRVAL1': sip_header['CRVAL1'],
                                   'CUNIT1': sip_header['CUNIT1'], 'CTYPE1': sip_header['CTYPE1'],
                                   'CRPIX1': sip_header['CRPIX1']})
    
    #apply offset on flux and create spec1D
    sip_flux = (sip_data + (offset * (spec_list.index(sip)))) * u.Jy
    sip_spec1D = Spectrum1D(flux=sip_flux, wcs=sip_wcs)
    
    #add spec1D to spec1DList
    spec1D_list.append((sip_spec1D, sip_header))
        
        
#create a fig
fig = plt.subplots(figsize=(16, 9))

#create a line plot for each spec1D in the list
for spec1Dip in spec1D_list:
    plt.plot(spec1Dip[0].spectral_axis, spec1Dip[0].flux, label=spec1Dip[1]["DATE-OBS"])
    
#Plot configuration 
plt.legend(loc='upper right')
plt.xlabel("Wavelenght ($\lambda$) in $\AA$ ")
plt.ylabel("Relative Flux")
plt.title("gamCas - Spectrum Comparaison - Alpy600", fontsize=16, fontweight='bold')
plt.show()