Coverage for tests / test_singleColumnMagnitudeScatterPlot.py: 32%

39 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-28 09:21 +0000

1# This file is part of analysis_tools. 

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 <http://www.gnu.org/licenses/>. 

21 

22from unittest import TestCase, main 

23 

24import numpy as np 

25 

26import lsst.utils.tests 

27from lsst.analysis.tools.atools.actionMagnitudeScatterPlot import SingleColumnMagnitudeScatterPlot 

28from lsst.analysis.tools.math import sqrt 

29 

30 

31class SingleColumnMagnitudeScatterPlotTestCase(TestCase): 

32 """Test the generic quantity vs magnitude scatter plot""" 

33 

34 def setUp(self) -> None: 

35 super().setUp() 

36 

37 # Set up a quasi-plausible measurement catalog 

38 band = "i" 

39 mag = 12.5 + 2.5 * np.log10(np.arange(10, 100000)) 

40 flux = 10 ** (-0.4 * (mag - (mag[-1] + 1))) 

41 rng = np.random.default_rng(0) 

42 extendedness = 0.0 + (rng.uniform(size=len(mag)) < 0.99 * (mag - mag[0]) / (mag[-1] - mag[0])) 

43 flux_meas = flux + rng.normal(scale=sqrt(flux * (1 + extendedness))) 

44 flux_err = sqrt(flux_meas * (1 + extendedness)) 

45 good = (flux_meas / sqrt(flux * (1 + extendedness))) > 3 

46 n_good = np.sum(good) 

47 extendedness = extendedness[good] 

48 flux_meas = flux_meas[good] 

49 flux_err = flux_err[good] 

50 key_flux = f"{band}_cModelFlux" 

51 

52 data = { 

53 "objectId": np.arange(n_good), 

54 key_flux: flux_meas, 

55 f"{key_flux}Err": flux_err, 

56 "detect_isPrimary": np.ones(n_good, dtype=bool), 

57 "refExtendedness": extendedness, 

58 "y": np.arange(n_good), 

59 } 

60 

61 self.action = SingleColumnMagnitudeScatterPlot( 

62 key_y="y", 

63 mag_x="cmodel_err", 

64 ) 

65 self.action.finalize() 

66 self.band = band 

67 self.data = data 

68 plotInfo = {key: "test" for key in ("plotName", "run", "tableName")} 

69 plotInfo["bands"] = [band] 

70 self.plotInfo = plotInfo 

71 

72 def testAction(self) -> None: 

73 results = self.action( 

74 self.data, 

75 band=self.band, 

76 # skymap=None, 

77 plotInfo=self.plotInfo, 

78 ) 

79 assert tuple(results.keys()) == ("ScatterPlotWithTwoHists",) 

80 

81 

82class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

83 pass 

84 

85 

86def setup_module(module): 

87 lsst.utils.tests.init() 

88 

89 

90if __name__ == "__main__": 90 ↛ 91line 90 didn't jump to line 91 because the condition on line 90 was never true

91 lsst.utils.tests.init() 

92 main()