Coverage for tests/test_tex_util.py: 21%
66 statements
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-28 10:09 +0000
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-28 10:09 +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.
23"""
25import unittest
26import os
27import numpy as np
29from lsst.afw.table import SimpleCatalog
30from lsst.faro.utils.tex import (TraceSize, PsfTraceSizeDiff,
31 E1, E2, E1Resids, E2Resids,
32 RhoStatistics)
34TESTDIR = os.path.abspath(os.path.dirname(__file__))
35DATADIR = os.path.join(TESTDIR, 'data')
38class TEXUtilTest(unittest.TestCase):
39 """Test TEX utility functions."""
41 def loadData(self):
42 """Helper to load data to process."""
43 cat_file = 'src_HSC_i_HSC-I_903986_0_31_HSC_runs_ci_hsc_20210407T021858Z.fits'
44 cat = SimpleCatalog.readFits(os.path.join(DATADIR, cat_file))
46 # selection = np.isfinite(cat.get('e1')) & np.isfinite(cat.get('e2'))
47 selection = np.tile(True, len(cat))
49 return cat.subset(selection).copy(deep=True)
51 def testEllipticityDefinitions(self):
52 """Test ellipticity functors."""
54 cat = self.loadData()
56 column = 'slot_Shape'
57 columnPsf = 'slot_PsfShape'
59 trace = TraceSize(column)
60 result = np.nanmean(trace(cat))
61 expected = 4.36377821335775
62 self.assertEqual(result, expected)
64 traceDiff = PsfTraceSizeDiff(column, columnPsf)
65 result = np.nanmean(traceDiff(cat))
66 expected = 25.301812428201995
67 self.assertEqual(result, expected)
69 e1 = E1(column)
70 result = np.nanmean(e1(cat))
71 expected = 0.0012636175684993878
72 self.assertEqual(result, expected)
74 e1 = E1(column, shearConvention=True)
75 result = np.nanmean(e1(cat))
76 expected = 0.00043009504274617235
77 self.assertEqual(result, expected)
79 e2 = E2(column)
80 result = np.nanmean(e2(cat))
81 expected = 0.080076033827269
82 self.assertEqual(result, expected)
84 e2 = E2(column, shearConvention=True)
85 result = np.nanmean(e2(cat))
86 expected = 0.04194134295796996
87 self.assertEqual(result, expected)
89 e1Resids = E1Resids(column, columnPsf)
90 result = np.nanmean(e1Resids(cat))
91 expected = -0.0009098947676481413
92 self.assertEqual(result, expected)
94 e2Resids = E2Resids(column, columnPsf)
95 result = np.nanmean(e2Resids(cat))
96 expected = -0.02280606766168935
97 self.assertEqual(result, expected)
99 def testRhoStats(self):
100 """Compute six Rho statistics."""
102 cat = self.loadData()
103 column = 'slot_Shape'
104 columnPsf = 'slot_PsfShape'
106 treecorrKwargs = dict(nbins=5,
107 min_sep=0.25,
108 max_sep=1,
109 sep_units='arcmin',
110 brute=True)
111 rhoStatistics = RhoStatistics(column, columnPsf, **treecorrKwargs)
112 result = rhoStatistics(cat)
114 expected = [0.2344471639428089,
115 0.0010172306766334468,
116 -0.0021045081490440086,
117 0.0028001762296714734,
118 -0.0013278190624450364,
119 0.005010295952053786]
121 self.assertAlmostEqual(np.mean(result[0].xi), expected[0], places=7)
122 self.assertAlmostEqual(np.mean(result[1].xip), expected[1], places=7)
123 self.assertAlmostEqual(np.mean(result[2].xip), expected[2], places=7)
124 self.assertAlmostEqual(np.mean(result[3].xip), expected[3], places=7)
125 self.assertAlmostEqual(np.mean(result[4].xip), expected[4], places=7)
126 self.assertAlmostEqual(np.mean(result[5].xip), expected[5], places=7)
129if __name__ == "__main__": 129 ↛ 130line 129 didn't jump to line 130, because the condition on line 129 was never true
130 unittest.main()