scopesim.effects.spectral_trace_list_utils module

This module contains
  • the definition of the SpectralTrace class.

  • the definition of the XiLamImage class

  • utility functions for use with spectral traces

class scopesim.effects.spectral_trace_list_utils.SpectralTrace(trace_tbl, **kwargs)[source]

Bases: object

Definition of one spectral trace

A SpectralTrace describes the mapping of spectral slit coordinates to the focal plane. The class reads an order layout and fits several functions to describe the geometry of the trace.

Slit coordinates are: - xi : spatial position along the slit [arcsec] - lam : Wavelength [um] Focal plane coordinates are: - x, y : [mm]

compute_interpolation_functions()[source]

Compute various interpolation functions between slit and focal plane

footprint(wave_min=None, wave_max=None, xi_min=None, xi_max=None)[source]

Return corners of rectangle enclosing spectral trace

Parameters:
wave_min, wave_maxfloat [um], Quantity

Minimum and maximum wavelength to compute the footprint on. If None, use the full range that the spectral trace is defined on. Float values are interpreted as microns.

xi_min, xi_maxfloat [arcsec], Quantity

Minimum and maximum slit position on the sky. If None, use the full range that the spectral trace is defined on. Float values are interpreted as arcsec.

fov_grid()[source]

Provide information on the source space volume required by the effect

Returns:
A dictionary with entries wave_min and wave_max.
Spatial limits are determined by the ApertureMask effect
and are not returned here.
map_spectra_to_focal_plane(fov)[source]

Apply the spectral trace mapping to a spectral cube

The cube is contained in a FieldOfView object, which also has world coordinate systems for the Source (sky coordinates and wavelengths) and for the focal plane. The method returns a section of the fov image along with info on where this image lies in the focal plane.

plot(wave_min=None, wave_max=None, c='r')[source]

Plot control points of the SpectralTrace

class scopesim.effects.spectral_trace_list_utils.Transform2D(matrix, pretransform_x=None, pretransform_y=None, posttransform=None)[source]

Bases: object

2-dimensional polynomial transform

The class is instantiated from a m x n matrix A that contains the coefficients of the polynomial. Along rows, the power of x increases; along columns, the power of y increases, such that A[j, i] is the coefficient of x^i y^j.

The functions pretransform_x and pretransform_y can be used to transform the input variables before the matrix is applied. The function posttransform can be applied to the output after application of the matrix.

In Scopesim, a usecase for the pre- and post-transform functions is the METIS LMS, where the matrices are applied to phases while Scopesim operates on wavelengths. The functions to pass are lam2phase and phase2lam.

Parameters:
matrixnp.array

matrix of polynomial coefficients

pretransform_xfunction, tuple
pretransform_yfunction, tuple

If not None, the function is applied to the input variable x or y before the actual 2D transform is computed

posttransformfunction, tuple

If not None, the function is applied to the output variable after the 2D transform is computed

When passed as a tuple, the first element is the function itself,
the second element is a dictionary of arguments to the function.
Example:
```
def rescale(x, scale=1.):

return x * scale

pretransform_x = (rescale, {“scale”: 0.5})
```
classmethod fit(xin, yin, xout, degree=4)[source]

Determine polynomial fits

gradient()[source]

Compute the gradient of a 2d polynomial transformation

class scopesim.effects.spectral_trace_list_utils.XiLamImage(fov, dlam_per_pix)[source]

Bases: object

Class to compute a rectified 2D spectrum

The class produces and holds an image of xi (relative position along the spatial slit direction) and wavelength lambda.

scopesim.effects.spectral_trace_list_utils.fill_zeros(x)[source]

Fills in zeros in a sequence with the previous non-zero number

scopesim.effects.spectral_trace_list_utils.fit2matrix(fit)[source]

Return coefficients from a polynomial fit as a matrix

The Polynomial2D fits of degree n have coefficients for all i, j with i + j <= n. How would one rearrange those?

scopesim.effects.spectral_trace_list_utils.get_affine_parameters(coords)[source]

Returns rotation and shear for each MTC point along a SpectralTrace

Parameters:
coordsdict of 2D arrays

Each dict entry [“x”, “y”, “s”] contains a [N, M] 2D array of coordinates, where:

  • N is the number of points along the slit (e.g. ~5), and

  • M is the number of positions along the trace (e.g. >100)

Returns:
rotationsarray

[deg] Rotation angles for M positions along the Trace

shearsarray

[deg] Shear angles for M positions along the Trace

scopesim.effects.spectral_trace_list_utils.rolling_median(x, n)[source]

Calculates the rolling median of a sequence for +/- n entries

scopesim.effects.spectral_trace_list_utils.xilam2xy_fit(layout, params)[source]

Determine polynomial fits of FPA position

Fits are of degree 4 as a function of slit position and wavelength.

scopesim.effects.spectral_trace_list_utils.xy2xilam_fit(layout, params)[source]

Determine polynomial fits of wavelength/slit position

Fits are of degree 4 as a function of focal plane position