src.acoustools.Constraints
1import torch 2from torch import Tensor 3 4 5def constrain_amplitude(x:Tensor) -> Tensor: 6 ''' 7 Constrains the amplitude of a hologram to be 1, χ(x) in AcousTools Paper\n 8 :param x: Hologram 9 :return: constrained hologram 10 ''' 11 return x / torch.abs(x) 12 13_abs = torch.abs 14def constrain_field(field:Tensor, target:Tensor) -> Tensor: 15 ''' 16 Constrains the amplitude of points in field to be the same as target\n 17 :param field: propagated hologram-> points 18 :param target: complex number with target amplitude 19 :return: constrained field 20 ''' 21 field_amp = _abs(field) 22 norm_field = field / field_amp 23 target_field = target * norm_field 24 # target_field = torch.multiply(target,torch.divide(field,torch.abs(field))) 25 return target_field 26 27def constrain_field_weighted(field:Tensor, target:Tensor, current:Tensor) -> tuple[Tensor, Tensor]: 28 ''' 29 Constrains the amplitude of points in field to be the same as target with weighting\n 30 :param field: propagated hologram-> points 31 :param target: complex number with target amplitude 32 :param current: current amplitude of field 33 :return: constrained weighted field 34 ''' 35 36 current = target * current / torch.abs(field) 37 38 39 current = current / torch.max(torch.abs(current),dim=1,keepdim=True).values 40 field = constrain_field(field,current) 41 return field, current
def
constrain_amplitude(x: torch.Tensor) -> torch.Tensor:
6def constrain_amplitude(x:Tensor) -> Tensor: 7 ''' 8 Constrains the amplitude of a hologram to be 1, χ(x) in AcousTools Paper\n 9 :param x: Hologram 10 :return: constrained hologram 11 ''' 12 return x / torch.abs(x)
Constrains the amplitude of a hologram to be 1, χ(x) in AcousTools Paper
Parameters
- x: Hologram
Returns
constrained hologram
def
constrain_field(field: torch.Tensor, target: torch.Tensor) -> torch.Tensor:
15def constrain_field(field:Tensor, target:Tensor) -> Tensor: 16 ''' 17 Constrains the amplitude of points in field to be the same as target\n 18 :param field: propagated hologram-> points 19 :param target: complex number with target amplitude 20 :return: constrained field 21 ''' 22 field_amp = _abs(field) 23 norm_field = field / field_amp 24 target_field = target * norm_field 25 # target_field = torch.multiply(target,torch.divide(field,torch.abs(field))) 26 return target_field
Constrains the amplitude of points in field to be the same as target
Parameters
- field: propagated hologram-> points
- target: complex number with target amplitude
Returns
constrained field
def
constrain_field_weighted( field: torch.Tensor, target: torch.Tensor, current: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
28def constrain_field_weighted(field:Tensor, target:Tensor, current:Tensor) -> tuple[Tensor, Tensor]: 29 ''' 30 Constrains the amplitude of points in field to be the same as target with weighting\n 31 :param field: propagated hologram-> points 32 :param target: complex number with target amplitude 33 :param current: current amplitude of field 34 :return: constrained weighted field 35 ''' 36 37 current = target * current / torch.abs(field) 38 39 40 current = current / torch.max(torch.abs(current),dim=1,keepdim=True).values 41 field = constrain_field(field,current) 42 return field, current
Constrains the amplitude of points in field to be the same as target with weighting
Parameters
- field: propagated hologram-> points
- target: complex number with target amplitude
- current: current amplitude of field
Returns
constrained weighted field