ECOdyagnostics/operations.py
def _shift_position(self, da, output_position, elements=None, bd='interp', bd_value=None, bd_scaling=1, **kwargs):
        """
        Returns the variable interpolated to a prescribed output position.

        :param da:                  data variable or vector to shift
        :param output_position:     desired output position
        :param elements:            elements to include in the shift if a data vector is given, List(Boolean, ..)

        :return:                    interpolated data variable or vector onto the output_position
        """

        # If da is a list (vector), interpolate every element in da along the axes to match the output_position
        # If elements is given only indices where True is given are included. Default is True for every element
        if type(da) == list or type(da) == np.ndarray:
            if elements is None:
                elements = [True] * len(da)
            if type(output_position) is str:
                output_position = [output_position] * len(da)
            da_out = []
            for i in range(len(da)):
                if elements[i]:
                    element = da[i]
                    pos = output_position[i]
                    if self._matching_pos(element, pos):
                        da_out.append(element)
                    else:
                        missmatch = self._get_missmatch(element, pos)
                        if bd == 'interp':
                            da_out_i = self.interp(da[i].fillna(0), axis=missmatch, **kwargs)
                            da_out_i *= self.nan_mask(da_out_i)
                        elif bd == 'fill':
                            da_out_i = self.interp(da[i], axis=missmatch, **kwargs)
                            shift_mask = self._get_shift_mask(da[i], fill_value=bd_value, scaling=bd_scaling)
                            da_out_i = da_out_i.copy(data=np.nan_to_num(da_out_i,0) + shift_mask.values)
                            da_out_i *= self.nan_mask(da_out_i)
                        else:
                            raise Exception('Unknown handling of boundary values. Please use "interp" or "fill".')
                        da_out.append(da_out_i)
                else:
                    da_out.append(da[i])

        # Else interpolate the data variable along the axes to match the output_position
        else:
            if self._matching_pos(da, output_position):
                da_out = da
            else:
                missmatch = self._get_missmatch(da, output_position)
                if bd == 'interp':
                    da_out = self.interp(da.fillna(0),axis=missmatch, **kwargs)
                    da_out *= self.nan_mask(da_out)
                elif bd == 'fill':
                    da_out = self.interp(da, axis=missmatch, **kwargs)
                    shift_mask = self._get_shift_mask(da, fill_value=bd_value, scaling=bd_scaling)
                    da_out = da_out.copy(data=np.nan_to_num(da_out, 0) + shift_mask.values)
                    da_out *= self.nan_mask(da_out)
                else:
                    raise Exception('Unknown handling of boundary values. Please use "interp" or "fill".')
        return da_out

        Returns the variable interpolated to a prescribed output position.

        :param da:                  data variable or vector to shift
        :param output_position:     desired output position
        :param elements:            elements to include in the shift if a data vector is given, List(Boolean, ..)

        :return:                    interpolated data variable or vector onto the output_position
        
Returns the variable interpolated to a prescribed output position.
Returns the variable interpolated to a prescribed output position .
def _shift_position(self, da, output_position, elements=None, bd='interp', bd_value=None, bd_scaling=1, **kwargs):
        if type(da) == list or type(da) == np.ndarray:
            if elements is None:
                elements = [True] * len(da)
            if type(output_position) is str:
                output_position = [output_position] * len(da)
            da_out = []
            for i in range(len(da)):
                if elements[i]:
                    element = da[i]
                    pos = output_position[i]
                    if self._matching_pos(element, pos):
                        da_out.append(element)
                    else:
                        missmatch = self._get_missmatch(element, pos)
                        if bd == 'interp':
                            da_out_i = self.interp(da[i].fillna(0), axis=missmatch, **kwargs)
                            da_out_i *= self.nan_mask(da_out_i)
                        elif bd == 'fill':
                            da_out_i = self.interp(da[i], axis=missmatch, **kwargs)
                            shift_mask = self._get_shift_mask(da[i], fill_value=bd_value, scaling=bd_scaling)
                            da_out_i = da_out_i.copy(data=np.nan_to_num(da_out_i,0) + shift_mask.values)
                            da_out_i *= self.nan_mask(da_out_i)
                        else:
                            raise Exception('Unknown handling of boundary values. Please use "interp" or "fill".')
                        da_out.append(da_out_i)
                else:
                    da_out.append(da[i])
        else:
            if self._matching_pos(da, output_position):
                da_out = da
            else:
                missmatch = self._get_missmatch(da, output_position)
                if bd == 'interp':
                    da_out = self.interp(da.fillna(0),axis=missmatch, **kwargs)
                    da_out *= self.nan_mask(da_out)
                elif bd == 'fill':
                    da_out = self.interp(da, axis=missmatch, **kwargs)
                    shift_mask = self._get_shift_mask(da, fill_value=bd_value, scaling=bd_scaling)
                    da_out = da_out.copy(data=np.nan_to_num(da_out, 0) + shift_mask.values)
                    da_out *= self.nan_mask(da_out)
                else:
                    raise Exception('Unknown handling of boundary values. Please use "interp" or "fill".')
        return da_out
