Batch Generation¶
Tools for designing WFE budgets and generating large PSF datasets (e.g. for ML training).
build_wfe_budget¶
from psfcraft.utils import build_wfe_budget
Converts a radial WFE budget into a flat list used by generate_coefficients.
Each entry budget[i] is repeated i+1 times, reflecting the increasing number of
Zernike modes per radial order:
| Radial order | # modes | Typical budget (nm) |
|---|---|---|
| 0 (piston) | 1 | 0 |
| 1 (tip/tilt) | 2 | 100 |
| 2 (defocus, astig) | 3 | 50 |
| 3 (coma, trefoil) | 4 | 36 |
| 4 | 5 | 18 |
from psfcraft.utils import build_wfe_budget
budget = build_wfe_budget([0, 100, 50, 36, 18, 9, 5])
print(budget)
# [0, 100, 100, 50, 50, 50, 36, 36, 36, 36, ...]
build_wfe_budget ¶
build_wfe_budget(radial_budget: list = [0, 100, 50, 36, 18, 9, 5]) -> list
Build a flat WFE budget list from a per-radial-order specification.
Each entry radial_budget[i] is repeated i + 1 times to account for
the increasing number of Zernike modes per radial order (order 0 has 1
mode, order 1 has 2 modes, etc.).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Example
build_wfe_budget([0, 100, 50]) [0, 100, 100, 50, 50, 50]
Source code in psfcraft/utils.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
generate_coefficients¶
from psfcraft.utils import generate_coefficients
Draws a random Zernike coefficient vector respecting a given WFE budget.
from psfcraft.utils import build_wfe_budget, generate_coefficients
import numpy as np
budget = build_wfe_budget([0, 100, 50, 36, 18, 9, 5])
rng = np.random.default_rng(42)
# Generate one random coefficient set
coefs = generate_coefficients(budget, rng=rng)
print(coefs) # array in metres RMS, length = len(budget)
generate_coefficients ¶
generate_coefficients(wfe_budget, sec_factor: float = 1.0) -> np.ndarray
Draw a random realisation of Zernike coefficients from a uniform distribution.
Each coefficient is drawn independently from a uniform distribution
over [-budget_i * sec_factor, +budget_i * sec_factor]
(converted from nm to metres internally).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Example
import numpy as np np.random.seed(0) budget = build_wfe_budget([0, 50, 30]) # 6 coefficients coefs = generate_coefficients(budget) coefs.shape (6,)
Source code in psfcraft/utils.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
PSF_Generator¶
High-level batch generation engine. Handles parallelism, FITS output, and HDF5 dataset writing.
from psfcraft.utils import PSF_Generator
gen = PSF_Generator(
optics_name="NewtonianTelescope",
optics_version="1_3",
size_psf=32,
)
gen.run(n_psfs=1000, output_path="dataset.h5")
PSF_Generator ¶
PSF_Generator(optics_name=OPTICS_NAME_DEFAULT, optics_version=OPTICS_VERSION_DEFAULT, optics_primary_radius=OPTICS_PRIMARY_RADIUS, optics_secondary_radius=OPTICS_SECONDARY_RADIUS, size_psf=SIZE_PSF, N_psfs=N_PSFS, wfe_budget=WFE_BUDGET, source=SOURCE_DEFAULT, detector_oversampling=DETECTOR_OVERSAMPLING, fov_arcsec=FOV_ARCSEC)
This class generates a database of Point Spread Functions (PSFs) for optical systems.
Parameters¶
optics_name : str, optional Name of the optical system. Defaults to 'NewtonianTelescope'. Options: 'Euclid'. optics_version : str, optional Version of the optical system. Defaults to '0', indicating no struts. size_psf : int, optional Size of the PSFs in pixels. Defaults to 32. N_psfs : int, optional Total number of PSFs to generate for the dataset. Defaults to 1000. wfe_budget : list, optional List of the Wavefront Error (WFE) budget for each Zernike coefficient. source : float or list, optional Wavelength of the monochromatic source in nanometers or a list specifying the type of random spectral source.
Attributes¶
OPTICS_NAME_DEFAULT : str Default name of the optical system. OPTICS_VERSION_DEFAULT : str Default version of the optical system. ...
Methods¶
init(optics_name, optics_version, size_psf, N_psfs, wfe_budget, source, ) Initializes the PSF_Generator with specified parameters. optical_system_initiator() Initiates the optical system using psfcraft_core. simulate_single_psf(wfe_budget, source) Simulates a single PSF. simulate_worst_psf() Returns the PSF with maximum coefficients. write_database_hdf5() Writes the generated PSFs to an HDF5 file.
Source code in psfcraft/utils.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
filename_builder ¶
filename_builder(extension)
Builds the filename of the PSFs, containing all the parameters AND the extension. Should be called inside each method that writes a file.
Source code in psfcraft/utils.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
get_custom_fov ¶
get_custom_fov()
Pickle-safe method to return custom FOV
Source code in psfcraft/utils.py
334 335 336 | |
simulate_worst_psf ¶
simulate_worst_psf()
Returns the PSF with all maximum coefficients.
Source code in psfcraft/utils.py
450 451 452 453 454 455 | |