# Path: pymicro/view/vol_utils.py
# def min_max_cumsum(data, cut=0.001, verbose=False):
#     """Compute the indices corresponding to the edge of a distribution.
#     
#     The min and max indices are calculated according to a cutoff value (0.001 by default) meaning 99.99% 
#     of the distribution lies within this range.
#     
#     """
#     total = np.sum(data)
#     p = np.cumsum(data)
#     nb_bins = data.shape[0]
# 
#     mini = 0.0
#     maxi = 0.0
#     for i in range(nb_bins):
#         if p[i] > total * cut:
#             mini = i
#             if verbose:
#                 print('min = %f (i=%d)' % (mini, i))
#             break
#     for i in range(nb_bins):
#         if total - p[nb_bins - 1 - i] > total * cut:
#             maxi = nb_bins - 1 - i
#             if verbose:
#                 print('max = %f (i=%d)' % (maxi, i))
#             break
#     return mini, maxi
# 
# def auto_min_max(data, cut=0.0002, nb_bins=256, verbose=False):
#     """Compute the min and max values in a numpy data array.
# 
#     The min and max values are calculated based on the histogram of the
#     array which is limited at both ends by the cut parameter (0.0002 by
#     default). This means 99.98% of the values are within the [min, max]
#     range.
# 
#     :param data: the data array to analyse.
#     :param float cut: the cut off value to use on the histogram (0.0002 by default).
#     :param int nb_bins: number of bins to use in the histogram (256 by default).
#     :param bool verbose: activate verbose mode (False by default).
#     :returns tuple (val_mini, val_maxi): a tuple containing the min and max values.
#     """
#     n, bins = np.histogram(data, bins=nb_bins, density=False)
#     mini, maxi = min_max_cumsum(n, cut=cut, verbose=verbose)
#     val_mini, val_maxi = bins[mini], bins[maxi]
#     return val_mini, val_maxi


import unittest
import numpy as np
from pymicro.view.vol_utils import min_max_cumsum, auto_min_max
        from scipy import misc

class VolUtilsTests(unittest.TestCase):

    def setUp(self):
        print('testing the vol_utils module')
        self.mu, self.sigma = 0, 0.2  # mean and standard deviation
        np.random.seed(42)

# Path: pymicro/view/vol_utils.py
# def min_max_cumsum(data, cut=0.001, verbose=False):
#     """Compute the indices corresponding to the edge of a distribution.
#     
#     The min and max indices are calculated according to a cutoff value (0.001 by default) meaning 99.99% 
#     of the distribution lies within this range.
#     
#     """
#     total = np.sum(data)
#     p = np.cumsum(data)
#     nb_bins = data.shape[0]
# 
#     mini = 0.0
#     maxi = 0.0
#     for i in range(nb_bins):
#         if p[i] > total * cut:
#             mini = i
#             if verbose:
#                 print('min = %f (i=%d)' % (mini, i))
#             break
#     for i in range(nb_bins):
#         if total - p[nb_bins - 1 - i] > total * cut:
#             maxi = nb_bins - 1 - i
#             if verbose:
#                 print('max = %f (i=%d)' % (maxi, i))
#             break
#     return mini, maxi
# 
# def auto_min_max(data, cut=0.0002, nb_bins=256, verbose=False):
#     """Compute the min and max values in a numpy data array.
# 
#     The min and max values are calculated based on the histogram of the
#     array which is limited at both ends by the cut parameter (0.0002 by
#     default). This means 99.98% of the values are within the [min, max]
#     range.
# 
#     :param data: the data array to analyse.
#     :param float cut: the cut off value to use on the histogram (0.0002 by default).
#     :param int nb_bins: number of bins to use in the histogram (256 by default).
#     :param bool verbose: activate verbose mode (False by default).
#     :returns tuple (val_mini, val_maxi): a tuple containing the min and max values.
#     """
#     n, bins = np.histogram(data, bins=nb_bins, density=False)
#     mini, maxi = min_max_cumsum(n, cut=cut, verbose=verbose)
#     val_mini, val_maxi = bins[mini], bins[maxi]
#     return val_mini, val_maxi


# Path: pymicro/view/tests/test_Vol_utils.py
import unittest
import numpy as np
from pymicro.view.vol_utils import min_max_cumsum, auto_min_max
        from scipy import misc


class VolUtilsTests(unittest.TestCase):

    def setUp(self):
        print('testing the vol_utils module')
        self.mu, self.sigma = 0, 0.2  # mean and standard deviation
        np.random.seed(42)

        self.data = np.random.normal(self.mu, self.sigma, 3000)