pado.light.PolarizedLight

class PolarizedLight(dim, pitch, wvl, fieldX=None, fieldY=None, device='cuda:0')[source]

Light wave with polarized complex field wavefront.

Represent a light wave with X and Y polarization components that can be manipulated through various optical operations.

Parameters:
__init__(dim, pitch, wvl, fieldX=None, fieldY=None, device='cuda:0')[source]

Create polarized light wave instance with X and Y field components.

Parameters:
  • dim (tuple) – Field dimensions (B, Ch, R, C) for batch, channels, rows, cols

  • pitch (float) – Pixel pitch in meters

  • wvl (float) – Wavelength in meters

  • fieldX (torch.Tensor, optional) – Initial X-polarized field [B, Ch, R, C]

  • fieldY (torch.Tensor, optional) – Initial Y-polarized field [B, Ch, R, C]

  • device (str) – Device for computation (‘cpu’, ‘cuda:0’, etc.)

Return type:

None

Examples

>>> light = PolarizedLight(dim=(1, 1, 1024, 1024), pitch=6.4e-6, wvl=633e-9)
>>> light = PolarizedLight(dim=(2, 1, 512, 512), pitch=2e-6, wvl=532e-9,
...                       fieldX=torch.ones(2,1,512,512),
...                       fieldY=torch.zeros(2,1,512,512))
clone()[source]

Create deep copy of polarized light instance.

Returns:

New polarized light instance with copied attributes

Return type:

PolarizedLight

Examples

>>> light_copy = light.clone()
crop(crop_width)[source]

Crop light wavefront.

Parameters:

crop_width (tuple) – Crop dimensions (left, right, top, bottom)

Return type:

None

Examples

>>> light.crop((32, 32, 32, 32))
get_amplitude()[source]

Return total amplitude of polarized field.

Returns:

Total amplitude

Return type:

torch.Tensor

get_amplitudeX()[source]

Return amplitude of X-polarized field.

Returns:

Amplitude of X-polarized field

Return type:

torch.Tensor

get_amplitudeY()[source]

Return amplitude of Y-polarized field.

Returns:

Amplitude of Y-polarized field

Return type:

torch.Tensor

get_field()[source]

Return complex field.

Returns:

Complex field values for X and Y components

Return type:

torch.Tensor

Examples

>>> field = light.get_field()
get_fieldX()[source]

Return X-polarized field component.

Returns:

Complex field tensor for X polarization

Return type:

torch.Tensor

Examples

>>> x_field = light.get_fieldX()
get_fieldY()[source]

Return Y-polarized field component.

Returns:

Complex field tensor for Y polarization

Return type:

torch.Tensor

Examples

>>> y_field = light.get_fieldY()
get_imag()[source]

Get imaginary part of field for both components.

Returns:

Imaginary part values for X and Y components

Return type:

torch.Tensor

Examples

>>> imag_parts = light.get_imag()
get_intensity()[source]

Return total intensity of polarized field.

Returns:

Total intensity

Return type:

torch.Tensor

get_intensityX()[source]

Return intensity of X-polarized field.

Returns:

Intensity of X-polarized field

Return type:

torch.Tensor

get_intensityY()[source]

Return intensity of Y-polarized field.

Returns:

Intensity of Y-polarized field

Return type:

torch.Tensor

get_lightX()[source]

Return X-polarized Light instance.

Returns:

Light instance for X component

Return type:

Light

Examples

>>> x_light = light.get_lightX()
get_lightY()[source]

Return Y-polarized Light instance.

Returns:

Light instance for Y component

Return type:

Light

Examples

>>> y_light = light.get_lightY()
get_phase()[source]

Return phase of field.

Returns:

Phase values for X and Y components

Return type:

torch.Tensor

Examples

>>> phase = light.get_phase()
get_phaseX()[source]

Return phase of X-polarized field.

Returns:

Phase of X-polarized field

Return type:

torch.Tensor

get_phaseY()[source]

Return phase of Y-polarized field.

Returns:

Phase of Y-polarized field

Return type:

torch.Tensor

get_real()[source]

Get real part of field for both components.

Returns:

Real part values for X and Y components

Return type:

torch.Tensor

Examples

>>> real_parts = light.get_real()
magnify(scale_factor, interp_mode='nearest')[source]

Change wavefront resolution without changing pixel pitch.

Parameters:
  • scale_factor (float) – Scale factor for interpolation

  • interp_mode (str) – Interpolation method (‘bilinear’, ‘nearest’)

Return type:

None

Examples

>>> light.magnify(2.0, 'bilinear')
pad(pad_width, padval=0)[source]

Pad light field.

Parameters:
  • pad_width (tuple) – Padding width (left, right, top, bottom)

  • padval (complex) – Padding value (default: 0+0j)

Return type:

None

Examples

>>> light.pad((10, 10, 10, 10))
resize(new_pitch, interp_mode='nearest')[source]

Resize light field to match new pixel pitch.

Parameters:
  • new_pitch (float) – New pixel pitch in meters

  • interp_mode (str) – Interpolation mode (‘nearest’, ‘bilinear’)

Return type:

None

Examples

>>> light.resize(8e-6)
set_amplitude(amplitude)[source]

