Coverage for tests/test_transformObject.py : 23%

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)
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 config.camelCase = True
59 # Want y band columns despite the input data do not have them
60 # Exclude g band columns despite the input data have them
61 config.outputBands = ["r", "i", "y"]
62 task = TransformObjectCatalogTask(config=config)
63 funcs = {'Fwhm': HsmFwhm(dataset='meas')}
64 df = task.run(self.parq, funcs=funcs, dataId=self.dataId)
65 self.assertIsInstance(df, pd.DataFrame)
67 for filt in config.outputBands:
68 self.assertIn(filt + 'Fwhm', df.columns)
70 self.assertNotIn('gFwhm', df.columns)
71 self.assertTrue(df['yFwhm'].isnull().all())
72 self.assertTrue(df['iFwhm'].notnull().all())
74 def testUnderscoreColumnFormat(self):
75 """Test the per-filter column format with an underscore"""
76 config = TransformObjectCatalogConfig()
77 config.outputBands = ["g", "r", "i"]
78 config.camelCase = False
79 task = TransformObjectCatalogTask(config=config)
80 funcs = {'Fwhm': HsmFwhm(dataset='meas')}
81 df = task.run(self.parq, funcs=funcs, dataId=self.dataId)
82 self.assertIsInstance(df, pd.DataFrame)
83 for filt in config.outputBands:
84 self.assertIn(filt + '_Fwhm', df.columns)
86 def testMultilevelOutput(self):
87 """Test the non-flattened result dataframe with a multilevel column index"""
88 config = TransformObjectCatalogConfig()
89 config.outputBands = ["r", "i"]
90 config.multilevelOutput = True
91 task = TransformObjectCatalogTask(config=config)
92 funcs = {'Fwhm': HsmFwhm(dataset='meas')}
93 df = task.run(self.parq, funcs=funcs, dataId=self.dataId)
94 self.assertIsInstance(df, pd.DataFrame)
95 self.assertNotIn('g', df)
96 for filt in config.outputBands:
97 self.assertIsInstance(df[filt], pd.DataFrame)
98 self.assertIn('Fwhm', df[filt].columns)
100 def testNoOutputBands(self):
101 """All the input bands should go into the output, and nothing else.
102 """
103 config = TransformObjectCatalogConfig()
104 config.multilevelOutput = True
105 task = TransformObjectCatalogTask(config=config)
106 funcs = {'Fwhm': HsmFwhm(dataset='meas')}
107 df = task.run(self.parq, funcs=funcs, dataId=self.dataId)
108 self.assertIsInstance(df, pd.DataFrame)
109 self.assertNotIn('HSC-G', df)
110 for filt in ['g', 'r', 'i']:
111 self.assertIsInstance(df[filt], pd.DataFrame)
112 self.assertIn('Fwhm', df[filt].columns)