Coverage for tests/test_match_probabilistic_task.py: 31%
43 statements
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-12 10:15 +0000
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-12 10:15 +0000
1# This file is part of meas_astrom.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://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 <https://www.gnu.org/licenses/>.
23import unittest
24import lsst.utils.tests
26import lsst.afw.geom as afwGeom
27from lsst.meas.astrom import MatchProbabilisticConfig, MatchProbabilisticTask
29import numpy as np
30import pandas as pd
33class MatchProbabilisticTaskTestCase(lsst.utils.tests.TestCase):
34 """MatchProbabilisticTask test case."""
35 def setUp(self):
36 ra = np.array([-0.1, -0.2, 0., 0.1, 0.2])
37 dec = np.array([-0.15, 0.15, 0, 0.15, -0.15])
38 mag_g = np.array([23., 24., 25., 25.5, 26.])
39 mag_r = mag_g + [0.5, -0.2, -0.8, -0.5, -1.5]
40 zeropoint = MatchProbabilisticConfig.mag_zeropoint_ref.default
41 fluxes = tuple(-0.4*10**(mag - zeropoint) for mag in (mag_g, mag_r))
42 eps_coord = np.full_like(ra, lsst.geom.Angle(0.2, lsst.geom.arcseconds).asDegrees())
43 eps_flux = np.full_like(eps_coord, 10)
44 flags = np.ones_like(eps_coord, dtype=bool)
46 columns_flux = ['flux_g', 'flux_r']
47 columns_ref_meas = [
48 MatchProbabilisticConfig.column_ref_coord1.default,
49 MatchProbabilisticConfig.column_ref_coord2.default,
50 ] + columns_flux
52 data_ref = {
53 columns_ref_meas[0]: ra[::-1],
54 columns_ref_meas[1]: dec[::-1],
55 columns_flux[0]: fluxes[0][::-1],
56 columns_flux[1]: fluxes[1][::-1],
57 }
58 self.catalog_ref = pd.DataFrame(data=data_ref)
60 columns_target_meas = [
61 MatchProbabilisticConfig.column_target_coord1.default,
62 MatchProbabilisticConfig.column_target_coord2.default,
63 ] + columns_flux
64 columns_target_err = [f'{column}Err' for column in columns_target_meas]
66 data_target = {
67 columns_target_meas[0]: ra + eps_coord,
68 columns_target_meas[1]: dec + eps_coord,
69 f'{columns_target_meas[0]}Err': eps_coord,
70 f'{columns_target_meas[1]}Err': eps_coord,
71 columns_flux[0]: fluxes[0] + eps_flux,
72 columns_flux[1]: fluxes[1] - eps_flux,
73 f'{columns_flux[0]}Err': eps_flux,
74 f'{columns_flux[1]}Err': eps_flux,
75 MatchProbabilisticConfig.columns_target_select_true.default[0]: flags,
76 MatchProbabilisticConfig.columns_target_select_false.default[0]: ~flags,
77 }
78 self.catalog_target = pd.DataFrame(data=data_target)
80 self.task = MatchProbabilisticTask(config=MatchProbabilisticConfig(
81 columns_ref_flux=columns_flux,
82 columns_ref_meas=columns_ref_meas,
83 columns_target_meas=columns_target_meas,
84 columns_target_err=columns_target_err,
85 ))
86 self.wcs = afwGeom.makeSkyWcs(crpix=lsst.geom.Point2D(9000, 9000),
87 crval=lsst.geom.SpherePoint(180., 0., lsst.geom.degrees),
88 cdMatrix=afwGeom.makeCdMatrix(scale=0.2*lsst.geom.arcseconds))
90 def tearDown(self):
91 del self.catalog_ref
92 del self.catalog_target
93 del self.task
94 del self.wcs
96 def test_MatchProbabilisticTask(self):
97 result = self.task.run(
98 catalog_ref=self.catalog_ref,
99 catalog_target=self.catalog_target,
100 wcs=self.wcs,
101 logging_n_rows=2,
102 )
103 indices_target = list(result.cat_output_target.match_row.values)
104 self.assertEqual(indices_target, list(np.arange(len(indices_target))[::-1]))
107class MemoryTester(lsst.utils.tests.MemoryTestCase):
108 pass
111def setup_module(module):
112 lsst.utils.tests.init()
115if __name__ == "__main__": 115 ↛ 116line 115 didn't jump to line 116, because the condition on line 115 was never true
116 lsst.utils.tests.init()
117 unittest.main()