Coverage for tests/test_StellarLocus.py: 38%
Shortcuts 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
Shortcuts 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# This file is part of faro.
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"""Unit tests for the metrics measurement system: wPerp, extinction_corr.
23"""
25import unittest
26import numpy as np
27import os
28import astropy.units as u
30import lsst.utils.tests
31from lsst.utils import getPackageDir
32from astropy.table import Table
33from lsst.faro.utils.stellar_locus import stellarLocusResid
34from lsst.faro.utils.extinction_corr import extinction_corr
35from lsst.faro.measurement import WPerpTask
38DATADIR = os.path.join(getPackageDir('faro'), 'tests', 'data')
41class StellarLocusTest(lsst.utils.tests.TestCase):
43 def load_data(self):
44 """Helper to load data to process."""
45 cat_file = 'tract9813_patches55to72_gri_filtered.fits.gz'
46 catalog = Table.read(os.path.join(DATADIR, cat_file))
47 return catalog
49 def test_extinction_corr(self):
50 """Test lookup of extinction corrections on a known catalog."""
51 cat = self.load_data()
52 # 'r' must come first, because the coord column is named 'coord_ra_r', and
53 # extinction_corr assumes the first bandpass provided is used for the coord column.
54 bands = ['r', 'g', 'i']
55 ext_vals = extinction_corr(cat, bands)
56 ebvValues = ext_vals['E(B-V)']
57 expected_mean_ebv = 0.020206410437822342
58 expected_len_ebv = 209
59 self.assertEqual(np.mean(ebvValues), expected_mean_ebv)
60 self.assertEqual(len(ebvValues), expected_len_ebv)
62 def test_wPerp(self):
63 """Test calculation of wPerp (stellar locus metric) on a known catalog."""
64 cat = self.load_data()
65 bands = ['r', 'g', 'i']
66 ext_vals = extinction_corr(cat, bands)
68 expected_wperp = 12.18208045737346 * u.mmag
70 config = WPerpTask.ConfigClass()
71 task = WPerpTask(config=config)
72 result = task.calcWPerp('wPerp', cat, ext_vals)
73 # checks modified to pass when using MKL conda stack
74 self.assertEqual(result.measurement.quantity.unit, expected_wperp.unit)
75 self.assertFloatsAlmostEqual(result.measurement.quantity.value,
76 expected_wperp.value, rtol=1E-10)
78 def test_stellarLocusResid(self):
79 """Test calculation of stellar locus residuals on a known catalog."""
80 cat = self.load_data()
81 bands = ['r', 'g', 'i']
82 ext_vals = extinction_corr(cat, bands)
84 p1, p2, p1coeffs, p2coeffs = stellarLocusResid(cat['base_PsfFlux_mag_g']-ext_vals['A_g'],
85 cat['base_PsfFlux_mag_r']-ext_vals['A_r'],
86 cat['base_PsfFlux_mag_i']-ext_vals['A_i'])
88 expected_p1coeffs = [0.0, 0.8865855025842218, -0.424020754027349,
89 -0.46256474855687274, 0.0, -0.3073194572752734]
90 expected_p2coeffs = [0.0, -0.2754432193878283, 0.8033778833591981,
91 -0.5279346639713699, 0.0, 0.03544642888292535]
92 expected_p1median = 0.1775458238071685
93 expected_p2median = 4.766061008374539e-05
94 # checks modified to pass when using MKL conda stack
95 self.assertFloatsAlmostEqual(np.median(p1), expected_p1median, rtol=1E-10)
96 self.assertFloatsAlmostEqual(np.median(p2), expected_p2median, rtol=1E-10)
97 self.assertFloatsAlmostEqual(np.array(p1coeffs), np.array(expected_p1coeffs), rtol=1E-10)
98 self.assertFloatsAlmostEqual(np.array(p2coeffs), np.array(expected_p2coeffs), rtol=1E-10)
101if __name__ == "__main__": 101 ↛ 102line 101 didn't jump to line 102, because the condition on line 101 was never true
102 unittest.main()