API Reference
AbstractSimulation
tiptop.AbstractSimulation is the abstract base class from which all TipTop simulation backends are derived (since v1.5.1). It implements the core simulation lifecycle using the Template Method pattern: shared logic (configuration loading, FITS output, metrics, 1D PSF profiles) lives in AbstractSimulation, while backend-specific physics is delegated to subclasses via abstract methods.
baseSimulation (the standard P3-based backend) is a concrete subclass of AbstractSimulation. Custom backends such as TipTorch or AOPERA can be built by subclassing AbstractSimulation and implementing the required abstract methods.
Abstract methods to implement
| Method | Description |
|---|---|
_configure_LO_parameters(astIndex) | Configure asterism geometry and LO matrices if LO is active. |
_prepare_static_PSF_state(astIndex) | Initialise the backend model and cache geometry. |
_compute_LO_terms(astIndex) → dict | Compute Low Order terms; return a dict with keys HO_res, LO_res, GF_res, GFinPSD. |
_generate_final_PSF(astIndex, lo_data) | Generate final PSFs; must populate self.cubeResultsArray. |
_finalize_full_field_results(astIndex) | Compute OL and DL reference PSFs; must populate self.psf_ol_array and self.psf_dl_array, then call self.computePSF1D(). |
computeMetrics() | Compute SR, FWHM and EE; must populate self.sr, self.fwhm, self.ee. |
_plot_final_PSFs() | Handle backend-specific rendering (called if self.doPlot is True). |
Concrete methods available to all subclasses
loadConfigurationFile()— loads.inior.ymlparameter files intoself.my_data_mapdoOverallSimulation(astIndex)— orchestrates the full simulation lifecyclecomputePSF1D()— computes radial PSF profiles fromself.cubeResultsArraysavePSFprofileJSON()— serialises PSF profiles to JSONsaveResults()— writes the standard FITS output
baseSimulation
tiptop.baseSimulation is the standard concrete simulation class. It subclasses AbstractSimulation and uses P3 as the HO backend and MASTSEL as the LO backend. This is the class to instantiate when you need direct access to simulation results — for parameter sweeps, custom post-processing, or any workflow where you want to inspect internal state rather than just write a FITS file.
baseSimulation vs overallSimulationUse overallSimulation for a simple one-shot simulation that writes a FITS file.
Use baseSimulation directly when you need access to the PSF arrays, metrics, or want to run multiple simulations in memory without file I/O.
from tiptop.tiptop import baseSimulation
sim = baseSimulation(path, parametersFile, outputDir, outputFile,
doConvolve=True, doPlot=False, addSrAndFwhm=True,
verbose=False, getHoErrorBreakDown=False,
savePSDs=False, ensquaredEnergy=False, eeRadiusInMas=50,
exactMultiWavelengthPSD=False)
Constructor parameters:
- path (str, required) — Path to the folder containing the parameter file.
- parametersFile (str, required) — Name of the parameter file without the extension.
- outputDir (str, required) — Path to the folder in which to write the output.
- outputFile (str, required) — Prefix for output files.
- doConvolve (bool, optional, default:
True) — IfTrue, uses the natural convolution operation. - doPlot (bool, optional, default:
False) — IfTrue, displays PSFs after the simulation. - addSrAndFwhm (bool, optional, default:
True) — Adds SR and FWHM to the FITS header. - verbose (bool, optional, default:
False) — IfTrue, prints all messages. - getHoErrorBreakDown (bool, optional, default:
False) — IfTrue, computes HO error breakdown. - savePSDs (bool, optional, default:
False) — IfTrue, saves the PSD in the output FITS file. - ensquaredEnergy (bool, optional, default:
False) — IfTrue, computes ensquared energy instead of encircled energy. - eeRadiusInMas (float, optional, default:
50) — Radius in mas for the encircled/ensquared energy computation. - exactMultiWavelengthPSD (bool, optional, default:
False) — One exact PSD grid per science wavelength (seeoverallSimulation). Since TipTop v1.6.0.
Key methods
| Method | Description |
|---|---|
doOverallSimulation(astIndex=None) | Runs the full simulation lifecycle. Call this after instantiation. |
computeMetrics() | Computes SR, FWHM and EE from cubeResultsArray. Must be called explicitly when using baseSimulation directly. |
saveResults() | Writes the standard FITS output to outputDir/outputFile.fits. |
loadConfigurationFile() | Reloads the configuration file into my_data_map. |
Key attributes
Populated after doOverallSimulation():
| Attribute | Type | Description |
|---|---|---|
my_data_map | dict | The full configuration dictionary. Can be modified between simulation calls for in-memory parameter sweeps. |
cubeResultsArray | ndarray | AO-corrected PSF cube. Shape: (Nwvl, Nsrc, N, N) for multi-wavelength or (Nsrc, N, N) for monochromatic. |
psf_ol_array | ndarray | Open-loop (seeing-limited) PSF. 2D numpy array — no conversion needed. |
psf_dl_array | ndarray | Diffraction-limited PSF. 2D numpy array — no conversion needed. |
psf1d_data | ndarray | 1D radial profiles of the PSFs. |
LOisOn | bool | True if a [sensor_LO] section is present in the configuration. |
Populated after computeMetrics():
| Attribute | Type | Description |
|---|---|---|
sr | list | Strehl ratio for each science source. |
fwhm | list | FWHM in mas for each science source. |
ee | list | Encircled (or ensquared) energy within eeRadiusInMas for each science source. |
📍 OverallSimulation function documentation
tiptop.overallSimulation runs a complete TipTop simulation based on an input parameter file.
The function accepts several optional arguments to enable or disable specific features and select desired outputs.
tiptop.overallSimulation(path2param, parametersFile, outputDir, outputFile, doConvolve=True, doPlot=False, returnRes=False, returnMetrics=False, addSrAndFwhm=True, verbose=False, getHoErrorBreakDown=False, ensquaredEnergy=False, eeRadiusInMas=50, savePSDs=False, saveJson=False, gpuIndex=0,
exactMultiWavelengthPSD=False)
Parameters:
-
path2param (str, required) — Path to the folder containing the parameter file.
-
parametersFile (str, required) — Name of the parameter file without the extension.
-
outputDir (str, required) — Path to the folder in which to write the output.
-
outputFile (str, required) — Prefix for output files (
.fits,.json) when saving. -
doConvolve (bool, optional, default:
True) — IfTrue, uses the natural convolution operation. -
doPlot (bool, optional, default:
False) — IfTrue, displays the result in Python after the simulation. -
verbose (bool, optional, default:
False) — IfTrue, prints all messages. -
returnRes (bool, optional, default:
False) — IfTrue, returns the HO residual (and LO residual if applicable) in nm RMS. No FITS file is written. -
returnMetrics (bool, optional, default:
False) — IfTrue, returns Strehl Ratio, FWHM, and encircled energy withineeRadiusInMas. No FITS file is written. -
addSrAndFwhm (bool, optional, default:
True) — Adds SR, FWHM, and EE withineeRadiusInMasto the FITS header for each PSF. -
getHoErrorBreakDown (bool, optional, default:
False) — IfTrue, computes HO error breakdown (verbosemust also beTrue). -
ensquaredEnergy (bool, optional, default:
False) — IfTrue, computes ensquared energy instead of encircled energy. -
eeRadiusInMas (float, optional, default:
50) — Radius in mas for the encircled energy computation (ifensquaredEnergy=True, this is half the side of the square). -
savePSDs (bool, optional, default:
False) — IfTrue, saves the PSD in the output FITS file. -
saveJson (bool, optional, default:
False) — IfTrue, saves the PSF radial profile in a JSON file. -
gpuIndex (int, optional, default:
0) — Target GPU device index. -
exactMultiWavelengthPSD (bool, optional, default:
False) — With more than one science wavelength, computes one exact PSD grid per wavelength, so that each PSF is identical to a single-wavelength run. IfFalse, all wavelengths share one approximate grid. Memory and computing time grow roughly with the number of wavelengths, since the HO PSD (reconstructor and controller included) is computed once per wavelength. Since TipTop v1.6.0.
⚠️ Note: If returnMetrics=True or returnRes=True, no FITS file is written.
Returns:
The return value depends on which flags are set:
| Condition | Returns |
|---|---|
returnRes=True, LO active | (HO_res, LO_res) — tuple of two numpy arrays (HO and LO residual wavefront errors) |
returnRes=True, LO inactive | HO_res — numpy array (HO residual wavefront error) |
returnMetrics=True | (sr, fwhm, ee) — three numpy arrays: Strehl ratio, FWHM in mas, encircled energy |
| default | None — results are saved to disk as a .fits file |
📍 gpuSelect
tiptop.tiptop.gpuSelect selects the GPU used by P3 and MASTSEL. It has no effect if neither package runs on the GPU. overallSimulation and the asterism-selection functions call it for you through their gpuIndex argument.
from tiptop.tiptop import gpuSelect
gpuSelect(1) # use the second GPU
- gpuIndex (int, required) — GPU index. If it is larger than the last available index, a warning is printed and the current device is kept.
To run P3 or MASTSEL on the CPU, see Choosing CPU or GPU for each package.
📍 Asterism selection functions
These functions are documented in detail in the Asterism selection section:
| Function | Purpose | Documentation |
|---|---|---|
asterismSelection | Evaluate the NGS asterisms of the [ASTERISM_SELECTION] section (requires a LO loop). | Running selections |
hoAsterismSelection | Evaluate HO asterisms of the [HO_ASTERISM_SELECTION] section, with P3 only (no LO). | Running selections |
reloadAsterismSelection | Reload the .npy results of a previous asterismSelection run. | Running selections |
generateHeuristicModel | Run asterismSelection, then fit (and optionally test) a heuristic model of the asterism metrics. | Heuristic models |
📍 Atmospheric profiles
The module tiptop.atmoProfile (since v1.6.0) generates parametric Cn² profiles for a given isoplanatic angle θ₀ and/or ground-layer fraction: generateProfile, logGrid, layerWind, theta0FromProfile, seeingToR0, r0ToSeeing.
See the dedicated page: Atmospheric profiles.