From 8a4a55d2e3c6a6df1fd92dc5bbcf1915033c2d43 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 18 May 2012 13:00:54 -0400 Subject: [PATCH] Ensure that printed histograms always have at least two bins listed. Otherwise it is impossible to calculate the bin width from the printed histogram. --- pysawsim/histogram.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pysawsim/histogram.py b/pysawsim/histogram.py index cdb0bbf..6c326d2 100644 --- a/pysawsim/histogram.py +++ b/pysawsim/histogram.py @@ -151,11 +151,21 @@ class Histogram (object): 1.5e-10\t10 2e-10\t40 2.5e-10\t5 + >>> h.bin_edges = h.bin_edges[:2] + >>> h.counts = h.counts[:1] + >>> h.to_stream(sys.stdout) + ... # doctest: +NORMALIZE_WHITESPACE, +REPORT_UDIFF + #Force (N)\tUnfolding events + 1.5e-10\t10 + 2e-10\t0 """ if self.headings != None: stream.write('#%s\n' % '\t'.join(self.headings)) for bin,count in zip(self.bin_edges, self.counts): stream.write('%g\t%g\n' % (bin, count)) + if len(self.counts) == 1: + # print an extra line so that readers can determine bin width + stream.write('%g\t0\n' % (self.bin_edges[-1])) def analyze(self): """Analyze `.counts` and `.bin_edges` if the raw data is missing. -- 2.26.2