Skip to content

odak.wave.linear_grating

A definition to generate a linear grating.

Parameters:

Name Type Description Default
nx int

Size of the output along X.

required
ny int

Size of the output along Y.

required
every int

Add the add value at every given number.

2
add float

Angle to be added.

3.14
axis string

Axis eiter X,Y or both.

'x'

Returns:

Type Description
ndarray

Linear grating term.

Source code in odak/wave/lens.py
def linear_grating(nx, ny, every=2, add=3.14, axis='x'):
    """
    A definition to generate a linear grating.

    Parameters
    ----------
    nx         : int
                 Size of the output along X.
    ny         : int
                 Size of the output along Y.
    every      : int
                 Add the add value at every given number.
    add        : float
                 Angle to be added.
    axis       : string
                 Axis eiter X,Y or both.

    Returns
    -------
    field      : ndarray
                 Linear grating term.
    """
    grating = np.zeros((nx, ny), dtype=np.complex64)
    if axis == 'x':
        grating[::every, :] = np.exp(1j*add)
    if axis == 'y':
        grating[:, ::every] = np.exp(1j*add)
    if axis == 'xy':
        checker = np.indices((nx, ny)).sum(axis=0) % every
        checker += 1
        checker = checker % 2
        grating = np.exp(1j*checker*add)
    return grating

See also