_ni_docstrings.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. """Docstring components common to several ndimage functions."""
  2. from typing import Final
  3. from scipy._lib import doccer
  4. __all__ = ['docfiller']
  5. _input_doc = (
  6. """input : array_like
  7. The input array.""")
  8. _axis_doc = (
  9. """axis : int, optional
  10. The axis of `input` along which to calculate. Default is -1.""")
  11. _output_doc = (
  12. """output : array or dtype, optional
  13. The array in which to place the output, or the dtype of the
  14. returned array. By default an array of the same dtype as input
  15. will be created.""")
  16. _nan_doc = (
  17. """The behavior of this function with NaN elements is undefined. To control
  18. behavior in the presence of NaNs, consider using `vectorized_filter`.""")
  19. _size_foot_doc = (
  20. """size : scalar or tuple, optional
  21. See footprint, below. Ignored if footprint is given.
  22. footprint : array, optional
  23. Either `size` or `footprint` must be defined. `size` gives
  24. the shape that is taken from the input array, at every element
  25. position, to define the input to the filter function.
  26. `footprint` is a boolean array that specifies (implicitly) a
  27. shape, but also which of the elements within this shape will get
  28. passed to the filter function. Thus ``size=(n,m)`` is equivalent
  29. to ``footprint=np.ones((n,m))``. We adjust `size` to the number
  30. of dimensions of the input array, so that, if the input array is
  31. shape (10,10,10), and `size` is 2, then the actual size used is
  32. (2,2,2). When `footprint` is given, `size` is ignored.""")
  33. _mode_reflect_doc = (
  34. """mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional
  35. The `mode` parameter determines how the input array is extended
  36. beyond its boundaries. Default is 'reflect'. Behavior for each valid
  37. value is as follows:
  38. 'reflect' (`d c b a | a b c d | d c b a`)
  39. The input is extended by reflecting about the edge of the last
  40. pixel. This mode is also sometimes referred to as half-sample
  41. symmetric.
  42. 'constant' (`k k k k | a b c d | k k k k`)
  43. The input is extended by filling all values beyond the edge with
  44. the same constant value, defined by the `cval` parameter.
  45. 'nearest' (`a a a a | a b c d | d d d d`)
  46. The input is extended by replicating the last pixel.
  47. 'mirror' (`d c b | a b c d | c b a`)
  48. The input is extended by reflecting about the center of the last
  49. pixel. This mode is also sometimes referred to as whole-sample
  50. symmetric.
  51. 'wrap' (`a b c d | a b c d | a b c d`)
  52. The input is extended by wrapping around to the opposite edge.
  53. For consistency with the interpolation functions, the following mode
  54. names can also be used:
  55. 'grid-mirror'
  56. This is a synonym for 'reflect'.
  57. 'grid-constant'
  58. This is a synonym for 'constant'.
  59. 'grid-wrap'
  60. This is a synonym for 'wrap'.""")
  61. _mode_interp_constant_doc = (
  62. """mode : {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest', \
  63. 'mirror', 'grid-wrap', 'wrap'}, optional
  64. The `mode` parameter determines how the input array is extended
  65. beyond its boundaries. Default is 'constant'. Behavior for each valid
  66. value is as follows (see additional plots and details on
  67. :ref:`boundary modes <ndimage-interpolation-modes>`):
  68. 'reflect' (`d c b a | a b c d | d c b a`)
  69. The input is extended by reflecting about the edge of the last
  70. pixel. This mode is also sometimes referred to as half-sample
  71. symmetric.
  72. 'grid-mirror'
  73. This is a synonym for 'reflect'.
  74. 'constant' (`k k k k | a b c d | k k k k`)
  75. The input is extended by filling all values beyond the edge with
  76. the same constant value, defined by the `cval` parameter. No
  77. interpolation is performed beyond the edges of the input.
  78. 'grid-constant' (`k k k k | a b c d | k k k k`)
  79. The input is extended by filling all values beyond the edge with
  80. the same constant value, defined by the `cval` parameter. Interpolation
  81. occurs for samples outside the input's extent as well.
  82. 'nearest' (`a a a a | a b c d | d d d d`)
  83. The input is extended by replicating the last pixel.
  84. 'mirror' (`d c b | a b c d | c b a`)
  85. The input is extended by reflecting about the center of the last
  86. pixel. This mode is also sometimes referred to as whole-sample
  87. symmetric.
  88. 'grid-wrap' (`a b c d | a b c d | a b c d`)
  89. The input is extended by wrapping around to the opposite edge.
  90. 'wrap' (`d b c d | a b c d | b c a b`)
  91. The input is extended by wrapping around to the opposite edge, but in a
  92. way such that the last point and initial point exactly overlap. In this
  93. case it is not well defined which sample will be chosen at the point of
  94. overlap.""")
  95. _mode_interp_mirror_doc = (
  96. _mode_interp_constant_doc.replace("Default is 'constant'",
  97. "Default is 'mirror'")
  98. )
  99. assert _mode_interp_mirror_doc != _mode_interp_constant_doc, \
  100. 'Default not replaced'
  101. _mode_multiple_doc = (
  102. """mode : str or sequence, optional
  103. The `mode` parameter determines how the input array is extended
  104. when the filter overlaps a border. By passing a sequence of modes
  105. with length equal to the number of dimensions of the input array,
  106. different modes can be specified along each axis. Default value is
  107. 'reflect'. The valid values and their behavior is as follows:
  108. 'reflect' (`d c b a | a b c d | d c b a`)
  109. The input is extended by reflecting about the edge of the last
  110. pixel. This mode is also sometimes referred to as half-sample
  111. symmetric.
  112. 'constant' (`k k k k | a b c d | k k k k`)
  113. The input is extended by filling all values beyond the edge with
  114. the same constant value, defined by the `cval` parameter.
  115. 'nearest' (`a a a a | a b c d | d d d d`)
  116. The input is extended by replicating the last pixel.
  117. 'mirror' (`d c b | a b c d | c b a`)
  118. The input is extended by reflecting about the center of the last
  119. pixel. This mode is also sometimes referred to as whole-sample
  120. symmetric.
  121. 'wrap' (`a b c d | a b c d | a b c d`)
  122. The input is extended by wrapping around to the opposite edge.
  123. For consistency with the interpolation functions, the following mode
  124. names can also be used:
  125. 'grid-constant'
  126. This is a synonym for 'constant'.
  127. 'grid-mirror'
  128. This is a synonym for 'reflect'.
  129. 'grid-wrap'
  130. This is a synonym for 'wrap'.""")
  131. _cval_doc = (
  132. """cval : scalar, optional
  133. Value to fill past edges of input if `mode` is 'constant'. Default
  134. is 0.0.""")
  135. _origin_doc = (
  136. """origin : int, optional
  137. Controls the placement of the filter on the input array's pixels.
  138. A value of 0 (the default) centers the filter over the pixel, with
  139. positive values shifting the filter to the left, and negative ones
  140. to the right.""")
  141. _origin_multiple_doc = (
  142. """origin : int or sequence, optional
  143. Controls the placement of the filter on the input array's pixels.
  144. A value of 0 (the default) centers the filter over the pixel, with
  145. positive values shifting the filter to the left, and negative ones
  146. to the right. By passing a sequence of origins with length equal to
  147. the number of dimensions of the input array, different shifts can
  148. be specified along each axis.""")
  149. _extra_arguments_doc = (
  150. """extra_arguments : sequence, optional
  151. Sequence of extra positional arguments to pass to passed function.""")
  152. _extra_keywords_doc = (
  153. """extra_keywords : dict, optional
  154. dict of extra keyword arguments to pass to passed function.""")
  155. _prefilter_doc = (
  156. """prefilter : bool, optional
  157. Determines if the input array is prefiltered with `spline_filter`
  158. before interpolation. The default is True, which will create a
  159. temporary `float64` array of filtered values if ``order > 1``. If
  160. setting this to False, the output will be slightly blurred if
  161. ``order > 1``, unless the input is prefiltered, i.e. it is the result
  162. of calling `spline_filter` on the original input.""")
  163. docdict = {
  164. 'input': _input_doc,
  165. 'axis': _axis_doc,
  166. 'output': _output_doc,
  167. 'size_foot': _size_foot_doc,
  168. 'mode_interp_constant': _mode_interp_constant_doc,
  169. 'mode_interp_mirror': _mode_interp_mirror_doc,
  170. 'mode_reflect': _mode_reflect_doc,
  171. 'mode_multiple': _mode_multiple_doc,
  172. 'cval': _cval_doc,
  173. 'origin': _origin_doc,
  174. 'origin_multiple': _origin_multiple_doc,
  175. 'extra_arguments': _extra_arguments_doc,
  176. 'extra_keywords': _extra_keywords_doc,
  177. 'prefilter': _prefilter_doc,
  178. 'nan': _nan_doc,
  179. }
  180. docfiller: Final = doccer.filldoc(docdict)