Coverage for python / lsst / images / tests / _creation.py: 73%
11 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-25 08:35 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-25 08:35 +0000
1# This file is part of lsst-images.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
12from __future__ import annotations
14__all__ = ("make_random_projection",)
17import astropy.units as u
18import astropy.wcs.wcsapi
19import numpy as np
21from .._geom import Box
22from .._transforms import Frame, Projection
25def make_random_projection[F: Frame](rng: np.random.Generator, pixel_frame: F, bbox: Box) -> Projection[F]:
26 """Create a test projection with random parameters.
28 Parameters
29 ----------
30 rng
31 Random number generator.
32 pixel_frame
33 Coordinate frame for the pixel grid.
34 bbox
35 Bounding box for the pixel grid.
37 Returns
38 -------
39 `.Projection`
40 A projection. Guaranteed to be FITS-representable and have no FITS
41 approximation attached.
42 """
43 header = {
44 "CTYPE1": "RA---TAN",
45 "CTYPE2": "DEC--TAN",
46 "CRPIX1": rng.uniform(low=1, high=bbox.x.size),
47 "CRPIX2": rng.uniform(low=1, high=bbox.y.size),
48 "CRVAL1": rng.uniform(low=0.0, high=2 * np.pi),
49 "CRVAL2": rng.uniform(low=-np.pi, high=np.pi),
50 "CDELT1": (rng.uniform(low=0.18, high=0.22) * u.arcsec).to_value(u.deg),
51 "CDELT2": (rng.uniform(low=0.18, high=0.22) * u.arcsec).to_value(u.deg),
52 "CROTA1": rng.uniform(low=0.0, high=2 * np.pi),
53 }
54 fits_wcs = astropy.wcs.WCS(header)
55 return Projection.from_fits_wcs(
56 fits_wcs, pixel_frame, pixel_bounds=bbox, x0=bbox.x.start, y0=bbox.y.start
57 )