blue_fits_file = catalogue_df.iloc[i]['zBlue_file'] red_fits_file = catalogue_df.iloc[i]['zRed_file'] CodeName_Blue, FileName_Blue, FileFolder_Blue = dz.Analyze_Address(blue_fits_file) CodeName_Red, FileName_Red, FileFolder_Red = dz.Analyze_Address(red_fits_file) wave_Blue, flux_Blue, ExtraData_Blue = dz.get_spectra_data(blue_fits_file) wave_Red, flux_Red, ExtraData_Red = dz.get_spectra_data(red_fits_file) idx_blue = searchsorted(wave_Blue, joining_wavelength) idx_red = searchsorted(wave_Red, joining_wavelength) wave_comb = concatenate([wave_Blue[0:idx_blue], wave_Red[idx_red:-1]]) flux_comb = concatenate([flux_Blue[0:idx_blue], flux_Red[idx_red:-1]]) dz.data_plot(wave_comb, flux_comb, label = '{} combined arms emission'.format(objName)) dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Redshift correction') #Store the figure output_pickle = FileFolder_Blue + script_code + '_' + CodeName_Blue + '_combined_emission' dz.save_manager(output_pickle, save_pickle = True) dz.Data_2_Fits(FileFolder_Blue, CodeName_Blue + '_WHT.fits', ExtraData_Blue, wave_comb, flux_comb, NewKeyWord = ['WHTJOINW', str(joining_wavelength)]) #Store file address in dataframe combined_fits_name = FileFolder_Blue + CodeName_Blue + '_WHT.fits' catalogue_df.iloc[i]['reduction_fits'] = combined_fits_name print "\nAll data treated generated" #Store the dataframe
dz = Dazer() nb = Nebular_Bayesian() #Define plot frame and colors dz.FigConf(n_colors=5) nb.ObjectData_dict = {} nb.ObjectData_dict['nHeII_HII'] = 0.075 nb.ObjectData_dict['TOIII'] = 10000 nb.ObjectData_dict['TOIII_error'] = 500.0 nb.ObjectData_dict['Flux_Hbeta_Normalize'] = 2.86 * 1e-14 / 1e-14 nb.ObjectData_dict['Error_Hbeta_Normalize'] = 0.05 * 1e-14 / 1e-14 wave = np.linspace(3500, 7000, 7000 - 3500 - 1) nebular_flux_n = nb.Calculate_Nebular_gamma(nb.ObjectData_dict['TOIII'], nb.ObjectData_dict['Flux_Hbeta_Normalize'], nb.ObjectData_dict['nHeII_HII'] , 0.00, wave) dz.data_plot(wave, nebular_flux_n, 'Nebular flux normalized', dz.ColorVector[2][1]) #---------------Bayesian mod----------------- #Declare the MCMC dictionary MCMC_dict = nb.model_parameters(wave, nebular_flux_n, 0.05) #Run MCMC with MAP MAP_Model = pymc.MAP(MCMC_dict) MAP_Model.fit(method = 'fmin_powell') MAP_Model.revert_to_max() version = '_real_2000_100' Folder_database = '/home/vital/Desktop/db_Testing/' Db_name = 'db_Continuum' + version
] # flux_calibrated = ['/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Blue_cr_f_t_w_e_fglobal.fits', # '/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Red_cr_f_t_w_bg_e_fglobal.fits'] flux_calibrated = [ '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A1/MRK36_A1_Blue_fglobal.fits', '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A2/MRK36_A2_Blue_fglobal.fits', '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A1/MRK36_A1_Red_fglobal.fits', '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A2/MRK36_A2_Red_fglobal.fits', ] for i in range(len(flux_calibrated)): # color = 'Blue' if 'Blue' in extracted_files[i] else 'Red' CodeName, FileName, FileFolder = dz.Analyze_Address(flux_calibrated[i]) wavelength, Flux_array, Header_0 = dz.get_spectra_data(flux_calibrated[i]) # for j in range(Header_0['NAXIS2']): # # color_plot = 'orangish' if j == 0 else 'dark blue' # dz.data_plot(wavelength, Flux_array[j], label = 'Apperture {} {}'.format(j, color), color=dz.colorVector[color_plot]) dz.data_plot(wavelength, Flux_array, label=FileName) dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'MRK36') dz.display_fig()
#Plot ionization parameters versus EqW x_array = array([]) y_array = array([]) Sulfur_Ratio = (Flux_Frame.loc['S2_6716A'] + Flux_Frame.loc['S2_6731A']) / (Flux_Frame.loc['S3_9069A'] + Flux_Frame.loc['S3_9531A']) obj_SIIbySIII = np_log10(Sulfur_Ratio.astype('float64')) colors_list = ['#CC79A7', '#D55E00', '#bcbd22'] metals_list = [0.0001, 0.004, 0.02] for i in range(len(metals_list)): Z = metals_list[i] indeces = (Frame_MetalsEmission["Z"] == Z) x = np_log10((Frame_MetalsEmission.loc[indeces, '[SII]6716'] + Frame_MetalsEmission.loc[indeces, '[SII]6731']) / (Frame_MetalsEmission.loc[indeces, '[SIII]9069'] + Frame_MetalsEmission.loc[indeces, '[SIII]9532'])) y = Frame_MetalsEmission.loc[indeces, 'logU'] dz.data_plot(x, y, label='z = {Z}'.format(Z = Z), markerstyle=markers[i], color=colors_list[i]) x_array = hstack([x_array, x]) y_array = hstack([y_array, y]) #Lineal model lineal_mod = LinearModel(prefix='lineal_') Lineal_parameters = lineal_mod.guess(y_array, x=x_array) x_lineal = linspace(np_min(x_array), np_max(x_array), 100) y_lineal = Lineal_parameters['lineal_slope'].value * x_lineal + Lineal_parameters['lineal_intercept'].value label = r'U = {} $I_{{I([SII])/I([SIII])}}$ + {}'.format(round(Lineal_parameters['lineal_slope'].value,2), round(Lineal_parameters['lineal_intercept'].value,2)) dz.data_plot(x_lineal, y_lineal, label=label, color = 'black', linestyle='--') obj_u = Lineal_parameters['lineal_slope'].value * obj_SIIbySIII + Lineal_parameters['lineal_intercept'].value # dz.data_plot(obj_SIIbySIII, obj_u, label='Sample galaxies in linear fitting', color = 'black', markerstyle='x')
Wave_T, Int_T, header_T = dz.get_spectra_data(fits_file) Wave_N, Int_N, header_T = dz.get_spectra_data(ouput_folder + objName + nebular_fits_exten) #Perform the reddening correction cHbeta = catalogue_df.iloc[i][cHbeta_type] spectrum_dered = dz.derreddening_continuum(Wave_T, Int_T - Int_N, cHbeta.nominal_value) #Generating the starlight files FileName = basename(fits_file) Grid_FileName, Sl_OutputFile, Sl_OutputFolder, X_1Angs, Y_1Angs = dz.GenerateStarlightFiles(ouput_folder, FileName, objName, catalogue_df.iloc[i], Wave_T, spectrum_dered) print '--Output file ', Sl_OutputFile #Plot the data dz.data_plot(Wave_T, spectrum_dered, "Reduced spectrum") dz.data_plot(X_1Angs, Y_1Angs, "Resampled spectrum", linestyle='--') # Set titles and legend PlotTitle = 'Object {} Resampled spectrum for starlight'.format(objName) dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', PlotTitle) # Save data output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format(objFolder=ouput_folder, stepCode=dz.ScriptCode, objCode=objName, ext='Resampled_Spectrum') dz.save_manager(output_pickle, save_pickle = True) print 'Data treated' #----------------------------------------------------------------------------------------------------- # print "All data treated"
statistics = dz.extract_traces_statistics(traces_list = ['He_abud', 'Te', 'Flux_Recomb']) HeII_HII_inf = statistics['He_abud']['mean'] Te_inf = statistics['Te']['mean'] Flux_Recomb_inf = statistics['Flux_Recomb']['mean'] nebular_flux_bayes = nb.Calculate_Nebular_gamma(Te_inf, Flux_Recomb_inf * Hbeta_Flux.nominal_value, HeII_HII_inf, nHeIII_HII.nominal_value, Wavelength_Range=wave_clean) nebular_flux_theo = nb.Calculate_Nebular_gamma(8000.0, Flux_Recomb_inf * Hbeta_Flux.nominal_value, HeII_HII_inf, nHeIII_HII.nominal_value, Wavelength_Range=wave_clean) print print Te_inf print Flux_Recomb_inf print HeII_HII_inf print #nebular_flux = nb.Calculate_Nebular_gamma(Te.nominal_value, Hbeta_Flux.nominal_value, nHeII_HII.nominal_value, nHeIII_HII.nominal_value, Wavelength_Range=wave_clean) #nebular_flux_n = nebular_flux / Hbeta_Flux.nominal_value #dz.data_plot(wave_clean, nebular_flux, 'Inference prediction', dz.ColorVector[2][3]) #Make plots dz.data_plot(wave_obs, flux_obs, 'Gas spectrum', dz.ColorVector[2][1]) dz.data_plot(wave_clean, flux_clean, 'Continuum points', dz.ColorVector[2][2], markerstyle='o') dz.data_plot(wave_clean, nebular_flux_bayes, 'Fit output', dz.ColorVector[2][3], linewidth=2.0) dz.data_plot(wave_clean, nebular_flux_theo, 'Te = 15000', dz.ColorVector[2][4], linewidth=2.0) dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', '', title_Size=30) dz.display_fig() print i+1, '/' , len(FilesList) #----------------------------------------------------------------------------------------------------- print "All plots generated"
#Get stellar spectrum from starlight file Input_Wavelength, Input_Flux, Output_Flux, MaskPixels, ClippedPixels, FlagPixels, Parameters = dz.File_to_data( Sl_OutputFolder, Sl_OutputFile) #Export data to fits file stellar_cont_fits = objName + '_StellarContinuum_emis.fits' dz.Data_2_Fits(ouput_folder, stellar_cont_fits, header_0, Input_Wavelength, Output_Flux, NewKeyWord=['STALIGHT', 'Basic Treatment']) #Plot the data dz.data_plot(wave, flux_dered, "obs de-red") dz.data_plot(Input_Wavelength, Input_Flux, "Input Spectra") dz.data_plot(Input_Wavelength, Output_Flux, "Stellar absorption") #Set titles and legend PlotTitle = 'Object ' + objName + ' emission and stellar and spectra' dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', PlotTitle) mean_flux = Input_Flux.mean() dz.Axis.set_ylim(-0.05 * mean_flux, 15 * mean_flux) dz.Axis.set_xlim(3500, 5250) #Save plot output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format( objFolder=ouput_folder,
nebCalc.PropertiesfromUser(Te, Hbeta_Flux.nominal_value, nHeII_HII, nHeIII_HII, NebWave, Calibration="Zanstra") # -- Calculate continuous emissino coefficients: Gamma_Total, Gamma_lambda, Gamma_FB_HI, Gamma_FB_HeI, Gamma_FB_HeII, Gamma_2q, Gamma_FF = ( nebCalc.Calculate_Nebular_gamma() ) # -- Caculate nebular flux with different calibration methods NebularInt_Hbeta = nebCalc.Zanstra_Calibration("Hbeta", Hbeta_Flux.nominal_value, Gamma_Total) NebularInt_Halpha = nebCalc.Zanstra_Calibration("Halpha", Hbeta_Flux.nominal_value, Gamma_Total) # -- Determine or predict the intensity of the balmer jump x_trendline, y_trendline, BalmerJump_Int = nebCalc.Estimate_BalmerJumpFlux(spectrum_dered) # Plotting the data dz.data_plot(wave, spectrum_dered, "Reduced spectrum") dz.data_plot(NebWave, NebularInt_Hbeta, "Nebular continuum - Hbeta calibration") # dz.data_plot(NebWave, NebularInt_Halpha, 'Nebular continuum - Halfa calibration') dz.data_plot(x_trendline, y_trendline, "Balmer jump regression", linestyle="--") # Format the graphs plotTitle = r"Object {} Nebular continuum calculation".format(objName) dz.FigWording(r"Wavelength $(\AA)$", "Flux" + r"$(erg\,cm^{-2} s^{-1} \AA^{-1})$", plotTitle) mean_flux = spectrum_dered.mean() dz.Axis.set_ylim(-0.05 * mean_flux, 15 * mean_flux) dz.Axis.set_xlim(3500, 5250) output_pickle = "{objFolder}{stepCode}_{objCode}_{ext}".format( objFolder=ouput_folder, stepCode=dz.ScriptCode, objCode=objName, ext="NebularContinuum_Comparison" ) dz.save_manager(output_pickle, save_pickle=True)
#Determine recombination coefficients for several combinations object_data = catalogue_df.iloc[i] ratios_dict = dz.compare_RecombCoeffs(object_data, lineslog_frame) cHbeta_all_MagEr, n_all_MagEr = LinfitLinearRegression( ratios_dict['all_x'], ratios_dict['all_y']) trendline_all = cHbeta_all_MagEr * ratios_dict['all_x'] + n_all_MagEr cHbeta_in_MagEr, n_in_MagEr = LinfitLinearRegression( ratios_dict['in_x'], ratios_dict['in_y']) trendline_in = cHbeta_in_MagEr * ratios_dict['in_x'] + n_in_MagEr #--Blue points if len(ratios_dict['blue_x']) > 0: dz.data_plot(unumpy.nominal_values(ratios_dict['blue_x']), unumpy.nominal_values(ratios_dict['blue_y']), 'blue arm emissions', markerstyle='o', color='#0072B2', y_error=unumpy.std_devs(ratios_dict['blue_y'])) dz.plot_text(unumpy.nominal_values(ratios_dict['blue_x']), unumpy.nominal_values(ratios_dict['blue_y']), ratios_dict['blue_ions'], color='#0072B2') #--Red points if len(ratios_dict['red_x']) > 0: dz.data_plot(unumpy.nominal_values(ratios_dict['red_x']), unumpy.nominal_values(ratios_dict['red_y']), 'red arm emissions', markerstyle='o', color='#D55E00', y_error=unumpy.std_devs(ratios_dict['red_y']))
#Load reddening curve for the lines lines_wavelengths = lineslog_frame.lambda_theo.values lineslog_frame['line_f'] = dz.Reddening_curve(lines_wavelengths, 'Cardelli1989') #WARNING ESTO NO APUNTA AL REDDENING CLASS SI NO A UNA AQUI #Determine recombination coefficients for several combinations ratios_dict = dz.compare_RecombCoeffs(object_data, lineslog_frame) cHbeta_all_MagEr, n_all_MagEr = LinfitLinearRegression(ratios_dict['all_x'], ratios_dict['all_y']) trendline_all = cHbeta_all_MagEr * ratios_dict['all_x'] + n_all_MagEr cHbeta_in_MagEr, n_in_MagEr = LinfitLinearRegression(ratios_dict['in_x'], ratios_dict['in_y']) trendline_in = cHbeta_in_MagEr * ratios_dict['in_x'] + n_in_MagEr #--Blue points if len(ratios_dict['blue_x']) > 0: dz.data_plot(unumpy.nominal_values(ratios_dict['blue_x']), unumpy.nominal_values(ratios_dict['blue_y']), 'blue arm emissions', markerstyle='o', color = '#0072B2', y_error=unumpy.std_devs(ratios_dict['blue_y'])) dz.plot_text(unumpy.nominal_values(ratios_dict['blue_x']), unumpy.nominal_values(ratios_dict['blue_y']), ratios_dict['blue_ions'], color = '#0072B2') #--Red points if len(ratios_dict['red_x']) > 0: dz.data_plot(unumpy.nominal_values(ratios_dict['red_x']), unumpy.nominal_values(ratios_dict['red_y']), 'red arm emissions', markerstyle='o', color = '#D55E00', y_error=unumpy.std_devs(ratios_dict['red_y'])) dz.plot_text(unumpy.nominal_values(ratios_dict['red_x']), unumpy.nominal_values(ratios_dict['red_y']), ratios_dict['red_ions'], color = '#D55E00') #--Outside points if ratios_dict['out_x'] is not None: dz.data_plot(unumpy.nominal_values(ratios_dict['out_x']), unumpy.nominal_values(ratios_dict['out_y']), 'Invalid emissions', markerstyle='o', color = '#009E73', y_error=unumpy.std_devs(ratios_dict['out_y'])) dz.plot_text(unumpy.nominal_values(ratios_dict['out_x']), unumpy.nominal_values(ratios_dict['out_y']), ratios_dict['out_ions'], color = '#009E73') #--Trendline dz.data_plot(unumpy.nominal_values(ratios_dict['in_x']), unumpy.nominal_values(trendline_in), 'Valid points regression', linestyle='--', color = 'black')
dz.quick_indexing(catalogue_df) idcs = (pd.notnull(catalogue_df.OI_HI_emis2nd)) & (pd.notnull(catalogue_df.NI_HI_emis2nd)) & (pd.notnull(catalogue_df.HeII_HII_from_O_emis2nd)) & (catalogue_df.quick_index.notnull()) & (~catalogue_df.index.isin(['SHOC593'])) #Prepare data O_values = catalogue_df.loc[idcs].OI_HI_emis2nd.values N_values = catalogue_df.loc[idcs].NI_HI_emis2nd.values HeII_HI = catalogue_df.loc[idcs].HeII_HII_from_O_emis2nd.values objects = catalogue_df.loc[idcs].quick_index.values N_O_ratio = N_values/O_values x_coords = unumpy.nominal_values(HeII_HI) y_coords = unumpy.nominal_values(N_O_ratio) dz.data_plot(unumpy.nominal_values(HeII_HI), unumpy.nominal_values(N_O_ratio), label = '', markerstyle='o', x_error=unumpy.std_devs(HeII_HI), y_error=unumpy.std_devs(N_O_ratio)) #dz.plot_text(unumpy.nominal_values(HeII_HI), unumpy.nominal_values(N_O_ratio), text=objects, x_pad=1.005, y_pad=1.01, fontsize=20) #dz.Axis.set_yscale('log') for i in range(len(objects)): if objects[i] in dic_cords: label_x, label_y = dic_cords[objects[i]] dz.Axis.annotate(objects[i], xy=(x_coords[i], y_coords[i]), xycoords='data', xytext=(label_x,label_y), textcoords='data', arrowprops=dict(arrowstyle="->", lw= 1.5), fontsize=19) dz.FigWording(r'y', r'$N/O$', '') #dz.display_fig() dz.savefig('/home/vital/Dropbox/Astrophysics/Papers/Yp_AlternativeMethods/images/NO_to_y') # from dazer_methods import Dazer # from uncertainties import unumpy
gamma_ff = H_He_frac * specS.freefreeGammaCont(wave, Te, Z_ion=1.0) # Get the wavelength range in ryddbergs for the Ercolano grids wave_ryd = (specS.nebConst['h'] * specS.nebConst['c_Angs']) / (specS.nebConst['Ryd2erg'] * wave) # Free-Bound continuum gamma_fb_HI = specS.freeboundGammaCont(wave_ryd, Te, specS.HI_fb_dict) gamma_fb_HeI = specS.freeboundGammaCont(wave_ryd, Te, specS.HeI_fb_dict) gamma_fb_HeII = specS.freeboundGammaCont(wave_ryd, Te, specS.HeII_fb_dict) gamma_fb = gamma_fb_HI + HeII_HII * gamma_fb_HeI + HeIII_HII * gamma_fb_HeII # dz.data_plot(wave, gamma_ff, r'Bremsstrahlung') # dz.data_plot(wave, gamma_fb, r'Free-Bound') # dz.data_plot(wave, gamma_2q, r'Two photon continuum') nebular_components = ['Bremsstrahlung', 'Free-Bound', 'Two photon continuum'] gamma_nu = [gamma_ff, gamma_fb, gamma_2q] saving_folder = '/home/vital/Dropbox/Astrophysics/Thesis/images/' for i in range(len(nebular_components)): dz.data_plot(wave, gamma_nu[i], r'Two photon continuum') dz.Axis.set_yscale('log') Title = '' y_Title = r'$\gamma_{nu}\left(erg\ cm^{}\ s^{-1}\ Hz^{-1}\right)$' x_Title = r'$Wavelength (\AA)$' dz.FigWording(x_Title, y_Title, Title) # dz.display_fig() dz.savefig(saving_folder + nebular_components[i])
nebCalc.PropertiesfromUser(Te, Hbeta_Flux.nominal_value, nHeII_HII, nHeIII_HII, wave, Calibration = 'Zanstra') #-- Calculate continuous emissino coefficients: Gamma_Total, Gamma_lambda, Gamma_FB_HI, Gamma_FB_HeI, Gamma_FB_HeII, Gamma_2q, Gamma_FF = nebCalc.Calculate_Nebular_gamma() #-- Caculate nebular flux with different calibration methods NebularInt_Hbeta = nebCalc.Zanstra_Calibration('Hbeta', Hbeta_Flux.nominal_value, Gamma_Total) #Removing nebular component Int_dedNeb = spectrum_dered - NebularInt_Hbeta Flux_deNeb = dz.reddening_continuum(wave, Int_dedNeb, cHbeta.nominal_value) nebularFlux_cont = dz.derreddening_continuum(wave, NebularInt_Hbeta, cHbeta.nominal_value) #Plotting the data dz.data_plot(wave, flux, 'Reduced spectrum') dz.data_plot(wave, Flux_deNeb, 'Removed Nebular continuum') dz.data_plot(wave, nebularFlux_cont, 'Nebular flux') #Format the graphs PlotTitle = r'Object {} Nebular continuum substraction'.format(objName) dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', PlotTitle) mean_flux = spectrum_dered.mean() dz.Axis.set_ylim(-0.05*mean_flux, 15*mean_flux) dz.Axis.set_xlim(3500, 5250) output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format(objFolder=ouput_folder, stepCode=dz.ScriptCode, objCode=objName, ext='NebularContinuum_substraction') dz.save_manager(output_pickle, save_pickle = True) #Export nebular continuum dz.Data_2_Fits(ouput_folder, objName + nebular_fits_exten, header_0, wave, nebularFlux_cont, NewKeyWord = ['NEBUSPEC', 'zanstra_hbeta'])
print '-- Treating {} @ {}'.format(objName, fits_file) #Spectrum data wave, flux, header_0 = dz.get_spectra_data(fits_file) #Plot the regions of interest if wave[-1] > 8498: ind_low, ind_high = searchsorted(wave, lambda_limits) subWave, subFlux = wave[ind_low:ind_high], flux[ind_low:ind_high] medianFlux = full(3, median(subFlux), dtype=float) #Plot data dz.data_plot(subWave, subFlux, '{} spectrum'.format(objName), color=dz.colorVector['yellow']) dz.data_plot(lambda_CaII, medianFlux, 'CaII absorptions', markerstyle= 'o', color=dz.colorVector['orangish']) #Set titles and legend dz.FigWording(r'Wavelength $(\AA)$', r'Flux $(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Object {} CaII triplet region'.format(objName)) #Save data ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format(objFolder=ouput_folder, stepCode=dz.ScriptCode, objCode=objName, ext='CalIIRegion') dz.display_fig() dz.save_manager(output_pickle, save_pickle = True) print "\nAll data treated generated" # #!/usr/bin/python
objName = catalogue_df.iloc[i].name if objName == '8': #Joining pointing joining_wavelength = catalogue_df.iloc[i].join_wavelength #Treat each arm file blue_fits_file = catalogue_df.iloc[i]['zBlue_file'] red_fits_file = catalogue_df.iloc[i]['zRed_file'] CodeName_Blue, FileName_Blue, FileFolder_Blue = dz.Analyze_Address(blue_fits_file) CodeName_Red, FileName_Red, FileFolder_Red = dz.Analyze_Address(red_fits_file) wave_Blue, flux_Blue, ExtraData_Blue = dz.get_spectra_data(blue_fits_file) wave_Red, flux_Red, ExtraData_Red = dz.get_spectra_data(red_fits_file) idx_blue = searchsorted(wave_Blue, joining_wavelength) idx_red = searchsorted(wave_Red, joining_wavelength) wave_comb = concatenate([wave_Blue[0:idx_blue], wave_Red[idx_red:-1]]) flux_comb = concatenate([flux_Blue[0:idx_blue], flux_Red[idx_red:-1]]) dz.data_plot(wave_Blue, flux_Blue, label = 'WHT blue arm') dz.data_plot(wave_Red, flux_Red, label = 'WHT red arm') dz.insert_image('/home/vital/Dropbox/Astrophysics/Seminars/Angeles_Seminar/8.png', Image_Coordinates = [0.85,0.70], Zoom=0.20, Image_xyCoords = 'axes fraction') dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'HII galaxy: SDSSJ024815.93-081716.5, WHT observation') dz.display_fig() #dz.savefig('/home/vital/Dropbox/Astrophysics/Seminars/Angeles_Seminar/' + '8_WHT', extension='.png')
#------Plot Oxygen lines element_lines = reduc_lineslog_df.loc[(reduc_lineslog_df.index.isin(oxygen_emision))].index.values if len(element_lines) > 0: dz.FigConf(plotStyle='seaborn-colorblind', Figtype = 'grid', plotSize = sizing_dict, n_columns = int(len(element_lines)), n_rows = int(np_ceil(len(element_lines)/n_columns))) for j in range(len(element_lines)): #Define plotting regions regions_wavelengths = reduc_lineslog_df.loc[element_lines[j], ['Wave1', 'Wave2', 'Wave3', 'Wave4', 'Wave5', 'Wave6']].values idcs_obj, idcs_stellar = searchsorted(wave_reduc, regions_wavelengths), searchsorted(wave_stellar, regions_wavelengths) subwave_solar, subFlux_solar = wave_stellar[idcs_stellar[0]:idcs_stellar[5]], flux_stellar[idcs_stellar[0]:idcs_stellar[5]] subWwave, subFlux = wave_reduc[idcs_obj[0]:idcs_obj[5]], flux_reduc[idcs_obj[0]:idcs_obj[5]] subWwave_emis, subFlux_emis = wave_emis[idcs_obj[0]:idcs_obj[5]], flux_emis[idcs_obj[0]:idcs_obj[5]] dz.data_plot(subWwave, subFlux, label='', linestyle='step', graph_axis=dz.Axis[j]) dz.data_plot(subwave_solar, subFlux_solar, label='', linestyle='step', graph_axis=dz.Axis[j]) dz.FigWording(xlabel='', ylabel='', title=element_lines[j], graph_axis=dz.Axis[j]) plt.tight_layout() dz.fig_to_pdf(label='{} oxygen lines'.format(objName.replace('_','-')), add_page=True) dz.reset_fig() #------Plot Nitrogen lines element_lines = reduc_lineslog_df.loc[(reduc_lineslog_df.index.isin(nitrogen_emision))].index.values if len(element_lines) > 0: dz.FigConf(plotStyle='seaborn-colorblind', Figtype = 'grid', plotSize = sizing_dict, n_columns = int(len(element_lines)), n_rows = int(np_ceil(len(element_lines)/n_columns))) for j in range(len(element_lines)):
Wave_StellarExtension = np.linspace(3000.0,3399.0,200) Int_StellarExtension = np.zeros(len(Wave_StellarExtension)) #Increase the range of Wave_S so it is greater than the observational range Int_S = np.hstack((Int_StellarExtension, Int_S)) Wave_S = np.hstack((Wave_StellarExtension, Wave_S)) #Resampling stellar spectra Interpolation = interp1d(Wave_S, Int_S, kind = 'slinear') Int_Stellar_Resampled = Interpolation(Wave_T) #Remove the continua Int_E = Int_T - Int_N - Int_Stellar_Resampled #Plot the data dz.data_plot(Wave_S, Int_S, 'Stellar fitting') dz.data_plot(Wave_T, Int_Stellar_Resampled, 'Resampled stellar fitting') dz.data_plot(Wave_T, Int_T, 'Reduced spectra') dz.data_plot(Wave_T, Int_E, 'Emitting component') #Set titles and legend PlotTitle = r'Object {} Stellar continuum substraction'.format(objName) dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', PlotTitle) #Save data output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format(objFolder=ouput_folder, stepCode=dz.ScriptCode, objCode=objName, ext='StellarContinuum_substraction') dz.save_manager(output_pickle, save_pickle = True) #Export fits dz.Data_2_Fits(ouput_folder, objName + emitting_ext, ExtraData_T, Wave_T, Int_E, NewKeyWord = ['EMISSPEC', 'only emission lines']) catalogue_df.loc[objName].stellar_fits = ouput_folder + objName + emitting_ext
# Case we can (and we want) to perform the telluric correction: if (len(objects) > 0) and (favoured_star != "None"): star_dict = {} for i in range(len(objects)): wave_star, flux_star, header_0_star = dz.get_spectra_data(Files_Folders[i] + Files_Names[i]) idx_print_low, idx_print_high = searchsorted(wave_star, [9000, 9650]) idx_join_region = searchsorted(wave_star, [wave_join]) if len(flux_star) == 2: flux_star = flux_star[0][0] star_dict[objects[i] + "_wave"], star_dict[objects[i] + "_flux"] = wave_star, flux_star star_dict[objects[i] + "_idx_join"] = idx_join_region dz.data_plot(wave_star, flux_star, label=objects[i], graph_axis=dz.ax2) obj_red_region = array(range(idx_obj_join, idx_obj_join + len_red_region)) mean_flux = mean(flux_obs) # Loop through the diagnostic lines obj_dict = {} for line in lines_interest: if line in lick_idcs_df.index: dz.Current_Label = lick_idcs_df.loc[line].name dz.Current_Ion = lick_idcs_df.loc[line].Ion dz.Current_TheoLoc = redshift_factor * lick_idcs_df.loc[line].TheoWavelength selections = redshift_factor * lick_idcs_df.loc[line][3:9].values # Measure the line intensity
CodeName, FileName, FileFolder = dz.Analyze_Address(FilesList[i]) Wave, Flux, ExtraData = dz.File_to_data(FileFolder, FileName) #Get the emission line location Line_label, line_wavelength = 'N2_6548A', 6548.050 Line_selections = dz.RangesR([], line_wavelength, FileFolder + CodeName + '_WHT_LinesLog_v3.txt') print 'selections', Line_selections Line_selections = [6485.44, 6515.86, 6535.03, 6593.01, 6601.26, 6616.07] subWave, subFlux, line_heith, line_exploc = dz.Emission_Threshold(5016.0, Wave, Flux) #Fit the line Fitting_single = dz.command_LineMesuring(subWave, subFlux, Line_selections, line_wavelength, Line_label, Measuring_Method = 'lmfit', store_data = False) #Plotting data dz.data_plot(Wave, Flux, label = CodeName + ' spectrum', color=dz.ColorVector[2][0], linestyle='step') dz.data_plot(Wave[dz.ind3:dz.ind4], Fitting_single['ContinuumFlux'][dz.ind3:dz.ind4], label = CodeName + ' spectrum', color=dz.ColorVector[2][0], linestyle='step') dz.data_plot(Fitting_single['x_resample'], Fitting_single['y_resample'][0], label = 'Simple fitting', color=dz.ColorVector[2][1]) dz.data_plot(Fitting_single['x_resample'], Fitting_single['zerolev_resample'], label = 'simple zero level', linestyle= ':', color=dz.ColorVector[2][1]) dz.data_plot(subWave[dz.ind3:dz.ind4][dz.Fitting_dict['wide mask']], subFlux[dz.ind3:dz.ind4][dz.Fitting_dict['wide mask']], label = CodeName + ' original', color='red', markerstyle='o') dz.data_plot(dz.Fitting_dict['Maxima_Waves'], dz.Fitting_dict['Maxima_peaks'], label = 'Maxima peaks = ' + str(len(dz.Fitting_dict['Maxima_peaks'])), color='orange', markerstyle='o') # dz.data_plot(dz.Fitting_dict['Maxima_Waves_pu'], dz.Fitting_dict['Maxima_peaks_pu'], label = 'Maxima peaks = ' + str(len(dz.Fitting_dict['Maxima_Waves_pu'])), color='black', markerstyle='o') #dz.data_plot(subWave[dz.ind3:dz.ind4], dz.Fitting_dict['emis_limpio'] * dz.Fitting_dict['y_scaler'], label = CodeName + ' original', color='green', markerstyle='o') # #Plot the masks regions # sigmas_limits = [1.5,4,3] # for k in [0,1,2]: # index_str = str(k) # limit = dz.Fitting_dict['sigma'+index_str].nominal_value * sigmas_limits[k] # dz.Axis.axvspan(dz.Fitting_dict['mu'+index_str].nominal_value - limit, dz.Fitting_dict['mu'+index_str].nominal_value + limit, facecolor = 'yellow', alpha=0.5) #
dz.task_attributes['run folder'] = FileFolder dz.task_attributes['color'] = color dz.task_attributes['input'] = fits_file dz.task_attributes['output'] = z_fits_file dz.task_attributes['redshift'] = redshift dz.task_attributes['flux'] = 'yes' dz.run_iraf_task('dopcor') #Store file address in dataframe catalogue_df.iloc[i]['z{}_file'.format(color)] = z_fits_file #Load spectrum wave, flux, ExtraData = dz.get_spectra_data(fits_file) wave_z, flux_z, ExtraData_z = dz.get_spectra_data(z_fits_file) dz.data_plot(wave, flux, label = '{} {} arm'.format(CodeName, color)) dz.data_plot(wave_z, flux_z, label = '{} {} arm redshift corrected'.format(CodeName,color)) #Wording for the figure dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Redshift correction') #Store the figure output_address = FileFolder + script_code + '_' + CodeName + '_RedShiftCorrection' dz.save_manager(output_address, save_pickle = True) dz.save_dataframe(catalogue_df, catalogue_dict['dataframe']) print 'Data treated'
trendline_in = cHbeta_in_MagEr * ratios_dict['in_x'] + n_in_MagEr range_blue = array(range(len(ratios_dict['blue_ions']))) + 1 range_red = array(range(len(ratios_dict['red_ions']))) + 1 + len( ratios_dict['blue_ions']) total_range = list(range_blue) + list(range_red) if j < 1: #--Blue points if len(ratios_dict['blue_x']) > 0: dz.data_plot( range_blue, log10( unumpy.nominal_values( ratios_dict['line_Flux_Blue'])), 'Observed fluxes', markerstyle='o', color='black' ) #, y_error=log10(unumpy.std_devs(ratios_dict['blue_y']))) #--Red points if len(ratios_dict['red_x']) > 0: dz.data_plot( range_red, log10( unumpy.nominal_values( ratios_dict['line_Flux_Red'])), 'Observed fluxes', markerstyle='o', color='black'
size_dict = {'axes.labelsize':20, 'legend.framealpha':None, 'font.family':'Times New Roman', 'mathtext.default':'regular', 'xtick.labelsize':18, 'ytick.labelsize':18} dz.FigConf(plotSize = size_dict) #Load catalogue dataframe catalogue_df = dz.load_excel_DF('/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx') dz.quick_indexing(catalogue_df) idcs = ~catalogue_df.OII_HII_emis2nd.isnull() & ~catalogue_df.OIII_HII_emis2nd.isnull() & ~catalogue_df.SII_HII_emis2nd.isnull() & ~catalogue_df.SIII_HII_emis2nd.isnull() & (catalogue_df.quick_index.notnull()) TeOIII_array = catalogue_df.loc[idcs].TeOIII_emis.values TeSIII_array = catalogue_df.loc[idcs].TeSIII_emis.values #Axis values objects = catalogue_df.loc[idcs].index.values OII_HII_abundances = catalogue_df.loc[idcs].OII_HII_emis2nd.values OIII_HII_abundances = catalogue_df.loc[idcs].OIII_HII_emis2nd.values SII_HII_abundances = catalogue_df.loc[idcs].SII_HII_emis2nd.values SIII_HII_abundances = catalogue_df.loc[idcs].SIII_HII_emis2nd.values quick_reference = catalogue_df.loc[idcs].quick_index.values oxygen_ratio = OII_HII_abundances / OIII_HII_abundances sulfur_ratio = SII_HII_abundances / SIII_HII_abundances dz.data_plot(unumpy.nominal_values(sulfur_ratio), unumpy.nominal_values(oxygen_ratio), 'HII galaxies', markerstyle='o', x_error=unumpy.std_devs(sulfur_ratio), y_error=unumpy.std_devs(oxygen_ratio)) dz.plot_text(unumpy.nominal_values(sulfur_ratio), unumpy.nominal_values(oxygen_ratio), quick_reference) Title = r'Oxygen versus Sulfur ionization fractions' y_Title = r'$\frac{O^{+}}{O^{2+}}$' x_Title = r'$\frac{S^{+}}{S^{2+}}$' dz.FigWording(x_Title, y_Title, Title) #, XLabelPad = 20 dz.savefig('/home/vital/Dropbox/Astrophysics/Papers/Yp_AlternativeMethods/Images/ionizationFraction')
#Declare object dz = Dazer() dz.FigConf(n_colors=5) CodeName1 = '70' CodeName2 = 'SDSS2' extension = '_WHT.fits' Folder_1 = '/home/vital/Dropbox/Astrophysics/Data/WHT_Catalogue_SulfurRegression/Objects/' + CodeName1 + '/' Folder_2 = '/home/vital/Dropbox/Astrophysics/Data/WHT_Catalogue_SulfurRegression/Objects/' + CodeName2 + '/' Wave1, Flux1, ExtraData1 = dz.File_to_data(Folder_1, 'obj' + CodeName1 + extension) Wave2, Flux2, ExtraData2 = dz.File_to_data(Folder_2, 'obj' + CodeName2 + extension) dz.Axis.set_yscale('log') print Flux1 print Flux2 dz.data_plot(Wave1, Flux1, label=CodeName1, color=dz.ColorVector[2][0]) dz.data_plot(Wave2, Flux2, label=CodeName2, color=dz.ColorVector[2][1]) dz.FigWording( r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Objects {obj1} and {obj2} comparison'.format(obj1=CodeName1, obj2=CodeName2)) dz.display_fig()
dz.FigConf() #Loop through files for i in range(len(FilesList)): #Analyze file address CodeName, FileName, FileFolder = dz.Analyze_Address(FilesList[i]) #Import fits file fits_file = pf.open(FilesList[i]) Wave = fits_file[1].data['WAVELENGTH'] Int = fits_file[1].data['FLUX'] fits_file.close() dz.data_plot(Wave, Int, label=FileName.replace('_', '')) dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Calspec library') dz.Axis.set_yscale('log') dz.Axis.set_xlim(7000, 10000) dz.display_fig() # /home/vital/Dropbox/Astrophysics/Telescope Time/Standard_Stars/Calspec_Spectra/bd_17d4708_stisnic_006.fits # file_address = '/home/vital/Dropbox/Astrophysics/Telescope Time/Standard_Stars/Calspec_Spectra/bd_17d4708_stisnic_006.fits' # # fits_file = pf.open(file_address) # print fits_file[1].data['WAVELENGTH'] # print fits_file[1].data['FLUX'] #
from pymc import deterministic, stochastic, Normal, Uniform, MCMC, Bernoulli, stochastic_from_dist from dazer_methods import Dazer #Generate dazer object dz = Dazer() #Choose plots configuration dz.FigConf() #Import catalogue Catalogue = dz.import_catalogue() #Perform operations x = [1,2,3,4,5,6] y = [1,2,3,4,5,6] #Plot the data dz.data_plot(x, y, markerstyle = 'o') #Generate the figure dz.display_fig()
# print 'kapteyn' # print n_Median_kp, n_84th_kp - n_Median_kp ,n_Median_kp - n_16th_kp #Linear data x_regression_range = linspace(0.0, max(nominal_values(x)) * 1.10, 20) y_regression_range = m_Median_cf * x_regression_range + n_Median_cf label_regr = 'Linear fit' #label_regr = 'SCIPY bootstrap: $Y_{{P}} = {n}_{{-{lowerlimit}}}^{{+{upperlimit}}}$'.format(title = Regresions_dict['title'][i], n = round_sig(n_Median,4, scien_notation=False), lowerlimit = round_sig(n_Median-n_16th,2, scien_notation=False), upperlimit = round_sig(n_84th-n_Median,2, scien_notation=False)) #Plotting the data, label_regression = r'Plank prediction: $Y = 0.24709\pm0.00025$' dz.data_plot(nominal_values(x), nominal_values(y), color=Regresions_dict['Colors'][i], label='HII galaxies included', markerstyle='o', x_error=std_devs(x), y_error=std_devs(y)) dz.data_plot(x_regression_range, y_regression_range, label=label_regr, color=Regresions_dict['Colors'][i], linestyle='--') dz.plot_text(nominal_values(x), nominal_values(y), quick_ref) #Plotting NO objects dz.data_plot(nominal_values(x_NO), nominal_values(y_NO), color=Regresions_dict['Colors'][i], label='HII galaxies excluded',
#Launch starlight print '--Initiating starlight for ', fits_name, Sigma #dz.Starlight_Launcher(Grid_FileName, dz.RootFolder) print '--Starlight finished succesfully ended:', Sl_OutputFile #Get stellar spectrum from starlight file Input_Wavelength, Input_Flux, Output_Flux, MaskPixels, ClippedPixels, FlagPixels, Parameters = dz.File_to_data(Sl_OutputFolder, Sl_OutputFile) #Export data to fits file stellar_cont_fits = objName + '_StellarContinuum.fits' Flux_stellar_redd = dz.reddening_continuum(Input_Wavelength, Output_Flux, cHbeta.nominal_value) dz.Data_2_Fits(ouput_folder, stellar_cont_fits, header_0, Input_Wavelength, Flux_stellar_redd, NewKeyWord = ['STALIGHT', 'Basic Treatment']) #Plot the data dz.data_plot(Input_Wavelength, Input_Flux, "Input Spectra") dz.data_plot(Input_Wavelength, Output_Flux, "Stellar absorption") dz.data_plot(Input_Wavelength, Flux_stellar_redd, "Stellar absorption redened") #Set titles and legend PlotTitle = 'Object ' + objName + ' emission and stellar and spectra' dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', PlotTitle) mean_flux = Input_Flux.mean() dz.Axis.set_ylim(-0.05*mean_flux, 15*mean_flux) dz.Axis.set_xlim(3500, 5250) #dz.display_fig() #Save plot output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format(objFolder=ouput_folder, stepCode=dz.ScriptCode, objCode=objName, ext='StellarContinuum')
#Run the fits for k in range(MC_iterations): x_i = metal_matrix[:,k] y_i = Y_matrix[:,k] m, n, r_value, p_value, std_err = stats.linregress(x_i, y_i) m_vector[k], n_vector[k] = m, n #Get fit mean values n_Median, n_16th, n_84th = median(n_vector), percentile(n_vector,16), percentile(n_vector,84) m_Median, m_16th, m_84th = median(m_vector), percentile(m_vector,16), percentile(m_vector,84) #Linear data x_regression_range = linspace(0.0, max(nominal_values(x)) * 1.10, 20) y_regression_range = m_Median * x_regression_range + n_Median #Plotting the data dz.data_plot(nominal_values(x), nominal_values(y), color = Regresions_dict['Colors'][i], label=regression, markerstyle='o', x_error=std_devs(x), y_error=std_devs(y)) dz.data_plot(WMAP_coordinates[0].nominal_value, WMAP_coordinates[1].nominal_value, color = dz.colorVector['pink'], label='WMAP prediction', markerstyle='o', x_error=WMAP_coordinates[0].std_dev, y_error=WMAP_coordinates[1].std_dev) dz.data_plot(x_regression_range, y_regression_range, label = 'Linear regression', color = Regresions_dict['Colors'][i], linestyle = '--') dz.plot_text(nominal_values(x), nominal_values(y), objects) plotTitle = r'{title}: $Y_{{P}} = {n}_{{-{lowerlimit}}}^{{+{upperlimit}}}$'.format(title = regression, n = round_sig(n_Median,4, scien_notation=False), lowerlimit = round_sig(n_Median-n_16th,4, scien_notation=False), upperlimit = round_sig(n_84th-n_Median,4, scien_notation=False)) dz.FigWording(Regresions_dict['x label'][i], Regresions_dict['y label'][i], plotTitle, loc='lower right') output_pickle = '{objFolder}{element}_regression'.format(objFolder=catalogue_dict['Data_Folder'], element = element) dz.save_manager(output_pickle, save_pickle = True)
from dazer_methods import Dazer import os import numpy as np dz = Dazer() dz.FigConf() file_address = '/home/vital/Dropbox/Astrophysics/Seminars/Cloudy School 2017/code5varyZ.lin' #Cont nu incident trans DiffOut net trans reflc total reflin outlin lineID cont nLine OIII = np.loadtxt(file_address, usecols = (09, unpack = True) dz.data_plot(nu, incident, label = 'Incident spectrum') dz.data_plot(nu, trans, label = 'Transmitted spectrum') dz.data_plot(nu, total, label = 'Total spectrum') dz.Axis.set_xlim(0.01,10000) dz.Axis.set_ylim(1e-37,1e-22) # # # dz.Axis.set_ylim(1e-9,1) dz.Axis.set_yscale('log') dz.Axis.set_xscale('log') dz.FigWording(r'Wavelength (microns)', r'Radiation spectrum', 'Coronal') dz.display_fig()
joining_wavelength = catalogue_df.iloc[i].join_wavelength #Treat each arm file for color in ['Blue', 'Red']: fits_file = catalogue_df.iloc[i]['z{}_file'.format(color)] print fits_file CodeName, FileName_Blue, FileFolder = dz.Analyze_Address(fits_file) wave, flux, ExtraData = dz.get_spectra_data(fits_file) dz.data_plot(wave, flux, label = '{} {} arm'.format(CodeName, color), color=color_dict[color]) idx_point = searchsorted(wave, joining_wavelength) if (wave[0] < joining_wavelength) and (joining_wavelength < wave[-1]): # dz.data_plot(wave[idx_point], flux[idx_point], label = 'Joining lambda {} $\AA$'.format(joining_wavelength), color=dz.colorVector['green'], markerstyle = 'o') dz.Axis.axvline(joining_wavelength, label = 'Joining lambda {} $\AA$'.format(joining_wavelength), color=dz.colorVector['green']) else: mean_continuum_flux = median(flux) #dz.data_plot(joining_wavelength, mean_continuum_flux, label = 'Joining lambda {} $\AA$'.format(joining_wavelength), color=dz.colorVector['green'], markerstyle = 'o') dz.Axis.axvline(joining_wavelength, label = 'Joining lambda {} $\AA$'.format(joining_wavelength), color=dz.colorVector['green']) mean_flux = median(flux) dz.Axis.set_ylim(mean_flux / 15, mean_flux * 10) dz.Axis.set_xlim(joining_wavelength-300, joining_wavelength+300) dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Redshift correction')
from dazer_methods import Dazer #Declare object dz = Dazer() dz.FigConf(n_colors=5) CodeName1 = '70' CodeName2 = 'SDSS2' extension = '_WHT.fits' Folder_1 = '/home/vital/Dropbox/Astrophysics/Data/WHT_Catalogue_SulfurRegression/Objects/' + CodeName1 + '/' Folder_2 = '/home/vital/Dropbox/Astrophysics/Data/WHT_Catalogue_SulfurRegression/Objects/' + CodeName2 + '/' Wave1, Flux1, ExtraData1 = dz.File_to_data(Folder_1, 'obj' + CodeName1 + extension) Wave2, Flux2, ExtraData2 = dz.File_to_data(Folder_2, 'obj' + CodeName2 + extension) dz.Axis.set_yscale('log') print Flux1 print Flux2 dz.data_plot(Wave1, Flux1, label = CodeName1, color=dz.ColorVector[2][0]) dz.data_plot(Wave2, Flux2, label = CodeName2, color=dz.ColorVector[2][1]) dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Objects {obj1} and {obj2} comparison'.format(obj1= CodeName1, obj2= CodeName2)) dz.display_fig()
# # Title = r'Sample SDSS model magnitudes' # Title_X = r'r $(model)$' # Title_Y = r'g $(model)$' # dz.FigWording(Title_X, Title_Y, Title, legend_loc='best') # dz.display_fig() # dz.savefig(output_address = Catalogue_Dic['Data_Folder'] + 'g_r_magnitudes_M', reset_fig = True) # # #------Plot magnitudes x_values = array(Hbeta_values) y_values = array(Declination_values) dz.data_plot(x_values, y_values, color = dz.ColorVector[2][0], label='Candidate objects', markerstyle='o') dz.text_plot( x_values, y_values, names, color = dz.ColorVector[1], fontsize = 11) Title = r'Sample declination versus equivalent width' Title_X = r'$Eqw$ $(H\beta)$' Title_Y = r'dec $(deg)$' dz.FigWording(Title_X, Title_Y, Title, legend_loc='best') # dz.display_fig() dz.savefig(output_address = Catalogue_Dic['Folder'] + 'dec_eqw_M', reset_fig = True) # print 'donde va esto', Catalogue_Dic['Folder'] + 'dec_eqw_M' #------Plot Flux vs Eqw x_values = array(Hbeta_values) y_values = array(Flux_values)
#Object objName = catalogue_df.iloc[i].name fits_file = catalogue_df.iloc[i].reduction_fits print '-- Treating {} @ {}'.format(objName, fits_file) #Spectrum data wave, flux, header_0 = dz.get_spectra_data(fits_file) #Plot the regions of interest if wave[-1] > 8498: ind_low, ind_high = searchsorted(wave, lambda_limits) subWave, subFlux = wave[ind_low:ind_high], flux[ind_low:ind_high] medianFlux = full(3, median(subFlux), dtype=float) #Plot data dz.data_plot(subWave, subFlux, '{} spectrum'.format(objName)) dz.data_plot(lambda_CaII, medianFlux, 'CaII absorptions', markerstyle= 'o', color=dz.colorVector['orangish']) #Set titles and legend dz.FigWording(r'Wavelength $(\AA)$', r'Flux $(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Object {} CaII triplet region'.format(objName)) #Save data ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format(objFolder=ouput_folder, stepCode=dz.ScriptCode, objCode=objName, ext='CalIIRegion') dz.save_manager(output_pickle, save_pickle = True) print "\nAll data treated generated"
for i in range(len(FilesList)): #Analyze file address CodeName, FileName, FileFolder = dz.Analyze_Address(FilesList[i]) #Import fits file Wave, Int, ExtraData = dz.File_to_data(FileFolder,FileName) #Getting the masks as a two lists with initial and final points #WARNING the masks generated do not distinguish the absorptions MaskFileName = CodeName + '_Mask.lineslog' InitialPoints, FinalPoints = loadtxt(FileFolder + MaskFileName, usecols=(0,1) ,skiprows=1,unpack=True) #Change by new method #Plot the data dz.data_plot(Wave, Int, "Input spectrum", dz.ColorVector[2][1]) dz.area_fill(InitialPoints, FinalPoints, 'Masks', dz.ColorVector[2][0], 0.2) # Set titles and legend PlotTitle = r'Object ' + CodeName + ' spectrum with masked and flagged pixels' dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', PlotTitle) # Save data dz.save_manager(FileFolder + dz.ScriptCode + '_' + CodeName + '_Sl_MasksFlags') print i+1, '/' , len(FilesList) #----------------------------------------------------------------------------------------------------- print "All data treated"
#Case we can (and we want) to perform the telluric correction: if (len(objects) > 0) and (favoured_star != 'None'): star_dict = {} for i in range(len(objects)): wave_star, flux_star, header_0_star = dz.get_spectra_data(Files_Folders[i] + Files_Names[i]) idx_print_low, idx_print_high = searchsorted(wave_star,[9000, 9650]) idx_join_region = searchsorted(wave_star,[wave_join]) if len(flux_star) == 2: flux_star = flux_star[0][0] star_dict[objects[i]+'_wave'], star_dict[objects[i]+'_flux'] = wave_star, flux_star star_dict[objects[i]+'_idx_join'] = idx_join_region dz.data_plot(wave_star, flux_star, label=objects[i], graph_axis=dz.ax2) obj_red_region = array(range(idx_obj_join,idx_obj_join + len_red_region)) mean_flux = mean(flux_obs) #Loop through the diagnostic lines obj_dict = {} for line in lines_interest: if line in lick_idcs_df.index: dz.Current_Label = lick_idcs_df.loc[line].name dz.Current_Ion = lick_idcs_df.loc[line].Ion dz.Current_TheoLoc = redshift_factor * lick_idcs_df.loc[line].lambda_theo selections = redshift_factor * lick_idcs_df.loc[line][3:9].values #Measure the line intensity
#Generate dazer object dz = Dazer() #Choose plots configuration dz.FigConf() #Import catalogue Catalogue = dz.import_catalogue() #Perform operations x = [1,2,3,4,5,6] y = [1,2,3,4,5,6] #Plot the data dz.data_plot(x, y, markerstyle = 'o') #Generate the figure dz.display_fig() # from DZ_DataExplorer import Plots_Manager # # # We declare the folder and log file to drop the lines data # pv = Plots_Manager() # # # Forcing the remake of new files # pv.RemakeFiles = True # # #Object and line to treat # Obj_Folder = '/home/vital/Dropbox/Astrophysics/Data/WHT_Catalogue/Objects/SHOC579/' # Obj_Pattern = 'objSHOC579_WHT.fits'
#Spectrum data wave, flux, header_0 = dz.get_spectra_data(fits_file) subwave, subflux, lineHeight, LineExpLoc = Emission_Threshold(6548.0, wave, flux) #Establish current line dz.Current_Label = 'N2_6548A' dz.Current_Ion = 'N2' dz.Current_TheoLoc = 6548.050 selections = array([6497.701, 6522.331, 6537.998, 6591.29, 6592.324, 6610.83]) #Proceed to measure line_data = dz.measure_line(wave, flux, selections, lines_dataframe=None, store_data = False) #Plot Global component dz.data_plot(subwave, subflux, label='Spectrum', linestyle='step', color = dz.colorVector['silver']) dz.data_plot(line_data['x_resample'], line_data['y_resample'], 'Gaussian mixture', linewidth=2.0, color = dz.colorVector['yellow']) #Plot individual components for i in range(line_data['line_number']): dz.data_plot(line_data['x_resample'], line_data['y_comps'][i], 'Components', linestyle = '--', color=dz.colorVector['orangish'], linewidth=1.0) #Plot peaks #dz.data_plot(line_data['peak_waves'], line_data['peak_Maxima'], 'Input values', markerstyle='o', color = dz.colorVector['pink']) dz.Axis.set_xlim([subwave[0],subwave[-1]]) dz.Axis.set_ylim(median(subflux)/10, lineHeight*2) dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', r'Object {} $H\alpha$ wide component'.format(objName)) #Plot output figures output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format(objFolder=ouput_folder, stepCode=dz.ScriptCode, objCode=objName, ext='_Halpha_region')
# Generate dazer object dz = Dazer() # Choose plots configuration dz.FigConf() # Import catalogue Catalogue = dz.import_catalogue() # Perform operations x = [1, 2, 3, 4, 5, 6] y = [1, 2, 3, 4, 5, 6] # Plot the data dz.data_plot(x, y, markerstyle="o") # Generate the figure dz.display_fig() # from DZ_DataExplorer import Plots_Manager # # # We declare the folder and log file to drop the lines data # pv = Plots_Manager() # # # Forcing the remake of new files # pv.RemakeFiles = True # # #Object and line to treat # Obj_Folder = '/home/vital/Dropbox/Astrophysics/Data/WHT_Catalogue/Objects/SHOC579/'
data_array_0 = fits.getdata(fits_address, ext=0) data_array_1 = fits.getdata(fits_address, ext=1) show_me_the_bits(header_0) show_me_the_bits(header_1) # wavel Angstrom # spec Angstrom-1 cm-2 erg s-1 # spec_var Angstrom-2 cm-4 erg2 s-2 # specw Angstrom-1 cm-2 erg s-1 wavel = data_array_0['wavel'] spec = data_array_1['spec'] sigma_spectrum = np.sqrt(data_array_1['spec_var']) specw = data_array_1['specw'] print wavel print spec print sigma_spectrum dz.data_plot(wavel, spec, label='spec key') # dz.data_plot(wavel, sigma_spectrum, label='sqrt(var)') dz.Axis.fill_between(wavel, spec-sigma_spectrum, spec+sigma_spectrum, alpha=0.5) dz.data_plot(wavel, specw, label='spec', linestyle=':') dz.Axis.set_yscale('log') dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Muse spectrum') dz.display_fig()
Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/extPHL70blue.fits' Fileaddress = '/home/vital/Astrodata/WHT_HIIGalaxies_FluxCalibration/2011_12_Night1/Blue/obj70_s_c_cr_f_a_bg.0001_fxW.fits' Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/fcx2PHLblue.fits' Fileaddress = '/home/vital/Astrodata/pypeLine_Spectra/Elena_Specs/PHL-blue/extblueBD17fl.fits' # Fileaddress = '/home/vital/Desktop/Testing_reduction/stdG191v1_bg_Blue.fits' #Identify file CodeName, FileName, FileFolder = dz.Analyze_Address(Fileaddress) #Load fits file data Wave, Int, ExtraData = dz.File_to_data(FileFolder, FileName) dz.data_plot(Wave, Int, FileName, 'black') # dz.Axis.set_yscale('log') dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Object ' + FileName) dz.display_fig() # import CodeTools.PlottingManager as plotMan # from Scientific_Lib.IrafMethods import Pyraf_Workflow # from numpy import median # # pv = plotMan.myPickle() # py_w = Pyraf_Workflow('WHT') # Pattern, CatalogueFolder = py_w.DataFormat(Reduction_Operation = 'Std_FluxCalibration') #
#-- Calculate continuous emissino coefficients: Gamma_Total, Gamma_lambda, Gamma_FB_HI, Gamma_FB_HeI, Gamma_FB_HeII, Gamma_2q, Gamma_FF = nebCalc.Calculate_Nebular_gamma( ) #-- Caculate nebular flux with different calibration methods NebularInt_Hbeta = nebCalc.Zanstra_Calibration('Hbeta', Hbeta_Flux.nominal_value, Gamma_Total) #Removing nebular component Int_dedNeb = spectrum_dered - NebularInt_Hbeta #nebularFlux_cont = dz.derreddening_continuum(wave, NebularInt_Hbeta, cHbeta.nominal_value) #Plotting the data dz.data_plot(wave, spectrum_dered, 'Reduced spectrum (without reddening)') dz.data_plot(wave, NebularInt_Hbeta, 'Nebular flux') dz.data_plot(wave, Int_dedNeb, 'Removed Nebular contribution') #Format the graphs PlotTitle = r'Object {} Nebular continuum substraction'.format(objName) dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', PlotTitle) mean_flux = spectrum_dered.mean() dz.Axis.set_ylim(-0.05 * mean_flux, 15 * mean_flux) dz.Axis.set_xlim(3500, 5250) output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format( objFolder=ouput_folder, stepCode=dz.ScriptCode, objCode=objName,
# flux_calibrated = ['/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Blue_cr_f_t_w_e_fglobal.fits', # '/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Red_cr_f_t_w_bg_e_fglobal.fits'] flux_calibrated = [ '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A1/MRK36_A1_Blue_fglobal.fits', '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A2/MRK36_A2_Blue_fglobal.fits', '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A1/MRK36_A1_Red_fglobal.fits', '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A2/MRK36_A2_Red_fglobal.fits', ] for i in range(len(flux_calibrated)): # color = 'Blue' if 'Blue' in extracted_files[i] else 'Red' CodeName, FileName, FileFolder = dz.Analyze_Address(flux_calibrated[i]) wavelength, Flux_array, Header_0 = dz.get_spectra_data(flux_calibrated[i]) # for j in range(Header_0['NAXIS2']): # # color_plot = 'orangish' if j == 0 else 'dark blue' # dz.data_plot(wavelength, Flux_array[j], label = 'Apperture {} {}'.format(j, color), color=dz.colorVector[color_plot]) dz.data_plot(wavelength, Flux_array, label = FileName) dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'MRK36') dz.display_fig()
x_regression = linspace(0.8 * np_min(unumpy.nominal_values(TeOIII_array)), 1.20 * np_max(unumpy.nominal_values(TeOIII_array)), 10) y_regression_Garnet92 = (0.83 * x_regression / 10000 + 0.17) * 10000 y_regression_EpmDiaz05 = (1.05 * x_regression / 10000 - 0.08) * 10000 y_regression_Epm2014 = (0.92 * x_regression / 10000 + 0.078) * 10000 #Perform the fit regr_dict = bces_regression(unumpy.nominal_values(TeOIII_array), unumpy.nominal_values(TeSIII_array), unumpy.std_devs(TeOIII_array), unumpy.std_devs(TeSIII_array)) # for i in range(len(regr_dict['m'])): reg_code = 3 y_fit = regr_dict['m'][reg_code] * x_regression + regr_dict['n'][reg_code] dz.data_plot(x_regression, y_fit, 'Linear fit', linestyle='-') dz.data_plot(unumpy.nominal_values(TeOIII_array), unumpy.nominal_values(TeSIII_array), 'HII galaxies', markerstyle='o', x_error=unumpy.std_devs(TeOIII_array), y_error=unumpy.std_devs(TeSIII_array), color='tab:blue') dz.plot_text(unumpy.nominal_values(TeOIII_array), unumpy.nominal_values(TeSIII_array), objects, fontsize=17) dz.data_plot(x_regression, y_regression_Garnet92,
dz.FigConf() #Loop through files for i in range(len(FilesList)): #Analyze file address CodeName, FileName, FileFolder = dz.Analyze_Address(FilesList[i]) #Import fits file fits_file = pf.open(FilesList[i]) Wave = fits_file[1].data['WAVELENGTH'] Int = fits_file[1].data['FLUX'] fits_file.close() dz.data_plot(Wave, Int, label=FileName.replace('_', '')) dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Calspec library') dz.Axis.set_yscale('log') dz.Axis.set_xlim(7000, 10000) dz.display_fig() # /home/vital/Dropbox/Astrophysics/Telescope Time/Standard_Stars/Calspec_Spectra/bd_17d4708_stisnic_006.fits # file_address = '/home/vital/Dropbox/Astrophysics/Telescope Time/Standard_Stars/Calspec_Spectra/bd_17d4708_stisnic_006.fits' # # fits_file = pf.open(file_address) # print fits_file[1].data['WAVELENGTH'] # print fits_file[1].data['FLUX'] # # fits_file.close()
ions_colors_O = ['tab:blue', 'tab:green'] line_type = ['--', '-'] for i in range(len(file_name_list_S)): file_name = file_name_list_S[i] elemIon_df = pd.read_csv(folder_data + file_name, sep='\t') for j in range(len(ions_list_S)): ion = ions_list_S[j] radious = elemIon_df['#depth'].values ion_frac = elemIon_df[ion].values label = r'{0:1.1e} $M_\odot$'.format(float(z_list[i])) dz.data_plot(radious / 1e19, ion_frac, color=ions_colors_S[j], linestyle=line_type[i], label=r'Cluster mass {}'.format(label), linewidth=2) dz.plot_text(labels_coords_S[j][i][0] / 1e19, labels_coords_S[j][i][1], text=ions_labels_S[j], color=ions_colors_S[j], fontsize=20, axis_plot=None) file_name = file_name_list_O[i] elemIon_df = pd.read_csv(folder_data + file_name, sep='\t') for j in range(len(ions_list_O)): ion = ions_list_O[j] radious = elemIon_df['#depth'].values ion_frac = elemIon_df[ion].values label = r'{0:1.1e} $M_\odot$'.format(float(z_list[i])) dz.data_plot(radious / 1e19, ion_frac, color=ions_colors_O[j], linestyle=line_type[i], label=r'Cluster mass {}'.format(label)) dz.plot_text(labels_coords_O[j][i][0] / 1e19, labels_coords_O[j][i][1], text=ions_labels_O[j],