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
30from lsst.utils import getPackageDir
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
37DATADIR = os.path.join(getPackageDir('faro'), 'tests', 'data')
40class StellarLocusTest(unittest.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 self.assertEqual(result.measurement.quantity, expected_wperp)
74 def test_stellarLocusResid(self):
75 """Test calculation of stellar locus residuals on a known catalog."""
76 cat = self.load_data()
77 bands = ['r', 'g', 'i']
78 ext_vals = extinction_corr(cat, bands)
80 p1, p2, p1coeffs, p2coeffs = stellarLocusResid(cat['base_PsfFlux_mag_g']-ext_vals['A_g'],
81 cat['base_PsfFlux_mag_r']-ext_vals['A_r'],
82 cat['base_PsfFlux_mag_i']-ext_vals['A_i'])
84 expected_p1coeffs = [0.0, 0.8865855025842218, -0.424020754027349,
85 -0.46256474855687274, 0.0, -0.3073194572752734]
86 expected_p2coeffs = [0.0, -0.2754432193878283, 0.8033778833591981,
87 -0.5279346639713699, 0.0, 0.03544642888292535]
88 expected_p1median = 0.1775458238071685
89 expected_p2median = 4.766061008374539e-05
90 self.assertEqual(np.median(p1), expected_p1median)
91 self.assertEqual(np.median(p2), expected_p2median)
92 self.assertEqual(p1coeffs, expected_p1coeffs)
93 self.assertEqual(p2coeffs, expected_p2coeffs)
96if __name__ == "__main__": 96 ↛ 97line 96 didn't jump to line 97, because the condition on line 96 was never true
97 unittest.main()