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, DTYPE 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 nB = act.shape[1] 45 46 # act[:,0,:] = torch.e**(1j*(sig + torch.angle(act[:,0,:].clone()))) 47 if sig is None: 48 sig = torch.ones_like(act) 49 if mode == 'Trap': 50 sig = torch.stack([torch.ones_like(act[:,0,:]) * torch.pi, torch.zeros_like(act[:,0,:])],dim=1) 51 if mode == 'Focal': 52 sig = torch.zeros_like(act) 53 if mode == 'Vortex': 54 plane = board[:,0:2] 55 sig = torch.atan2(plane[:,0], plane[:,1]).unsqueeze(0).unsqueeze(2).reshape((B,-1, board_size)) 56 if mode == 'Twin': 57 plane = board[:,0:2] 58 sig = torch.zeros_like(sig) + torch.pi * (plane[:,0].real > 0).unsqueeze(0).unsqueeze(2).reshape((B,-1, board_size)) 59 if mode == 'Eye': 60 61 b = board.reshape(-1,board_size,3) 62 63 plane = board[:,0:2] 64 sig = torch.atan2(plane[:,0], plane[:,1]).unsqueeze(0).unsqueeze(2).reshape((B,-1, board_size)) 65 mask = torch.sqrt(b[:,:,0] ** 2 + b[:,:,1] ** 2) < 0.06 66 67 68 69 sig[0,0,:][mask[0,:] == 1] = torch.pi 70 sig[0,1,:][mask[0,:] == 1] = 0 71 72 73 74 x = torch.abs(act) * torch.exp(1j* (torch.angle(act) + sig)) 75 76 x = torch.reshape(x,s) 77 78 if return_sig: 79 return x, sig 80 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 nB = act.shape[1] 47 48 # act[:,0,:] = torch.e**(1j*(sig + torch.angle(act[:,0,:].clone()))) 49 if sig is None: 50 sig = torch.ones_like(act) 51 if mode == 'Trap': 52 sig = torch.stack([torch.ones_like(act[:,0,:]) * torch.pi, torch.zeros_like(act[:,0,:])],dim=1) 53 if mode == 'Focal': 54 sig = torch.zeros_like(act) 55 if mode == 'Vortex': 56 plane = board[:,0:2] 57 sig = torch.atan2(plane[:,0], plane[:,1]).unsqueeze(0).unsqueeze(2).reshape((B,-1, board_size)) 58 if mode == 'Twin': 59 plane = board[:,0:2] 60 sig = torch.zeros_like(sig) + torch.pi * (plane[:,0].real > 0).unsqueeze(0).unsqueeze(2).reshape((B,-1, board_size)) 61 if mode == 'Eye': 62 63 b = board.reshape(-1,board_size,3) 64 65 plane = board[:,0:2] 66 sig = torch.atan2(plane[:,0], plane[:,1]).unsqueeze(0).unsqueeze(2).reshape((B,-1, board_size)) 67 mask = torch.sqrt(b[:,:,0] ** 2 + b[:,:,1] ** 2) < 0.06 68 69 70 71 sig[0,0,:][mask[0,:] == 1] = torch.pi 72 sig[0,1,:][mask[0,:] == 1] = 0 73 74 75 76 x = torch.abs(act) * torch.exp(1j* (torch.angle(act) + sig)) 77 78 x = torch.reshape(x,s) 79 80 if return_sig: 81 return x, sig 82 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)