Coverage for tests/test_loadref_hsc.py : 19%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# See COPYRIGHT file at the top of the source tree.
2#
3# This file is part of fgcmcal.
4#
5# Developed for the LSST Data Management System.
6# This product includes software developed by the LSST Project
7# (https://www.lsst.org).
8# See the COPYRIGHT file at the top-level directory of this distribution
9# for details of code ownership.
10#
11# This program is free software: you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation, either version 3 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program. If not, see <https://www.gnu.org/licenses/>.
23"""Test the fgcmcal fgcmLoadReferenceCatalog code with testdata_jointcal/hsc.
25"""
27import unittest
28import os
29import numpy as np
30import healpy as hp
31import esutil
33import lsst.utils
34import lsst.pipe.tasks
35import lsst.daf.persistence as dafPersist
37import lsst.fgcmcal as fgcmcal
40class FgcmLoadReferenceTestHSC(lsst.utils.tests.TestCase):
41 @classmethod
42 def setUpClass(cls):
43 try:
44 cls.dataDir = lsst.utils.getPackageDir('testdata_jointcal')
45 except LookupError:
46 raise unittest.SkipTest("testdata_jointcal not setup")
48 def setUp(self):
49 self.inputDir = os.path.join(self.dataDir, 'hsc')
51 lsst.log.setLevel("HscMapper", lsst.log.FATAL)
53 def test_fgcmLoadReference(self):
54 """
55 Test loading of the fgcm reference catalogs.
56 """
58 filterList = ['r', 'i']
60 config = fgcmcal.FgcmLoadReferenceCatalogConfig()
61 config.applyColorTerms = True
62 config.refObjLoader.ref_dataset_name = 'sdss-dr9-fink-v5b'
63 config.refFilterMap = {'r': 'r', 'i': 'i'}
64 config.colorterms.data = {}
65 config.colorterms.data['sdss*'] = lsst.pipe.tasks.colorterms.ColortermDict()
66 config.colorterms.data['sdss*'].data = {}
67 config.colorterms.data['sdss*'].data['g'] = lsst.pipe.tasks.colorterms.Colorterm()
68 config.colorterms.data['sdss*'].data['g'].primary = 'g'
69 config.colorterms.data['sdss*'].data['g'].secondary = 'r'
70 config.colorterms.data['sdss*'].data['g'].c0 = -0.00816446
71 config.colorterms.data['sdss*'].data['g'].c1 = -0.08366937
72 config.colorterms.data['sdss*'].data['g'].c2 = -0.00726883
73 config.colorterms.data['sdss*'].data['r'] = lsst.pipe.tasks.colorterms.Colorterm()
74 config.colorterms.data['sdss*'].data['r'].primary = 'r'
75 config.colorterms.data['sdss*'].data['r'].secondary = 'i'
76 config.colorterms.data['sdss*'].data['r'].c0 = 0.0013181
77 config.colorterms.data['sdss*'].data['r'].c1 = 0.01284177
78 config.colorterms.data['sdss*'].data['r'].c2 = -0.03068248
79 config.colorterms.data['sdss*'].data['i'] = lsst.pipe.tasks.colorterms.Colorterm()
80 config.colorterms.data['sdss*'].data['i'].primary = 'i'
81 config.colorterms.data['sdss*'].data['i'].secondary = 'z'
82 config.colorterms.data['sdss*'].data['i'].c0 = 0.00130204
83 config.colorterms.data['sdss*'].data['i'].c1 = -0.16922042
84 config.colorterms.data['sdss*'].data['i'].c2 = -0.01374245
86 butler = dafPersist.Butler(self.inputDir)
87 loadCat = fgcmcal.FgcmLoadReferenceCatalogTask(butler, config=config)
89 ra = 320.0
90 dec = 0.0
91 rad = 0.1
93 refCat = loadCat.getFgcmReferenceStarsSkyCircle(ra, dec, rad, filterList)
95 # Check the number of mags and ranges
96 self.assertEqual(len(filterList), refCat['refMag'].shape[1])
97 self.assertEqual(len(filterList), refCat['refMagErr'].shape[1])
98 self.assertLess(np.max(refCat['refMag'][:, 0]), 99.1)
99 self.assertLess(np.max(refCat['refMag'][:, 1]), 99.1)
100 self.assertLess(np.max(refCat['refMagErr'][:, 0]), 99.1)
101 self.assertLess(np.max(refCat['refMagErr'][:, 1]), 99.1)
102 test, = np.where((refCat['refMag'][:, 0] < 30.0) &
103 (refCat['refMag'][:, 1] < 30.0))
104 self.assertGreater(test.size, 0)
106 # Check the separations from the center
107 self.assertLess(np.max(esutil.coords.sphdist(ra, dec, refCat['ra'], refCat['dec'])), rad)
109 # And load a healpixel
110 nside = 256
111 pixel = 393614
113 refCat = loadCat.getFgcmReferenceStarsHealpix(nside, pixel, filterList)
115 ipring = hp.ang2pix(nside, np.radians(90.0 - refCat['dec']), np.radians(refCat['ra']))
116 self.assertEqual(pixel, np.max(ipring))
117 self.assertEqual(pixel, np.min(ipring))
119 def test_fgcmLoadReferenceOtherFilters(self):
120 """
121 Test loading of the fgcm reference catalogs using unmatched filter names.
122 """
124 filterList = ['r2', 'i2']
126 config = fgcmcal.FgcmLoadReferenceCatalogConfig()
127 config.applyColorTerms = True
128 config.refObjLoader.ref_dataset_name = 'sdss-dr9-fink-v5b'
129 config.refFilterMap = {'r2': 'r', 'i2': 'i'}
130 config.colorterms.data = {}
131 config.colorterms.data['sdss*'] = lsst.pipe.tasks.colorterms.ColortermDict()
132 config.colorterms.data['sdss*'].data = {}
133 config.colorterms.data['sdss*'].data['r2'] = lsst.pipe.tasks.colorterms.Colorterm()
134 config.colorterms.data['sdss*'].data['r2'].primary = 'r'
135 config.colorterms.data['sdss*'].data['r2'].secondary = 'i'
136 config.colorterms.data['sdss*'].data['r2'].c0 = 0.0013181
137 config.colorterms.data['sdss*'].data['r2'].c1 = 0.01284177
138 config.colorterms.data['sdss*'].data['r2'].c2 = -0.03068248
139 config.colorterms.data['sdss*'].data['i2'] = lsst.pipe.tasks.colorterms.Colorterm()
140 config.colorterms.data['sdss*'].data['i2'].primary = 'i'
141 config.colorterms.data['sdss*'].data['i2'].secondary = 'z'
142 config.colorterms.data['sdss*'].data['i2'].c0 = 0.00130204
143 config.colorterms.data['sdss*'].data['i2'].c1 = -0.16922042
144 config.colorterms.data['sdss*'].data['i2'].c2 = -0.01374245
146 butler = dafPersist.Butler(self.inputDir)
147 loadCat = fgcmcal.FgcmLoadReferenceCatalogTask(butler, config=config)
149 ra = 320.0
150 dec = 0.0
151 rad = 0.1
153 refCat = loadCat.getFgcmReferenceStarsSkyCircle(ra, dec, rad, filterList)
155 self.assertEqual(len(filterList), refCat['refMag'].shape[1])
156 self.assertEqual(len(filterList), refCat['refMagErr'].shape[1])
157 test, = np.where((refCat['refMag'][:, 0] < 30.0) &
158 (refCat['refMag'][:, 1] < 30.0))
159 self.assertGreater(test.size, 0)
162class TestMemory(lsst.utils.tests.MemoryTestCase):
163 pass
166def setup_module(module):
167 lsst.utils.tests.init()
170if __name__ == "__main__": 170 ↛ 171line 170 didn't jump to line 171, because the condition on line 170 was never true
171 lsst.utils.tests.init()
172 unittest.main()