ptypy.utils.array_utils.crop_pad#

ptypy.utils.array_utils.crop_pad(A, hplane_list, axes=None, cen=None, fillpar=0.0, filltype='scalar')#

Crops or pads a volume array A with a number of hyperplanes according to parameters in hplanes Wrapper for crop_pad_axis.

Parameters:
  • A (array-like) – input array of any shape

  • hplane_list (array-like, list) – list of scalars or tupels counting the number of hyperplanes to crop / pad see crop_pad_axis() for detail. If N=len(hplane_list) has less entries than dimensions of A, the last N axes are used

  • axes (tuple, list) – tuple / list of axes to be used for cropping / padding, has to be same length as hplanes

  • cen – center of array, padding/cropping occurs at cen + A.shape / 2

Returns:

Cropped or padded array.

Return type:

array-like

See also

crop_pad_axis

Examples

>>> import numpy as np
>>> from ptypy.utils import crop_pad
>>> V=np.random.rand(3,5,5)

Pads 4 planes of zeros on the last axis (2 on low side and 2 on high side) and pads 3 planes of zeros on the second last axis (2 on low side and 1 on high side):

>>> B=crop_pad(V,[3,4])

Also equivalent:

>>> B=crop_pad(V,[(2,1),(2,2)])
>>> B=crop_pad(V,[(2,1),(2,2)], axes=[-2,-1],fillpar=0.0,filltype='scalar')

None-peripheral cropping /padding:

>>> from ptypy.utils import grids
>>> fftshift_grid = grids((6,4),center = 'fft')
>>> cropped_grid=crop_pad(V,[-2,4],cen='fft')

Note that cropping/ padding now occurs at the start and end of fourier coordinates useful for cropping /padding high frequencies in fourier space.