Coverage for tests/test_healSparseMapFormatter.py: 33%
40 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-27 03:59 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-27 03:59 -0700
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(self.root, run="testrun")
55 datasetType = DatasetType("map", [], "HealSparseMap",
56 universe=butler.dimensions)
57 butler.registry.registerDatasetType(datasetType)
58 ref = butler.put(self.hspMap, datasetType)
59 uri = butler.getURI(ref)
60 self.assertEqual(uri.getExtension(), '.hsp')
62 # Retrieve the full map.
63 hspMap = butler.get('map')
64 self.assertTrue(np.all(hspMap._sparse_map == self.hspMap._sparse_map))
66 # Retrieve the coverage map
67 coverage = butler.get('map.coverage')
68 self.assertTrue(np.all(coverage.coverage_mask == self.hspMap.coverage_mask))
70 # Retrieve a partial map
71 pixels = [0, 6]
72 partialMap = butler.get('map', parameters={'pixels': pixels})
74 self.assertTrue(np.all(np.where(partialMap.coverage_mask)[0] == np.array(pixels)))
75 self.assertTrue(np.all(partialMap[0: 10000] == self.hspMap[0: 10000]))
76 self.assertTrue(np.all(partialMap[100000: 110000] == self.hspMap[100000: 110000]))
78 # Retrieve a degraded map
79 degradedMapRead = butler.get('map', parameters={'degrade_nside': 512})
80 degradedMap = self.hspMap.degrade(512)
82 self.assertTrue(np.all(degradedMapRead._sparse_map == degradedMap._sparse_map))
85if __name__ == "__main__": 85 ↛ 86line 85 didn't jump to line 86, because the condition on line 85 was never true
86 unittest.main()