I am trying to simplify this code, in python,  so that I do not have to list each file separately.   Is there a way that I can access the FITS files via a folder on my Desktop to produce one plot of several FITS files.     import numpy as np import matplotlib.pyplot as plt from astropy.io import fits from astropy.wcs import WCS %matplotlib inline %matplotlib widget plt.figure(figsize=(10,10)) legends = [] def plot_fits_file(file_path):     # used this data to test ----------     # lam = np.random.random(100)     # flux = np.random.random(100)     # --------------------     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]     plt.plot(lam, flux)     plt.ylim(0, )     plt.xlabel('RV[km/s]')     plt.ylabel('Normalized CCF')     legends.append(file_path)  spec_list = [     '~/Desktop/r.HARPN.2018-01-18T14:25:36.145_CCF_A.fits',     '~/Desktop/r.HARPN.2018-01-18T14:20:10.645_CCF_A.fits',     '~/Desktop/r.HARPN.2018-01-18T14:31:00.875_CCF_A.fits',     '~/Desktop/r.HARPN.2018-01-18T14:36:26.373_CCF_A.fits'] for file_path in spec_list:     plot_fits_file(file_path) plt.show()

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I am trying to simplify this code, in python,  so that I do not have to list each file separately.  

Is there a way that I can access the FITS files via a folder on my Desktop to produce one plot of several FITS files.

 

 

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


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

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

    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]

    plt.plot(lam, flux)
    plt.ylim(0, )
    plt.xlabel('RV[km/s]')
    plt.ylabel('Normalized CCF')
    legends.append(file_path) 

spec_list = [
    '~/Desktop/r.HARPN.2018-01-18T14:25:36.145_CCF_A.fits',
    '~/Desktop/r.HARPN.2018-01-18T14:20:10.645_CCF_A.fits',
    '~/Desktop/r.HARPN.2018-01-18T14:31:00.875_CCF_A.fits',
    '~/Desktop/r.HARPN.2018-01-18T14:36:26.373_CCF_A.fits']

for file_path in spec_list:
    plot_fits_file(file_path)


plt.show()

←
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
steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY