Beispiel #1
0
 def test__to_tuple(self):
     self.assertEqual(_to_tuple((1, 2, 3)), (1, 2, 3))
     self.assertEqual(_to_tuple('1.Zeile'), ('1.Zeile', ))
     self.assertEqual(_to_tuple(['1.Zeile']), ('1.Zeile', ))
     self.assertEqual(_to_tuple(['1.Zeile', '2.Zeile']),
                      ('1.Zeile', '2.Zeile'))
     self.assertEqual(_to_tuple(None), (None, ))
Beispiel #2
0
    def normalize(self,
                  reference='data', ref_dtype='mag', norm_dtypes='all', vval=None,
                  norm_method='max', norm_factor=None,
                  normalize_variable=False, dont_normalize=None,
                  norm_initial_state=True):
        """
        normalizes all available data to reference value, using norm_method

        Parameter
        ---------
           reference: str
              reference state, to which to normalize to e.g. 'NRM'
              also possible to normalize to mass
           ref_dtype: str
              component of the reference, if applicable. standard - 'mag'
           norm_dtypes: list
              dtype to be normalized, if dtype = 'all' all variables will be normalized
           vval: float
              variable value, if reference == value then it will search for the point closest to the vval
           norm_method: str
              how the norm_factor is generated, could be min
           normalize_variable: bool
              if True, variable is also normalized
              default: False
           dont_normalize: list
              list of dtypes that will not be normalized
              default: None
           norm_initial_state: bool
              if true, initial state values are normalized in the same manner as normal data
              default: True
        """
        # todo normalize by results
        #getting normalization factor
        if not norm_factor: # if norm_factor specified
            norm_factor = self._get_norm_factor(reference, ref_dtype, vval, norm_method)

        norm_dtypes = _to_tuple(norm_dtypes)  # make sure its a list/tuple
        for dtype, dtype_data in self.data.iteritems():  #cycling through all dtypes in data
            if dtype_data: #if dtype_data == None
                if 'all' in norm_dtypes:  # if all, all non stype data will be normalized
                    norm_dtypes = [i for i in dtype_data.column_names if not 'stype' in i]

                ### DO not normalize:
                # variable
                if not normalize_variable:
                    variable = dtype_data.column_names[dtype_data.column_dict['variable'][0]]
                    norm_dtypes = [i for i in norm_dtypes if not i == variable]

                if dont_normalize:
                    dont_normalize = _to_tuple(dont_normalize)
                    norm_dtypes = [i for i in norm_dtypes if not i in dont_normalize]

                for ntype in norm_dtypes:  #else use norm_dtypes specified
                    try:
                        dtype_data[ntype] = dtype_data[ntype].v / norm_factor
                    except KeyError:
                        self.logger.warning('CAN\'T normalize << %s, %s >> to %s' %(self.sample_obj.name, self.mtype, ntype))

                if 'mag' in dtype_data.column_names:
                    try:
                        self.data[dtype]['mag'] = self.data[dtype].magnitude(('x', 'y', 'z'))
                    except:
                        self.logger.debug('no (x,y,z) data found keeping << mag >>')

        if self.initial_state and norm_initial_state:
            for dtype, dtype_rpd in self.initial_state.data.iteritems():
                self.initial_state.data[dtype] = dtype_rpd / norm_factor
                if 'mag' in self.initial_state.data[dtype].column_names:
                    self.initial_state.data[dtype]['mag'] = self.initial_state.data[dtype].magnitude(('x', 'y', 'z'))
        return self
Beispiel #3
0
    def normalize(self,
                  reference='data',
                  ref_dtype='mag',
                  norm_dtypes='all',
                  vval=None,
                  norm_method='max',
                  norm_factor=None,
                  normalize_variable=False,
                  dont_normalize=None,
                  norm_initial_state=True):
        """
        normalizes all available data to reference value, using norm_method

        Parameter
        ---------
           reference: str
              reference state, to which to normalize to e.g. 'NRM'
              also possible to normalize to mass
           ref_dtype: str
              component of the reference, if applicable. standard - 'mag'
           norm_dtypes: list
              dtype to be normalized, if dtype = 'all' all variables will be normalized
           vval: float
              variable value, if reference == value then it will search for the point closest to the vval
           norm_method: str
              how the norm_factor is generated, could be min
           normalize_variable: bool
              if True, variable is also normalized
              default: False
           dont_normalize: list
              list of dtypes that will not be normalized
              default: None
           norm_initial_state: bool
              if true, initial state values are normalized in the same manner as normal data
              default: True
        """
        # todo normalize by results
        #getting normalization factor
        if not norm_factor:  # if norm_factor specified
            norm_factor = self._get_norm_factor(reference, ref_dtype, vval,
                                                norm_method)

        norm_dtypes = _to_tuple(norm_dtypes)  # make sure its a list/tuple
        for dtype, dtype_data in self.data.iteritems(
        ):  #cycling through all dtypes in data
            if dtype_data:  #if dtype_data == None
                if 'all' in norm_dtypes:  # if all, all non stype data will be normalized
                    norm_dtypes = [
                        i for i in dtype_data.column_names if not 'stype' in i
                    ]

                ### DO not normalize:
                # variable
                if not normalize_variable:
                    variable = dtype_data.column_names[
                        dtype_data.column_dict['variable'][0]]
                    norm_dtypes = [i for i in norm_dtypes if not i == variable]

                if dont_normalize:
                    dont_normalize = _to_tuple(dont_normalize)
                    norm_dtypes = [
                        i for i in norm_dtypes if not i in dont_normalize
                    ]

                for ntype in norm_dtypes:  #else use norm_dtypes specified
                    try:
                        dtype_data[ntype] = dtype_data[ntype].v / norm_factor
                    except KeyError:
                        self.logger.warning(
                            'CAN\'T normalize << %s, %s >> to %s' %
                            (self.sample_obj.name, self.mtype, ntype))

                if 'mag' in dtype_data.column_names:
                    try:
                        self.data[dtype]['mag'] = self.data[dtype].magnitude(
                            ('x', 'y', 'z'))
                    except:
                        self.logger.debug(
                            'no (x,y,z) data found keeping << mag >>')

        if self.initial_state and norm_initial_state:
            for dtype, dtype_rpd in self.initial_state.data.iteritems():
                self.initial_state.data[dtype] = dtype_rpd / norm_factor
                if 'mag' in self.initial_state.data[dtype].column_names:
                    self.initial_state.data[dtype][
                        'mag'] = self.initial_state.data[dtype].magnitude(
                            ('x', 'y', 'z'))
        return self
 def test__to_tuple(self):
     self.assertEqual(_to_tuple( (1,2,3)), (1,2,3))
     self.assertEqual(_to_tuple( '1.Zeile'), ('1.Zeile',))
     self.assertEqual(_to_tuple( ['1.Zeile']), ('1.Zeile',))
     self.assertEqual(_to_tuple( ['1.Zeile', '2.Zeile']), ('1.Zeile', '2.Zeile'))
     self.assertEqual(_to_tuple( None), (None,))