# Path: PySpectrograph/Utilities/Functions.py
# def Normal(arr, mean, sigma, scale=1):
#     """Return the normal distribution of N dimensions
# 
#        arr--The input array of N dimensions
#        mean--the mean of the distribution--either a scalor or N-dimensional array
#        sigma--the std deviation of the distribution--either a scalor or N-dimensial array
#        scale--the scale of the distrubion
# 
#     """
#     arr = arr
#     mean = mean
#     sigma = sigma
#     scale = scale
#     dim = np.ndim(arr) - 1
# 
#     # check to make sure that mean and sigma have dimensions that match dim
#     # and create the arrays to calculate the distribution
#     if isinstance(mean, np.ndarray):
#         if len(mean) != dim:
#             raise FunctionsError('Mean and input array are different number of dimensions')
#         mean = np.reshape(mean, (dim, 1, 1))
#     if isinstance(sigma, np.ndarray):
#         if len(sigma) != dim:
#             raise FunctionsError('Sigma and input array are different number of dimensions')
#         sigma = np.reshape(sigma, (dim, 1, 1))
# 
#     # calculate the gaussian
#     z = scale * np.exp(-0.5 * (arr - mean) ** 2 / sigma)
#     return z


import numpy as np
from PySpectrograph.Utilities.Functions import Normal
    def set_wavelength(self, wavelength, new=False):
        """Set the wavelength scale

           If new is True, then it will create a new wavelength
           using wrange and dw

        """

        if self.wrange is None and wavelength is not None:
            self.wrange = [wavelength.min(), wavelength.max()]

        if self.stype == 'line' or new:
            self.wavelength = np.arange(self.wrange[0], self.wrange[1], self.dw)
        elif self.stype == 'continuum':
            self.wavelength = wavelength
        else:
            self.wavelength = wavelength

        self.nwave = len(self.wavelength)

    def set_flux(self, wavelength, flux):
        """Set the flux levels"""

        if flux is not None and len(flux) == self.nwave:
            self.flux = flux

        elif flux is not None and wavelength is not None:
            if self.stype == 'line':
                self.flux = np.zeros(self.nwave, dtype=float)
                for w, f in zip(wavelength, flux):

# Path: PySpectrograph/Utilities/Functions.py
# def Normal(arr, mean, sigma, scale=1):
#     """Return the normal distribution of N dimensions
# 
#        arr--The input array of N dimensions
#        mean--the mean of the distribution--either a scalor or N-dimensional array
#        sigma--the std deviation of the distribution--either a scalor or N-dimensial array
#        scale--the scale of the distrubion
# 
#     """
#     arr = arr
#     mean = mean
#     sigma = sigma
#     scale = scale
#     dim = np.ndim(arr) - 1
# 
#     # check to make sure that mean and sigma have dimensions that match dim
#     # and create the arrays to calculate the distribution
#     if isinstance(mean, np.ndarray):
#         if len(mean) != dim:
#             raise FunctionsError('Mean and input array are different number of dimensions')
#         mean = np.reshape(mean, (dim, 1, 1))
#     if isinstance(sigma, np.ndarray):
#         if len(sigma) != dim:
#             raise FunctionsError('Sigma and input array are different number of dimensions')
#         sigma = np.reshape(sigma, (dim, 1, 1))
# 
#     # calculate the gaussian
#     z = scale * np.exp(-0.5 * (arr - mean) ** 2 / sigma)
#     return z


# Path: PySpectrograph/Spectra/Spectrum.py
import numpy as np
from PySpectrograph.Utilities.Functions import Normal

    def set_wavelength(self, wavelength, new=False):
        """Set the wavelength scale

           If new is True, then it will create a new wavelength
           using wrange and dw

        """

        if self.wrange is None and wavelength is not None:
            self.wrange = [wavelength.min(), wavelength.max()]

        if self.stype == 'line' or new:
            self.wavelength = np.arange(self.wrange[0], self.wrange[1], self.dw)
        elif self.stype == 'continuum':
            self.wavelength = wavelength
        else:
            self.wavelength = wavelength

        self.nwave = len(self.wavelength)

    def set_flux(self, wavelength, flux):
        """Set the flux levels"""

        if flux is not None and len(flux) == self.nwave:
            self.flux = flux

        elif flux is not None and wavelength is not None:
            if self.stype == 'line':
                self.flux = np.zeros(self.nwave, dtype=float)
                for w, f in zip(wavelength, flux):

                    self.flux += Normal(self.wavelength, w, self.sigma * self.dw, f)