Coverage for tests/test_ndf_starlink_ingest.py: 94%

36 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-16 15:24 -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 

14import os 

15 

16import numpy as np 

17import pytest 

18 

19from lsst.images import Image 

20from lsst.images.fits._common import ExtensionKey 

21 

22try: 

23 from lsst.images.ndf import read_starlink 

24 

25 HAVE_H5PY = True 

26except ImportError: 

27 HAVE_H5PY = False 

28 

29skip_np_h5py = pytest.mark.skipif(not HAVE_H5PY, reason="h5py is not installed") 

30 

31 

32# Starlink-generated NDF fixture (M57 image, hds-v5 HDF5). 

33EXAMPLE = os.path.join(os.path.dirname(__file__), "data", "example-ndf.sdf") 

34 

35 

36@skip_np_h5py 

37def test_round_trips_to_image() -> None: 

38 """Verify the auto-detect path returns an Image with the correct 

39 array shape. 

40 """ 

41 result = read_starlink(Image, EXAMPLE) 

42 assert isinstance(result, Image) 

43 assert result.array.shape == (611, 609) 

44 

45 

46@skip_np_h5py 

47def test_wcs_produces_projection() -> None: 

48 """Verify the auto-detect path builds a Projection from the NDF WCS 

49 component. 

50 """ 

51 image = read_starlink(Image, EXAMPLE) 

52 assert image.sky_projection is not None 

53 # M57 (Ring Nebula) is near RA~283.4 deg, Dec~33.0 deg. 

54 sky = image.sky_projection.pixel_to_sky_transform.apply_forward( 

55 x=np.array([300.0]), 

56 y=np.array([300.0]), 

57 ) 

58 ra_deg = float(np.degrees(sky.x[0])) 

59 dec_deg = float(np.degrees(sky.y[0])) 

60 assert abs(ra_deg - 283.4) < 0.5 

61 assert abs(dec_deg - 33.0) < 0.5 

62 

63 

64@skip_np_h5py 

65def test_opaque_fits_metadata_recovered() -> None: 

66 """Verify MORE/FITS cards are surfaced in ``_opaque_metadata``.""" 

67 image = read_starlink(Image, EXAMPLE) 

68 opaque = image._opaque_metadata 

69 assert ExtensionKey() in opaque.headers 

70 primary = opaque.headers[ExtensionKey()] 

71 # The fixture is a real Starlink M57 NDF; MORE/FITS carries standard 

72 # FITS dimension keywords regardless of any later processing. 

73 assert "NAXIS" in primary 

74 assert "NAXIS1" in primary 

75 assert "NAXIS2" in primary