def file_to_histogram(file_in, bins=None): """ Reads in a file, and saves the values found there as histograms one histogram is returned for each column in the file (space delimitated) in a list. Bins defines the upper bounds of the bins to be used. The first item should be the lower bound of the first bin. If only two arguments are given for bins these are taken as the absolute lower and upper bounds of the histogram """ data = [] res = [] with open(file_in, "r") as file_in: for line in file_in: if not is_all_numbers(line): continue line = line.split() for histogram, value in map(None, data, line): # if a new column is encountered add another list if histogram == None: histogram = [] data.append(histogram) # if there is a value to be added, add it if value: histogram.append(float(value)) for histogram in data: res.append(Histogram(data_list=histogram, bins=bins)) return res
def calc_pedestals(pedestal_file, comments=(":", ),): """ Opens the pedestal_file and returns the average of each column of numbers as the pedestal for that channel. It will ignore any lines that contain the strings contained in the comments iterable. """ # TODO see if there's a better place for this sums = [] count = 0 with open(pedestal_file, "r") as in_file: for line in in_file: if not is_all_numbers(line): continue line = line.split() count += 1 while len(sums) < len(line): sums.append(0) for i in range(len(line)): sums[i] += float(line[i]) res = [] for val in sums: res.append(val/count) return res