ptypy.utils.array_utils.crop_pad_axis#

ptypy.utils.array_utils.crop_pad_axis(A, hplanes, axis=-1, roll=0, fillpar=0.0, filltype='scalar')#

Crops or pads a volume array A at beginning and end of axis axis with a number of hyperplanes specified by hplanes

Parameters:
  • A (array-like) – Input array, should be at least one-dimensional

  • hplanes (int or tuple of int) – Number of hyperplanes to add or remove in total. If tuple of 2 ints, this value is interpreted as (begin, end). See the Note for more information.

  • axis (int, optional) – axis to be used for cropping / padding

  • roll (int,) – Roll array backwards by this number prior to padding / cropping. The roll is reversed afterwards

  • fillpar – See pad_lr for explqanation

  • filltype – See pad_lr for explqanation

Returns:

Cropped / padded array

Return type:

array-like

See also

pad_lr, crop_pad

Note

  • if hplanes is scalar and negativ :

    crops symmetrically, low-index end of axis is preferred if hplane is odd,

  • if hplanes is scalar and positiv :

    pads symmetrically with a fill specified with ‘fillpar’ and ‘filltype’ look at function pad_lr() for detail.

  • if hplanes is tupel :

    function pads /crops at (begin, end) according to the tupel.

Examples

>>> import numpy as np
>>> from ptypy.utils import crop_pad_axis
>>> A=np.ones((8,9))

Add a total of 2 rows, one at top, one at bottom.

>>> B=crop_pad_axis(A,2,0)

That is the same as

>>> B = crop_pad_axis(A,(1,1),0))

Crop 3 columns on the left side and pad 2 columns on the right:

>>> B = crop_pad_axis(A,(-3,2),1)

Crop one plane on low-side and high-side (total of 2) of Volume V:

>>> V=np.random.rand(3,5,5)
>>> B=crop_pad_axis(V,-2,0)

Mirror volume 3 planes on low side of row axis, crop 2 planes on high side:

>>> B=crop_pad_axis(V,(3,-2),1,filltype='mirror')