def __init__(self, title, xLabel, yLabel=None, roundingDecimals=2, nBins=None, dropOutliers=False, sigmaLimit=5, storeHistogram=True): """ __init__ Initialize a more complex histogram structure, containing different data to calculate online average and standard deviations. This data is also stored in the JSON to allow rebuilding and adding histograms. All histograms are binned when requested, the resolution can be specified through nBins, otherwise the value used is the one recommended in: Wand, M.P. (1997), "Data-Based Choice of Histogram Bin Width," The American Statistician, 51, 59-64. If specified, outlier farther than sigmaLimit standard deviations from the mean will not be included in the binned histogram. """ # Initialize the parent object SummaryHistogram.__init__(self, title, xLabel) # Indicate this is a discrete histogram self.continuous = True # Add data only used in the continuous version self.yLabel = yLabel self.nPoints = 0 self.QValue = None self.average = None # Configuration parameters for the continuous histograms self.roundingDecimals = roundingDecimals self.fixedNBins = nBins self.dropOutliers = dropOutliers self.sigmaLimit = sigmaLimit self.binned = False self.storeHistogram = storeHistogram # Override initialization of some attributes self.average = 0.0 self.stdDev = 0.0 return
def __init__(self, title, xLabel, yLabel = None, roundingDecimals = 2, nBins = None, dropOutliers = False, sigmaLimit = 5, storeHistogram = True): """ __init__ Initialize a more complex histogram structure, containing different data to calculate online average and standard deviations. This data is also stored in the JSON to allow rebuilding and adding histograms. All histograms are binned when requested, the resolution can be specified through nBins, otherwise the value used is the one recommended in: Wand, M.P. (1997), "Data-Based Choice of Histogram Bin Width," The American Statistician, 51, 59-64. If specified, outlier farther than sigmaLimit standard deviations from the mean will not be included in the binned histogram. """ # Initialize the parent object SummaryHistogram.__init__(self, title, xLabel) # Indicate this is a discrete histogram self.continuous = True # Add data only used in the continuous version self.yLabel = yLabel self.nPoints = 0 self.QValue = None self.average = None # Configuration parameters for the continuous histograms self.roundingDecimals = roundingDecimals self.fixedNBins = nBins self.dropOutliers = dropOutliers self.sigmaLimit = sigmaLimit self.binned = False self.storeHistogram = storeHistogram # Override initialization of some attributes self.average = 0.0 self.stdDev = 0.0 return
def __init__(self, title, xLabel): """ __init__ Initialize a simpler histogram that only stores the histogram. Everything else is calculated when the JSON is requested. """ # Initialize the parent object SummaryHistogram.__init__(self, title, xLabel) # Indicate this is a discrete histogram self.continuous = False # Add data only used in the discrete version self.yLabels = set() # Override initialization of some attributes self.average = {} self.stdDev = {} return
def toJSON(self): """ _toJSON_ Calculate average and standard deviation, store it and call the parent class toJSON method """ for yLabel in self.yLabels: numList = [] for xValue in self.data: numList.append(self.data[xValue][yLabel]) (self.average[yLabel], self.stdDev[yLabel]) = getAverageStdDev(numList) return SummaryHistogram.toJSON(self)
def toJSON(self): """ _toJSON_ Bin the histogram if any, calculate the standard deviation. Store the internal data needed for reconstruction of the histogram from JSON and call superclass toJSON method. """ if self.nPoints: self.stdDev = calculateStdDevFromQ(self.QValue, self.nPoints) if not self.binned and self.storeHistogram: self.binHistogram() self.jsonInternal = {} self.jsonInternal['yLabel'] = self.yLabel self.jsonInternal['QValue'] = self.QValue self.jsonInternal['nPoints'] = self.nPoints return SummaryHistogram.toJSON(self)