Coverage for tests/utils.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-14 19:17 +0000

1# This file is part of pipe_tasks. 

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# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21 

22__all__ = ["makeTestVisitInfo", "make_exposure_record"] 

23 

24import astropy.units as u 

25 

26from lsst.afw.coord import Observatory 

27import lsst.afw.image as afwImage 

28import lsst.daf.base as dafBase 

29import lsst.daf.butler 

30import lsst.geom as geom 

31 

32 

33def makeTestVisitInfo(id=1): 

34 """Return a non-NaN visitInfo.""" 

35 return afwImage.VisitInfo(id=id, 

36 date=dafBase.DateTime(65321.1, dafBase.DateTime.MJD, dafBase.DateTime.TAI), 

37 era=45.1*geom.degrees, 

38 boresightRaDec=geom.SpherePoint(23.1, 73.2, geom.degrees), 

39 boresightAzAlt=geom.SpherePoint(134.5, 33.3, geom.degrees), 

40 boresightRotAngle=73.2*geom.degrees, 

41 rotType=afwImage.RotType.SKY, 

42 observatory=Observatory(11.1*geom.degrees, 22.2*geom.degrees, 0.333)) 

43 

44 

45def make_exposure_record(exposure, instrument="testCam"): 

46 """Return an ``exposure`` dimension record that describes a test exposure. 

47 

48 Parameters 

49 ---------- 

50 exposure : `lsst.afw.image.Exposure` 

51 Exposure to take the observation metadata from. 

52 instrument : `str`, optional 

53 Name of the instrument to record. 

54 

55 Returns 

56 ------- 

57 record : `lsst.daf.butler.DimensionRecord` 

58 Record holding the observation metadata that 

59 `lsst.images.VisitImage.from_legacy` reads. 

60 """ 

61 visit_info = exposure.visitInfo 

62 begin = visit_info.date.toAstropy() 

63 universe = lsst.daf.butler.DimensionUniverse() 

64 return universe["exposure"].RecordClass( 

65 instrument=instrument, 

66 id=visit_info.id, 

67 obs_id=f"test_{visit_info.id}", 

68 group=str(visit_info.id), 

69 physical_filter=exposure.filter.physicalLabel, 

70 day_obs=int(begin.strftime("%Y%m%d")), 

71 exposure_time=visit_info.exposureTime, 

72 seq_num=1, 

73 seq_start=1, 

74 seq_end=1, 

75 can_see_sky=True, 

76 timespan=lsst.daf.butler.Timespan(begin=begin, end=begin + visit_info.exposureTime*u.s), 

77 )