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