Filters in lys.filters

class lys.filters.filter.Convolution.LaplacianConvFilter(axes)[source]

Bases: _ConvolutionFilter

Apply Laplacian by convolution.

Parameters

axes (tuple of int) – axes of wave along which to apply.

Example:

from lys import filters
f = filters.LaplacianConvFilter(axes=[0])
result = f.execute([1, 2, 3, 4, 5])
print(result) # [1,0,0,0,-1]
class lys.filters.filter.Convolution.PrewittFilter(axes)[source]

Bases: _ConvolutionFilter

Apply prewitt filter. See scipy.ndimage.filters.prewitt for detail.

Parameters

axes (tuple of int) – axes of wave along which to apply.

Example:

from lys import filters
f = filters.PrewittFilter(axes=[0])
result = f.execute([1, 2, 3, 4, 5])
print(result) # [1,2,2,2,1]
class lys.filters.filter.Convolution.SobelFilter(axes)[source]

Bases: _ConvolutionFilter

Apply prewitt filter. See scipy.ndimage.filters.sobel for detail.

Parameters

axes (tuple of int) – axes of wave along which to apply.

Example:

from lys import filters
f = filters.SobelFilter(axes=[0])
result = f.execute([1, 2, 3, 4, 5])
print(result) # [1,2,2,2,1]
class lys.filters.filter.Dask.RechunkFilter(chunks='auto')[source]

Bases: FilterInterface

Rechunk dask array

Users should proper chunk size for efficient parallel calculation for dask array.

RechunkFilter enables users to rechunk dask array manually.

See dask manual (https://docs.dask.org/en/latest/array-chunks.html) for detail.

Parameters

chunks ('auto' or tuple of int) – chunk size.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Differentiate.GradientFilter(axes)[source]

Bases: FilterInterface

Differentiate wave along axes (implementation of np.gradient in lys)

Parameters

axes (list of int) – axes to be differentiated

Example:

from lys import Wave, filters

w = Wave([1, 2, 3, 4, 5], [1, 2, 3, 4, 5])

f = filters.GradientFilter(axes=[0])
result = f.execute(w)
print(result.data) # [1,1,1,1,1]
getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Differentiate.LaplacianFilter[source]

Bases: FilterInterface

Apply Laplacian

See FilterInterface.FilterInterface for general description of Filters.

Example:

import numpy as np
from lys import Wave, filters

x = np.linspace(0,100,100)
w = Wave(x**2, x)

f = filters.LaplacianFilter()
result = f.execute(w)
print(result.data) # [1, 1.5, 2, 2, 2, ...]
getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Differentiate.NablaFilter[source]

Bases: FilterInterface

Apply nabla vector

Example:

import numpy as np
from lys import Wave, filters

ar = np.array([1, 2, 3])
w = Wave([ar + i for i in range(3)], ar, ar, name="wave")

f = filters.NablaFilter()
result = f.execute(w)
print(result.data) # [[1,1,1], [1,1,1], [1,1,1]]
getParameters()[source]

Returns parameters used for this filter as dict

getRelativeDimension()[source]

Returns change of dimension for this filter

class lys.filters.filter.FreeLine.FreeLineFilter(axes, range, width)[source]

Bases: FilterInterface

Cut 2-dimensional data along arbitrary line with finite width.

range specifies start and end points in axes coordinates, [(x1, y1), (x2, y2)]. For example, [(0,0),(5,10)] means that data is cut along y=2x.

Parameters
  • axes (tuple of size 2) – axes to be cut.

  • range (2*2 sequence) – see description above.

  • width (int) – width of integration around the line in pixel unit.

Example:

from lys import Wave, filters

# prepare data
w = Wave([[1, 2, 3], [2, 3, 4], [3, 4, 5]], [1, 2, 3], [1, 2, 3], name="wave")

# apply FreeLineFilter
f = filters.FreeLineFilter(axes=[0, 1], range=[(1, 1), (3, 3)], width=1)
result = f.execute(w)
print(result.data) # [1, 3, 5]
getParameters()[source]

Returns parameters used for this filter as dict

getRelativeDimension()[source]

Returns change of dimension for this filter

class lys.filters.filter.Frequency.BandPassFilter(order, cutoff, axes)[source]

Bases: FilterInterface

Apply band-pass (butterworth) filter by scipy.signal.filtfilt.

Parameters
  • order (int) – order of butterworth filter.

  • cutoff (length-2 sequence) – cutoff frequency in the Nyquist frequency unit (0 < cutoff < 1).

  • axes – axes to be applied.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Frequency.BandStopFilter(order, cutoff, axes)[source]

Bases: FilterInterface

Apply band-stop (butterworth) filter by scipy.signal.filtfilt.

Parameters
  • order (int) – order of butterworth filter.

  • cutoff (length-2 sequence) – cutoff frequency in the Nyquist frequency unit (0 < cutoff < 1).

  • axes – axes to be applied.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Frequency.FourierFilter(axes, type='forward', process='absolute', window='Rect', roll=True)[source]

Bases: FilterInterface

Apply fast Fourier transformation (FFT).

If process is not complex, postprocessing is applied to FFT data. For example, when process =”real”, real part of FFT data is returned.

Note

dask.array.fft requires chunk along axes along which the FFT is applied should be one. Uses should rechunk before applying this filter by RechunkFilter.

Parameters
  • axes (list of int) – axes to be transformed

  • type ('forward' or 'backward') – specify foward or backward FFT.

  • process ('absolute' or 'real' or 'imag' or 'complex' or 'phase' or 'complex') – see description above.

  • window ('Rect' or 'Hann' or 'Hamming' or 'Blackman') – a window function used for FFT

Examle:

from lys import Wave, filters

# prepare data and filter
w = Wave(np.ones([3, 3]))
f = filters.FourierFilter(axes=[0, 1])
result = f.execute(w)

# FFT changes x axis as well as data
print(result.data) # [0,0,0], [0,9,0], [0,0,0]
print(result.x)    # [-0.3333333, 0, 0.33333333]
getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Frequency.HighPassFilter(order, cutoff, axes)[source]

Bases: FilterInterface

Apply high-pass (butterworth) filter by scipy.signal.filtfilt.

Parameters
  • order (int) – order of butterworth filter.

  • cutoff (float) – cutoff frequency in the Nyquist frequency unit (0 < cutoff < 1).

  • axes – axes to be applied.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Frequency.LowPassFilter(order, cutoff, axes)[source]

Bases: FilterInterface

Apply low-pass (butterworth) filter by scipy.signal.filtfilt.

Parameters
  • order (int) – order of butterworth filter.

  • cutoff (float) – cutoff frequency in the Nyquist frequency unit (0 < cutoff < 1).

  • axes – axes to be applied.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Integral.IntegralAllFilter(axes, sumtype)[source]

Bases: FilterInterface

Integrate wave along axes (implementation of np.sum, mean, max, min, and median in lys)

See FilterInterface.FilterInterface for general description of Filters.

Parameters
  • axes (list of int) – axes to be integrated

  • sumtype ('Sum', 'Mean', 'Max', 'Min', or 'Median') –

Example:

from lys import Wave, filters
import numpy as np

w = Wave(np.ones(3,4), [2,3,4], [5,6,7,8])
f = filters.IntegralAllFilter(axes=[0], sumtype="Sum")
result = f.execute(w)

print(result.data) # [3,3,3,3]
print(result.x)    # [5,6,7,8]

See also

IntegralFilter

getParameters()[source]

Returns parameters used for this filter as dict

getRelativeDimension()[source]

Returns change of dimension for this filter

class lys.filters.filter.Integral.IntegralCircleFilter(center, radiuses, axes=(0, 1))[source]

Bases: FilterInterface

Circular integration of wave.

Circularly integrate f*(*x,*y*) and returns f*(*r).

This filter is under development. Do not use.

See FilterInterface.FilterInterface for general description of Filters.

Parameters
  • center (tuple of size 2) – position where r = 0

  • radiuses (tuple of size 2) –

  • axes (tuple of size 2) – axes to be integrated, i.e. (x,y)

getParameters()[source]

Returns parameters used for this filter as dict

getRelativeDimension()[source]

Returns change of dimension for this filter

class lys.filters.filter.Integral.IntegralFilter(range, sumtype='Sum')[source]

Bases: FilterInterface

Integrate wave.

Range of integration is specified by range.

Note that the range is specified in the units of axes of (Dask)Wave.

See FilterInterface.FilterInterface for general description of Filters.

Parameters
  • range (list of length 2 sequence or None) – region to be integrated. It it is None, the corresponding axis is not integrated.

  • sumtype ('Sum', 'Mean', 'Max', 'Min', or 'Median') –

Example:

from lys import Wave, filters
import numpy as np

w = Wave(np.ones([5, 5, 5]), [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [2, 3, 4, 5, 6])
f = filters.IntegralFilter([(1, 4), (2, 4), None])
result = f.execute(w)

print(result.data)  # [6, 6, 6, 6, 6]
print(result.x)     # [2, 3, 4, 5, 6]
getParameters()[source]

Returns parameters used for this filter as dict

getRelativeDimension()[source]

Returns change of dimension for this filter

class lys.filters.filter.Interporation.InterpFilter(size)[source]

Bases: FilterInterface

Interpolate data by scipy.interpolate

Parameters

size (tuple of int) – new shape

Example:

import numpy as np
from lys import Wave, filters

x = np.linspace(0, 100, 100)
w = Wave(x**2, x)
f = filters.InterpFilter(size=(200,))
result = f.execute(w)

print(w.shape, result.shape) # (100,), (200,)
getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.MatrixMath.IndexMathFilter(axis, type, index1, index2)[source]

Bases: FilterInterface

Calculate wave[index1] op wave[index2].

Parameters
  • axis (int) – axis to be calculated

  • type ('+' or '-' or '*' or '/') – operator type

  • index1 (int) – index1 along axis

  • index2 (int) – index2 along axis

getParameters()[source]

Returns parameters used for this filter as dict

getRelativeDimension()[source]

Returns change of dimension for this filter

class lys.filters.filter.MatrixMath.SelectIndexFilter(index, axis=0)[source]

Bases: FilterInterface

Indexing of data.

For example, when axis = 1 and index=4, data[:,4] is returned.

For more complex indexing, use SliceFilter.

Parameters
  • index (int) – index to be evaluated.

  • axis (int) – axis to be evaluated.

getParameters()[source]

Returns parameters used for this filter as dict

getRelativeDimension()[source]

Returns change of dimension for this filter

class lys.filters.filter.MatrixMath.SliceFilter(slices)[source]

Bases: FilterInterface

Slicing waves.

Parameters

slices (sequence of slice object) – slices to be applied.

Example:

from lys import Wave, filters

w = Wave([[1, 2, 3], [4, 5, 6]], [7, 8], [9, 10, 11], name="wave")
f = filters.SliceFilter([slice(None), slice(1, 3)])

result = f.execute(w)
print(result.data, result.x, result.y) # [[2, 3], [5, 6]], [7, 8], [10, 11]
getParameters()[source]

Returns parameters used for this filter as dict

getRelativeDimension()[source]

Returns change of dimension for this filter

class lys.filters.filter.MatrixMath.TransposeFilter(axes)[source]

Bases: FilterInterface

Tranpose data by np.transpose.

If the data is 1-dimensional, the data and x axis is swapped.

Parameters

axes (sequence of int) – order of axes.

Example:

from lys import Wave, filters

w = Wave([[1, 2, 3], [4, 5, 6]])
f = filters.TransposeFilter(axes=[1, 0])

result = f.execute(w)
print(result.data)  # [[1, 4], [2, 5], [3, 6]]
getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Region.NormalizeFilter(range, axis)[source]

Bases: FilterInterface

Normalize data specified by range.

Data is integrated along the axes specified by axis and then used for normalization.

If axis is (1,2) For 4-dimensional data I(x,y,z,t), then I_norm(x,y,z,t) = I(x,y,z,t)/N(x,t) is calculated where N(x,t) = I_sliced.mean(axis=1).mean(axis=2). I_sliced is determined by range parameter. For example, when range= [None, (0,1), (2,3), None], I_sliced = Int_0^1 Int_1^2 dydz I(x,y,z,t).

Parameters
  • range (sqeuence of length-2 float or None) – see description above.

  • axis (tuple of int) – axes along which the wave is integrated.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Region.ReferenceNormalizeFilter(axis, type, refIndex)[source]

Bases: FilterInterface

Normalize data by reference specified by refIndex.

When data.ndim=2 and axis = 1, type=’Divide’, refIndex=5, data is normalized as data[:,0] = data[:,0]/data[:,5], data[:,1]=data[:,1]/dsata[:,5], …

Parameters
  • axis (int) – axis along which data is normalized.

  • type ('Diff' or 'Divide') – operator between data and reference.

  • refIndex (int) – index of reference data.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Region.SelectRegionFilter(range)[source]

Bases: FilterInterface

Cut data by range specified by region

range should be [(x1,x2),(y1,y2),…], where x1 and y2 specifies selected region in axes units.

The calculated result is data[x1:x2, y1:y2, …]

Parameters

range (sequence of length-2 tuple or None) – see above description.

Example:

from lys import Wave, filters
import numpy as np

w = Wave(np.ones([5, 5]), [1, 2, 3, 4, 5], [11, 12, 13, 14, 15])
f = filters.SelectRegionFilter(range=[(2, 4), (11, 14)]) # range is given in axes unit
result = f.execute(w)

print(result.data.shape)  # (2, 3)
print(result.x)           # [2, 3]
print(result.y)           # [11, 12, 13]
getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Resize.PaddingFilter(axes, value=0, size=100, position='first')[source]

Bases: FilterInterface

Add value at the edge of data

Parameters
  • axes (list of int) – axes to be padded.

  • value (float) – value to be added.

  • size (int) – size of padding.

  • position ('first' or 'last' or 'both') – position of padding.

Example:

from lys import Wave, filters

w = Wave([1, 2, 3], [0, 1, 2])
f = filters.PaddingFilter(axes=[0], value=0, size=2, position="first")
result = f.execute(w)

print(result.data)  # [0, 0, 1, 2, 3]
print(result.x)     # [-2, -1, 0, 1, 2]
getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Resize.ReduceSizeFilter(kernel)[source]

Bases: FilterInterface

Reduce size of data.

When kernel = (xn,yn), shape of data is reduced to 1/xn and 1/yn along both x and y direction, respectively.

This filter is used to gain signal to noise ratio by summation.

Parameters

kernel (sequence of int) – see above description.

Example:

from lys import Wave, filters
import numpy as np

w = Wave(np.ones([6, 6]), [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5])
f = filters.ReduceSizeFilter(kernel=(2, 2))
result = f.execute(w)

print(result.shape)  # (3, 3)
print(result.x)      # [0, 2, 4]
getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Segmentation.AdaptiveThresholdFilter(size, c, mode='Median', output='Mask', axes=(0, 1))[source]

Bases: FilterInterface

Segmentation by adaptive thresholding.

When mode=’Median’, and if data >= median(data, size)+c, the result is one. Otherwise, result is np.nan.

axes specifies which axes are used for thresholding. Median (and Gaussian) filter is applied along these axes. For 2-dimensional image, axes*=(0,1) is used. If data.ndim != 2, users should specifies *axes manually.

If output = ‘MaskedData’, then this filter returns mask*data. If ‘inv’ is included in output, the mask is reverted.

Parameters
  • size (int or float) – size of Median and Gaussian filter in pixel units.

  • c (float) – offset for thresholding.

  • mode ('Median' or 'Gaussian') – specifies whether Median or Gaussian is applied to original data to generate adaptive threshold.

  • output ('Mask', or 'MaskedData', or 'Mask_inv' or 'MaskedData_inv') – see description above.

  • axes (tuple of int) – specifies axes used for adaptive thresholding.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Segmentation.ThresholdFilter(threshold, output='Mask')[source]

Bases: FilterInterface

Segmentation by thresholding.

If data >= threshold, the result is one. Otherwise, result is np.nan.

If output = ‘MaskedData’, then this filter returns mask*data.

If ‘inv’ is included in output, the mask is reverted.

Parameters
  • threshold (float) – value of threshold

  • output ('Mask', or 'MaskedData', or 'Mask_inv' or 'MaskedData_inv') – ‘inv’ means the mask is reverted.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Shift.ReflectFilter(type, axes)[source]

Bases: FilterInterface

Reflect data.

type(‘center’ or ‘first’ or ‘last’): specifies where the data is reflected. axes(tuple of int): specifies axes reflected.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Shift.ReverseFilter(axes)[source]

Bases: FilterInterface

Reverse data by dask.array.flip

Parameters

axes (list of int) – axes to be reversed.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Shift.RollFilter(amount, axes)[source]

Bases: FilterInterface

Reverse data by dask.array.roll

Parameters
  • amount ('1/2' or '1/4' or '-1/4') – amount of roll.

  • axes (list of int) – axes to be rolled.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Shift.ShiftFilter(shift=None)[source]

Bases: FilterInterface

Shift data by scipy.ndimage.interpolation.shift.

Parameters

shift (tuple of float) – The shift along the axes.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.SimpleMath.ComplexFilter(type)[source]

Bases: FilterInterface

Calculate absolute, real, and image part of complex wave.

Parameters

type ('absolute' or 'real' or 'imag') – operation type.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.SimpleMath.NanToNumFilter(value)[source]

Bases: FilterInterface

Replace np.nan to value.

Parameters

value (any) – value by which replace np.nan.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.SimpleMath.PhaseFilter(rot, unit='deg')[source]

Bases: FilterInterface

Rotate complex value by rot

Parameters
  • rot (float) – rotation angle.

  • unit ('deg' or 'rad') – unit used to specify rotation angle.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.SimpleMath.SimpleMathFilter(type, value)[source]

Bases: FilterInterface

Apply simple mathematical calculation.

Parameters
  • type ('+' or '-' or '*' or '/') – operator type.

  • value (float) – value used for calculation.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Smooth.AverageFilter(kernel)[source]

Bases: FilterInterface

Apply average filter (scipy.ndimage.uniform_filter) to data.

Parameters

kernel (list of int) – kernel size along each axis.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Smooth.GaussianFilter(kernel)[source]

Bases: FilterInterface

Apply gaussian filter (scipy.ndimage.gaussian_filter) to data.

Parameters

kernel (list of int) – kernel size (=sigma) along each axis.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Smooth.MedianFilter(kernel)[source]

Bases: FilterInterface

Apply median filter (scipy.ndimage.median_filter) to data.

Parameters

kernel (list of int) – kernel size along each axis.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Smooth.RemoveImpulsiveNoise(kernel, threshold)[source]

Bases: FilterInterface

Remove impulsive noise.

This filter removes impulsive noise by the code below:

median = scipy.ndfilters.median_filter(data, size=kernel)
new_data = np.where(abs(data - median) > threshold, median, data)
Parameters
  • kernel (int or tuple of int) – The kernel that is pssed to median filter.

  • threshold (float) – The threshold value. See description.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Transform.AxisShiftFilter(shift, axes)[source]

Bases: FilterInterface

Shit axes by shift

Parameters
  • shift (list of float) – The values to be added to the axes.

  • axes (list of int) – The shifted axes.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Transform.MagnificationFilter(mag, axes)[source]

Bases: FilterInterface

Magnify axes by mag

Parameters
  • shift (list of float) – The values to be added to the axes.

  • axes (list of int) – The shifted axes.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Transform.MirrorFilter(positions, axes=(0, 1), sum=True)[source]

Bases: FilterInterface

Reflect 2D data with respect to a line.

Parameters
  • positions (2*2 array) – The positions that specify mirror axis in the form of [(x1, y1), (x2, y2)].

  • axes (length 2 sequence) – The axes to be symmetrized.

  • sum (bool) – If sum is False, the image is reflected with respect to the mirror axis. Otherwise, the mirrored image is added to the original image.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Transform.OffsetFilter(offset)[source]

Bases: FilterInterface

Add offset to data.

Parameters

offset (list) – The offset added for each axes.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Transform.Rotation2DFilter(angle, axes=(0, 1))[source]

Bases: FilterInterface

The array is rotated in the plane defined by the two axes given by the axes parameter using spline interpolation.

Parameters
  • angle (float) – The rotation angle in degrees

  • axes – (tuple of 2 ints): The two axes that define the plane of rotation.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Transform.SetAxisFilter(axis, val1, val2, type)[source]

Bases: FilterInterface

Set axis value.

When type=’step’, then the new axis is val1, val1 + val2, val1 + 2 * val2, … When type=’stop’, then the new axis is val1, …, val2.

Parameters
  • axis (int) – axis to be set.

  • val1 (float) – see description above.

  • val2 (float) – see description above.

  • type ('step' or 'stop') – see description above.

getParameters()[source]

Returns parameters used for this filter as dict

class lys.filters.filter.Transform.SymmetrizeFilter(rotation, center, axes=(0, 1))[source]

Bases: FilterInterface

Symmetrize 2D data.

Parameters
  • rotation (int) – The image is rotation-fold symmetrized.

  • center (length 2 sequence) – The central position of rotation.

  • axes (length 2 sequence) – The axes to be symmetrized.

getParameters()[source]

Returns parameters used for this filter as dict