Exemple #1
0
 def func(band_data):
     log_root = np.log10(0.0223)
     denom = (1.0 - log_root) * 0.75
     band_data *= 0.01
     band_data = xu.log10(band_data)
     band_data -= log_root
     band_data /= denom
     return band_data
Exemple #2
0
 def func(band_data):
     log_root = np.log10(0.0223)
     denom = (1.0 - log_root) * 0.75
     band_data *= 0.01
     band_data = xu.log10(band_data)
     band_data -= log_root
     band_data /= denom
     return band_data
Exemple #3
0
 def func(band_data):
     log_root = np.log10(0.0223)
     denom = (1.0 - log_root) * 0.75
     band_data *= 0.01
     band_data = band_data.clip(np.finfo(float).eps)
     band_data = xu.log10(band_data)
     band_data -= log_root
     band_data /= denom
     return band_data
Exemple #4
0
def ds_arithmetics(ds: DatasetLike.TYPE,
                   op: str,
                   monitor: Monitor = Monitor.NONE) -> xr.Dataset:
    """
    Do arithmetic operations on the given dataset by providing a list of
    arithmetic operations and the corresponding constant. The operations will
    be applied to the dataset in the order in which they appear in the list.
    For example:
    'log,+5,-2,/3,*2'

    Currently supported arithmetic operations:
    log,log10,log2,log1p,exp,+,-,/,*

    where:
        log - natural logarithm
        log10 - base 10 logarithm
        log2 - base 2 logarithm
        log1p - log(1+x)
        exp - the exponential

    The operations will be applied element-wise to all arrays of the dataset.

    :param ds: The dataset to which to apply arithmetic operations
    :param op: A comma separated list of arithmetic operations to apply
    :param monitor: a progress monitor.
    :return: The dataset with given arithmetic operations applied
    """
    ds = DatasetLike.convert(ds)
    retset = ds
    with monitor.starting('Calculate result', total_work=len(op.split(','))):
        for item in op.split(','):
            with monitor.child(1).observing("Calculate"):
                item = item.strip()
                if item[0] == '+':
                    retset = retset + float(item[1:])
                elif item[0] == '-':
                    retset = retset - float(item[1:])
                elif item[0] == '*':
                    retset = retset * float(item[1:])
                elif item[0] == '/':
                    retset = retset / float(item[1:])
                elif item[:] == 'log':
                    retset = xu.log(retset)
                elif item[:] == 'log10':
                    retset = xu.log10(retset)
                elif item[:] == 'log2':
                    retset = xu.log2(retset)
                elif item[:] == 'log1p':
                    retset = xu.log1p(retset)
                elif item[:] == 'exp':
                    retset = xu.exp(retset)
                else:
                    raise ValueError('Arithmetic operation {} not'
                                     ' implemented.'.format(item[0]))

    return retset
Exemple #5
0
def ds_arithmetics(ds: xr.Dataset, op: str) -> xr.Dataset:
    """
    Do arithmetic operations on the given dataset by providing a list of
    arithmetic operations and the corresponding constant. The operations will
    be applied to the dataset in the order in which they appear in the list.
    For example:
    'log,+5,-2,/3,*2'

    Currently supported arithmetic operations:
    log,log10,log2,log1p,exp,+,-,/,*

    where:
        log - natural logarithm
        log10 - base 10 logarithm
        log2 - base 2 logarithm
        log1p - log(1+x)
        exp - the exponential

    The operations will be applied element-wise to all arrays of the dataset.

    :param ds: The dataset to which to apply arithmetic operations
    :param op: A comma separated list of arithmetic operations to apply
    :return: The dataset with given arithmetic operations applied
    """
    retset = ds
    for item in op.split(','):
        item = item.strip()
        if item[0] == '+':
            retset = retset + float(item[1:])
        elif item[0] == '-':
            retset = retset - float(item[1:])
        elif item[0] == '*':
            retset = retset * float(item[1:])
        elif item[0] == '/':
            retset = retset / float(item[1:])
        elif item[:] == 'log':
            retset = xu.log(retset)
        elif item[:] == 'log10':
            retset = xu.log10(retset)
        elif item[:] == 'log2':
            retset = xu.log2(retset)
        elif item[:] == 'log1p':
            retset = xu.log1p(retset)
        elif item[:] == 'exp':
            retset = xu.exp(retset)
        else:
            raise ValueError('Arithmetic operation {} not'
                             ' implemented.'.format(item[0]))

    return retset
Exemple #6
0
    def plot(self):
        """
		Plot the weights distribution of the window and the associated
		spectrum (work only for 1D and 2D windows).
		"""
        win_array = xr.DataArray(self.coefficients.squeeze(),
                                 dims=self.dims).squeeze()
        win_spectrum = psd(
            fft(win_array, nfft=1024, dim=self.dims, dx=self.dx, sym=True))
        win_spectrum_norm = 20 * log10(win_spectrum / abs(win_spectrum).max())
        self.win_spectrum_norm = win_spectrum_norm
        if self.ndim == 1:
            _plot1d_window(win_array, win_spectrum_norm)
        elif self.ndim == 2:
            _plot2d_window(win_array, win_spectrum_norm)
        else:
            raise ValueError(
                "This number of dimension is not supported by the "
                "plot function")