def setUp(self) -> None: np.random.seed(0) self.objects = pd.DataFrame( index=[ 'ZTF18abakgtm', 'ZTF18abvvcko', 'ZTF17aaaaaxg', 'ZTF18aaveorp' ], columns=['corrected'], data=np.random.choice( a=[False, True], size=(4,) ) ) preprocess_ztf = DetectionsPreprocessorZTF() raw_det_ZTF18abakgtm = pd.read_csv( os.path.join(EXAMPLES_PATH, 'ZTF18abakgtm_det.csv'), index_col="oid") raw_det_ZTF18abakgtm['sigmapsf_corr_ext'] = raw_det_ZTF18abakgtm['sigmapsf_corr'] raw_det_ZTF18abvvcko = pd.read_csv( os.path.join(EXAMPLES_PATH, 'ZTF18abvvcko_det.csv'), index_col="oid") raw_det_ZTF18abvvcko['sigmapsf_corr_ext'] = raw_det_ZTF18abvvcko['sigmapsf_corr'] raw_det_ZTF17aaaaaxg = pd.read_csv( os.path.join(EXAMPLES_PATH, 'ZTF17aaaaaxg_det.csv'), index_col="oid") raw_det_ZTF17aaaaaxg['sigmapsf_corr_ext'] = raw_det_ZTF17aaaaaxg['sigmapsf_corr'] raw_det_ZTF18aaveorp = pd.read_csv( os.path.join(EXAMPLES_PATH, 'ZTF18aaveorp_det.csv'), index_col="oid") raw_det_ZTF18aaveorp['sigmapsf_corr_ext'] = raw_det_ZTF18aaveorp['sigmapsf_corr'] keys = [ 'mjd', 'fid', 'magpsf_corr', 'sigmapsf_corr_ext', 'isdiffpos', 'magpsf', 'sigmapsf', 'ra', 'dec', 'sgscore1', 'rb' ] self.detections = pd.concat( [raw_det_ZTF17aaaaaxg[keys], raw_det_ZTF18abvvcko[keys], raw_det_ZTF18abakgtm[keys], raw_det_ZTF18aaveorp[keys]], axis=0 ) self.detections = preprocess_ztf.get_magpsf_ml( self.detections, objects=self.objects ) self.detections = self.detections[['fid', 'magpsf_ml']]
class TestObjectsMethods(unittest.TestCase): def setUp(self) -> None: self.preprocessor_ztf = DetectionsPreprocessorZTF() self.raw_data_ZTF18abakgtm = pd.read_csv( os.path.join(EXAMPLES_PATH, 'ZTF18abakgtm_det.csv'), index_col="oid") self.raw_data_ZTF18abakgtm['sigmapsf_corr_ext'] = self.raw_data_ZTF18abakgtm['sigmapsf_corr'] self.fake_objects = pd.DataFrame( columns=['corrected'], index=['ZTF18abakgtm'], data=[[True]] ) def test_preprocess_one_object(self): self.assertEqual(self.preprocessor_ztf.has_necessary_columns( self.preprocessor_ztf.get_magpsf_ml( self.raw_data_ZTF18abakgtm, self.fake_objects )), True) self.assertEqual(self.raw_data_ZTF18abakgtm.index.name, "oid") preprocessed_data = self.preprocessor_ztf.preprocess( self.raw_data_ZTF18abakgtm, objects=self.fake_objects) self.assertEqual(type(preprocessed_data), pd.DataFrame)
def setUp(self) -> None: np.random.seed(0) self.objects = pd.DataFrame( index=[ "ZTF18abakgtm", "ZTF18abvvcko", "ZTF17aaaaaxg", "ZTF18aaveorp" ], columns=["corrected"], data=np.random.choice(a=[False, True], size=(4, )), ) preprocess_ztf = DetectionsPreprocessorZTF() raw_det_ZTF18abakgtm = pd.read_csv(os.path.join( EXAMPLES_PATH, "ZTF18abakgtm_det.csv"), index_col="oid") raw_det_ZTF18abakgtm["sigmapsf_corr_ext"] = raw_det_ZTF18abakgtm[ "sigmapsf_corr"] raw_det_ZTF18abvvcko = pd.read_csv(os.path.join( EXAMPLES_PATH, "ZTF18abvvcko_det.csv"), index_col="oid") raw_det_ZTF18abvvcko["sigmapsf_corr_ext"] = raw_det_ZTF18abvvcko[ "sigmapsf_corr"] raw_det_ZTF17aaaaaxg = pd.read_csv(os.path.join( EXAMPLES_PATH, "ZTF17aaaaaxg_det.csv"), index_col="oid") raw_det_ZTF17aaaaaxg["sigmapsf_corr_ext"] = raw_det_ZTF17aaaaaxg[ "sigmapsf_corr"] raw_det_ZTF18aaveorp = pd.read_csv(os.path.join( EXAMPLES_PATH, "ZTF18aaveorp_det.csv"), index_col="oid") raw_det_ZTF18aaveorp["sigmapsf_corr_ext"] = raw_det_ZTF18aaveorp[ "sigmapsf_corr"] keys = [ "mjd", "fid", "magpsf_corr", "sigmapsf_corr_ext", "isdiffpos", "magpsf", "sigmapsf", "ra", "dec", "sgscore1", "rb", ] self.detections = pd.concat( [ raw_det_ZTF17aaaaaxg[keys], raw_det_ZTF18abvvcko[keys], raw_det_ZTF18abakgtm[keys], raw_det_ZTF18aaveorp[keys], ], axis=0, ) self.detections = preprocess_ztf.get_magpsf_ml(self.detections, objects=self.objects) self.detections = self.detections[["sgscore1"]]