import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.mlab as mlab import os import re import sys import math import scipy.optimize as sopt from scipy import interpolate from astropy.io import fits # Laboratorio di Astronomia # 4/12/2024 A. Pizzella # semplice programmino che introduce all'utilizzo dei file FITS con python # # leggo il file FITS, sia i dati che l'header # hdul = fits.open('IMA129850.fits') #header in hdul[0].header data = hdul[0].data # data contiene i dati header=hdul[0].header # header contiene l'header hdul.close() # plot dello spettro bidimensionale # plt.imshow(data, cmap='gray', origin='lower', vmin=1000, vmax=2000) plt.colorbar() plt.show() # vedo tutto l'header # print(header) # selezioni i campi che mi interessano # npix=header.get('NAXIS1') start=header.get('CRVAL1') step=header.get('CDELT1') print('npix, start e step= ',npix,start, step) # estraggo lo spettro lungo una posizione della fenditura # data1 = data[335,0:npix] fig=plt.figure() ax=fig.add_subplot(1,1,1) ax.plot(data1,'-') plt.show() # creo una array che contiene le lunghezze d'onda dei pixel # per fare questo uso start, step e npix letto dall'header # lam=np.arange(0,npix)*step+start print(lam[0:10]) fig=plt.figure() ax=fig.add_subplot(1,1,1) ax.plot(lam,data1,'-') plt.show() # posso selezionare uno spefico intervallo # di lunghezze d'onda # lam2=lam[1050:1300] data2=data1[1050:1300] fig=plt.figure() ax=fig.add_subplot(1,1,1) ax.plot(lam2,data2,'-') plt.show() # posso fare una statistica su una specifica # regione lam3=lam[1080:1140] data3=data1[1080:1140] meann = np.mean(data3) stdn = np.std(data3) print('mean, std= ',meann,stdn) fig=plt.figure() ax=fig.add_subplot(1,1,1) ax.plot(lam3,data3,'-') plt.show()