def plot_Ownposteriors_histagram(self, Traces, labels, sigfig_n=4, xlim=None, ylim=None): n_traces = len(Traces) self.FigConf(Figtype='Posteriors', n_colors=n_traces) for i in range(len(Traces)): Trace = Traces[i] Axis_Location = int(str(n_traces) + '1' + str(i + 1)) Axis = plt.subplot(Axis_Location) HDP_coords = [percentile(Trace, 16), percentile(Trace, 84)] mean_value = median(Trace) for HDP in HDP_coords: Axis.axvline( x=HDP, label='Percentiles: 16th-84th: ' + round_sig( HDP_coords[0], n=sigfig_n, scien_notation=False) + ' - ' + round_sig(HDP_coords[1], n=sigfig_n, scien_notation=False), color='grey', linestyle='dashed') Median_text_legend = r'Median value: $' + round_sig( mean_value, n=sigfig_n, scien_notation=False) + '_{-' + round_sig( mean_value - HDP_coords[0], n=sigfig_n, scien_notation=False) + '}^{+' + round_sig( HDP_coords[1] - mean_value, n=sigfig_n, scien_notation=False) + '}$' Axis.axvline(x=mean_value, label=Median_text_legend, color='grey', linestyle='solid') Axis.hist(Trace, histtype='stepfilled', bins=35, alpha=.7, color=self.ColorVector[2][i], normed=False) Axis.set_ylabel(labels[i], fontsize=20) self.legend_conf(Axis, loc='best', edgelabel=True) # Axis.yaxis.set_ticks(arange(0, 250, 50)) if xlim != None: Axis.set_xlim(xlim[0], xlim[1]) if ylim != None: Axis.set_ylim(ylim[0], ylim[1]) return
def plot_Ownposteriors_histagram(self, Traces, labels, sigfig_n = 4, xlim = None, ylim = None): n_traces = len(Traces) self.FigConf(Figtype = 'Posteriors', n_colors = n_traces) for i in range(len(Traces)): Trace = Traces[i] Axis_Location = int(str(n_traces) + '1' + str(i + 1)) Axis = plt.subplot(Axis_Location) HDP_coords = [percentile(Trace, 16), percentile(Trace, 84)] mean_value = median(Trace) for HDP in HDP_coords: Axis.axvline(x = HDP, label = 'Percentiles: 16th-84th: ' + round_sig(HDP_coords[0], n=sigfig_n, scien_notation=False) + ' - ' + round_sig(HDP_coords[1], n=sigfig_n, scien_notation=False), color='grey', linestyle = 'dashed') Median_text_legend = r'Median value: $' + round_sig(mean_value, n=sigfig_n, scien_notation=False) + '_{-' + round_sig(mean_value - HDP_coords[0], n=sigfig_n, scien_notation=False) + '}^{+' + round_sig(HDP_coords[1] - mean_value, n=sigfig_n, scien_notation=False) + '}$' Axis.axvline(x = mean_value, label = Median_text_legend, color='grey', linestyle = 'solid') Axis.hist(Trace, histtype='stepfilled', bins=35, alpha=.7, color=self.ColorVector[2][i], normed=False) Axis.set_ylabel(labels[i],fontsize=20) self.legend_conf(Axis, loc='best', edgelabel=True) # Axis.yaxis.set_ticks(arange(0, 250, 50)) if xlim != None: Axis.set_xlim(xlim[0], xlim[1]) if ylim != None: Axis.set_ylim(ylim[0], ylim[1]) return
def plot_posteriors_histagram(self, Traces, labels): n_traces = len(Traces) self.FigConf(Figtype='Posteriors', n_colors=n_traces) for i in range(len(Traces)): Trace = Traces[i] Axis_Location = int(str(n_traces) + '1' + str(i + 1)) Axis = plt.subplot(Axis_Location) HDP_coords = self.statistics_dict[Trace]['95% HPD interval'] for HDP in HDP_coords: Axis.axvline(x=HDP, label='HPD interval: ' + round_sig(HDP_coords[0], 4) + ' - ' + round_sig(HDP_coords[1], 4), color='grey', linestyle='dashed') Axis.axvline(x=self.statistics_dict[Trace]['mean'], label='Mean value: ' + round_sig(self.statistics_dict[Trace]['mean'], 4), color='grey', linestyle='solid') Axis.hist(self.Traces_dict[Trace][:], histtype='stepfilled', bins=35, alpha=.7, color=self.ColorVector[2][i], normed=False) Axis.set_ylabel(labels[i], fontsize=20) self.legend_conf(Axis, loc='best', edgelabel=True)
def plot_chiSq_Behaviour(self, Traces, labels): n_traces = len(Traces) self.FigConf(Figtype='Grid', n_colors=n_traces, n_columns=4, n_rows=2, FigHeight=9, FigWidth=16) chisq_adapted = reshape( self.pymc_database.trace('ChiSq')[:], len(self.pymc_database.trace('ChiSq')[:])) * -2 y_lim = 30 min_chi_index = argmin(chisq_adapted) for i in range(len(Traces)): Trace = Traces[i] label = labels[i] if Trace != 'ChiSq': self.Axis1[i].scatter(x=self.pymc_database.trace(Trace)[:], y=chisq_adapted, color=self.ColorVector[2][i]) x_min = npmin(self.pymc_database.trace(Trace)[:]) x_max = npmax(self.pymc_database.trace(Trace)[:]) self.Axis1[i].axvline( x=self.statistics_dict[Trace]['mean'], label='Inference value: ' + round_sig(self.statistics_dict[Trace]['mean'], 4, scien_notation=False), color='grey', linestyle='solid') self.Axis1[i].scatter( self.pymc_database.trace(Trace)[:][min_chi_index], chisq_adapted[min_chi_index], color='Black', label=r'$\chi^{2}_{min}$ value: ' + round_sig( self.pymc_database.trace(Trace)[:][min_chi_index], 4, scien_notation=False)) self.Axis1[i].set_ylabel(r'$\chi^{2}$', fontsize=20) self.Axis1[i].set_ylim(0, y_lim) self.Axis1[i].set_xlim(x_min, x_max) self.Axis1[i].set_title(label, fontsize=20) legend_i = self.Axis1[i].legend(loc='best', fontsize='x-large') legend_i.get_frame().set_facecolor('white')
def format_for_table(entry, rounddig=4, scientific_notation=False): # Check None entry if entry != None: # Check string entry if type(entry) == str: formatted_entry = entry # Case of Numerical entry else: # Case of an array scalarVariable = True if isinstance(entry, (Sequence, np.ndarray)): # Confirm is not a single value array if len(entry) == 1: entry = entry[0] # Case of an array else: scalarVariable = False formatted_entry = "_".join(entry) # we just put all together in a "_' joined string # Case single scalar if scalarVariable: # Case with error quantified if isinstance(entry, UFloat): formatted_entry = ( round_sig(nominal_values(entry), rounddig, scien_notation=scientific_notation) + r"$\pm$" + round_sig(std_devs(entry), rounddig - 2, scien_notation=scientific_notation) ) # Case single float else: formatted_entry = round_sig(entry, rounddig, scien_notation=scientific_notation) else: # None entry is converted to None formatted_entry = "None" return formatted_entry
def plot_tracers(self, Traces, labels): n_traces = len(Traces) self.FigConf(Figtype = 'Posteriors', n_colors = n_traces) for i in range(len(Traces)): Trace = Traces[i] Axis_Location = int(str(n_traces) + '1' + str(i + 1)) Axis = plt.subplot(Axis_Location) Variable_value = self.statistics_dict[Trace]['mean'] Variable_error = self.statistics_dict[Trace]['standard deviation'] label = labels[i] + ': ' + round_sig(Variable_value, 4) + r'$\pm$' + round_sig(Variable_error,4) Axis.plot(self.pymc_database.trace(Trace)[:], label = label, color=self.ColorVector[2][i]) Axis.axhline(y = self.statistics_dict[Trace]['mean'], color=self.ColorVector[2][i], linestyle = '--' ) Axis.set_ylabel(labels[i],fontsize=20) self.legend_conf(Axis, loc=1, edgelabel=True) plt.locator_params(axis = 'y', nbins = 5)
def format_for_table(entry, rounddig = 4, scientific_notation = False): #Check None entry if entry != None: #Check string entry if type(entry) == str: formatted_entry = entry #Case of Numerical entry else: #Case of an array scalarVariable = True if isinstance(entry, (Sequence, np.ndarray)): #Confirm is not a single value array if len(entry) == 1: entry = entry[0] #Case of an array else: scalarVariable = False formatted_entry = '_'.join(entry) # we just put all together in a "_' joined string #Case single scalar if scalarVariable: #Case with error quantified if isinstance(entry, UFloat): formatted_entry = round_sig(nominal_values(entry), rounddig, scien_notation = scientific_notation) + r'$\pm$' + round_sig(std_devs(entry), rounddig - 2, scien_notation = scientific_notation) #Case single float else: formatted_entry = round_sig(entry, rounddig, scien_notation = scientific_notation) else: #None entry is converted to None formatted_entry = 'None' return formatted_entry
def plot_tracers(self, Traces, labels): n_traces = len(Traces) self.FigConf(Figtype='Posteriors', n_colors=n_traces) for i in range(len(Traces)): Trace = Traces[i] Axis_Location = int(str(n_traces) + '1' + str(i + 1)) Axis = plt.subplot(Axis_Location) Variable_value = self.statistics_dict[Trace]['mean'] Variable_error = self.statistics_dict[Trace]['standard deviation'] label = labels[i] + ': ' + round_sig( Variable_value, 4) + r'$\pm$' + round_sig(Variable_error, 4) Axis.plot(self.pymc_database.trace(Trace)[:], label=label, color=self.ColorVector[2][i]) Axis.axhline(y=self.statistics_dict[Trace]['mean'], color=self.ColorVector[2][i], linestyle='--') Axis.set_ylabel(labels[i], fontsize=20) self.legend_conf(Axis, loc=1, edgelabel=True) plt.locator_params(axis='y', nbins=5)
def plot_posteriors_histagram(self, Traces, labels): n_traces = len(Traces) self.FigConf(Figtype = 'Posteriors', n_colors = n_traces) for i in range(len(Traces)): Trace = Traces[i] Axis_Location = int(str(n_traces) + '1' + str(i + 1)) Axis = plt.subplot(Axis_Location) HDP_coords = self.statistics_dict[Trace]['95% HPD interval'] for HDP in HDP_coords: Axis.axvline(x = HDP, label = 'HPD interval: ' + round_sig(HDP_coords[0], 4) + ' - ' + round_sig(HDP_coords[1], 4), color='grey', linestyle = 'dashed') Axis.axvline(x = self.statistics_dict[Trace]['mean'], label = 'Mean value: ' + round_sig(self.statistics_dict[Trace]['mean'], 4), color='grey', linestyle = 'solid') Axis.hist(self.Traces_dict[Trace][:], histtype='stepfilled', bins=35, alpha=.7, color=self.ColorVector[2][i], normed=False) Axis.set_ylabel(labels[i],fontsize=20) self.legend_conf(Axis, loc='best', edgelabel=True)
def plot_chiSq_Behaviour(self, Traces, labels): n_traces = len(Traces) self.FigConf(Figtype = 'Grid', n_colors = n_traces, n_columns=4, n_rows=2, FigHeight=9, FigWidth=16) chisq_adapted = reshape(self.pymc_database.trace('ChiSq')[:], len(self.pymc_database.trace('ChiSq')[:])) * -2 y_lim = 30 min_chi_index = argmin(chisq_adapted) for i in range(len(Traces)): Trace = Traces[i] label = labels[i] if Trace != 'ChiSq': self.Axis1[i].scatter(x = self.pymc_database.trace(Trace)[:], y = chisq_adapted, color=self.ColorVector[2][i]) x_min = npmin(self.pymc_database.trace(Trace)[:]) x_max = npmax(self.pymc_database.trace(Trace)[:]) self.Axis1[i].axvline(x = self.statistics_dict[Trace]['mean'], label = 'Inference value: ' + round_sig(self.statistics_dict[Trace]['mean'], 4,scien_notation=False), color='grey', linestyle = 'solid') self.Axis1[i].scatter(self.pymc_database.trace(Trace)[:][min_chi_index], chisq_adapted[min_chi_index], color='Black', label = r'$\chi^{2}_{min}$ value: ' + round_sig(self.pymc_database.trace(Trace)[:][min_chi_index],4,scien_notation=False)) self.Axis1[i].set_ylabel(r'$\chi^{2}$',fontsize=20) self.Axis1[i].set_ylim(0, y_lim) self.Axis1[i].set_xlim(x_min, x_max) self.Axis1[i].set_title(label,fontsize=20) legend_i = self.Axis1[i].legend(loc='best', fontsize='x-large') legend_i.get_frame().set_facecolor('white')
value = str(Data_Dict[Galaxy][parameter]) table.add_hline() table.add_row((Label, value)) doc.append(r'\newpage') doc.append(r'\tiny') with doc.create(Table('|c|c|c|c|c|c|c|c|')) as table: # List_Headers = Lines_Dict[CodeName].keys() + [r'$F_{Nebular}$', r'$F_{Stellar}$'] List_Lines = Lines_Dict[CodeName]['Ion'] table.add_hline() table.add_row(Labels_list + [r'$F_{Nebular}$', r'$F_{Stellar}$']) for j in range(len(List_Lines)): Column1 = Lines_Dict[CodeName]['Ion'][j].replace('_', '-') Column2 = round_sig(Lines_Dict[CodeName]['TheoWavelength'][j], 5) Column3 = round_sig(Lines_Dict[CodeName]['WaveBrute'][j], 5) Column4 = round_sig(Lines_Dict[CodeName]['FluxBrute'][j], 4) Column5 = round_sig(Lines_Dict[CodeName]['FluxGauss'][j], 3) + r'$\pm$' + round_sig(Lines_Dict[CodeName]['ErrorEL_MCMC'][j], 3) Column6 = round_sig(Lines_Dict[CodeName]['Eqw'][j], 2, scien_notation=False) + r'$\pm$' + round_sig(Lines_Dict[CodeName]['ErrorEqw'][j], 3, scien_notation=False) Column7 = round_sig(Lines_Dict[CodeName]['Flux Neb'][j], 3) + r'$\pm$' + round_sig(Lines_Dict[CodeName]['Error Neb'][j], 3) Column8 = round_sig(Lines_Dict[CodeName]['Flux Stellar'][j], 3) + r'$\pm$' + round_sig(Lines_Dict[CodeName]['Error Neb'][j], 3) table.add_hline() table.add_row((Column1,Column2,Column3,Column4,Column5,Column6,Column7,Column8)) # with doc.create(Subsection(r'$\chi^{2}$ plots:')): # with doc.create(Figure(position='h!')) as kitten_pic: # kitten_pic.add_image('docs/static/kitten.jpg', width='120px') # kitten_pic.add_caption('Look it\'s on its back')
table.add_hline() table.add_row((Label, value)) doc.append(r'\newpage') doc.append(r'\tiny') with doc.create(Table('|c|c|c|c|c|c|c|c|')) as table: # List_Headers = Lines_Dict[CodeName].keys() + [r'$F_{Nebular}$', r'$F_{Stellar}$'] List_Lines = Lines_Dict[CodeName]['Ion'] table.add_hline() table.add_row(Labels_list + [r'$F_{Nebular}$', r'$F_{Stellar}$']) for j in range(len(List_Lines)): Column1 = Lines_Dict[CodeName]['Ion'][j].replace('_', '-') Column2 = round_sig( Lines_Dict[CodeName]['TheoWavelength'][j], 5) Column3 = round_sig(Lines_Dict[CodeName]['WaveBrute'][j], 5) Column4 = round_sig(Lines_Dict[CodeName]['FluxBrute'][j], 4) Column5 = round_sig( Lines_Dict[CodeName]['FluxGauss'][j], 3) + r'$\pm$' + round_sig( Lines_Dict[CodeName]['ErrorEL_MCMC'][j], 3) Column6 = round_sig( Lines_Dict[CodeName]['Eqw'][j], 2, scien_notation=False) + r'$\pm$' + round_sig( Lines_Dict[CodeName]['ErrorEqw'][j], 3, scien_notation=False)
pv.SaveParameter_ObjLog('WHT_Catalogue_properties.txt', Catalogue_Dic['Data_Folder'], Parameter = 'Gradient_'+Element+'_16th_p', Magnitude = m_16th, Error = '-', Log_extension='') pv.SaveParameter_ObjLog('WHT_Catalogue_properties.txt', Catalogue_Dic['Data_Folder'], Parameter = 'Gradient_'+Element+'_84th_p', Magnitude = m_84th, Error = '-', Log_extension='') Obj_Elem, Metal_abun, Ymass_Metal = Abundances_dict[regression][0], Abundances_dict[regression][1], Abundances_dict[regression][2] #Plotting the data element_label = r'$Y_{{P}} = {n}_{{-{lowerlimit}}}^{{+{upperlimit}}}$'.format(n = round(n_Median,4), lowerlimit = round(n_Median-n_16th,4), upperlimit = round(n_84th-n_Median,4)) dz.data_plot(nominal_values(Metal_abun), nominal_values(Ymass_Metal), color = dz.ColorVector[2][j], label=element_label, markerstyle='o', x_error=std_devs(Metal_abun), y_error=std_devs(Ymass_Metal)) dz.data_plot(Y_WMAP_coord[0].nominal_value, Y_WMAP_coord[1].nominal_value, color = dz.ColorVector[2][len(Regression_list) + 1], label='WMAP prediction', markerstyle='o', x_error=Y_WMAP_coord[0].std_dev, y_error=Y_WMAP_coord[1].std_dev) dz.text_plot(Obj_Elem, nominal_values(Metal_abun), nominal_values(Ymass_Metal), color = dz.ColorVector[1], x_pad = 0.95, y_pad = 1) #Plot the linear trendlines x_regression_range = linspace(0.0, max(Metal_matrix[:,0])*1.10, 20) y_regression_range = m_Median * x_regression_range + n_Median label_S = r'Median value: $' + round_sig(n_Median, n=4, scien_notation=False) + '_{-' + round_sig(n_Median - n_16th, n=4, scien_notation=False) + '}^{+' + round_sig(n_84th - n_Median, n=4, scien_notation=False) + '}$' dz.data_plot(x_regression_range, y_regression_range, label = 'Linear regression', color = dz.ColorVector[2][j], linestyle = '--') dz.FigWording(Titles_wording[regression][2], Titles_wording[regression][3], Titles_wording[regression][1],legend_loc='best') #Set legends # dz.Axis.set_xlim(0.0, x_regression_range[-1]*1.10) print 'bien' #Save the data SavingName = regression + '_MC_pyneb' dz.savefig(Catalogue_Dic['Data_Folder'] + SavingName, reset_fig = True) # pv.SaveManager(SavingName = SavingName, SavingFolder = Catalogue_Dic['Data_Folder'], ForceSave=True, savevectorfile=False) #Save PlotVector pv.ResetPlot()
#Dictionary properties Data_Dict = OrderedDict() Lines_Dict = OrderedDict() Address_dict = OrderedDict() #Generate list of objects (Dazer should have a method for this) for i in range(len(FilesList)): #--------------------Prepare scientific data-------------------------------- CodeName, FileName, FileFolder = pv.Analyze_Address(FilesList[i]) cHbeta_mag = pv.GetParameter_ObjLog(CodeName, FileFolder, Parameter = 'cHBeta_stellar', Assumption = 'cHbeta_min') print 'Chbeta', cHbeta_mag print round_sig(cHbeta_mag.std_dev, 3) #Load lines data lineslog_dict = pv.load_object_lines(FileFolder, CodeName, Log_extension = Log_extension) lineslog_dered_dict = pv.load_object_lines(FileFolder, CodeName, Log_extension = Log_extension, chbeta_coef=cHbeta_mag) #lineslog_neb_dict = pv.load_object_lines(FileFolder, CodeName, Log_extension = Log_extension_Neb) #lineslog_stellar_dict = pv.load_object_lines(FileFolder, CodeName, Log_extension = Log_extension_Stellar) # for i in range(len(lineslog_dered_dict['Line_Label'])): # print lineslog_dered_dict['Line_Label'][i], lineslog_dered_dict['Eqw'][i], lineslog_dered_dict['f_lambda'][i] #Get Hbeta values Hbeta_Flux = pv.get_line_value(lineslog_dict, 'H1_4861A', variable_out = 'Flux') Hbeta_Flux_dered = pv.get_line_value(lineslog_dered_dict, 'H1_4861A', variable_out = 'Flux') #Hbeta_Flux_Neb = pv.get_line_value(lineslog_neb_dict, 'H1_4861A', variable_out = 'Flux')
Lines_Dict = OrderedDict() Address_dict = OrderedDict() #Generate list of objects (Dazer should have a method for this) for i in range(len(FilesList)): #--------------------Prepare scientific data-------------------------------- CodeName, FileName, FileFolder = pv.Analyze_Address(FilesList[i]) cHbeta_mag = pv.GetParameter_ObjLog(CodeName, FileFolder, Parameter='cHBeta_stellar', Assumption='cHbeta_min') print 'Chbeta', cHbeta_mag print round_sig(cHbeta_mag.std_dev, 3) #Load lines data lineslog_dict = pv.load_object_lines(FileFolder, CodeName, Log_extension=Log_extension) lineslog_dered_dict = pv.load_object_lines(FileFolder, CodeName, Log_extension=Log_extension, chbeta_coef=cHbeta_mag) #lineslog_neb_dict = pv.load_object_lines(FileFolder, CodeName, Log_extension = Log_extension_Neb) #lineslog_stellar_dict = pv.load_object_lines(FileFolder, CodeName, Log_extension = Log_extension_Stellar) # for i in range(len(lineslog_dered_dict['Line_Label'])): # print lineslog_dered_dict['Line_Label'][i], lineslog_dered_dict['Eqw'][i], lineslog_dered_dict['f_lambda'][i]