Coverage for tests/test_transformObject.py : 22%

Hot-keys 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 pipe_tasks.
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/>.
22import os
23import unittest
24import pandas as pd
26import lsst.utils.tests
28import pyarrow as pa
29import pyarrow.parquet as pq
30from lsst.pipe.tasks.parquetTable import MultilevelParquetTable
31from lsst.pipe.tasks.functors import HsmFwhm
32from lsst.pipe.tasks.postprocess import TransformObjectCatalogTask, TransformObjectCatalogConfig
34ROOT = os.path.abspath(os.path.dirname(__file__))
37def setup_module(module):
38 lsst.utils.tests.init()
41class TransformObjectCatalogTestCase(unittest.TestCase):
42 def setUp(self):
43 # Note that this test input includes HSC-G, HSC-R, and HSC-I data
44 df = pd.read_csv(os.path.join(ROOT, 'data', 'test_multilevel_parq.csv.gz'),
45 header=[0, 1, 2], index_col=0)
46 with lsst.utils.tests.getTempFilePath('*.parq') as filename:
47 table = pa.Table.from_pandas(df)
48 pq.write_table(table, filename, compression='none')
49 self.parq = MultilevelParquetTable(filename)
51 self.dataId = {"tract": 9615, "patch": "4,4"}
53 def testNullFilter(self):
54 """Test that columns for all filters are created despite they may not
55 exist in the input data.
56 """
57 config = TransformObjectCatalogConfig()
58 # Want y band columns despite the input data do not have them
59 # Exclude g band columns despite the input data have them
60 config.outputBands = ["r", "i", "y"]
61 task = TransformObjectCatalogTask(config=config)
62 funcs = {'Fwhm': HsmFwhm(dataset='meas')}
63 df = task.run(self.parq, funcs=funcs, dataId=self.dataId)
64 self.assertIsInstance(df, pd.DataFrame)
65 for column in ('coord_ra', 'coord_dec'):
66 self.assertIn(column, df.columns)
68 for filt in config.outputBands:
69 self.assertIn(filt + 'Fwhm', df.columns)
71 self.assertNotIn('gFwhm', df.columns)
72 self.assertTrue(df['yFwhm'].isnull().all())
73 self.assertTrue(df['iFwhm'].notnull().all())
75 def testUnderscoreColumnFormat(self):
76 """Test the per-filter column format with an underscore"""
77 config = TransformObjectCatalogConfig()
78 config.outputBands = ["g", "r", "i"]
79 config.camelCase = False
80 task = TransformObjectCatalogTask(config=config)
81 funcs = {'Fwhm': HsmFwhm(dataset='meas')}
82 df = task.run(self.parq, funcs=funcs, dataId=self.dataId)
83 self.assertIsInstance(df, pd.DataFrame)
84 for filt in config.outputBands:
85 self.assertIn(filt + '_Fwhm', df.columns)
87 def testMultilevelOutput(self):
88 """Test the non-flattened result dataframe with a multilevel column index"""
89 config = TransformObjectCatalogConfig()
90 config.outputBands = ["r", "i"]
91 config.multilevelOutput = True
92 task = TransformObjectCatalogTask(config=config)
93 funcs = {'Fwhm': HsmFwhm(dataset='meas')}
94 df = task.run(self.parq, funcs=funcs, dataId=self.dataId)
95 self.assertIsInstance(df, pd.DataFrame)
96 self.assertNotIn('g', df)
97 for filt in config.outputBands:
98 self.assertIsInstance(df[filt], pd.DataFrame)
99 self.assertIn('Fwhm', df[filt].columns)
101 def testNoOutputBands(self):
102 """All the input bands should go into the output, and nothing else.
103 """
104 config = TransformObjectCatalogConfig()
105 config.multilevelOutput = True
106 task = TransformObjectCatalogTask(config=config)
107 funcs = {'Fwhm': HsmFwhm(dataset='meas')}
108 df = task.run(self.parq, funcs=funcs, dataId=self.dataId)
109 self.assertIsInstance(df, pd.DataFrame)
110 self.assertNotIn('HSC-G', df)
111 for filt in ['g', 'r', 'i']:
112 self.assertIsInstance(df[filt], pd.DataFrame)
113 self.assertIn('Fwhm', df[filt].columns)