Extension modules

This part of the documentation covers ltapy’s extension modules. This auxiliary functionality should simplify the programmatic access to LightTools.

Apodization

This module provides objects for dealing with source apodization.

class ltapy.apodization.CylinderGridMesh(values, bounds)

Container object for interacting with cylinder grid mesh data.

Store the grid mesh data required for cylinder apodization and enable data export to various file formats.

Parameters:
  • values (numpy.ndarray) – Data values of the cylinder grid mesh given as two-dimensional array.
  • bounds (tuple of floats) – Radial and linear data set bounds given as (rmin, rmax, lmin, lmax).
values

numpy.ndarray – Data values of the cylinder grid mesh.

bounds

tuple of floats – Radial and linear data set bounds.

dim

tuple of ints – Dimensions of the data set as (n, m) tuple, where n is the number of columns and m is the number of rows.

Examples

Create a CylinderGridMesh object from two-dimensional mesh data and data bounds:

>>> import numpy as np
>>> values = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
>>> bounds = (-1.0, -0.5, 1.0, 0.5)
>>> cgmesh = CylinderGridMesh(values, bounds)
>>> cgmesh.values
array([[ 1.,  2.,  3.],
       [ 4.,  5.,  6.]])
>>> cgmesh.bounds
(-1.0, -0.5, 1.0, 0.5)
>>> cgmesh.dim
(3, 2)

Write the grid mesh data to a cylinder apodization file:

>>> cgmesh.write("cylinder_apodization.txt")
to_csv(filepath, sort=False)

Write cylinder grid mesh data to a comma-separated values (CSV) file.

Each line in the 3-column CSV file corresponds to a specific data value, with the radial and linear coordinates of the mesh grid midpoint in the first two columns and the data value itself in the third column.

Parameters:
  • filepath (str) – Filepath of the CSV file.
  • sort (bool, optional) – Numerically sort CSV file values along rows if sort is True.
write(filepath, comment=None)

Write grid mesh data to an apodization file.

Parameters:
  • filepath (str) – Filepath of the apodization file.
  • comment (str, optional) – Additional comment that appears at the beginning of the apodization file.
class ltapy.apodization.SurfaceGridMesh(values, bounds=None)

Container object for interacting with surface grid mesh data.

Store the grid mesh data required for surface apodization and enable data export to various file formats.

Parameters:
  • values (numpy.ndarray) – Data values of the surface grid mesh given as two-dimensional array.
  • bounds (tuple of floats, optional) – Spatial or angular data set bounds given as (umin, vmin, umax, vmax).
values

numpy.ndarray – Data values of the surface grid mesh.

bounds

tuple of floats – Spatial or angular data set bounds.

dim

tuple of ints – Dimensions of the data set as (n, m) tuple, where n is the number of columns and m is the number of rows.

Examples

Create a SurfaceGridMesh object from two-dimensional mesh data and (optional) data bounds:

>>> import numpy as np
>>> values = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
>>> bounds = (-1.0, -0.5, 1.0, 0.5)
>>> sgmesh = SurfaceGridMesh(values, bounds)
>>> sgmesh.values
array([[ 1.,  2.,  3.],
       [ 4.,  5.,  6.]])
>>> sgmesh.bounds
(-1.0, -0.5, 1.0, 0.5)
>>> sgmesh.dim
(3, 2)

Write the grid mesh data to a surface apodization file:

>>> sgmesh.write("surface_apodization.txt")
to_csv(filepath, sort=False, ascending=False)

Write surface grid mesh data to a comma-separated values (CSV) file.

Each line in the 3-column CSV file corresponds to a specific data value, with the xy-coordinates of the mesh grid midpoint in the first two columns and the data value itself in the third column.

Data bounds must be specified because they are required for the calculation of the mesh grid midponts.

Parameters:
  • filepath (str) – Filepath of the CSV file.
  • sort (bool, optional) – Numerically sort CSV file values along rows if sort is True.
  • ascending (bool, optional) – The minimum value of V (vmin) is in the first row if ascending is True. Refer to the LightTools Help (Section: Apodization Data Bounds) for an explanation how bounds are mapped to the data values.
Raises:

ValueError – If no data bounds are specified.

write(filepath, comment=None)

Write grid mesh data to an apodization file.

Parameters:
  • filepath (str) – Filepath of the apodization file.
  • comment (str, optional) – Additional comment that appears at the beginning of the apodization file.
