mascado.utility.zemax module

Helpers for Zemax files.

mascado.utility.zemax.distortions_on_sky(cats, platescale=None, scale=1)[source]

Get distortions and normalized positions on-sky.

By default, an affine transform is used for the transformation from focal plane to sky. The affine transform is the least-squares solution for the first catalog and the same trafo is applied to all catalogs, so that a drift in linear terms is conserved. If platescale is passed, no affine transform, but a fixed scale is used.

Normalized positions are calculated by shifting and scaling the position catalog into the domain \([-1, 1]\times[-1, 1]\).

Parameters:
  • cats (list of pandas.DataFrame) – Catalogs as described by doc of load_grid_data().
  • platescale (float or None) – Optional fixed plate scale in arcseconds per mm.
  • scale (float) – Additional, dimensionless scale apply applied to every position.
Returns:

  • atrafo ((3, 3)-shaped array) – Affine transformation applied to translate from focal plane (real coordinates) to sky (field coordinates).
  • posnormscale (float) – Scale in arcsecond for normalized positions.
  • positions ((N, 2)-shaped array) – Dimensionless, normalized positions.
  • distortions (list of (N, 2)-shaped arrays) – Distortions of each catalog in arcseconds.

Raises:

ValueError – If not all catalogs have the same reference grid (field coordinates).

mascado.utility.zemax.have_same_grid(cats)[source]

Check if all grid catalogs have the same grid in field coordinates.

Parameters:cats (list of pandas.DataFrame) – Catalogs as described by doc of load_grid_data().
Returns:
Return type:bool
mascado.utility.zemax.load_grid_data(fname, encoding='latin1', footer=7, nonsquareokay=False)[source]

Load Zemax Grid Distortion Data from file.

Parameters:
  • fname (string) – File name.
  • encoding (string) – File encoding, defaults to latin1.
  • footer (int) – Number of non-empty lines that are not data rows at the end of the file
  • nonsquareokay (bool) – Set to True to avoid exception if the number of points in the data set is not a square number.
Returns:

DataFrame with 9 columns: i, j, x-field (degree), y-field (degrees), r-field (degrees), x-predicted (mm), y-predicted (mm), x-real (mm), y-real (mm).

Return type:

pandas.DataFrame

Raises:

ValueError – If the number of points is not a square number and nonsquareokay is False.

mascado.utility.zemax.load_grid_data_B(fname, encoding='latin1', nonsquareokay=False)[source]
Parameters:
  • fname (string) – File name.
  • encoding (string) – File encoding, defaults to latin1.
  • nonsquareokay (bol) – Complain if the number of points in the data set is not a square number.
Returns:

DataFrame with 5 columns: n (running number), x-field (degree), y-field (degree), x-real (mm), y-real (mm).

Return type:

pandas.DataFrame

Raises:

ValueError – If the number of points is not a square number and nonsquareokay is False.

mascado.utility.zemax.load_grid_data_C(fname, encoding='latin1', nonsquareokay=False)[source]
Parameters:
  • fname (string) – File name.
  • encoding (string) – File encoding, defaults to latin1.
  • nonsquareokay (bol) – Complain if the number of points in the data set is not a square number.
Returns:

DataFrame with 6 columns: x-field (degree), y-field (degree), x-predicted (degree), y-predicted (degree). x-real (mm), y-real (mm).

Return type:

pandas.DataFrame

Raises:

ValueError – If the number of points is not a square number and nonsquareokay is False.

mascado.utility.zemax.load_grid_data_variant(variantkey, fname, **kwargs)[source]

Load distortion data from files in various formats.

Scripts and macros in Zemax produce different outputs that may be added here as input format variants for convenience. Different variants are enumerated by upper case letters, where A is the default Zemax Grid Distortion export file.

Parameters:
  • variantkey (str) – Upper case letter denoting format variant.
  • fname (str) – Path to input file.
  • kwargs (keyword arguments) – Additional arguments for format loaders.
Returns:

Which should have at least the columns: x-field (degree), y-field (degree), x-real (mm), y-real (mm). Check variant loader documentations.

Return type:

pandas.DataFrame