Coverage for tests / test_healSparseMapFormatter.py: 31%
40 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 08:30 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 08:30 +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# (http://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/>.
22"""Tests for HealSparseMapFormatter.
23"""
25import unittest
26import os
27import numpy as np
28import healsparse as hsp
30from lsst.daf.butler import Butler, DatasetType
31from lsst.daf.butler.tests.utils import makeTestTempDir, removeTestTempDir
33TESTDIR = os.path.abspath(os.path.dirname(__file__))
36class HealSparseMapFormatterTestCase(unittest.TestCase):
37 """Test for HealSparseMapFormatter.
38 """
40 def setUp(self):
41 self.root = makeTestTempDir(TESTDIR)
42 Butler.makeRepo(self.root)
44 self.hspMap = hsp.HealSparseMap.make_empty(nside_coverage=32, nside_sparse=4096, dtype=np.float32)
45 self.hspMap[0: 10000] = 1.0
46 self.hspMap[100000: 110000] = 2.0
47 self.hspMap[500000: 510000] = 3.0
49 def tearDown(self):
50 removeTestTempDir(self.root)
51 del self.hspMap
53 def testHealSparseMapFormatter(self):
54 butler = Butler.from_config(self.root, run="testrun")
55 self.enterContext(butler)
56 datasetType = DatasetType("map", [], "HealSparseMap",
57 universe=butler.dimensions)
58 butler.registry.registerDatasetType(datasetType)
59 ref = butler.put(self.hspMap, datasetType)
60 uri = butler.getURI(ref)
61 self.assertEqual(uri.getExtension(), '.hsp')
63 # Retrieve the full map.
64 hspMap = butler.get('map')
65 self.assertTrue(np.all(hspMap._sparse_map == self.hspMap._sparse_map))
67 # Retrieve the coverage map
68 coverage = butler.get('map.coverage')
69 self.assertTrue(np.all(coverage.coverage_mask == self.hspMap.coverage_mask))
71 # Retrieve a partial map
72 pixels = [0, 6]
73 partialMap = butler.get('map', parameters={'pixels': pixels})
75 self.assertTrue(np.all(np.where(partialMap.coverage_mask)[0] == np.array(pixels)))
76 self.assertTrue(np.all(partialMap[0: 10000] == self.hspMap[0: 10000]))
77 self.assertTrue(np.all(partialMap[100000: 110000] == self.hspMap[100000: 110000]))
79 # Retrieve a degraded map
80 degradedMapRead = butler.get('map', parameters={'degrade_nside': 512})
81 degradedMap = self.hspMap.degrade(512)
83 self.assertTrue(np.all(degradedMapRead._sparse_map == degradedMap._sparse_map))
86if __name__ == "__main__": 86 ↛ 87line 86 didn't jump to line 87 because the condition on line 86 was never true
87 unittest.main()