src.acoustools.Utilities.Signatures
1from torch import Tensor 2import torch 3 4from typing import Literal 5 6from acoustools.Utilities.Boards import TRANSDUCERS 7from acoustools.Utilities.Setup import device 8 9def add_lev_sig(activation:Tensor, board:Tensor|None=None, 10 mode:Literal['Focal', 'Trap', 'Vortex','Twin', 'Eye']='Trap', sig:Tensor|None=None, return_sig:bool=False, board_size:int=256) -> Tensor: 11 ''' 12 Adds signature to hologram for a board \n 13 :param activation: Hologram input 14 :param board: Board to use 15 :param mode: Type of signature to add, should be one of 16 * Focal: No signature 17 * Trap: Add $\\pi$ to the top board - creates a trap 18 * Vortex: Add a circular signature to create a circular trap 19 * Twin: Add $\\pi$ to half of the board laterally to create a twin trap 20 * Eye: Add a vortex trap combined with a central disk of the Trap method. Produces a eye like shape around the focus 21 :param sig: signature to add to top board. If `None` then value is determined by value of `mode` 22 :param board_size: Transducers per board in total. Default 256 (16x16) 23 :return: hologram with signature added 24 25 ```Python 26 from acoustools.Utilities import create_points, add_lev_sig 27 from acoustools.Solvers import wgs 28 29 p = create_points(1,x=0,y=0,z=0) 30 x = wgs(p, board=board) 31 x_sig, sig = add_lev_sig(x.clone(), mode=mode, return_sig=True, board=board) 32 33 ``` 34 ''' 35 if board is None: 36 board = TRANSDUCERS 37 38 act = activation.clone().to(device) 39 40 s = act.shape 41 B = s[0] 42 43 act = torch.reshape(act,(B,-1, board_size)) 44 45 # act[:,0,:] = torch.e**(1j*(sig + torch.angle(act[:,0,:].clone()))) 46 if sig is None: 47 sig = torch.ones_like(act) 48 if mode == 'Trap': 49 sig = torch.stack([torch.ones_like(act[:,0,:]) * torch.pi, torch.zeros_like(act[:,0,:])],dim=1) 50 if mode == 'Focal': 51 sig = torch.zeros_like(act) 52 if mode == 'Vortex': 53 plane = board[:,0:2] 54 sig = torch.atan2(plane[:,0], plane[:,1]).unsqueeze(0).unsqueeze(2).reshape((B,-1, board_size)) 55 if mode == 'Twin': 56 plane = board[:,0:2] 57 sig = torch.zeros_like(sig) + torch.pi * (plane[:,0] > 0).unsqueeze(0).unsqueeze(2).reshape((B,-1, board_size)) 58 if mode == 'Eye': 59 60 b = board.reshape(-1,board_size,3) 61 62 plane = board[:,0:2] 63 sig = torch.atan2(plane[:,0], plane[:,1]).unsqueeze(0).unsqueeze(2).reshape((B,-1, board_size)) 64 mask = torch.sqrt(b[:,:,0] ** 2 + b[:,:,1] ** 2) < 0.06 65 66 67 68 sig[0,0,:][mask[0,:] == 1] = torch.pi 69 sig[0,1,:][mask[0,:] == 1] = 0 70 71 x = torch.abs(act) * torch.exp(1j* (torch.angle(act) + sig)) 72 73 x = torch.reshape(x,s) 74 75 if return_sig: 76 return x, sig 77 return x
def
add_lev_sig( activation: torch.Tensor, board: torch.Tensor | None = None, mode: Literal['Focal', 'Trap', 'Vortex', 'Twin', 'Eye'] = 'Trap', sig: torch.Tensor | None = None, return_sig: bool = False, board_size: int = 256) -> torch.Tensor:
11def add_lev_sig(activation:Tensor, board:Tensor|None=None, 12 mode:Literal['Focal', 'Trap', 'Vortex','Twin', 'Eye']='Trap', sig:Tensor|None=None, return_sig:bool=False, board_size:int=256) -> Tensor: 13 ''' 14 Adds signature to hologram for a board \n 15 :param activation: Hologram input 16 :param board: Board to use 17 :param mode: Type of signature to add, should be one of 18 * Focal: No signature 19 * Trap: Add $\\pi$ to the top board - creates a trap 20 * Vortex: Add a circular signature to create a circular trap 21 * Twin: Add $\\pi$ to half of the board laterally to create a twin trap 22 * Eye: Add a vortex trap combined with a central disk of the Trap method. Produces a eye like shape around the focus 23 :param sig: signature to add to top board. If `None` then value is determined by value of `mode` 24 :param board_size: Transducers per board in total. Default 256 (16x16) 25 :return: hologram with signature added 26 27 ```Python 28 from acoustools.Utilities import create_points, add_lev_sig 29 from acoustools.Solvers import wgs 30 31 p = create_points(1,x=0,y=0,z=0) 32 x = wgs(p, board=board) 33 x_sig, sig = add_lev_sig(x.clone(), mode=mode, return_sig=True, board=board) 34 35 ``` 36 ''' 37 if board is None: 38 board = TRANSDUCERS 39 40 act = activation.clone().to(device) 41 42 s = act.shape 43 B = s[0] 44 45 act = torch.reshape(act,(B,-1, board_size)) 46 47 # act[:,0,:] = torch.e**(1j*(sig + torch.angle(act[:,0,:].clone()))) 48 if sig is None: 49 sig = torch.ones_like(act) 50 if mode == 'Trap': 51 sig = torch.stack([torch.ones_like(act[:,0,:]) * torch.pi, torch.zeros_like(act[:,0,:])],dim=1) 52 if mode == 'Focal': 53 sig = torch.zeros_like(act) 54 if mode == 'Vortex': 55 plane = board[:,0:2] 56 sig = torch.atan2(plane[:,0], plane[:,1]).unsqueeze(0).unsqueeze(2).reshape((B,-1, board_size)) 57 if mode == 'Twin': 58 plane = board[:,0:2] 59 sig = torch.zeros_like(sig) + torch.pi * (plane[:,0] > 0).unsqueeze(0).unsqueeze(2).reshape((B,-1, board_size)) 60 if mode == 'Eye': 61 62 b = board.reshape(-1,board_size,3) 63 64 plane = board[:,0:2] 65 sig = torch.atan2(plane[:,0], plane[:,1]).unsqueeze(0).unsqueeze(2).reshape((B,-1, board_size)) 66 mask = torch.sqrt(b[:,:,0] ** 2 + b[:,:,1] ** 2) < 0.06 67 68 69 70 sig[0,0,:][mask[0,:] == 1] = torch.pi 71 sig[0,1,:][mask[0,:] == 1] = 0 72 73 x = torch.abs(act) * torch.exp(1j* (torch.angle(act) + sig)) 74 75 x = torch.reshape(x,s) 76 77 if return_sig: 78 return x, sig 79 return x
Adds signature to hologram for a board
Parameters
- activation: Hologram input
- board: Board to use
- mode: Type of signature to add, should be one of
- Focal: No signature
- Trap: Add $\pi$ to the top board - creates a trap
- Vortex: Add a circular signature to create a circular trap
- Twin: Add $\pi$ to half of the board laterally to create a twin trap
- Eye: Add a vortex trap combined with a central disk of the Trap method. Produces a eye like shape around the focus
- sig: signature to add to top board. If
Nonethen value is determined by value ofmode - board_size: Transducers per board in total. Default 256 (16x16)
Returns
hologram with signature added
from acoustools.Utilities import create_points, add_lev_sig
from acoustools.Solvers import wgs
p = create_points(1,x=0,y=0,z=0)
x = wgs(p, board=board)
x_sig, sig = add_lev_sig(x.clone(), mode=mode, return_sig=True, board=board)