# Path: astroNN/config.py
# MAGIC_NUMBER = magic_num_reader()
# 
# Path: astroNN/nn/numpy.py
# def sigmoid_inv(x):
#     """
#     NumPy implementation of tf.sigmoid inverse, mask ``magicnumber``
# 
#     :param x: Data to be applied inverse sigmoid activation
#     :type x: Union[numpy.ndarray, float]
#     :return: Inverse Sigmoid activated data
#     :rtype: Union[numpy.ndarray, float]
#     :History: 2018-Apr-11 - Written - Henry Leung (University of Toronto)
#     """
#     x = np.ma.array(x, mask=(x == MAGIC_NUMBER))
#     return np.ma.log(np.ma.divide(x, np.ma.subtract(1, x)))
# 
# def sigmoid(x):
#     """
#     NumPy implementation of tf.sigmoid, mask ``magicnumber``
# 
#     :param x: Data to be applied sigmoid activation
#     :type x: Union[ndarray, float]
#     :return: Sigmoid activated data
#     :rtype: Union[ndarray, float]
#     :History: 2018-Apr-11 - Written - Henry Leung (University of Toronto)
#     """
#     x = np.ma.array(x, mask=(x == MAGIC_NUMBER))
#     return np.ma.divide(1, np.ma.add(1, np.divide(1, np.ma.exp(x))))
# 
# Path: astroNN/shared/dict_tools.py
# def list_to_dict(names, arrs):
#     """
#     Matching a list of array with names
#     """
#     # TODO: need detailed test
#     if type(arrs) is list:
#         final_dict = {}
#         if len(names) == len(arrs):
#             for name, arr in zip(names, arrs):
#                 final_dict.update({name: arr})
#         elif len(arrs):
#             for name in names:
#                 final_dict.update({name: arrs[0]})
#         else:
#             raise IndexError(f"names has a length of {len(names)} but arrs has a  length of {len(arrs)}")
#         return final_dict
#     elif type(arrs) is np.ndarray and len(names) == 1:
#         return {names[0]: arrs}
#     elif type(arrs) is np.ndarray and len(names) > 1:
#         final_dict = {}
#         for name in names:
#             final_dict.update({name: arrs})
#         return final_dict
#     else:
#         return arrs
# 
# def to_iterable(var):
#     """
#     convert things to list
#     treat string as not iterable!
#     """
#     try:
#         if type(var) is str:
#             raise Exception
#         iter(var)
#     except Exception:
#         return [var]
#     else:
#         return var


import warnings
import numpy as np
from astroNN.config import MAGIC_NUMBER
from astroNN.nn.numpy import sigmoid_inv, sigmoid
from astroNN.shared.dict_tools import list_to_dict, to_iterable
            except KeyError:
                self.std_labels.update({name: np.array([1.])})

            if calc is True:  # check if normalizing with predefine values or get a new one
                print(
                    f"""====Message from {self.__class__.__name__}==== \n You selected mode: {self.normalization_mode[name]} \n Featurewise Center: {self.featurewise_center} \n Datawise Center: {self.datasetwise_center} \n Featurewise std Center: {self.featurewise_stdalization} \n Datawise std Center: {self.datasetwise_stdalization} \n ====Message ends====""")

                if self.featurewise_center[name] is True:
                    self.mean_labels.update({name: np.ma.array(data_array[name], mask=magic_mask).mean(axis=0)})
                    data_array[name] -= self.mean_labels[name]
                elif self.datasetwise_center[name] is True:
                    self.mean_labels.update({name: np.ma.array(data_array[name], mask=magic_mask).mean()})
                    data_array[name] -= self.mean_labels[name]

                if self.featurewise_stdalization[name] is True:
                    self.std_labels.update({name: np.ma.array(data_array[name], mask=magic_mask).std(axis=0)})
                    data_array[name] /= self.std_labels[name]
                elif self.datasetwise_stdalization[name] is True:
                    self.std_labels.update({name: np.ma.array(data_array[name], mask=magic_mask).std()})
                    data_array[name] /= self.std_labels[name]
                if self.normalization_mode[name] == '255':
                    data_array[name] -= self.mean_labels[name]
                    data_array[name] /= self.std_labels[name]
            else:
                data_array[name] -= self.mean_labels[name]
                data_array[name] /= self.std_labels[name]

            if self._custom_norm_func is not None:
                data_array.update({name: self._custom_norm_func(data_array[name])})


