Coverage for tests/test_StellarLocus.py: 36%
51 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-10 09:37 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-10 09:37 +0000
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 astropy.table import Table
32from lsst.faro.utils.stellar_locus import stellarLocusResid
33from lsst.faro.utils.extinction_corr import extinction_corr
34from lsst.faro.measurement import WPerpTask
36TESTDIR = os.path.abspath(os.path.dirname(__file__))
37DATADIR = os.path.join(TESTDIR, 'data')
40class StellarLocusTest(lsst.utils.tests.TestCase):
42 def load_data(self):
43 """Helper to load data to process."""
44 cat_file = 'tract9813_patches55to72_gri_filtered.fits.gz'
45 catalog = Table.read(os.path.join(DATADIR, cat_file))
46 return catalog
48 def test_extinction_corr(self):
49 """Test lookup of extinction corrections on a known catalog."""
50 cat = self.load_data()
51 # 'r' must come first, because the coord column is named 'coord_ra_r', and
52 # extinction_corr assumes the first bandpass provided is used for the coord column.
53 bands = ['r', 'g', 'i']
54 ext_vals = extinction_corr(cat, bands)
55 ebvValues = ext_vals['E(B-V)']
56 expected_mean_ebv = 0.020206410437822342
57 expected_len_ebv = 209
58 self.assertEqual(np.mean(ebvValues), expected_mean_ebv)
59 self.assertEqual(len(ebvValues), expected_len_ebv)
61 def test_wPerp(self):
62 """Test calculation of wPerp (stellar locus metric) on a known catalog."""
63 cat = self.load_data()
64 bands = ['r', 'g', 'i']
65 ext_vals = extinction_corr(cat, bands)
67 expected_wperp = 12.18208045737346 * u.mmag
69 config = WPerpTask.ConfigClass()
70 task = WPerpTask(config=config)
71 result = task.calcWPerp('wPerp', cat, ext_vals)
72 # checks modified to pass when using MKL conda stack
73 self.assertEqual(result.measurement.quantity.unit, expected_wperp.unit)
74 self.assertFloatsAlmostEqual(result.measurement.quantity.value,
75 expected_wperp.value, rtol=1E-10)
77 def test_stellarLocusResid(self):
78 """Test calculation of stellar locus residuals on a known catalog."""
79 cat = self.load_data()
80 bands = ['r', 'g', 'i']
81 ext_vals = extinction_corr(cat, bands)
83 p1, p2, p1coeffs, p2coeffs = stellarLocusResid(cat['base_PsfFlux_mag_g']-ext_vals['A_g'],
84 cat['base_PsfFlux_mag_r']-ext_vals['A_r'],
85 cat['base_PsfFlux_mag_i']-ext_vals['A_i'])
87 expected_p1coeffs = [0.0, 0.8865855025842218, -0.424020754027349,
88 -0.46256474855687274, 0.0, -0.3073194572752734]
89 expected_p2coeffs = [0.0, -0.2754432193878283, 0.8033778833591981,
90 -0.5279346639713699, 0.0, 0.03544642888292535]
91 expected_p1median = 0.1775458238071685
92 expected_p2median = 4.766061008374539e-05
93 # checks modified to pass when using MKL conda stack
94 self.assertFloatsAlmostEqual(np.median(p1), expected_p1median, rtol=1E-10)
95 self.assertFloatsAlmostEqual(np.median(p2), expected_p2median, rtol=1E-10)
96 self.assertFloatsAlmostEqual(np.array(p1coeffs), np.array(expected_p1coeffs), rtol=1E-10)
97 self.assertFloatsAlmostEqual(np.array(p2coeffs), np.array(expected_p2coeffs), rtol=1E-10)
100if __name__ == "__main__": 100 ↛ 101line 100 didn't jump to line 101, because the condition on line 100 was never true
101 unittest.main()