dz.data_plot( unumpy.nominal_values(ratios_dict['in_x']), unumpy.nominal_values(trendline_in), r'First regression $c(H\beta) = {Value} \pm {Error}$'.format( Value=round(cHbeta_all_MagEr.nominal_value, 3), Error=round(cHbeta_all_MagEr.std_dev, 3)), linestyle='--', color='#0072B2') dz.data_plot( unumpy.nominal_values(ratios_dict2['in_x']), unumpy.nominal_values(trendline_in2), r'Second regression $c(H\beta) = {Value} \pm {Error}$'.format( Value=round(cHbeta_all_MagEr2.nominal_value, 3), Error=round(cHbeta_all_MagEr2.std_dev, 3)), linestyle='--', color='#D55E00') #Figure format dz.Axis.set_ylim(-0.5, 0.4) dz.Axis.set_xlim(-0.65, 0.4) Title = r'Object {Codename} reddening coefficient calculation'.format( Codename=catalogue_df.loc[objName].quick_index) y_Title = r'$log(I/I_{H\beta})_{th}-log(F/F_{H\beta})_{Obs}$' x_Title = r'$f(\lambda)-f(\lambda_{H\beta})$' dz.FigWording(x_Title, y_Title, Title, loc=4) output_pickle = '/home/vital/Dropbox/Astrophysics/Papers/Yp_AlternativeMethods/Images/reddening_evolution.png' dz.save_manager(output_pickle, save_pickle=False) print 'All data treated', dz.display_errors()
idx_sort = np.argsort(Te_vector) print Te_vector[idx_sort] He1 = pn.RecAtom('He', 1) HeI_5875_emis = He1.getEmissivity(Te_vector[idx_sort], 100.2, label='5876.0') print HeI_5875_emis print emis_dict['HE 1 5875.64A'][idx_sort] dz.data_plot(Te_vector[idx_sort], emis_dict['HE 1 5875.64A'][idx_sort], 'Cloudy emissivities') dz.data_plot(Te_vector[idx_sort], HeI_5875_emis, 'Pyneb emissivities') dz.FigWording(r'Temperature', 'Emissivity', 'Emissivities comparison') dz.display_fig() # # Defining the object that will manage the input file for Cloudy # c_input = pc.CloudyInput(full_model_name) # c_input.set_other(('init file "hheonly.ini"')) # c_input.set_other(('element helium abundance -3')) # c_input.set_BB(Teff=Teff, lumi_unit='q(H)', lumi_value=qH) # c_input.set_other(('constant temperature 4')) # c_input.set_cste_density(dens) # c_input.set_radius(r_in=dist) # c_input.set_other(('set dr 0')) # c_input.set_stop('zone 1') # c_input.set_other(('stop zone 1')) # c_input.set_emis_tab(emis_tab) # better use read_emis_file(file) for long list of lines, where file is an external file
axins.set_ylim(-0.2e-16, 2.0e-16) mark_inset(dz.ax1, axins, loc1=3, loc2=4, fc="none", ec="0.5") axins2 = zoomed_inset_axes(dz.ax1, zoom=6, loc=7) axins2.step(wave_obs[region_indeces(wave_join, wave_max, wave_obs)], flux_obs[region_indeces(wave_join, wave_max, wave_obs)], label='Observed spectrum', linestyle='--', color=colorVector['dark blue'], where = 'mid') axins2.step(wave_tell, flux_tell, color=colorVector['orangish'], where = 'mid', linewidth=0.75) axins2.set_xlim(9540, 9620) axins2.set_ylim(-0.2e-16, 3.0e-16) mark_inset(dz.ax1, axins2, loc1=2, loc2=4, fc="none", ec="0.5") axins.get_xaxis().set_visible(False) axins.get_yaxis().set_visible(False) axins2.get_xaxis().set_visible(False) axins2.get_yaxis().set_visible(False) dz.FigWording('', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', '', loc='upper left', graph_axis=dz.ax1, sort_legend=True) dz.FigWording(r'Wavelength $(\AA)$', 'Normalized flux', '', loc='lower center', graph_axis=dz.ax2, ncols_leg=4) dz.ax2.set_ylim(0.2,1.25) if 'S3_9531A_continuum' in obj_dict: dz.ax1.set_ylim(-2 * obj_dict['S3_9531A_continuum'], 1.1 * obj_dict['S3_9531A_Peak']) else: dz.ax1.set_ylim(0.005 * mean_flux, 20 * mean_flux) dz.insert_image('/home/vital/Downloads/obj08_SDSS_image_color.png', Image_Coordinates = [0.50,0.80], Zoom=0.25, Image_xyCoords = 'axes fraction', axis_plot=dz.ax1) dz.savefig(image_address, extension='.png') #dz.display_fig() # output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format(objFolder=ouput_folder, stepCode=script_code, objCode=objName, ext='Telluric correction') # dz.save_manager(output_pickle, save_pickle = True)
'Valid points regression', linestyle='--', color='black') #Store reddening coefficient catalogue_df.loc[objName, 'cHbeta_reduc'] = cHbeta_in_MagEr #Figure format dz.Axis.set_ylim(-0.4, 0.4) Title = r'Object {Codename} reddening: $c(H\beta) = {Value} \pm {Error}$'.format( Codename=objName, Value=round(cHbeta_all_MagEr.nominal_value, 3), Error=round(cHbeta_all_MagEr.std_dev, 3)) y_Title = r'$log(I/I_{H\beta})_{th}-log(F/F_{H\beta})_{Obs}$' x_Title = r'$f(\lambda)-f(\lambda_{H\beta})$' dz.FigWording(x_Title, y_Title, Title) #, XLabelPad = 20 output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format( objFolder=ouput_folder, stepCode=script_code, objCode=objName, ext='CHbeta_Calculation') dz.save_manager(output_pickle, save_pickle=True) dz.save_excel_DF( catalogue_df, '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx', df_sheet_format='catalogue_data') print 'All data treated', dz.display_errors()
objCodes = np.arange(1, len(df_dict[type].index) + 1).astype(str) NO = (unumpy.uarray(df_dict[type]['Nitrogen'].values, df_dict[type]['Nitrogen_error'].values) * 1e-6) / (unumpy.uarray(df_dict[type]['Oxygen'].values, df_dict[type]['Oxygen_error'].values) * 1e-5) dz.data_plot(y, unumpy.nominal_values(NO), label=conf_dict['legend_label'], color=conf_dict[element + '_color'], markerstyle='o', x_error=y_err, y_error=unumpy.std_devs(NO)) dz.plot_text(y, unumpy.nominal_values(NO), objCodes) dz.FigWording(conf_dict[element + '_xlabel'], 'N/O', conf_dict['title']) dz.display_fig() # import numpy as np # from uncertainties import ufloat, unumpy # from dazer_methods import Dazer # # #Generate dazer object # dz = Dazer() # # #Set figure format # dz.FigConf() # # file_tradional_reduc = '/home/vital/Dropbox/Astrophysics/Data/Fabian_Catalogue/data/Traditional_Abundances.xlsx' # file_starlight = '/home/vital/Dropbox/Astrophysics/Data/Fabian_Catalogue/data/Starlight_Abundances.xlsx'
idcs = (pd.notnull(catalogue_df.OI_HI_emis2nd)) & (pd.notnull( catalogue_df.NI_HI_emis2nd)) & ( ~catalogue_df.index.isin(['0564', '3', '70', '51991-224'])) #Prepare data O_values = catalogue_df.loc[idcs].OI_HI_emis2nd.values N_values = catalogue_df.loc[idcs].NI_HI_emis2nd.values objects = catalogue_df.loc[idcs].index.values print objects N_O_ratio = N_values / O_values for i in range(len(N_O_ratio)): print objects[i], O_values[i], N_values[i], N_O_ratio[i] dz.data_plot(unumpy.nominal_values(O_values) * 1e5, unumpy.nominal_values(N_O_ratio), label='Abundances from our sample', markerstyle='o', x_error=unumpy.std_devs(O_values) * 1e5, y_error=unumpy.std_devs(N_O_ratio)) dz.plot_text(unumpy.nominal_values(O_values) * 1e5, unumpy.nominal_values(N_O_ratio), text=objects) dz.FigWording(r'$O/H$ $(10^5)$', r'$N/O$', r'N/O relation for HII galaxy sample') dz.display_fig()
#Set figure format sizing_dict = {'figure.figsize': (8, 8)} dz.FigConf(sizing_dict) te_SIII = np.linspace(8000, 20000, 50) te_SII = 0.88 * te_SIII + 1560 line_unity = te_SIII dz.data_plot(te_SIII, te_SII, label=r'$T_e[SII]=0.88T_e[SIII]+1560$') dz.data_plot(te_SIII, te_SIII, label='', color='grey', linestyle='--') dz.Axis.set_xlim(8000, 20000) dz.Axis.set_ylim(8000, 20000) dz.Axis.grid(True) ticklines = dz.Axis.get_xticklines() + dz.Axis.get_yticklines() gridlines = dz.Axis.get_xgridlines() + dz.Axis.get_ygridlines() ticklabels = dz.Axis.get_xticklabels() + dz.Axis.get_yticklabels() for line in ticklines: line.set_linewidth(3) for line in gridlines: line.set_linestyle('-.') dz.FigWording(xlabel=r'$T_e[SIII]$ $(K)$', ylabel=r'$T_e[SII]$ $(K)$', title='Relation between $S^{+1}$ and $S^{+2}$ temperatures') dz.display_fig()
# Linear data elemt_scale = Regresions_dict['factor'][i] x_regression_range = np.linspace(0.0, np.max(x_nat) * 1.10, 20) y_regression_range = m_Median * x_regression_range + n_Median # Plotting the data, label_regression = r'Plank prediction: $Y = 0.24709\pm0.00025$' dz.data_plot(x_regression_range * elemt_scale, y_regression_range, label=label_regr, linestyle='--', color=Regresions_dict['color'][i]) dz.data_plot(x_nat * elemt_scale, y, label='HII galaxies included', markerstyle='o', x_error=x_er_nat * elemt_scale, y_error=y_er, color=Regresions_dict['color'][i]) #dz.plot_text(x_nat, y, objRegress) # Plot WMAP prediction dz.data_plot(WMAP_coordinates[0].nominal_value, WMAP_coordinates[1].nominal_value, color=dz.colorVector['pink'], label='Planck prediction', markerstyle='o', x_error=WMAP_coordinates[0].std_dev, y_error=WMAP_coordinates[1].std_dev) dz.FigWording(Regresions_dict['x label'][i], Regresions_dict['y label'][i], '', loc='lower center', ncols_leg=2) dz.Axis.set_ylim(0.1, 0.4) output_pickle = '{objFolder}{element}_BayesDataRegression'.format(objFolder=article_folder, element=element) dz.save_manager(output_pickle, save_pickle=False) # Perform the triple regression idcs_3Regres = bayes_catalogue_df['O_abund_nom'].notnull() &\ bayes_catalogue_df['N_abund_nom'].notnull() &\ bayes_catalogue_df['S_abund_nom'].notnull() &\ bayes_catalogue_df['Ymass_S_nom'].notnull() &\ ~bayes_catalogue_df.quick_reference.isin(Regresions_dict['excluded'][0] + Regresions_dict['excluded'][1] + Regresions_dict['excluded'][2]) objRegress = bayes_catalogue_df[idcs_3Regres].quick_reference.values O, O_er = bayes_catalogue_df.loc[idcs_3Regres, 'O_abund_nom'].values, bayes_catalogue_df.loc[idcs_3Regres, 'O_abund_er'].values
neb_gCont = neb.calculate_neb_gCont(wave, Te, HeI, HeII) neb_fCont = neb.gCont_calibration(wave, Te, Flux_recomb, neb_gCont) dz.data_plot(wave, neb_fCont, label='Total new') # dz.data_plot(wave, Gamma_FF_HI_fast, label = 'H Free-Free') # dz.data_plot(wave, 4 * Gamma_FF_HI_fast,label = 'He Free-Free') # dz.data_plot(wave, Gamma_2q_HI_fast, label = 'H Two-photon') # dz.data_plot(wave, Gamma_FB_HI_fast, label = 'H Free-Bound') # dz.data_plot(wave, Gamma_FB_HeI_fast, label = r'$He$ Free-Bound') # dz.data_plot(wave, Gamma_FB_HeII_fast, label = r'$He^{+}$ Free-Bound') # dz.data_plot(wave, Gamma_FB_HI, label = 'H Free-Bound EP') dz.Axis.set_yscale('log') dz.FigWording(r'Wavelength $(\AA)$', r'$\gamma$ $\left(erg\,cm^{3}\,s^{-1}\,Hz^{-1}\right)$', title='Hydrogen and helium nebular components') # dz.savefig('/home/vital/Dropbox/Astrophysics/Seminars/Cloudy School 2017/nebular_components') dz.display_fig() # start = timer() # Gamma_FF_HI = neb.FreeFreeContinuum("HI") # end = timer() # print 'FF', ' time ', (end - start) # # start = timer() # Gamma_2q = neb.TwoPhotonContinuum() # end = timer() # print '2q', ' time ', (end - start) # # start = timer() # Gamma_FB_HI = neb.FreeBoundContinuum_EP("HI")
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='Blue arm') dz.data_plot(wave_Red, flux_Red, label='Red arm') dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', '', ncols_leg=2) dz.savefig( '/home/vital/Dropbox/Astrophysics/Thesis/images/SHOC579_z.png') # dz.display_fig() # #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.loc[objName, 'reduction_fits'] = combined_fits_name
1.20 * np_max(unumpy.nominal_values(x_data)), 10) regr_dict = bces_regression(unumpy.nominal_values(x_data), unumpy.nominal_values(y_data), unumpy.std_devs(x_data), unumpy.std_devs(y_data)) y_fit = regr_dict['m'][reg_code] * x_regression + regr_dict['n'][reg_code] dz.data_plot(x_regression, y_fit, 'BCES linear fit from data', linestyle='-') dz.data_plot(x_regression, m_lmfit * x_regression + n_lmfit, 'lmfit Montecarlo', linestyle=':') print regr_dict['m'][reg_code] print regr_dict['n'][reg_code] Title = r'Sulfur versus Oxygen temperature comparison' y_Title = r'$T_{e}[SIII]\,(K)$' x_Title = r'$T_{e}[OIII]\,(K)$' dz.FigWording(x_Title, y_Title, Title) dz.display_fig() #dz.savefig('/home/vital/Dropbox/Astrophysics/Papers/Yp_AlternativeMethods/Images/temperatures_comparison') # #Run MCMC with MAP # MAP_Model = pm.MAP(bayes_model(unumpy.nominal_values(x_data), unumpy.std_devs(x_data), unumpy.nominal_values(y_data), unumpy.std_devs(y_data))) # MAP_Model.fit(method = 'fmin_powell') # MAP_Model.revert_to_max() # # print MAP_Model.variables # # MDL = pm.MCMC(MAP_Model.variables) # MDL.sample(iter=20000, burn=1000, thin=2) #Optimun test
dtype=types_list, unpack=True) objects = loadtxt(table_address, dtype=str, usecols=(0), unpack=True) O_mean = O_mean * 1e-4 O_err = O_err * 1e-4 print objects print Y_mean print Y_sys print Y_random print O_mean print O_err dz = Dazer() dz.FigConf() dz.data_plot(O_mean, Y_mean, label='Peimbert et al (2016)', markerstyle='o', x_error=O_err, y_error=Y_sys) dz.plot_text(O_mean, Y_mean, text=objects) dz.FigWording(xlabel='Oxygen abundance', ylabel='Helium mass fraction', title=r'$Y_{P}$ oxygen regression, Peimbert et al (2016)') dz.display_fig()
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 dz.data_plot(x_lineal, y_lineal, 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') #Displaying the figure dz.FigWording(r'$log(I([SII]\lambda\lambda6716+6731\AA)/I([SIII]\lambda\lambda9069+9531\AA))$', r'$log(U)$', '') dz.Axis.set_xlim(-1.55, 2) # dz.display_fig() dz.savefig(output_address = '/home/vital/Dropbox/Astrophysics/Papers/Yp_AlternativeMethods/images/logU_vs_Sratio')
#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 HeIII_HI = catalogue_df.loc[idcs].HeIII_HII_from_O_emis2nd.values objects = catalogue_df.loc[idcs].index.values He_ratio = HeII_HI / HeIII_HI print objects N_O_ratio = N_values / O_values for i in range(len(N_O_ratio)): print objects[i], O_values[i], N_values[i], N_O_ratio[i] dz.data_plot(unumpy.nominal_values(HeII_HI), unumpy.nominal_values(N_O_ratio), label='Abundances from our sample', 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) dz.FigWording(r'$HeII/HeIII$', r'$N/O$', r'N/O relation for HII galaxy sample') dz.display_fig()
# dz.data_plot(Wave_N, Int_N, '', color='tab:orange') # dz.data_plot(Wave_S, Int_S, '', color='tab:green') recombZones = [[4330, 4350], [4464, 4479], [4707, 4720], [4850, 4870], [4913, 4931], [5013, 5021]] colorLineZones(Wave_O, IntObs_dered, recombZones, 'tab:blue') recombZones = [[4356, 4373], [4947, 4969], [4992, 5013]] colorLineZones(Wave_O, IntObs_dered, recombZones, 'tab:pink') #Set titles and legend PlotTitle = r'{} continua comparison'.format(objName) dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', '', loc='upper right') mean_flux = Int_O.mean() #dz.Axis.set_yscale('log') dz.Axis.set_ylim(-0.05 * mean_flux, 4 * mean_flux) dz.Axis.set_xlim(4580, 4830) # colorLineZones(Wave_O, IntObs_dered, [[4750, 4780]], 'tab:red') # colorLineZones(Wave_O, IntObs_dered, [[4615, 4636]], 'tab:red') adjacentRegions = [[4750, 4780], [4615, 4636]] LineZones(Wave_O, IntObs_dered, adjacentRegions, 'tab:red') # colorLineZones(Wave_O, IntObs_dered, recombZones, 'tab:pink') LineZones(Wave_O, IntObs_dered, [[4707, 4720]], 'tab:blue')
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') dz.save_manager(output_pickle, save_pickle=True) print 'Data treated'
dz = Dazer() dz.FigConf() data_folder = '/home/vital/Dropbox/Astrophysics/Seminars/Cloudy School 2017/popstar_kroupa_004/' for file_name in sorted(os.listdir(data_folder)): print file_name file_address = os.path.abspath(os.path.join(data_folder, file_name)) wave, flux = np.loadtxt(file_address, usecols=(0, 3), unpack=True) age_float = 10**float(file_name[file_name.find('_t') + 2:]) print age_float / 1000000 age = 'age = {} Myr'.format(round(age_float / 1000000, 2)) dz.data_plot(wave, flux, label=age) dz.Axis.set_xlim(0, 10000) dz.Axis.set_ylim(1e-9, 1) dz.Axis.set_yscale('log') dz.FigWording( r'Wavelength $(\AA)$', r'Normalized flux', 'Popstar grid for Kroupa IMF, $Z_{gas}=0.004$\n (including nebular continua)' ) dz.display_fig()
#Plot the results dzp.FigConf() dzp.data_plot(dz.sspFit_dict['obs_wave'], dz.sspFit_dict['obs_flux'], label='obs_flux') dzp.data_plot(dz.sspFit_dict['obs_wave'], dz.sspFit_dict['zero_mask'], label='my mask') # dzp.data_plot(dz.fit_conf['obs_wave'], mis_cosas[1], label='Hector mask') # dzp.data_plot(dz.fit_conf['obs_wave'], mis_cosas[2], label='Hector fit') dzp.data_plot(dz.sspFit_dict['obs_wave'], fit_products['flux_sspFit'], label='my fit') dzp.FigWording('Wave', 'Flux', 'Input spectra') dzp.display_fig() # #Plot input spectra and regions # dzp.FigConf() # dzp.data_plot(dz.fit_conf['obs_wave'], dz.fit_conf['obs_flux'], label='obs_flux') # dzp.data_plot(dz.fit_conf['obs_wave'], dz.fit_conf['obs_flux_mask'], label='obs_flux_mask') # # dzp.data_plot(dz.fit_conf['obs_wave'], dz.fit_conf['Av_mask'], label='Av mask') # # dzp.data_plot(dz.fit_conf['obs_wave'], dz.fit_conf['obs_flux_err'], label='obs_flux_err') # # dz.data_plot(wave_unc, flux_unc_input, label='flux_unc_input') # # dz.data_plot(wave_unc, e_flux_unc, label='e_flux_unc') # # dz.data_plot(wave_unc, color_unc, label='color_unc') # # dz.data_plot(wave_unc, masked, label='masked') # # dz.data_plot(wave_unc, masked2, label='masked2') # # dz.data_plot(wave_unc, masked_Av, label='masked_Av') # # dz.data_plot(wave_unc, flux_masked, label='flux_masked')
unpack=True) dz.data_plot(He1_5875, He2_4685, markerstyle='o', color=colors_list[idx_color], label=r'log(age) = {}'.format(age)) dz.data_plot(9.82 / 100, 15.23 / 100, markerstyle='o', color='#bcbd22', label='Observational point') dz.FigWording(r'$F(HeI5876\AA/H\beta$)', r'$F(HeII4685\AA/H\beta$)', r'Relation He lines', loc='best') dz.Axis.set_yscale('log') dz.Axis.set_xscale('log') # dz.display_fig() dz.savefig( '/home/vital/Dropbox/Astrophysics/Seminars/Cloudy School 2017/teporingos/fluxes_grid_obs_age_effect', extension='.jpg') # from collections import OrderedDict # from dazer_methods import Dazer # import numpy as np #
dz.Axis.axhspan(value - error, value + error, alpha=0.5, label=label, color='saddlebrown') else: dz.data_plot(year, value, label='', markerstyle=marker_type, markersize=50, y_error=error, color='black') dz.Axis.set_ylim(0.18, 0.28) dz.FigWording(r'Year', r'$Y_{P}$', '', loc=8) #dz.savefig('/home/vital/Dropbox/Astrophysics/Thesis/images/Yp_references_evolution') dz.display_fig() # import pandas as pd # from dazer_methods import Dazer # # # #Import library object # dz = Dazer() # # #Read table data # df = pd.read_excel('/home/vital/Dropbox/Astrophysics/Thesis/notes/table_yp_literature.xlsx', sheetname='Sheet1') # # #Define plot frame and colors # size_dict = {'axes.labelsize':28, 'legend.fontsize':18, 'font.family':'Times New Roman', 'mathtext.default':'regular', 'xtick.labelsize':28, 'ytick.labelsize':28}
#Plot data dz.data_plot(wave_obs, flux_obs, label='Observed spectrum', linestyle='step', graph_axis=dz.ax1) dz.data_plot(wave_star, flux_star, label='Calibration star spectrum', linestyle='step', graph_axis=dz.ax2) dz.ax1.set_ylim(bottom=0) dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', r'Object {} Star {}'.format(codeName, calibration_star), loc='best', graph_axis=dz.ax1) dz.FigWording(r'Wavelength $(\AA)$', 'Normalized flux', '', loc='lower center', graph_axis=dz.ax2) output_pickle = '{objFolder}{stepCode}_{objCode}_{ext}'.format( objFolder=ouput_folder, stepCode=script_code, objCode=codeName, ext='check sky emission') dz.save_manager(output_pickle, save_pickle=True, 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) sn_values = array(sn_values) z_values = array(z_values) dz.data_plot(x_values, y_values,
dz.area_fill(metals_regions - 10, metals_regions + 10, 'Collisional excitation lines', color=dz.colorVector['olive'], alpha=0.5) dz.area_fill(recombination_regions - 10, recombination_regions + 10, 'Recombination lines', color=dz.colorVector['pink'], alpha=0.5) #Set titles and legend PlotTitle = '' dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', PlotTitle, loc='upper right', ncols_leg=2) dz.Axis.set_xlim(3550, 10000) axins2 = zoomed_inset_axes(dz.Axis, zoom=16, loc=7) axins2.step( Wave_O, Int_O, label='Observed spectrum' ) #, linestyle='--', color=colorVector['dark blue'], where = 'mid') axins2.step( Wave_N, Int_N, label='Nebular continuum model', linestyle='-' ) #,color=colorVector['orangish'], where = 'mid', linewidth=0.75) axins2.step( Wave_S, Int_S, label='Stellar continuum model', linestyle='-' ) #,color=colorVector['orangish'], where = 'mid', linewidth=0.75)
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') #Store the figure output_address = FileFolder + script_code + '_' + CodeName + '_joining_point' dz.save_manager(output_address, save_pickle=True) print "\nAll data treated generated"
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], color=ions_colors_O[j], fontsize=20, axis_plot=None) dz.FigWording(r'$R_{19}$ $(10^{19}cm)$', r'$X(A^{+i})$', '', ncols_leg=1) leg = dz.Axis.get_legend() leg.legendHandles[0].set_color('black') leg.legendHandles[1].set_color('black') #dz.display_fig() dz.savefig( '/home/vital/Dropbox/Astrophysics/Papers/Yp_AlternativeMethods/images/SulfurIonization_fraction_vs_cloudThickness' ) # dz.savefig('/home/vital/Dropbox/Astrophysics/Seminars/Stasinska conference/SulfurIonization_fraction_vs_cloudThickness') # #Load catalogue dataframe # catalogue_dict = dz.import_catalogue() # catalogue_df = dz.load_excel_DF('/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx') #
arcsec = lambda cm: conv_arc(dist=dist_small, dist_proj=cm) mask_cirleB = make_mask_circle(arcsec, smallCloud_sphere) #ap_size=[50, 1.5] mask_small = ~np.logical_not(mask_cirleB) #Calculate abundance small_lines_dict = extract_fluxes_combSlits(bigCloud_sphere, smallCloud_sphere, mask_big, mask_small) small_abund_dict = calculate_abundances(small_lines_dict, extensions=['comb']) print 'Small abund rad {}'.format(radius), small_abund_dict['S_comb'] dz.data_plot(float(radius), small_abund_dict['S_comb'], label = 'Secondary clouds abundance', color='red', markerstyle = 'o') # arcsec = lambda cm: conv_arc(dist=dist_small, dist_proj=cm) # mask_cirleB = make_mask_circle(arcsec, smallCloud_sphere) #ap_size=[50, 1.5] # mask_small = ~np.logical_not(mask_cirleB) # # #Calculate abundance # small_lines_dict = extract_fluxes_pure_slits(smallCloud_sphere) # small_abund_dict = calculate_abundances(small_lines_dict) # print 'Small abund rad {}'.format(radius), small_abund_dict['S_tot'], small_abund_dict['S_slit'] dz.FigWording(r'log(radious) (cm)', r'log(S/H)', 'Sulfur abundance evolution with high density clumps') dz.display_fig() print 'Data generated'
stellar_cont_fits = objName + '_StellarContinuum.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, stepCode=dz.ScriptCode, objCode=objName, ext='StellarContinuum') dz.save_manager(output_pickle, save_pickle=True) except: dz.log_error(objName)
Lineal_parameters = lineal_mod.guess(y_linealFitting, x=x_linealFitting) x_lineal = linspace(0, np_max(x_linealFitting), 100) y_lineal = Lineal_parameters[ 'lineal_slope'].value * x_lineal + Lineal_parameters[ 'lineal_intercept'].value dz.data_plot(x_lineal, y_lineal, label='Linear fitting', color='black', linestyle='-') # #Plot fitting formula formula = r"$log\left(Ar^{{+2}}/Ar^{{+3}}\right) = {m} \cdot log\left(S^{{+2}}/S^{{+3}}\right) + {n}$".format( m=round(Lineal_parameters['lineal_slope'].value, 3), n=round(Lineal_parameters['lineal_intercept'].value, 3)) dz.Axis.text(0.30, 0.15, formula, transform=dz.Axis.transAxes, fontsize=28) #Plot wording xtitle = r'$log\left(S^{{+2}}/S^{{+3}}\right)$' ytitle = r'$log\left(Ar^{{+2}}/Ar^{{+3}}\right)$' title = '' #'Argon - Sulfur ionic abundances\nfor a Z, Mass, log(t) cluster grid' dz.FigWording(xtitle, ytitle, title, loc='upper left') #Display figure #dz.display_fig() dz.savefig( output_address= '/home/vital/Dropbox/Astrophysics/Papers/Yp_AlternativeMethods/images/sulfur_argon_ionicAbundances', extension='.png') print 'Data treated otro'
lm.fit_dict.zerolev_mean, flux[lm.fit_dict.idx0:lm.fit_dict.idx1], facecolor=dz.colorVector['green'], step='mid', alpha=0.5) dz.Axis.fill_between(wave[lm.fit_dict.idx2:lm.fit_dict.idx3], lm.fit_dict.zerolev_mean, flux[lm.fit_dict.idx2:lm.fit_dict.idx3], facecolor=dz.colorVector['dark blue'], step='mid', alpha=0.5) dz.Axis.fill_between(wave[lm.fit_dict.idx4:lm.fit_dict.idx5], lm.fit_dict.zerolev_mean, flux[lm.fit_dict.idx4:lm.fit_dict.idx5], facecolor=dz.colorVector['green'], step='mid', alpha=0.5) dz.Axis.plot(lm.fit_dict.x_resample, lm.fit_dict.y_resample, linestyle='--') dz.Axis.plot(lm.fit_dict.x_resample, lm.fit_dict.zerolev_resample, linestyle='--') dz.Axis.scatter(lm.Current_TheoLoc, lm.fit_dict.zerolev_mean) dz.FigWording(r'Wavelength $(\AA)$', 'Flux' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', r'Object {} emission line: {}'.format(objName, line), loc='upper right') dz.display_fig() print 'DOne'
print 'New methods' print m[0], m[1], m[2], m[3] print m_err[0], m_err[1], m_err[2], m_err[3] print n[0], n[1], n[2], n[3] print n_err[0], n_err[1], n_err[2], n_err[3] #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) print 'Classical' print n_Median, round_sig(n_Median-n_16th,2, scien_notation=False), round_sig(n_84th-n_Median,2, scien_notation=False) #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=r'WMAP prediction: $Y = 0.24709\pm0.00025$', 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 = 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)) 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)