Coverage for tests / test_split_primary.py: 34%

42 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-26 09:21 +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 

23import unittest 

24 

25import numpy as np 

26import astropy.table 

27 

28import lsst.utils.tests 

29from lsst.daf.butler import DimensionUniverse 

30from lsst.pipe.base import PipelineGraph 

31from lsst.pipe.tasks.split_primary import SplitPrimaryConfig, SplitPrimaryTask 

32 

33 

34class SplitPrimaryTaskTestCase(lsst.utils.tests.TestCase): 

35 def test_connections(self): 

36 """Test that we can reconfigure the dimensions of the connections.""" 

37 universe = DimensionUniverse() 

38 config = SplitPrimaryConfig() 

39 config.dimensions = ["visit"] 

40 pg = PipelineGraph() 

41 pg.add_task("split_primary", SplitPrimaryTask, config=config) 

42 pg.resolve(dimensions=universe) 

43 self.assertEqual(pg.tasks["split_primary"].dimensions, universe.conform(["visit"])) 

44 self.assertEqual(pg.dataset_types["full"].dimensions, universe.conform(["visit"])) 

45 self.assertEqual(pg.dataset_types["primary"].dimensions, universe.conform(["visit"])) 

46 self.assertEqual(pg.dataset_types["nonprimary"].dimensions, universe.conform(["visit"])) 

47 

48 def test_run(self): 

49 """Test the 'run' method.""" 

50 rng = np.random.default_rng(10) 

51 n = 20 

52 full = astropy.table.Table( 

53 { 

54 "primary": rng.random(n) > 0.5, 

55 "a": rng.standard_normal(n), 

56 "b": rng.standard_normal(n), 

57 "c": rng.standard_normal(n), 

58 } 

59 ) 

60 config = SplitPrimaryConfig() 

61 config.primary_flag_column = "primary" 

62 # Note that column 'd' is not present; it should be ignored. 

63 config.discard_primary_columns = ["b", "d"] 

64 config.discard_nonprimary_columns = ["c", "d"] 

65 task = SplitPrimaryTask(config=config) 

66 result = task.run(full=full) 

67 self.assertEqual(result.primary.colnames, ["a", "c"]) 

68 self.assertEqual(result.nonprimary.colnames, ["a", "b"]) 

69 self.assertFloatsEqual(result.primary["a"], full["a"][full["primary"]]) 

70 self.assertFloatsEqual(result.primary["c"], full["c"][full["primary"]]) 

71 self.assertFloatsEqual(result.nonprimary["a"], full["a"][np.logical_not(full["primary"])]) 

72 self.assertFloatsEqual(result.nonprimary["b"], full["b"][np.logical_not(full["primary"])]) 

73 

74 

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

76 pass 

77 

78 

79def setup_module(module): 

80 lsst.utils.tests.init() 

81 

82 

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

84 lsst.utils.tests.init() 

85 unittest.main()