Coverage for tests/test_RBTransiNetInterface.py: 100%

29 statements  

« prev     ^ index     » next       coverage.py v7.14.3, created at 2026-07-01 09:00 +0000

1# This file is part of meas_transiNet. 

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 

22import unittest 

23 

24import numpy as np 

25 

26from lsst.meas.transiNet import RBTransiNetTask 

27from lsst.meas.transiNet import RBTransiNetInterface, CutoutInputs 

28 

29 

30class TestInference(unittest.TestCase): 

31 def setUp(self): 

32 

33 # Create a mock TransiNetTask. 

34 config = RBTransiNetTask.ConfigClass() 

35 config.modelPackageName = "dummy" 

36 config.modelPackageStorageMode = "local" 

37 self.task = RBTransiNetTask(config=config) 

38 self.interface = RBTransiNetInterface(self.task) 

39 

40 def test_version(self): 

41 self.assertEqual(self.interface.version, "0.0") 

42 

43 def test_infer_empty_inputs(self): 

44 """Test running infer on empty inputs to make sure it handles it 

45 gracefully, i.e. returns an empty array for empty inputs. 

46 """ 

47 inputs = [] 

48 result = self.interface.infer(inputs) 

49 self.assertTupleEqual(result.shape, (0,)) 

50 

51 def test_infer_single_empty(self): 

52 """Test running infer on a single blank triplet. 

53 """ 

54 data = np.zeros((256, 256), dtype=np.single) 

55 inputs = [CutoutInputs(science=data, difference=data, template=data)] 

56 result = self.interface.infer(inputs) 

57 self.assertTupleEqual(result.shape, (1,)) 

58 self.assertAlmostEqual(result[0], 0.5011908) # Empricial meaningless value spit by this very model 

59 

60 def test_infer_many(self): 

61 """Test running infer on a large number of images, 

62 to make sure partitioning to batches works. 

63 """ 

64 data = np.zeros((256, 256), dtype=np.single) 

65 inputs = [CutoutInputs(science=data, difference=data, template=data) for _ in range(100)] 

66 result = self.interface.infer(inputs) 

67 self.assertTupleEqual(result.shape, (100,)) 

68 self.assertAlmostEqual(result[0], 0.5011908)