Coverage for python/lsst/images/tests/_creation.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-24 01:50 -0700

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. 

11 

12from __future__ import annotations 

13 

14__all__ = ("make_random_sky_projection",) 

15 

16 

17import astropy.units as u 

18import astropy.wcs.wcsapi 

19import numpy as np 

20 

21from .._geom import Box 

22from .._transforms import Frame, SkyProjection 

23 

24 

25def make_random_sky_projection[F: Frame]( 

26 rng: np.random.Generator, pixel_frame: F, bbox: Box 

27) -> SkyProjection[F]: 

28 """Create a test sky_projection with random parameters. 

29 

30 Parameters 

31 ---------- 

32 rng 

33 Random number generator. 

34 pixel_frame 

35 Coordinate frame for the pixel grid. 

36 bbox 

37 Bounding box for the pixel grid. 

38 

39 Returns 

40 ------- 

41 `.SkyProjection` 

42 A projection. Guaranteed to be FITS-representable and have no FITS 

43 approximation attached. 

44 """ 

45 header = { 

46 "CTYPE1": "RA---TAN", 

47 "CTYPE2": "DEC--TAN", 

48 "CRPIX1": rng.uniform(low=1, high=bbox.x.size), 

49 "CRPIX2": rng.uniform(low=1, high=bbox.y.size), 

50 "CRVAL1": rng.uniform(low=0.0, high=2 * np.pi), 

51 "CRVAL2": rng.uniform(low=-np.pi, high=np.pi), 

52 "CDELT1": (rng.uniform(low=0.18, high=0.22) * u.arcsec).to_value(u.deg), 

53 "CDELT2": (rng.uniform(low=0.18, high=0.22) * u.arcsec).to_value(u.deg), 

54 "CROTA1": rng.uniform(low=0.0, high=2 * np.pi), 

55 } 

56 fits_wcs = astropy.wcs.WCS(header) 

57 return SkyProjection.from_fits_wcs( 

58 fits_wcs, pixel_frame, pixel_bounds=bbox, x0=bbox.x.start, y0=bbox.y.start 

59 )