def testComposite(self): self.columns.extend( ["modelfit_CModel_instFlux", "base_PsfFlux_instFlux"]) self.dataDict["modelfit_CModel_instFlux"] = np.full(self.nRecords, 1) self.dataDict["base_PsfFlux_instFlux"] = np.full(self.nRecords, 1) parq = self.simulateMultiParquet(self.dataDict) # Modify r band value slightly. parq._df[("meas", "r", "base_PsfFlux_instFlux")] -= 0.1 filt = 'g' funcDict = { 'psfMag_ref': Mag('base_PsfFlux', dataset='ref'), 'ra': RAColumn(), 'dec': DecColumn(), 'psfMag': Mag('base_PsfFlux', filt=filt), 'cmodel_magDiff': MagDiff('base_PsfFlux', 'modelfit_CModel', filt=filt) } func = CompositeFunctor(funcDict) df = self._compositeFuncVal(func, parq) # Repeat same, but define filter globally instead of individually funcDict2 = { 'psfMag_ref': Mag('base_PsfFlux', dataset='ref'), 'ra': RAColumn(), 'dec': DecColumn(), 'psfMag': Mag('base_PsfFlux'), 'cmodel_magDiff': MagDiff('base_PsfFlux', 'modelfit_CModel') } func2 = CompositeFunctor(funcDict2, filt=filt) df2 = self._compositeFuncVal(func2, parq) self.assertTrue(df.equals(df2)) func2.filt = 'r' df3 = self._compositeFuncVal(func2, parq) # Because we modified the R filter this should fail. self.assertFalse(df2.equals(df3)) # Make sure things work with passing list instead of dict funcs = [ Mag('base_PsfFlux', dataset='ref'), RAColumn(), DecColumn(), Mag('base_PsfFlux', filt=filt), MagDiff('base_PsfFlux', 'modelfit_CModel', filt=filt) ] df = self._compositeFuncVal(CompositeFunctor(funcs), parq)
def testCompositeColor(self): funcDict = { 'a': Mag('base_PsfFlux', dataset='meas', filt='HSC-G'), 'b': Mag('base_PsfFlux', dataset='forced_src', filt='HSC-G'), 'c': Color('base_PsfFlux', 'HSC-G', 'HSC-R') } # Covering the code is better than nothing df = self._compositeFuncVal(CompositeFunctor(funcDict)) # noqa
def testCompositeColor(self): self.dataDict["base_PsfFlux_instFlux"] = np.full(self.nRecords, 1000) self.dataDict["base_PsfFlux_instFluxErr"] = np.full(self.nRecords, 10) parq = self.simulateMultiParquet(self.dataDict) funcDict = { 'a': Mag('base_PsfFlux', dataset='meas', filt='HSC-G'), 'b': Mag('base_PsfFlux', dataset='forced_src', filt='HSC-G'), 'c': Color('base_PsfFlux', 'HSC-G', 'HSC-R') } # Covering the code is better than nothing df = self._compositeFuncVal(CompositeFunctor(funcDict), parq) # noqa
def testComposite(self): filt = 'HSC-G' funcDict = { 'psfMag_ref': Mag('base_PsfFlux', dataset='ref'), 'ra': RAColumn(), 'dec': DecColumn(), 'psfMag': Mag('base_PsfFlux', filt=filt), 'cmodel_magDiff': MagDiff('base_PsfFlux', 'modelfit_CModel', filt=filt) } func = CompositeFunctor(funcDict) df = self._compositeFuncVal(func) # Repeat same, but define filter globally instead of individually funcDict2 = { 'psfMag_ref': Mag('base_PsfFlux', dataset='ref'), 'ra': RAColumn(), 'dec': DecColumn(), 'psfMag': Mag('base_PsfFlux'), 'cmodel_magDiff': MagDiff('base_PsfFlux', 'modelfit_CModel') } func2 = CompositeFunctor(funcDict2, filt=filt) df2 = self._compositeFuncVal(func2) self.assertTrue(df.equals(df2)) func2.filt = 'HSC-R' df3 = self._compositeFuncVal(func2) self.assertFalse(df2.equals(df3)) # Make sure things work with passing list instead of dict funcs = [ Mag('base_PsfFlux', dataset='ref'), RAColumn(), DecColumn(), Mag('base_PsfFlux', filt=filt), MagDiff('base_PsfFlux', 'modelfit_CModel', filt=filt) ] df = self._compositeFuncVal(CompositeFunctor(funcs))
def testCompositeFail(self): """Test a composite functor where one of the functors should be junk. """ self.dataDict["base_PsfFlux_instFlux"] = np.full(self.nRecords, 1000) parq = self.simulateMultiParquet(self.dataDict) funcDict = { 'good': Column("base_PsfFlux_instFlux"), 'bad': Column('not_a_column') } df = self._compositeFuncVal(CompositeFunctor(funcDict), parq) # noqa
def testCompositeDifference(self): self.dataDict["base_PsfFlux_instFlux"] = np.full(self.nRecords, 1000) self.dataDict["base_PsfFlux_instFluxErr"] = np.full(self.nRecords, 10) parq1 = self.simulateMultiParquet(self.dataDict) self.dataDict["base_PsfFlux_instFlux"] = np.full(self.nRecords, 999) self.dataDict["base_PsfFlux_instFluxErr"] = np.full(self.nRecords, 9) parq2 = self.simulateMultiParquet(self.dataDict) funcDict = { 'a': Mag('base_PsfFlux', dataset='meas', filt='g'), 'b': Mag('base_PsfFlux', dataset='forced_src', filt='g'), 'c': Color('base_PsfFlux', 'g', 'r') } # Covering the code is better than nothing df = self._compositeDifferenceVal(CompositeFunctor(funcDict), parq1, parq2) # noqa
def testCompositeSimple(self): """Test single-level composite functor for functionality """ self.columns.extend( ["modelfit_CModel_instFlux", "base_PsfFlux_instFlux"]) self.dataDict["modelfit_CModel_instFlux"] = np.full(self.nRecords, 1) self.dataDict["base_PsfFlux_instFlux"] = np.full(self.nRecords, 1) parq = self.simulateParquet(self.dataDict) funcDict = { 'ra': RAColumn(), 'dec': DecColumn(), 'psfMag': Mag('base_PsfFlux'), 'cmodel_magDiff': MagDiff('base_PsfFlux', 'modelfit_CModel') } func = CompositeFunctor(funcDict) df = self._compositeFuncVal(func, parq) # noqa
def _get_funcs(self, x_data, x_data_custom, y_data, y_data_custom, labeller): if self.x_data_custom: xFunc = getFunc(self.x_data_custom) else: xFunc = getFunc(self.x_data) if self.y_data_custom: yFunc = getFunc(self.y_data_custom) else: yFunc = getFunc(self.y_data) labeller = getLabeller(self.labeller) return CompositeFunctor({ 'x': xFunc, 'y': yFunc, 'label': labeller, 'id': Column('id'), 'ra': RAColumn(), 'dec': DecColumn() })