docs: def median_filter(data, mask, radius, percent=50):
      '''Masked median filter with octagonal shape
  
      data - array of data to be median filtered.
      mask - mask of significant pixels in data
      radius - the radius of a circle inscribed into the filtering octagon
      percent - conceptually, order the significant pixels in the octagon,
                count them and choose the pixel indexed by the percent
                times the count divided by 100. More simply, 50 = median
      returns a filtered array.  In areas where the median filter does
        not overlap the mask, the filtered result is undefined, but in
        practice, it will be the lowest value in the valid area.
      '''
      if mask is None:
          mask = np.ones(data.shape, dtype=bool)
      if np.all(~ mask):
          return data.copy()
      #
      # Normalize the ranked data to 0-255
      #
      if (not np.issubdtype(data.dtype, np.int) or
          np.min(data) < 0 or np.max(data) > 255):
          ranked_data, translation = rank_order(data[mask], nbins=255)
          was_ranked = True
      else:
          ranked_data = data[mask]
          was_ranked = False
      input = np.zeros(data.shape, np.uint8 )
      input[mask] = ranked_data
  
      mmask = np.ascontiguousarray(mask, np.uint8)
  
      output = np.zeros(data.shape, np.uint8)
  
      _filter.median_filter(input, mmask, output, radius, percent)
      if was_ranked:
          result = translation[output]
      else:
          result = output
      return result