def _shift_position ( self , da , output_position , elements = None , bd = 'interp' , bd_value = None , bd_scaling = 1 , ** kwargs ) : if type ( da ) == list or type ( da ) == np . ndarray : if elements is None : elements = [ True ] * len ( da ) if type ( output_position ) is str : output_position = [ output_position ] * len ( da ) da_out = [ ] for i in range ( len ( da ) ) : if elements [ i ] : element = da [ i ] pos = output_position [ i ] if self . _matching_pos ( element , pos ) : da_out . append ( element ) else : missmatch = self . _get_missmatch ( element , pos ) if bd == 'interp' : da_out_i = self . interp ( da [ i ] . fillna ( 0 ) , axis = missmatch , ** kwargs ) da_out_i *= self . nan_mask ( da_out_i ) elif bd == 'fill' : da_out_i = self . interp ( da [ i ] , axis = missmatch , ** kwargs ) shift_mask = self . _get_shift_mask ( da [ i ] , fill_value = bd_value , scaling = bd_scaling ) da_out_i = da_out_i . copy ( data = np . nan_to_num ( da_out_i , 0 ) + shift_mask . values ) da_out_i *= self . nan_mask ( da_out_i ) else : raise Exception ( 'Unknown handling of boundary values. Please use "interp" or "fill".' ) da_out . append ( da_out_i ) else : da_out . append ( da [ i ] ) else : if self . _matching_pos ( da , output_position ) : da_out = da else : missmatch = self . _get_missmatch ( da , output_position ) if bd == 'interp' : da_out = self . interp ( da . fillna ( 0 ) , axis = missmatch , ** kwargs ) da_out *= self . nan_mask ( da_out ) elif bd == 'fill' : da_out = self . interp ( da , axis = missmatch , ** kwargs ) shift_mask = self . _get_shift_mask ( da , fill_value = bd_value , scaling = bd_scaling ) da_out = da_out . copy ( data = np . nan_to_num ( da_out , 0 ) + shift_mask . values ) da_out *= self . nan_mask ( da_out ) else : raise Exception ( 'Unknown handling of boundary values. Please use "interp" or "fill".' ) return da_out
Returns the variable interpolated to a prescribed output position.
Returns the variable interpolated to a prescribed output position .
"""
        Returns the variable interpolated to a prescribed output position.

        :param da:                  data variable or vector to shift
        :param output_position:     desired output position
        :param elements:            elements to include in the shift if a data vector is given, List(Boolean, ..)

        :return:                    interpolated data variable or vector onto the output_position
        """ # If da is a list (vector), interpolate every element in da along the axes to match the output_position # If elements is given only indices where True is given are included. Default is True for every element # Else interpolate the data variable along the axes to match the output_position
interpolated data variable or vector onto the output_position
interpolated data variable or vector onto the output_position
self
da
data variable or vector to shift
data variable or vector to shift
output_position
desired output position
desired output position
elements
elements to include in the shift if a data vector is given, List(Boolean, ..)
elements to include in the shift if a data vector is given List ( Boolean .. )
bd
bd_value
bd_scaling