def __find_threshold_histogram(self, channel):
        start  = self.histograms[channel][0]
        width  = self.histograms[channel][1]
        values = self.histograms[channel][2]
    
        # find the mode
        temp = self.sensor.water_distributions[self.sensor.band_names[channel]]['mode']
        (minv, maxv) = (temp['min'], temp['max'])
        i = int((minv - start) / width)
        biggest_bin = i
        while i < len(values) and start + i * width <= maxv:
            if values[i] > values[biggest_bin]:
                biggest_bin = i
            i += 1
        mode = start + biggest_bin * width
        
        if self.backscatter_model[channel] == RadarHistogram.BACKSCATTER_MODEL_PEAK:
            return (mode, None)

        # find the local minimum after the mode
        i = biggest_bin + 1
        while i < len(values)-3 and start + i * width <= maxv:
            if values[i] < values[i+1] and values[i] < values[i+2] and values[i] < values[i+3]:
                break
            i += 1
        local_min = start + i * width

        if self.backscatter_model[channel] == RadarHistogram.BACKSCATTER_MODEL_DIP:
            return (local_min, None)
    
        m = self.sensor.minimum_value
        if self.sensor.log_scale:
            m = math.log10(m)
        # find the other parameters of the distribution
        (value, result) = scipy.optimize.leastsq(self.__gamma_function_errors, [10], factor=1.0, args=(mode, mode, m, channel))
        params = (mode, value[0], m)
    
        # choose the best threshold where we can no longer discriminate
        mid = int((mode - start) / width)
        cumulative = sum(values[:mid]) + values[mid] / 2
        scale = cumulative / self.__cdf(params, params[0], self.backscatter_model[channel])
        i = mid
        while i < len(values):
            cumulative += values[i]
            diff = cumulative - scale * self.__cdf(params, start + i * width, self.backscatter_model[channel])
            if diff > 0.01:
                break
            i += 1
        threshold = start + i * width
    
        return (threshold, params)
dataset/ETHPy150Open nasa/CrisisMappingToolkit/cmt/radar/histogram.py/RadarHistogram.__find_threshold_histogram/original