# Path: astroNN/config.py
# MAGIC_NUMBER = magic_num_reader()
# 
# Path: astroNN/nn/numpy.py
# def sigmoid_inv(x):
#     """
#     NumPy implementation of tf.sigmoid inverse, mask ``magicnumber``
# 
#     :param x: Data to be applied inverse sigmoid activation
#     :type x: Union[numpy.ndarray, float]
#     :return: Inverse Sigmoid activated data
#     :rtype: Union[numpy.ndarray, float]
#     :History: 2018-Apr-11 - Written - Henry Leung (University of Toronto)
#     """
#     x = np.ma.array(x, mask=(x == MAGIC_NUMBER))
#     return np.ma.log(np.ma.divide(x, np.ma.subtract(1, x)))
# 
# def sigmoid(x):
#     """
#     NumPy implementation of tf.sigmoid, mask ``magicnumber``
# 
#     :param x: Data to be applied sigmoid activation
#     :type x: Union[ndarray, float]
#     :return: Sigmoid activated data
#     :rtype: Union[ndarray, float]
#     :History: 2018-Apr-11 - Written - Henry Leung (University of Toronto)
#     """
#     x = np.ma.array(x, mask=(x == MAGIC_NUMBER))
#     return np.ma.divide(1, np.ma.add(1, np.divide(1, np.ma.exp(x))))
# 
# Path: astroNN/shared/dict_tools.py
# def list_to_dict(names, arrs):
#     """
#     Matching a list of array with names
#     """
#     # TODO: need detailed test
#     if type(arrs) is list:
#         final_dict = {}
#         if len(names) == len(arrs):
#             for name, arr in zip(names, arrs):
#                 final_dict.update({name: arr})
#         elif len(arrs):
#             for name in names:
#                 final_dict.update({name: arrs[0]})
#         else:
#             raise IndexError(f"names has a length of {len(names)} but arrs has a  length of {len(arrs)}")
#         return final_dict
#     elif type(arrs) is np.ndarray and len(names) == 1:
#         return {names[0]: arrs}
#     elif type(arrs) is np.ndarray and len(names) > 1:
#         final_dict = {}
#         for name in names:
#             final_dict.update({name: arrs})
#         return final_dict
#     else:
#         return arrs
# 
# def to_iterable(var):
#     """
#     convert things to list
#     treat string as not iterable!
#     """
#     try:
#         if type(var) is str:
#             raise Exception
#         iter(var)
#     except Exception:
#         return [var]
#     else:
#         return var


# Path: astroNN/nn/utilities/normalizer.py
import warnings
import numpy as np
from astroNN.config import MAGIC_NUMBER
from astroNN.nn.numpy import sigmoid_inv, sigmoid
from astroNN.shared.dict_tools import list_to_dict, to_iterable

            except KeyError:
                self.std_labels.update({name: np.array([1.])})

            if calc is True:  # check if normalizing with predefine values or get a new one
                print(
                    f"""====Message from {self.__class__.__name__}==== \n You selected mode: {self.normalization_mode[name]} \n Featurewise Center: {self.featurewise_center} \n Datawise Center: {self.datasetwise_center} \n Featurewise std Center: {self.featurewise_stdalization} \n Datawise std Center: {self.datasetwise_stdalization} \n ====Message ends====""")

                if self.featurewise_center[name] is True:
                    self.mean_labels.update({name: np.ma.array(data_array[name], mask=magic_mask).mean(axis=0)})
                    data_array[name] -= self.mean_labels[name]
                elif self.datasetwise_center[name] is True:
                    self.mean_labels.update({name: np.ma.array(data_array[name], mask=magic_mask).mean()})
                    data_array[name] -= self.mean_labels[name]

                if self.featurewise_stdalization[name] is True:
                    self.std_labels.update({name: np.ma.array(data_array[name], mask=magic_mask).std(axis=0)})
                    data_array[name] /= self.std_labels[name]
                elif self.datasetwise_stdalization[name] is True:
                    self.std_labels.update({name: np.ma.array(data_array[name], mask=magic_mask).std()})
                    data_array[name] /= self.std_labels[name]
                if self.normalization_mode[name] == '255':
                    data_array[name] -= self.mean_labels[name]
                    data_array[name] /= self.std_labels[name]
            else:
                data_array[name] -= self.mean_labels[name]
                data_array[name] /= self.std_labels[name]

            if self._custom_norm_func is not None:
                data_array.update({name: self._custom_norm_func(data_array[name])})


            np.place(data_array[name], magic_mask, MAGIC_NUMBER)