Coverage for tests/test_match_probabilistic_task.py: 26%
47 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-19 10:27 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-19 10:27 +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 ConvertCatalogCoordinatesConfig, 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 coord_format = ConvertCatalogCoordinatesConfig
41 zeropoint = coord_format.mag_zeropoint_ref.default
42 fluxes = tuple(-0.4*10**(mag - zeropoint) for mag in (mag_g, mag_r))
43 eps_coord = np.full_like(ra, lsst.geom.Angle(0.2, lsst.geom.arcseconds).asDegrees())
44 eps_flux = np.full_like(eps_coord, 10)
45 flags = np.ones_like(eps_coord, dtype=bool)
46 name_index = 'index'
48 columns_flux = ['flux_g', 'flux_r']
49 columns_ref_meas = [
50 coord_format.column_ref_coord1.default,
51 coord_format.column_ref_coord2.default,
52 ] + columns_flux
54 data_ref = {
55 name_index: np.arange(len(ra)),
56 columns_ref_meas[0]: ra[::-1],
57 columns_ref_meas[1]: dec[::-1],
58 columns_flux[0]: fluxes[0][::-1],
59 columns_flux[1]: fluxes[1][::-1],
60 }
61 self.catalog_ref = pd.DataFrame(data=data_ref)
63 columns_target_meas = [
64 coord_format.column_target_coord1.default,
65 coord_format.column_target_coord2.default,
66 ] + columns_flux
67 columns_target_err = [f'{column}Err' for column in columns_target_meas]
69 data_target = {
70 name_index: np.arange(len(ra)),
71 columns_target_meas[0]: ra + eps_coord,
72 columns_target_meas[1]: dec + eps_coord,
73 f'{columns_target_meas[0]}Err': eps_coord,
74 f'{columns_target_meas[1]}Err': eps_coord,
75 columns_flux[0]: fluxes[0] + eps_flux,
76 columns_flux[1]: fluxes[1] - eps_flux,
77 f'{columns_flux[0]}Err': eps_flux,
78 f'{columns_flux[1]}Err': eps_flux,
79 MatchProbabilisticConfig.columns_target_select_true.default[0]: flags,
80 MatchProbabilisticConfig.columns_target_select_false.default[0]: ~flags,
81 }
82 self.catalog_target = pd.DataFrame(data=data_target)
84 self.task = MatchProbabilisticTask(config=MatchProbabilisticConfig(
85 columns_ref_flux=columns_flux,
86 columns_ref_meas=columns_ref_meas,
87 columns_ref_copy=[name_index],
88 columns_target_meas=columns_target_meas,
89 columns_target_err=columns_target_err,
90 columns_target_copy=[name_index],
91 ))
92 self.wcs = afwGeom.makeSkyWcs(crpix=lsst.geom.Point2D(9000, 9000),
93 crval=lsst.geom.SpherePoint(180., 0., lsst.geom.degrees),
94 cdMatrix=afwGeom.makeCdMatrix(scale=0.2*lsst.geom.arcseconds))
96 def tearDown(self):
97 del self.catalog_ref
98 del self.catalog_target
99 del self.task
100 del self.wcs
102 def test_MatchProbabilisticTask(self):
103 for (columns, catalog) in (
104 (self.task.columns_in_ref, self.catalog_ref),
105 (self.task.columns_in_target, self.catalog_target),
106 ):
107 self.assertTrue(all((column in catalog.columns for column in columns)))
108 result = self.task.run(
109 catalog_ref=self.catalog_ref,
110 catalog_target=self.catalog_target,
111 wcs=self.wcs,
112 logging_n_rows=2,
113 )
114 indices_target = list(result.cat_output_target.match_row.values)
115 self.assertEqual(indices_target, list(np.arange(len(indices_target))[::-1]))
118class MemoryTester(lsst.utils.tests.MemoryTestCase):
119 pass
122def setup_module(module):
123 lsst.utils.tests.init()
126if __name__ == "__main__": 126 ↛ 127line 126 didn't jump to line 127, because the condition on line 126 was never true
127 lsst.utils.tests.init()
128 unittest.main()