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/')
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/')
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images