def _plot_freq(self, kwargs): X = fft(self.x) X = X[range(self.L // 2)] k = np.arange(self.L // 2) frq = k * self.Fs / self.L plot(frq, np.abs(X), kwargs)
def solve(): data, to_plot = read_input() left_list, right_list = parse_input(data) left_list, right_list = handle_complex_input(left_list, right_list) object_list = [] object_list = get_list_of_objects(left_list, right_list) object_list.sort(key=sort_get_degree, reverse=True) handle_int_or_float(object_list) cleaned_object_list = [] cleaned_object_list = clean_object_list(object_list) reduced_form(cleaned_object_list) degree = handle_degree(cleaned_object_list) abc = () abc = solve_equation(degree, cleaned_object_list) if to_plot == 'Y': plot(abc)
def test_plot(): """A test for the plot() function""" assert (plotting.plot() is None)
def test_plot(): assert (plotting.plot() == None)
from src import plotting plotting.plot()
def _plot_time(self, kwargs): plot(self.t, self.x, kwargs)
def produce(self): print(' ### Step 2/4: produce fast rotation signal\n') # open input ROOT file containing the input positron counts histogram in_file = r.TFile(self.root_file) # retrive and style input histogram self.histogram = in_file.Get(self.histo_name) style.setTH1Style(self.histogram, '', 'Time [#mus]', 'Intensity') # save input histogram to ROOT file self.out_file.cd() self.histogram.Write('positron_spectrum') # define and style canvas (canvas local to 'produce' method because not needed elsewhere) canvas_fastrotation = r.TCanvas( 'c_fastrotation', 'c_fastrotation', 900, 600) style.setTCanvasStyle(canvas_fastrotation) # vary statistics in each bin of the input histogram if option specified if (self.stat_fluctuation): self.histogram = self.apply_stat_fluctutation() # rebin fast rotation histogram if (self.n_fit_param == 0): self.histogram.Rebin(self.rebin_frs_factor) # plot input histogram if option specified if (self.print_plot >= 2): for time in self.times_to_plot: plotting.plot(canvas_fastrotation, self.histogram, self.tag + '/Intensity', self.tS, self.tS + time, self.tM) # check number of hits in positron spectrum if option specified if (self.check_positron_hits): n_positron_hits = self.histogram.Integral( self.histogram.FindBin(self.tS), self.histogram.FindBin(self.tM)) if (self.verbose > 1): print(' Number of positron analyzed: ', n_positron_hits) if (n_positron_hits < self.positron_hits_threshold): print(' Warning -- low positron statistics: program exiting') sys.exit(1) else: n_positron_hits = -1 # return histogram if no need for fit (typically for simulated fast rotation signals) if (self.n_fit_param == 0): # optimize tS and tM opt_tS, opt_tM = self.optimize_tS_tM() bin_center, bin_content = self.return_frs_np_array(self.histogram) # save signal to ROOT file self.out_file.cd() self.histogram.Write('fast_rotation') return opt_tS, opt_tM, n_positron_hits, bin_center, bin_content # clone input histogram to produce wiggle plot (histogram local to 'produce' method because not needed elsewhere) wiggle_histogram = self.histogram.Clone() # rebin cloned histograms wiggle_histogram.Rebin(self.rebin_wiggle_factor) # plot wiggle plot if option specified if (self.print_plot >= 2): for time in self.times_to_plot: plotting.plot(canvas_fastrotation, wiggle_histogram, self.tag + '/Wiggle', self.tS, self.start_fit_time + time, self.tM) # fit wiggle plot (fit local to 'produce' method because not needed elsewhere) wiggle_fit = self.fit_wiggle(wiggle_histogram) # plot fitted wiggle plot if option specified if (self.print_plot >= 2): for time in self.times_to_plot: plotting.plot(canvas_fastrotation, wiggle_histogram, self.tag + '/FittedWiggle', self.tS, self.start_fit_time + time, self.tM, wiggle_fit) # create histogram of the fit residuals residuals = wiggle_histogram residuals.GetYaxis().SetTitle('Residual [%]') for i in range(wiggle_histogram.GetNbinsX()): if (wiggle_histogram.GetBinContent(i+1) != 0): residuals.SetBinContent(i+1, (wiggle_histogram.GetBinContent(i+1)-wiggle_fit.Eval( wiggle_histogram.GetBinCenter(i+1)))/wiggle_histogram.GetBinContent(i+1)*100) # plot histogram of residuals if option specified if (self.print_plot >= 2): for time in self.times_to_plot: plotting.plot(canvas_fastrotation, residuals, self.tag + '/Residuals', self.tS, self.start_fit_time + time, self.tM) plotting.plot(canvas_fastrotation, residuals, self.tag + '/Residuals', self.start_fit_time, self.start_fit_time + time, self.tM) # create fast rotation histogram for i in range(self.histogram.GetNbinsX()): self.histogram.SetBinContent(i+1, self.histogram.GetBinContent(i+1)/( wiggle_fit.Eval(self.histogram.GetBinCenter(i+1))/self.rebin_wiggle_factor)) # rebin fast rotation histogram if option specified self.histogram.Rebin(self.rebin_frs_factor) # optimize tS and tM opt_tS, opt_tM = self.optimize_tS_tM() # plot frs plot if option specified if (self.print_plot >= 1): plotting.plot(canvas_fastrotation, self.histogram, self.tag + '/FRS', 0, 10, self.tM) for time in self.times_to_plot: plotting.plot(canvas_fastrotation, self.histogram, self.tag + '/FRS', round(opt_tS, 6), round(opt_tS + time, 6), round(opt_tM, 6)) # save signal to ROOT file self.out_file.cd() self.histogram.Write('fast_rotation') # retrieve arrays of bin contents and bin centers bin_center, bin_content = self.return_frs_np_array(self.histogram) # return results return opt_tS, opt_tM, n_positron_hits, bin_center, bin_content