class ltapy.apodization.VolumeGridMesh(values, bounds)

Container object for interacting with volume grid mesh data.

Store the grid mesh data required for volume apodization and enable data export to various file formats.

Parameters:
  • values (numpy.ndarray) – Data values of the volume grid mesh given as three-dimensional array.
  • bounds (tuple of floats) – Cartesian data set bounds in XYZ direction given as (xmin, xmax, ymin, ymax, zmin, zmax).
values

numpy.ndarray – Data values of the volume grid mesh.

bounds

tuple of floats – Cartesian data set bounds in XYZ direction.

dim

tuple of ints – Dimensions of the data set as (n, m, p) tuple, where n is the number of columns, m is the number of rows and p is the number of layers (xy matrices).

Examples

Create a VolumeGridMesh object from three-dimensional mesh data and data bounds:

>>> import numpy as np
>>> values = np.array([
        [[1, 0, 7], [2, 1, 6], [4, 5 ,1], [1, 1, 6]],
        [[4, 5, 1], [1, 2, 3], [2, 2, 2], [1, 2, 3]],
    ])
>>> bounds = (-1.5, 1.5, -2.0, 2.0, 0, 5)
>>> vgmesh = VolumeGridMesh(values, bounds)
>>> vgmesh.values
array([[[1, 0, 7],
        [2, 1, 6],
        [4, 5, 1],
        [1, 1, 6]],
       [[4, 5, 1],
        [1, 2, 3],
        [2, 2, 2],
        [1, 2, 3]]])
>>> vgmesh.bounds
(-1.5, 1.5, -2.0, 2.0, 0, 5)
>>> vgmesh.dim
(3, 4, 2)

Write the grid mesh data to a volume apodization file:

>>> vgmesh.write("volume_apodization.txt")
to_csv(filepath, sort=False)

Write volume grid mesh data to a comma-separated values (CSV) file.

Each line in the 4-column CSV file corresponds to a specific data value, with the xyz-coordinates of the mesh grid midpoint in the first three columns and the data value itself in the fourth column.

Parameters:
  • filepath (str) – Filepath of the CSV file.
  • sort (bool, optional) – Numerically sort CSV file values along rows if sort is True.
write(filepath, comment=None)

Write grid mesh data to an apodization file.

Parameters:
  • filepath (str) – Filepath of the apodization file.
  • comment (str, optional) – Additional comment that appears at the beginning of the apodization file.
ltapy.apodization.read_cgmesh(filepath)

Read a cylinder apodization file into a CylinderGridMesh object.

Parameters:filepath (str) – Filepath of the cylinder apodization file.
Returns:
A container object for interacting with the
cylinder grid mesh data.
Return type:CylinderGridMesh
ltapy.apodization.read_sgmesh(filepath)

Read a surface apodization file into a SurfaceGridMesh object.

Parameters:filepath (str) – Filepath of the surface apodization file.
Returns:
A container object for interacting with the
surface grid mesh data.
Return type:SurfaceGridMesh
ltapy.apodization.read_vgmesh(filepath)

Read a volume apodization file into a VolumeGridMesh object.

Parameters:filepath (str) – Filepath of the volume apodization file.
Returns:
A container object for interacting with the volume
grid mesh data.
Return type:VolumeGridMesh

Utils

This module provides utility functions, useful for external consumption.

ltapy.utils.binspace(num, start, stop)

Return evenly spaced bin midpoints over the given interval.

Calculate num evenly spaced bin midpoints over the closed interval [start, stop].

Parameters:
  • num (int) – Number of bin midpoints to generate. Must be positive.
  • start (float) – The starting value of the interval.
  • stop (float) – The end value of the interval.
Returns:

num equally spaced bin midpoints in the interval

[start, stop].

Return type:

numpy.ndarray

Examples

>>> bins = binspace(11, -1, 1)
>>> bins
array([ -9.09090909e-01,  -7.27272727e-01,  -5.45454545e-01,
        -3.63636364e-01,  -1.81818182e-01,   8.32667268e-17,
         1.81818182e-01,   3.63636364e-01,   5.45454545e-01,
         7.27272727e-01,   9.09090909e-01])
ltapy.utils.get_current_file_folder(lt)

Return the folder of the current LightTools file.

Parameters:ltapi (ILTAPIx) – A handle to the LightTools session.
Returns:The file folder of the current LightTools file.
Return type:str