Limber API Documentation

Submodules

smug.limber_adapter module

class smug.limber_adapter.LimberAdapter(model, line_grid, dev=None)[source]

Bases: object

Prepare some data and run a Limber model on it.

Parameters
  • model (LimberModel) – The model to use (see limber_model.pretrained_limber

  • line_grid (array-like) – The wavelength grid used in the model.

  • dev (torch.device on which to run the model, optional) – The device to use (default: gpu if available, otherwise cpu).

reproject_data(image, wavelength, mu_observed, interp=None, batch_size=1024, reconstruct_original_shape=False, cpu=True)[source]

Use the limber model to reproject data from the provided viewing angle back to mu=1.

Parameters
  • image (array-like) – The image to rotate, expected axes [wavelength, y, x].

  • wavelength (array-like or astropy.Quantity) – The wavelength axis for the image. Will be converted to Angstrom if astropy.Quantity, otherwise assumed to be in Angstrom.

  • mu_observed (float) – The cosine of the viewing angle of the observation.

  • interp (Callable[[array-like, array-like, array-like], array-like], optional) – The interpolation function to use for up/downsampling the line profiles. Takes the same signature as np.interp (default: weno4).

  • batch_size (int, optional) – The batch size to use (default: 1024).

  • reconstruct_original_shape (bool, optional) – Whether to return data in the original shape [original_wavelengths, y, x]. or the internal shape used for the network [y, x, interpolated_wavelengths] (default: False).

  • cpu (bool, optional) – Whether to return the data to the CPU (default: True), can be useful to keep the data on GPU (as a torch.Tensor) if it’s to be used at later stages of a pipeline. reconstruct_original_shape can only be set if cpu is True. If true, result is returned as a np.array.

Returns

data – Three-dimensional array of the reconstructed data, the axis order of which depends on the result of reconstruct_original_shape and cpu. If cpu is False, a torch.Tensor will be returned.

Return type

array

smug.limber_model module

class smug.limber_model.LimberNet(in_size)[source]

Bases: Module

The class describing the Limber neural network.

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

smug.limber_model.pretrained_limber(line, map_location=None)[source]

Load a pretrained Limber model. The weights will be cached as described by torch.hub. See their documentation for details.

Parameters
  • line (str) – The spectral line variant of the model to load. (e.g. “Halpha” or “CaII8542”)

  • map_location (torch.device, optional) – Where to remap arrays during the loading process, by default this is set to “CPU” to allow loading on any platform.