I am trying to loop through several FITS files that are located on my Desktop. This is the code I have so far.  The final image that i need to produce is a "single plot". with multiple graphs overlayed (see image) import numpy as np import matplotlib.pyplot as plt import glob from astropy.io import fits from astropy.wcs import WCS from pathlib import Path %matplotlib inline %matplotlib widget plt.figure(figsize=(5,5)) legends = [] def plot_fits_file(file_path):     # used this data to test ----------     # lam = np.random.random(100)     # flux = np.random.random(100)     # --------------------     # below code will work when you have file     # all the plot will be on single chart     hdul = fits.open(file_path)     data = hdul[1].data     h1 = hdul[1].header     flux = data[1]     w = WCS(h1, naxis=1, relax=False, fix=False)     lam = w.wcs_pix2world(np.arange(len(flux)), 0)[0] file_path = Path(file_path) if file_path.exists():     plot_fits_file(file_path)     plt.show() else:     print('~/Desktop/harpn_sun_release_package_ccf_2018/2018-01-18/')

icon
Related questions
Question

I am trying to loop through several FITS files that are located on my Desktop.

This is the code I have so far.  The final image that i need to produce is a "single plot". with multiple graphs overlayed (see image)

import numpy as np
import matplotlib.pyplot as plt
import glob
from astropy.io import fits
from astropy.wcs import WCS
from pathlib import Path
%matplotlib inline
%matplotlib widget


plt.figure(figsize=(5,5))
legends = []

def plot_fits_file(file_path):
    # used this data to test ----------
    # lam = np.random.random(100)
    # flux = np.random.random(100)
    # --------------------

    # below code will work when you have file
    # all the plot will be on single chart

    hdul = fits.open(file_path)
    data = hdul[1].data
    h1 = hdul[1].header
    flux = data[1]
    w = WCS(h1, naxis=1, relax=False, fix=False)
    lam = w.wcs_pix2world(np.arange(len(flux)), 0)[0]

file_path = Path(file_path)
if file_path.exists():
    plot_fits_file(file_path)
    plt.show()
else:
    print('~/Desktop/harpn_sun_release_package_ccf_2018/2018-01-18/')   

←
00
80000
60000
40000
20000
0 T
10
T
20
Figure 1
30
RV[km/s]
40
50
Transcribed Image Text:← 00 80000 60000 40000 20000 0 T 10 T 20 Figure 1 30 RV[km/s] 40 50
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer