class_docstr: An internal class to manage filters/algorithms for uniform grid datasets.
class_docstr_tok: ["An","internal","class","to","manage","filters\/algorithms","for","uniform","grid","datasets","."]
docstr: Smooth data using a median filter.
  
  The Median filter that replaces each pixel with the median value from a
  rectangular neighborhood around that pixel. Neighborhoods can be no
  more than 3 dimensional. Setting one axis of the neighborhood
  kernelSize to 1 changes the filter into a 2D median.
  
  See `vtkImageMedian3D
  <https://vtk.org/doc/nightly/html/classvtkImageMedian3D.html#details>`_
  for more details.
  
  Parameters
  ----------
  kernel_size : sequence[int], default: (3, 3, 3)
      Size of the kernel in each dimension (units of voxels), for example
      ``(x_size, y_size, z_size)``. Default is a 3D median filter. If you
      want to do a 2D median filter, set the size to 1 in the dimension
      you don't want to filter over.
  
  scalars : str, optional
      Name of scalars to process. Defaults to currently active scalars.
  
  preference : str, default: "point"
      When scalars is specified, this is the preferred array
      type to search for in the dataset.  Must be either
      ``'point'`` or ``'cell'``.
  
  progress_bar : bool, default: False
      Display a progress bar to indicate progress.
  
  Returns
  -------
  pyvista.ImageData
      Uniform grid with smoothed scalars.
  
  Warnings
  --------
  Applying this filter to cell data will send the output to a new point
  array with the same name, overwriting any existing point data array
  with the same name.
  
  Examples
  --------
  First, create sample data to smooth. Here, we use
  :func:`pyvista.perlin_noise() <pyvista.core.utilities.features.perlin_noise>`
  to create meaningful data.
  
  >>> import numpy as np
  >>> import pyvista as pv
  >>> noise = pv.perlin_noise(0.1, (2, 5, 8), (0, 0, 0))
  >>> grid = pv.sample_function(
  ...     noise, [0, 1, 0, 1, 0, 1], dim=(20, 20, 20)
  ... )
  >>> grid.plot(show_scalar_bar=False)
  
  Next, smooth the sample data.
  
  >>> smoothed = grid.median_smooth(kernel_size=(10, 10, 10))
  >>> smoothed.plot(show_scalar_bar=False)
docstr_tok: ["Smooth","data","using","a","median","filter",".","The","Median","filter","that","replaces","each","pixel","with","the","median","value","from","a","rectangular","neighborhood","around","that","pixel",".","Neighborhoods","can","be","no","more","than","3","dimensional",".","Setting","one","axis","of","the","neighborhood","kernelSize","to","1","changes","the","filter","into","a","2D","median",".","See","`","vtkImageMedian3D","<","https",":","\/\/vtk.org\/doc\/nightly\/html\/classvtkImageMedian3D.html","#","details",">","`","_","for","more","details",".","Parameters","--","--","--","--","--","kernel_size",":","sequence","[","int","]",",","default",":","(","3",",","3",",","3",")","Size","of","the","kernel","in","each","dimension","(","units","of","voxels",")",",","for","example","``","(","x_size",",","y_size",",","z_size",")","``",".","Default","is","a","3D","median","filter",".","If","you","want","to","do","a","2D","median","filter",",","set","the","size","to","1","in","the","dimension","you","do","n't","want","to","filter","over",".","scalars",":","str",",","optional","Name","of","scalars","to","process",".","Defaults","to","currently","active","scalars",".","preference",":","str",",","default",":","``","point","''","When","scalars","is","specified",",","this","is","the","preferred","array","type","to","search","for","in","the","dataset",".","Must","be","either","``","'point","'","``","or","``","'cell","'","``",".","progress_bar",":","bool",",","default",":","False","Display","a","progress","bar","to","indicate","progress",".","Returns","--","--","--","-","pyvista.ImageData","Uniform","grid","with","smoothed","scalars",".","Warnings","--","--","--","--","Applying","this","filter","to","cell","data","will","send","the","output","to","a","new","point","array","with","the","same","name",",","overwriting","any","existing","point","data","array","with","the","same","name",".","Examples","--","--","--","--","First",",","create","sample","data","to","smooth",".","Here",",","we","use",":","func",":","`","pyvista.perlin_noise","(",")","<","pyvista.core.utilities.features.perlin_noise",">","`","to","create","meaningful","data",".",">",">",">","import","numpy","as","np",">",">",">","import","pyvista","as","pv",">",">",">","noise","=","pv.perlin_noise","(","0.1",",","(","2",",","5",",","8",")",",","(","0",",","0",",","0",")",")",">",">",">","grid","=","pv.sample_function","(","...","noise",",","[","0",",","1",",","0",",","1",",","0",",","1","]",",","dim=","(","20",",","20",",","20",")","...",")",">",">",">","grid.plot","(","show_scalar_bar=False",")","Next",",","smooth","the","sample","data",".",">",">",">","smoothed","=","grid.median_smooth","(","kernel_size=","(","10",",","10",",","10",")",")",">",">",">","smoothed.plot","(","show_scalar_bar=False",")"]
code: def median_smooth(
      self,
      kernel_size=(3, 3, 3),
      scalars=None,
      preference="point",
      progress_bar=False,
  ):
      """Smooth data using a median filter.
  
      The Median filter that replaces each pixel with the median value from a
      rectangular neighborhood around that pixel. Neighborhoods can be no
      more than 3 dimensional. Setting one axis of the neighborhood
      kernelSize to 1 changes the filter into a 2D median.
  
      See `vtkImageMedian3D
      <https://vtk.org/doc/nightly/html/classvtkImageMedian3D.html#details>`_
      for more details.
  
      Parameters
      ----------
      kernel_size : sequence[int], default: (3, 3, 3)
          Size of the kernel in each dimension (units of voxels), for example
          ``(x_size, y_size, z_size)``. Default is a 3D median filter. If you
          want to do a 2D median filter, set the size to 1 in the dimension
          you don't want to filter over.
  
      scalars : str, optional
          Name of scalars to process. Defaults to currently active scalars.
  
      preference : str, default: "point"
          When scalars is specified, this is the preferred array
          type to search for in the dataset.  Must be either
          ``'point'`` or ``'cell'``.
  
      progress_bar : bool, default: False
          Display a progress bar to indicate progress.
  
      Returns
      -------
      pyvista.ImageData
          Uniform grid with smoothed scalars.
  
      Warnings
      --------
      Applying this filter to cell data will send the output to a new point
      array with the same name, overwriting any existing point data array
      with the same name.
  
      Examples
      --------
      First, create sample data to smooth. Here, we use
      :func:`pyvista.perlin_noise() <pyvista.core.utilities.features.perlin_noise>`
      to create meaningful data.
  
      >>> import numpy as np
      >>> import pyvista as pv
      >>> noise = pv.perlin_noise(0.1, (2, 5, 8), (0, 0, 0))
      >>> grid = pv.sample_function(
      ...     noise, [0, 1, 0, 1, 0, 1], dim=(20, 20, 20)
      ... )
      >>> grid.plot(show_scalar_bar=False)
  
      Next, smooth the sample data.
  
      >>> smoothed = grid.median_smooth(kernel_size=(10, 10, 10))
      >>> smoothed.plot(show_scalar_bar=False)
  
      """
      alg = _vtk.vtkImageMedian3D()
      alg.SetInputDataObject(self)
      if scalars is None:
          set_default_active_scalars(self)
          field, scalars = self.active_scalars_info
      else:
          field = self.get_array_association(
              scalars, preference=preference
          )
      alg.SetInputArrayToProcess(
          0, 0, 0, field.value, scalars
      )  # args: (idx, port, connection, field, name)
      alg.SetKernelSize(kernel_size[0], kernel_size[1], kernel_size[2])
      _update_alg(alg, progress_bar, "Performing Median Smoothing")
      return _get_output(alg)
  
imports: import collections.abc
  from typing import Literal, Optional, cast
  import numpy
  import pyvista
  from pyvista.core import _vtk_core
  from pyvista.core.errors import AmbiguousDataError, MissingDataError
  from pyvista.core.filters import _get_output, _update_alg
  from pyvista.core.filters.data_set import DataSetFilters
  from pyvista.core.utilities.arrays import FieldAssociation, set_default_active_scalars
  from pyvista.core.utilities.helpers import wrap
  from pyvista.core.utilities.misc import abstract_class
label_desc: Use image node_id 2 for calling the ImageDataFilters obj's underlying member method code with example usage: obj.median_smooth(kernel_size, scalars, preference, progress_bar) and returns: _get_output