def test_init(self): set = fps.CosmicFish_PlotSettings(do_legend=False) test_plotter_1 = fp.CosmicFishPlotter(fishers=self.fisher_list_test, settings=set) assert test_plotter_1.plot_settings.do_legend == False test_plotter_2 = fp.CosmicFishPlotter(fishers=self.fisher_list_test, settings={'do_legend': False}) assert test_plotter_2.plot_settings.do_legend == False
def test_init_plot_single_2D(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) # get plot 1D of 1 parameter and all fishers: test_plotter.new_plot() test_plotter.plot2D([['yhe','logA']]) test_plotter.export(plot_dump+'test_realistic_4.pdf') test_plotter.close_plot()
def test_init_plot_multiple_2D(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) # get plot 1D of 2 parameter and all fishers: test_plotter.new_plot() test_plotter.plot2D([['ns','nrun'],['nt','r'],['tau','Bias_W_1']], title="Wonderfull plot") test_plotter.export(plot_dump+'test_realistic_5.pdf') test_plotter.close_plot()
def test_init_plot_mixed(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) # get plot 1D of 2 parameter and all fishers: test_plotter.new_plot() assert_raises( ValueError, test_plotter.plot_mixed, [['p1','p2'],['p1'],['p1','p2','p3']] ) test_plotter.export(plot_dump+'test_init_plot_mixed_1.pdf') test_plotter.close_plot()
def test_init_plot_tri(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) # get plot 1D of 2 parameter and all fishers: test_plotter.new_plot() test_plotter.plot_tri(['p1','p2','par1']) test_plotter.export(plot_dump+'test_init_plot_tri_1.pdf') test_plotter.close_plot() # get plot 1D of 2 parameter and some fishers: test_plotter.new_plot() test_plotter.plot_tri(['p1','p3'],['fisher1','fisher3']) test_plotter.export(plot_dump+'test_init_plot_tri_2.pdf') test_plotter.close_plot() # get plot 1D of all parameter and all fishers: test_plotter.new_plot() test_plotter.plot_tri(names=['fisher1','fisher3']) test_plotter.export(plot_dump+'test_init_plot_tri_3.pdf') test_plotter.close_plot() # get plot 1D of all parameter and all fishers: test_plotter.new_plot() test_plotter.plot_tri() test_plotter.export(plot_dump+'test_init_plot_tri_4.pdf') test_plotter.close_plot() # assert raises: test_plotter.new_plot() assert_raises( ValueError, test_plotter.plot_tri, ['p1','p2'],names=['fisher_3'] ) test_plotter.close_plot() test_plotter.new_plot() assert_raises( ValueError, test_plotter.plot_tri, ['p_1','p_2'],names=['fisher3'] ) test_plotter.close_plot()
def test_init_plot_tri(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) # get plot 1D of 2 parameter and all fishers: test_plotter.new_plot() test_plotter.plot_tri(['omegabh2','omegach2','omeganuh2'], title="Wonderfull plot") test_plotter.export(plot_dump+'test_realistic_6.pdf') test_plotter.export(plot_dump+'test_realistic_6.png') test_plotter.close_plot()
def test_plot_2D_options(self): # get plot 1D of 1 parameter and all fishers: test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, D2_show_x_ticks=False, D2_show_y_ticks=False ) test_plotter.new_plot() test_plotter.plot2D([['p1','p2']]) test_plotter.export(plot_dump+'test_plot_2D_options_1.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, D2_show_x_ticks_labels=False, D2_show_y_ticks_labels=False ) test_plotter.new_plot() test_plotter.plot2D([['p1','p2']]) test_plotter.export(plot_dump+'test_plot_2D_options_2.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, D2_show_xaxis_label=False, D2_show_yaxis_label=False ) test_plotter.new_plot() test_plotter.plot2D([['p1','p2']]) test_plotter.export(plot_dump+'test_plot_2D_options_3.pdf') test_plotter.close_plot()
def test_figure_1D_raises(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) test_plotter.new_plot() test_plotter.plot1D('p1') place = test_plotter.plot_grid[0,0] assert_raises( ValueError, test_plotter.figure_1D, subplot=place, param='test', names=['fisher1'] ) assert_raises( ValueError, test_plotter.figure_1D, subplot=place, param='p1', names=['fisher1','test'] ) test_plotter.close_plot()
def test_init_plot_single_1D(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) # get plot 1D of 1 parameter and all fishers: test_plotter.new_plot() test_plotter.plot1D('omegabh2', num_plots_per_line=2, title="Wonderfull plot" ) test_plotter.export(plot_dump+'test_realistic_1.png') test_plotter.export(plot_dump+'test_realistic_1.pdf') test_plotter.close_plot()
def test_plot_tri_legend(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, legend_takes_place_plot_tri=False ) legend_locs = ['upper right','upper left','lower left','lower right','right','center left','center right','lower center','upper center','center'] for num,place in enumerate(legend_locs): test_plotter.new_plot() test_plotter.plot_tri(['p1','p2'],legend_loc=place) test_plotter.export(plot_dump+'test_plot_tri_legend_'+str(num+1)+'.pdf') test_plotter.close_plot()
def test_plot_2D_legend(self): # get plot 1D of 1 parameter and all fishers: test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test) legend_locs = ['upper right','upper left','lower left','lower right','right','center left','center right','lower center','upper center','center'] for num,place in enumerate(legend_locs): test_plotter.new_plot() test_plotter.plot2D([['p1','p2']], legend_loc=place) test_plotter.export(plot_dump+'test_plot_2D_legend_'+str(num+1)+'.pdf') test_plotter.close_plot()
def test_bind_plot_settings_to_names(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) test_plotter.bind_plot_settings_to_names( names='fisher1', line_colors=['k'], solid_colors=['k'], labels = ['test'], linestyle = ['-'] ) assert test_plotter.bind_linestyle == {'fisher1': '-'} assert test_plotter.bind_labels == {'fisher1': 'test'} assert test_plotter.bind_solid_colors == {'fisher1': 'k'} assert test_plotter.bind_line_colors == {'fisher1': 'k'}
def test_init_plot_multiple_1D(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) # get plot 1D of 2 parameter and all fishers: test_plotter.new_plot() test_plotter.plot1D(['omegach2','omeganuh2','h']) test_plotter.export(plot_dump+'test_realistic_2.pdf') test_plotter.close_plot() # get plot 1D of all parameter and all fishers: test_plotter.new_plot() test_plotter.plot1D() test_plotter.export(plot_dump+'test_realistic_3.pdf') test_plotter.close_plot()
def test_init_plot_single_3D(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) # get plot 1D of 1 parameter and all fishers: test_plotter.new_plot() assert_raises( ValueError, test_plotter.plot3D, [['p1','p2','p3']] ) test_plotter.export(plot_dump+'test_init_plot_single_3D_1.pdf') test_plotter.close_plot() # get plot 1D of 1 parameter and some fishers: test_plotter.new_plot() assert_raises( ValueError, test_plotter.plot3D, [['p1','p2','p3']], ['fisher1','fisher3'] ) test_plotter.export(plot_dump+'test_init_plot_single_3D_2.pdf') test_plotter.close_plot()
def test_init_plot_single_2D(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) # get plot 1D of 1 parameter and all fishers: test_plotter.new_plot() test_plotter.plot2D([['p1','p2']]) test_plotter.export(plot_dump+'test_init_plot_single_2D_1.pdf') test_plotter.close_plot() # get plot 1D of 1 parameter and some fishers: test_plotter.new_plot() test_plotter.plot2D([['p1','p2']],['fisher1','fisher3']) test_plotter.export(plot_dump+'test_init_plot_single_2D_2.pdf') test_plotter.close_plot()
def test_init_plot_tri_2(self): # do spectral protection a couple of times: for i in range(4): fish = copy.deepcopy( self.fisher_list_test.get_fisher_list()[-1] ) fish.protect_degenerate( cache=True ) fish.name = str(i+1) self.fisher_list_test.add_fisher_matrix( fish ) test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) # get plot 1D of 2 parameter and all fishers: test_plotter.new_plot() test_plotter.plot_tri(['omegabh2','omegach2','omeganuh2','h','logA','ns'], title="Wonderfull plot") test_plotter.export(plot_dump+'test_realistic_7.png') test_plotter.close_plot() # ***************************************************************************************
fisher_list[0].name = args.sum_fish fishers_temp.add_fisher_matrix(fisher_list[0]) fishers = fishers_temp if args.eliminate: if params is None: raise ValueError( 'Avoiding marginalization only works if parameters are specified' ) fishers = fishers.reshuffle(params=params) # set up the plot settings plot_settings = fps.CosmicFish_PlotSettings() # set up the plotter plotter = fp.CosmicFishPlotter(settings=plot_settings, fishers=fishers) if params is not None: params = [list(i) for i in it.combinations(params, 2)] if len(params) == 0: raise ValueError('Not enough parameters for 2D plot.') plotter.new_plot() plotter.plot2D(params=params) plotter.export(outroot + '.' + output_format) plotter.close_plot() # print some final feedback: if not args.quiet: print('Done. Saved results in: ', outroot + '.' + output_format)
def test_setting_setter_raises(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) assert_raises( ValueError, test_plotter.setting_setter, 'test')
def test_plot_1D_options(self): # get plot 1D of 1 parameter and all fishers: test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, D1_filled=False, D1_show_x_ticks=False, D1_show_y_ticks=False) test_plotter.new_plot() test_plotter.plot1D('p1') test_plotter.export(plot_dump+'test_plot_1D_options_1.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, D1_show_x_ticks_labels=False, D1_show_y_ticks_labels=False ) test_plotter.new_plot() test_plotter.plot1D('p1') test_plotter.export(plot_dump+'test_plot_1D_options_2.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, D1_show_xaxis_label=False, D1_show_yaxis_label=False ) test_plotter.new_plot() test_plotter.plot1D('p1') test_plotter.export(plot_dump+'test_plot_1D_options_3.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, D1_norm_prob=True ) test_plotter.new_plot() test_plotter.plot1D('p1') test_plotter.export(plot_dump+'test_plot_1D_options_4.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, do_legend=False ) test_plotter.new_plot() test_plotter.plot1D('p1') test_plotter.export(plot_dump+'test_plot_1D_options_5.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, use_fixed_figure_width=True ) test_plotter.new_plot() test_plotter.plot1D('p1') test_plotter.export(plot_dump+'test_plot_1D_options_6.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, use_fixed_figure_height=True ) test_plotter.new_plot() test_plotter.plot1D('p1') test_plotter.export(plot_dump+'test_plot_1D_options_7.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, use_fixed_figure_width=True, use_fixed_figure_height=True ) test_plotter.new_plot() test_plotter.plot1D('p1') test_plotter.export(plot_dump+'test_plot_1D_options_8.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, D1_ylabel_right=True, D1_xlabel_up=True ) test_plotter.new_plot() test_plotter.plot1D('p1') test_plotter.export(plot_dump+'test_plot_1D_options_9.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, legend_takes_place_plot=True ) test_plotter.new_plot() test_plotter.plot1D('p1') test_plotter.export(plot_dump+'test_plot_1D_options_10.pdf') test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, legend_takes_place_plot=False ) test_plotter.new_plot() test_plotter.plot1D('p1') test_plotter.export(plot_dump+'test_plot_1D_options_11.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, tight_layout=True ) test_plotter.new_plot() test_plotter.plot1D('p1') test_plotter.export(plot_dump+'test_plot_1D_options_12.pdf') test_plotter.close_plot()
def test_plot_tri_options(self): test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, legend_takes_place_plot_tri=False ) test_plotter.new_plot() test_plotter.plot_tri(['p1','p2']) test_plotter.export(plot_dump+'test_plot_tri_options_1.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, use_fixed_figure_height=True ) test_plotter.new_plot() test_plotter.plot_tri(['p1','p2']) test_plotter.export(plot_dump+'test_plot_tri_options_2.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, use_fixed_figure_width=True ) test_plotter.new_plot() test_plotter.plot_tri(['p1','p2']) test_plotter.export(plot_dump+'test_plot_tri_options_3.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, use_fixed_figure_width=True, use_fixed_figure_height=True ) test_plotter.new_plot() test_plotter.plot_tri(['p1','p2']) test_plotter.export(plot_dump+'test_plot_tri_options_4.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) test_plotter.new_plot() test_plotter.plot_tri(['p1','p2']) for subplot in test_plotter.plot_dict.values(): subplot.yaxis.set_label_position('right') subplot.xaxis.set_label_position('top') test_plotter.set_triplot_dimensions( num_col=2, num_rows=2 ) test_plotter.export(plot_dump+'test_plot_tri_options_5.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) test_plotter.new_plot() test_plotter.plot_tri(['p1','p2']) for subplot in test_plotter.plot_dict.values(): subplot.yaxis.set_label_position('left') subplot.xaxis.set_label_position('bottom') test_plotter.set_triplot_dimensions( num_col=2, num_rows=2 ) test_plotter.export(plot_dump+'test_plot_tri_options_6.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, do_legend=False ) test_plotter.new_plot() test_plotter.plot_tri(['p1','p2']) test_plotter.export(plot_dump+'test_plot_tri_options_7.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test ) test_plotter.new_plot() test_plotter.plot_tri(['p1','p2']) del test_plotter.legend test_plotter.set_legend() test_plotter.export(plot_dump+'test_plot_tri_options_8.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, legend_filled=False ) test_plotter.new_plot() test_plotter.plot_tri(['p1','p2']) test_plotter.export(plot_dump+'test_plot_tri_options_9.pdf') test_plotter.close_plot() test_plotter = fp.CosmicFishPlotter( fishers=self.fisher_list_test, tight_layout=True ) test_plotter.new_plot() test_plotter.plot_tri(['p1','p2']) test_plotter.export(plot_dump+'test_plot_tri_options_10.pdf') test_plotter.close_plot()