Set amplitude for both X and Y components.

Parameters:

amplitude (torch.Tensor or tuple) – Amplitude values for both components or tuple of (amplitudeX, amplitudeY)

Return type:

None

Examples

>>> light.set_amplitude(torch.ones(1,1,512,512))
>>> light.set_amplitude((x_amplitude, y_amplitude))
set_amplitudeX(amplitude)[source]

Set amplitude for X component.

Parameters:

amplitude (torch.Tensor) – Amplitude values for X component

Return type:

None

Examples

>>> light.set_amplitudeX(torch.ones(1,1,512,512))
set_amplitudeY(amplitude)[source]

Set amplitude for Y component.

Parameters:

amplitude (torch.Tensor) – Amplitude values for Y component

Return type:

None

Examples

>>> light.set_amplitudeY(torch.ones(1,1,512,512))
set_field(field)[source]

Set both X and Y field components.

Parameters:

field (tuple) – Complex field values for X and Y components

Return type:

None

Examples

>>> light.set_field((x_field, y_field))
set_fieldX(field)[source]

Set X-polarized field.

Parameters:

field (torch.Tensor) – Complex field values

Return type:

None

Examples

>>> light.set_fieldX(torch.ones(1,1,512,512, dtype=torch.cfloat))
set_fieldY(field)[source]

Set Y-polarized field.

Parameters:

field (torch.Tensor) – Complex field values

Return type:

None

Examples

>>> light.set_fieldY(torch.ones(1,1,512,512, dtype=torch.cfloat))
set_imag(imag)[source]

Set imaginary part for both X and Y components.

Parameters:

imag (torch.Tensor or tuple) – Imaginary values for both components or tuple of (imagX, imagY)

Return type:

None

Examples

>>> light.set_imag(torch.zeros(1,1,512,512))
>>> light.set_imag((x_imag, y_imag))
set_imagX(imag)[source]

Set imaginary part of X-polarized field.

Parameters:

imag (torch.Tensor) – Imaginary component values

Return type:

None

Examples

>>> light.set_imagX(torch.zeros(1,1,512,512))
set_imagY(imag)[source]

Set imaginary part of Y-polarized field.

Parameters:

imag (torch.Tensor) – Imaginary component values

Return type:

None

Examples

>>> light.set_imagY(torch.zeros(1,1,512,512))
set_lightX(light)[source]

Set X-polarized Light instance.

Parameters:

light (Light) – Light instance for X component

Return type:

None

Examples

>>> light.set_lightX(x_light)
set_lightY(light)[source]

Set Y-polarized Light instance.

Parameters:

light (Light) – Light instance for Y component

Return type:

None

Examples

>>> light.set_lightY(y_light)
set_phase(phase)[source]

Set phase for both X and Y components.

Parameters:

phase (torch.Tensor or tuple) – Phase values for both components or tuple of (phaseX, phaseY)

Return type:

None

Examples

>>> light.set_phase(torch.zeros(1,1,512,512))
>>> light.set_phase((x_phase, y_phase))
set_phaseX(phase)[source]

Set phase of X-polarized field.

Parameters:

phase (torch.Tensor) – Phase values in radians

Return type:

None

Examples

>>> light.set_phaseX(torch.zeros(1,1,512,512))
set_phaseY(phase)[source]

Set phase of Y-polarized field.

Parameters:

phase (torch.Tensor) – Phase values in radians

Return type:

None

Examples

>>> light.set_phaseY(torch.zeros(1,1,512,512))
set_pitch(pitch)[source]

Set pixel pitch.

Parameters:

pitch (float) – Pixel pitch in meters

Return type:

None

set_plane_light()[source]

Set plane wave with unit amplitude and zero phase. :rtype: None

Examples

>>> light.set_plane_light()
Return type:

None

set_real(real)[source]

Set real part for both X and Y components.

Parameters:

real (torch.Tensor or tuple) – Real values for both components or tuple of (realX, realY)

Return type:

None

Examples

>>> light.set_real(torch.ones(1,1,512,512))
>>> light.set_real((x_real, y_real))
set_realX(real)[source]

Set real part of X-polarized field.

Parameters:

real (torch.Tensor) – Real component values

Return type:

None

Examples

>>> light.set_realX(torch.ones(1,1,512,512))
set_realY(real)[source]

Set real part of Y-polarized field.

Parameters:

real (torch.Tensor) – Real component values

Return type:

None

Examples

>>> light.set_realY(torch.ones(1,1,512,512))
set_spherical_light(z, dx=0, dy=0)[source]

Set spherical wavefront from point source.

Parameters:
  • z (float) – Z distance of source in meters

  • dx (float) – X offset of source in meters

  • dy (float) – Y offset of source in meters

Return type:

None

Examples

>>> light.set_spherical_light(0.1, dx=1e-3)
shape()[source]

Return shape of light wavefront.

Returns:

Shape of the field tensor

Return type:

tuple

Examples

>>> shape = light.shape()
visualize(b=0, c=0)[source]

Visualize polarized light components.

Parameters:
  • b (int) – Batch index to visualize

  • c (int) – Channel index to visualize

Return type:

None

Examples

>>> light.visualize(b=0, c=0)