# Path: blond/toolbox/filters_and_fitting.py
# def beam_profile_filter_chebyshev(Y_array, X_array, filter_option):
# def gaussian_fit(Y_array, X_array, p0):
# def gauss(x, *p):
# def rms(Y_array, X_array):
# def fwhm(Y_array, X_array, shift=0):
# def fwhm_multibunch(Y_array, X_array, n_bunches,
#                     bunch_spacing_buckets, bucket_size_tau,
#                     bucket_tolerance=0.40, shift=0):
# def rms_multibunch(Y_array, X_array, n_bunches,
#                    bunch_spacing_buckets, bucket_size_tau,
#                    bucket_tolerance=0.40):
# 
# Path: blond/utils/bmath.py
# def use_mpi():
# def mpiMode():
# def use_fftw():
# def use_precision(_precision='double'):
# def update_active_dict(new_dict):


from builtins import object
from scipy import ndimage
from ..toolbox import filters_and_fitting as ffroutines
from ..utils import bmath as bm
        from ..utils.mpi_config import worker
        from ..utils.mpi_config import worker
import numpy as np

    def scale_histo(self):
        if not bm.mpiMode():
            raise RuntimeError(
                'ERROR: Cannot use this routine unless in MPI Mode')

        if self.Beam.is_splitted:
            bm.mul(self.n_macroparticles, worker.workers, self.n_macroparticles)

    def _slice_smooth(self, reduce=True):
        """
        At the moment 4x slower than _slice but smoother (filtered).
        """
        bm.slice_smooth(self.Beam.dt, self.n_macroparticles, self.cut_left,
                        self.cut_right)

        if bm.mpiMode():
            self.reduce_histo(dtype=np.float64)

    def apply_fit(self):
        """
        It applies Gaussian fit to the profile.
        """

        if self.bunchLength == 0:
            p0 = [max(self.n_macroparticles), np.mean(self.Beam.dt),
                  np.std(self.Beam.dt)]
        else:
            p0 = [max(self.n_macroparticles), self.bunchPosition,
                  self.bunchLength/4]


# Path: blond/toolbox/filters_and_fitting.py
# def beam_profile_filter_chebyshev(Y_array, X_array, filter_option):
# def gaussian_fit(Y_array, X_array, p0):
# def gauss(x, *p):
# def rms(Y_array, X_array):
# def fwhm(Y_array, X_array, shift=0):
# def fwhm_multibunch(Y_array, X_array, n_bunches,
#                     bunch_spacing_buckets, bucket_size_tau,
#                     bucket_tolerance=0.40, shift=0):
# def rms_multibunch(Y_array, X_array, n_bunches,
#                    bunch_spacing_buckets, bucket_size_tau,
#                    bucket_tolerance=0.40):
# 
# Path: blond/utils/bmath.py
# def use_mpi():
# def mpiMode():
# def use_fftw():
# def use_precision(_precision='double'):
# def update_active_dict(new_dict):


# Path: blond/beam/profile.py
from builtins import object
from scipy import ndimage
from ..toolbox import filters_and_fitting as ffroutines
from ..utils import bmath as bm
        from ..utils.mpi_config import worker
        from ..utils.mpi_config import worker
import numpy as np

    def scale_histo(self):
        if not bm.mpiMode():
            raise RuntimeError(
                'ERROR: Cannot use this routine unless in MPI Mode')

        if self.Beam.is_splitted:
            bm.mul(self.n_macroparticles, worker.workers, self.n_macroparticles)

    def _slice_smooth(self, reduce=True):
        """
        At the moment 4x slower than _slice but smoother (filtered).
        """
        bm.slice_smooth(self.Beam.dt, self.n_macroparticles, self.cut_left,
                        self.cut_right)

        if bm.mpiMode():
            self.reduce_histo(dtype=np.float64)

    def apply_fit(self):
        """
        It applies Gaussian fit to the profile.
        """

        if self.bunchLength == 0:
            p0 = [max(self.n_macroparticles), np.mean(self.Beam.dt),
                  np.std(self.Beam.dt)]
        else:
            p0 = [max(self.n_macroparticles), self.bunchPosition,
                  self.bunchLength/4]


        self.fitExtraOptions = ffroutines.gaussian_fit(self.n_macroparticles,
