Ejemplo n.º 1
0
    def _calc(self, data, ret_obj, **kwargs):
        
        self._inst_als = _AlsCvxopt(**kwargs)
        
        try:
            # Get the subarray shape
            shp = data.shape[0:-2]
            total_num = _np.array(shp).prod()
   
            # Iterate over the sub-array -- super slick way of doing it
            for num, idx in enumerate(_np.ndindex(shp)):
                print('Detrended iteration {} / {}'.format(num+1, total_num))
                # Imaginary portion set
                if self.use_imag and _np.iscomplexobj(data):
                    if self.rng is None:
                        ret_obj[idx] -= 1j*self._inst_als.calculate(data[idx].imag)
                    else:
                        ret_obj[idx][..., self.rng] -= 1j*self._inst_als.calculate(data[idx][..., self.rng].imag)
                else:  # Real portion set or real object
                    if self.rng is None:
                        ret_obj[idx] -= self._inst_als.calculate(data[idx].real)
                    else:
                        ret_obj[idx][..., self.rng] -= self._inst_als.calculate(data[idx][..., self.rng].real)
        except:
            return False
        else:
#            print(self._inst_als.__dict__)
            return True
Ejemplo n.º 2
0
    def _calc(self, data, ret_obj, **kwargs):
        
        self._inst_als = _AlsCvxopt(**kwargs)
        
        try:
            # Get the subarray shape
            shp = data.shape[0:-2]
            total_num = _np.array(shp).prod()
   
            # Iterate over the sub-array -- super slick way of doing it
            for num, idx in enumerate(_np.ndindex(shp)):
                print('Detrended iteration {} / {}'.format(num+1, total_num))
                # Imaginary portion set
                if self.use_imag and _np.iscomplexobj(data):
                    # if self.rng is None:
                    #     ret_obj[idx] -= 1j*self._inst_als.calculate(data[idx].imag)
                    # else:
                    ret_obj[idx] -= 1j*self._inst_als.calculate(data[idx].imag)
                else:  # Real portion set or real object
                    # if self.rng is None:
                    #     ret_obj[idx] -= self._inst_als.calculate(data[idx].real)
                    # else:
                    ret_obj[idx] -= self._inst_als.calculate(data[idx].real)
        except:
            return False
        else:
#            print(self._inst_als.__dict__)
            return True
Ejemplo n.º 3
0
    def _calc(self, data, ret_obj, **kwargs):

        self._inst_als = _AlsCvxopt(**kwargs)

        try:
            shp = data.shape[0:-2]
            total_num = _np.array(shp).prod()

            counter = 1
            for idx in _np.ndindex(shp):
                print('Detrended iteration {} / {}'.format(counter, total_num))
                ph = _np.unwrap(_np.angle(data[idx]))
                if self.rng is None:
                    err_phase = self._inst_als.calculate(ph)
                else:
                    err_phase = self._inst_als.calculate(ph[..., self.rng])

                h = _np.zeros(err_phase.shape)
                h += _hilbert(err_phase)

                correction_factor = 1/_np.exp(h) * _np.exp(-1j*err_phase)

                if self.rng is None:
                    ret_obj[idx] *= correction_factor
                else:
                    ret_obj[idx][..., self.rng] *= correction_factor
                counter += 1
        except:
            return False
        else:
#            print(self._inst_als.__dict__)
            return True
Ejemplo n.º 4
0
    def _calc(self, data, ret_obj, **kwargs):

        self._inst_als = _AlsCvxopt(**kwargs)

        try:
            # if data.ndim>2:
            shp = data.shape[0:-2]
            total_num = _np.array(shp).prod()
            # else:
            #     shp = ()
            #     total_num = 1

            counter = 1
            for idx in _np.ndindex(shp):
                if self._k['verbose']:
                    print('Detrended iteration {} / {}'.format(
                        counter, total_num))
                ph = _np.unwrap(_np.angle(data[idx]))
                # if self.rng is None:
                err_phase = self._inst_als.calculate(ph)
                # else:
                # err_phase = self._inst_als.calculate(ph[..., self.rng])
                # print('Error phase shape: {}'.format(err_phase.shape))
                # print('Range: {}'.format(self.rng))
                # raise ValueError
                h = _np.zeros(err_phase[..., self.rng].shape)
                h += _hilbert(err_phase[..., self.rng])

                if self._k['wavenumber_increasing']:
                    correction_factor = _np.exp(h) * _np.exp(
                        -1j * err_phase[..., self.rng])
                else:
                    correction_factor = _np.exp(-h) * _np.exp(
                        -1j * err_phase[..., self.rng])

                # if self.rng is None:
                #     ret_obj[idx] *= correction_factor
                # else:

                # if len(idx) == 0:
                #     ret_obj[..., self.rng] *= correction_factor
                # else:
                ret_obj[idx][..., self.rng] *= correction_factor
                counter += 1
        except:
            return False
        else:
            #            print(self._inst_als.__dict__)
            return True
Ejemplo n.º 5
0
    def _calc(self, data, ret_obj, **kwargs):

        self._inst_als = _AlsCvxopt(**kwargs)

        try:
            # if data.ndim>2:
            shp = data.shape[0:-2]
            total_num = _np.array(shp).prod()
            # else:
            #     shp = ()
            #     total_num = 1
            
            counter = 1
            for idx in _np.ndindex(shp):
                print('Detrended iteration {} / {}'.format(counter, total_num))
                ph = _np.unwrap(_np.angle(data[idx]))
                # if self.rng is None:
                err_phase = self._inst_als.calculate(ph)
                # else:
                    # err_phase = self._inst_als.calculate(ph[..., self.rng])
                # print('Error phase shape: {}'.format(err_phase.shape))
                # print('Range: {}'.format(self.rng))
                # raise ValueError
                h = _np.zeros(err_phase[..., self.rng].shape)
                h += _hilbert(err_phase[..., self.rng])

                correction_factor = 1/_np.exp(h) * _np.exp(-1j*err_phase[...,self.rng])

                # if self.rng is None:
                #     ret_obj[idx] *= correction_factor
                # else:

                # if len(idx) == 0:
                #     ret_obj[..., self.rng] *= correction_factor
                # else:
                ret_obj[idx][..., self.rng] *= correction_factor
                counter += 1
        except:
            return False
        else:
#            print(self._inst_als.__dict__)
            return True