def sol_spec(fits_fil=None, xquery=None, show_plot=False, plot_spec=False, arc_fil=None): import xastropy.PH136.exercises.solarspec_exerc as ssp # Get wavelength solution if arc_fil == None: arc_fil = 'b1014.fits' fit = ssp.fit_lines(fits_fil=arc_fil) pv = np.poly1d(fit) # Read Solar spectrum if fits_fil == None: fits_fil = 'b1029.fits' spec = ssp.plot_spec(fits_fil, give_spec=True) npix = len(spec) xpix = np.arange(npix) wave = pv(xpix) # Plot pyplot.clf() pyplot.plot(wave, spec, drawstyle="steps-mid", ls='-') pyplot.xlim([3000., 5500]) pyplot.xlabel('Wavelength (Ang)') pyplot.ylabel('Counts') # Ca lines pyplot.axvline(3933.68, color='r') pyplot.axvline(3968.47, color='r') pyplot.show()
def sol_spec(fits_fil=None, xquery=None,show_plot=False, plot_spec=False, arc_fil=None): import xastropy.PH136.exercises.solarspec_exerc as ssp # Get wavelength solution if arc_fil == None: arc_fil = 'b1014.fits' fit = ssp.fit_lines(fits_fil=arc_fil) pv = np.poly1d(fit) # Read Solar spectrum if fits_fil == None: fits_fil = 'b1029.fits' spec = ssp.plot_spec(fits_fil, give_spec=True) npix = len(spec) xpix = np.arange(npix) wave = pv(xpix) # Plot pyplot.clf() pyplot.plot(wave, spec,drawstyle="steps-mid", ls='-') pyplot.xlim([3000., 5500]) pyplot.xlabel('Wavelength (Ang)') pyplot.ylabel('Counts') # Ca lines pyplot.axvline(3933.68, color='r') pyplot.axvline(3968.47, color='r') pyplot.show()
def fit_lines(fits_fil=None, xquery=None, show_plot=False, plot_spec=False): import xastropy.PH136.exercises.solarspec_exerc as ssp from astropy.io.fits import getdata if fits_fil == None: fits_fil = 'b1014.fits' spec = ssp.plot_spec(fits_fil, give_spec=True) npix = len(spec) xpix = np.arange(npix) # Generate the arrays wav_val = np.array([5085.82, 4799.92, 4358.33, 3466.55]) guess_pix_val = np.array([1930.5, 1664.72, 1241.46, 316.8]) # Centroid those lines! nlin = len(guess_pix_val) pix_val = np.zeros(nlin) ii = 0 for gpix in guess_pix_val: pix_val[ii] = ssp.gaussfit_line(xpix, spec, gpix) #,debug=True) ii += 1 #pdb.set_trace() # Fit fit = np.polyfit(pix_val, wav_val, 2) print 'Fit (dlam, w0): ', fit # Setup for plot pv = np.poly1d(fit) xval = np.linspace(1., 2000, 100) yval = pv(xval) # Plot? if show_plot: pyplot.clf() pyplot.plot(pix_val, wav_val, 'o') pyplot.plot(xval, yval) pyplot.xlabel('pixel') pyplot.ylabel('Wave (Ang)') #pyplot.show() pyplot.savefig('arclin_fit.pdf') # Plot the spectrum if plot_spec and (fits_fil != None): spec = ssp.plot_spec(fits_fil, give_spec=True, noplot=True) npix = len(spec) xval = np.arange(npix) wave = pv(xval) pyplot.clf() pyplot.plot(wave, spec, drawstyle="steps-mid", ls='-') pyplot.xlim([3000., 5500]) pyplot.xlabel('Wavelength (Ang)') pyplot.ylabel('Counts') pyplot.savefig('arclin_spec.pdf') # Print a value if xquery != None: wquery = pv(xquery) print 'Wavelength for pixel = ', xquery, ' is wave = ', wquery return fit
def fit_lines(fits_fil=None, xquery=None,show_plot=False, plot_spec=False): import xastropy.PH136.exercises.solarspec_exerc as ssp from astropy.io.fits import getdata if fits_fil == None: fits_fil = 'b1014.fits' spec = ssp.plot_spec(fits_fil, give_spec=True) npix = len(spec) xpix = np.arange(npix) # Generate the arrays wav_val = np.array( [5085.82, 4799.92, 4358.33, 3466.55]) guess_pix_val = np.array( [1930.5, 1664.72, 1241.46, 316.8]) # Centroid those lines! nlin = len(guess_pix_val) pix_val = np.zeros(nlin) ii=0 for gpix in guess_pix_val: pix_val[ii] = ssp.gaussfit_line(xpix,spec,gpix)#,debug=True) ii += 1 #pdb.set_trace() # Fit fit = np.polyfit(pix_val, wav_val, 2) print 'Fit (dlam, w0): ', fit # Setup for plot pv = np.poly1d(fit) xval = np.linspace(1., 2000, 100) yval = pv(xval) # Plot? if show_plot: pyplot.clf() pyplot.plot(pix_val, wav_val, 'o') pyplot.plot(xval, yval) pyplot.xlabel('pixel') pyplot.ylabel('Wave (Ang)') #pyplot.show() pyplot.savefig('arclin_fit.pdf') # Plot the spectrum if plot_spec and (fits_fil != None): spec = ssp.plot_spec(fits_fil, give_spec=True, noplot=True) npix = len(spec) xval = np.arange(npix) wave = pv(xval) pyplot.clf() pyplot.plot(wave, spec,drawstyle="steps-mid", ls='-') pyplot.xlim([3000., 5500]) pyplot.xlabel('Wavelength (Ang)') pyplot.ylabel('Counts') pyplot.savefig('arclin_spec.pdf') # Print a value if xquery != None: wquery = pv(xquery) print 'Wavelength for pixel = ', xquery, ' is wave = ', wquery return fit