complex_object_z_resample_torch#
- ptyrad.utils.physics.complex_object_z_resample_torch(obj, dz_now, resample_mode, resample_value, output_type='complex', return_np=True)[source]#
Resample a complex 3D object along the depth (z) axis while conserving amplitude product, phase sum, and total thickness.
This function performs interpolation along the z-axis of a complex-valued object using PyTorch. The object is decomposed into amplitude and phase, resampled with conservation laws applied, and recombined into the desired output representation.
- Parameters:
obj (ndarray or torch.Tensor) – Input complex object with shape (…, Nz, Ny, Nx). Can be a NumPy array or a torch.Tensor.
dz_now (float) – Current slice thickness along the z-axis.
resample_mode (str) – Resampling mode for the depth axis. Must be one of: - “scale_Nlayer”: Scale the number of layers by a float factor. - “scale_slice_thickness”: Scale slice thickness by a float factor. - “target_Nlayer”: Resample to a target integer number of layers. - “target_slice_thickness”: Resample to a target slice thickness.
resample_value (int or float) – Parameter value for the resampling mode. - Positive float for “scale_Nlayer” or “scale_slice_thickness”. - Positive integer (>=1) for “target_Nlayer”. - Positive float for “target_slice_thickness”.
output_type (str, optional) – Output representation. Must be one of: - “complex”: Return recombined complex object (default). - “amplitude”: Return amplitude only. - “phase”: Return phase only. - “amp_phase”: Return tuple (amplitude, phase).
return_np (bool, optional) – If True (default), convert outputs to NumPy arrays. If False, return PyTorch tensors.
- Returns:
The resampled object in the requested representation: - Complex ndarray/tensor if output_type == “complex”. - Real ndarray/tensor if output_type == “amplitude” or “phase”. - Tuple of (amplitude, phase) if output_type == “amp_phase”.
Type depends on return_np.
- Return type:
ndarray or torch.Tensor or tuple
- Raises:
ValueError – If resample_mode is invalid.
ValueError – If the target number of layers is less than 1.
ValueError – If the input object has unsupported dimensionality.
ValueError – If output_type is not one of the allowed options.
Examples
Resample by doubling the number of z-layers:
>>> out = complex_object_z_resample_torch( ... obj, dz_now=0.5, resample_mode="scale_Nlayer", ... resample_value=2.0, output_type="complex" ... ) >>> out.shape
Resample to a target of 64 layers, keeping total thickness fixed:
>>> out_amp, out_phase = complex_object_z_resample_torch( ... obj, dz_now=0.5, resample_mode="target_Nlayer", ... resample_value=64, output_type="amp_phase" ... )