Coverage for tests/test_loadref_hsc.py : 18%

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")
47 try:
48 lsst.utils.getPackageDir('obs_subaru')
49 except LookupError:
50 raise unittest.SkipTest("obs_subaru not setup")
52 def setUp(self):
53 self.inputDir = os.path.join(self.dataDir, 'hsc')
55 lsst.log.setLevel("HscMapper", lsst.log.FATAL)
57 def test_fgcmLoadReference(self):
58 """
59 Test loading of the fgcm reference catalogs.
60 """
62 filterList = ['r', 'i']
64 config = fgcmcal.FgcmLoadReferenceCatalogConfig()
65 config.applyColorTerms = True
66 config.refObjLoader.ref_dataset_name = 'sdss-dr9-fink-v5b'
67 config.refFilterMap = {'r': 'r', 'i': 'i'}
68 config.colorterms.data = {}
69 config.colorterms.data['sdss*'] = lsst.pipe.tasks.colorterms.ColortermDict()
70 config.colorterms.data['sdss*'].data = {}
71 config.colorterms.data['sdss*'].data['g'] = lsst.pipe.tasks.colorterms.Colorterm()
72 config.colorterms.data['sdss*'].data['g'].primary = 'g'
73 config.colorterms.data['sdss*'].data['g'].secondary = 'r'
74 config.colorterms.data['sdss*'].data['g'].c0 = -0.00816446
75 config.colorterms.data['sdss*'].data['g'].c1 = -0.08366937
76 config.colorterms.data['sdss*'].data['g'].c2 = -0.00726883
77 config.colorterms.data['sdss*'].data['r'] = lsst.pipe.tasks.colorterms.Colorterm()
78 config.colorterms.data['sdss*'].data['r'].primary = 'r'
79 config.colorterms.data['sdss*'].data['r'].secondary = 'i'
80 config.colorterms.data['sdss*'].data['r'].c0 = 0.0013181
81 config.colorterms.data['sdss*'].data['r'].c1 = 0.01284177
82 config.colorterms.data['sdss*'].data['r'].c2 = -0.03068248
83 config.colorterms.data['sdss*'].data['i'] = lsst.pipe.tasks.colorterms.Colorterm()
84 config.colorterms.data['sdss*'].data['i'].primary = 'i'
85 config.colorterms.data['sdss*'].data['i'].secondary = 'z'
86 config.colorterms.data['sdss*'].data['i'].c0 = 0.00130204
87 config.colorterms.data['sdss*'].data['i'].c1 = -0.16922042
88 config.colorterms.data['sdss*'].data['i'].c2 = -0.01374245
90 butler = dafPersist.Butler(self.inputDir)
91 loadCat = fgcmcal.FgcmLoadReferenceCatalogTask(butler, config=config)
93 ra = 320.0
94 dec = 0.0
95 rad = 0.1
97 refCat = loadCat.getFgcmReferenceStarsSkyCircle(ra, dec, rad, filterList)
99 # Check the number of mags and ranges
100 self.assertEqual(len(filterList), refCat['refMag'].shape[1])
101 self.assertEqual(len(filterList), refCat['refMagErr'].shape[1])
102 self.assertLess(np.max(refCat['refMag'][:, 0]), 99.1)
103 self.assertLess(np.max(refCat['refMag'][:, 1]), 99.1)
104 self.assertLess(np.max(refCat['refMagErr'][:, 0]), 99.1)
105 self.assertLess(np.max(refCat['refMagErr'][:, 1]), 99.1)
106 test, = np.where((refCat['refMag'][:, 0] < 30.0) &
107 (refCat['refMag'][:, 1] < 30.0))
108 self.assertGreater(test.size, 0)
110 # Check the separations from the center
111 self.assertLess(np.max(esutil.coords.sphdist(ra, dec, refCat['ra'], refCat['dec'])), rad)
113 # And load a healpixel
114 nside = 256
115 pixel = 393614
117 refCat = loadCat.getFgcmReferenceStarsHealpix(nside, pixel, filterList)
119 ipring = hp.ang2pix(nside, np.radians(90.0 - refCat['dec']), np.radians(refCat['ra']))
120 self.assertEqual(pixel, np.max(ipring))
121 self.assertEqual(pixel, np.min(ipring))
123 def test_fgcmLoadReferenceOtherFilters(self):
124 """
125 Test loading of the fgcm reference catalogs using unmatched filter names.
126 """
128 filterList = ['r2', 'i2']
130 config = fgcmcal.FgcmLoadReferenceCatalogConfig()
131 config.applyColorTerms = True
132 config.refObjLoader.ref_dataset_name = 'sdss-dr9-fink-v5b'
133 config.refFilterMap = {'r2': 'r', 'i2': 'i'}
134 config.colorterms.data = {}
135 config.colorterms.data['sdss*'] = lsst.pipe.tasks.colorterms.ColortermDict()
136 config.colorterms.data['sdss*'].data = {}
137 config.colorterms.data['sdss*'].data['r2'] = lsst.pipe.tasks.colorterms.Colorterm()
138 config.colorterms.data['sdss*'].data['r2'].primary = 'r'
139 config.colorterms.data['sdss*'].data['r2'].secondary = 'i'
140 config.colorterms.data['sdss*'].data['r2'].c0 = 0.0013181
141 config.colorterms.data['sdss*'].data['r2'].c1 = 0.01284177
142 config.colorterms.data['sdss*'].data['r2'].c2 = -0.03068248
143 config.colorterms.data['sdss*'].data['i2'] = lsst.pipe.tasks.colorterms.Colorterm()
144 config.colorterms.data['sdss*'].data['i2'].primary = 'i'
145 config.colorterms.data['sdss*'].data['i2'].secondary = 'z'
146 config.colorterms.data['sdss*'].data['i2'].c0 = 0.00130204
147 config.colorterms.data['sdss*'].data['i2'].c1 = -0.16922042
148 config.colorterms.data['sdss*'].data['i2'].c2 = -0.01374245
150 butler = dafPersist.Butler(self.inputDir)
151 loadCat = fgcmcal.FgcmLoadReferenceCatalogTask(butler, config=config)
153 ra = 320.0
154 dec = 0.0
155 rad = 0.1
157 refCat = loadCat.getFgcmReferenceStarsSkyCircle(ra, dec, rad, filterList)
159 self.assertEqual(len(filterList), refCat['refMag'].shape[1])
160 self.assertEqual(len(filterList), refCat['refMagErr'].shape[1])
161 test, = np.where((refCat['refMag'][:, 0] < 30.0) &
162 (refCat['refMag'][:, 1] < 30.0))
163 self.assertGreater(test.size, 0)
166class TestMemory(lsst.utils.tests.MemoryTestCase):
167 pass
170def setup_module(module):
171 lsst.utils.tests.init()
174if __name__ == "__main__": 174 ↛ 175line 174 didn't jump to line 175, because the condition on line 174 was never true
175 lsst.utils.tests.init()
176 unittest.main()