def testGalacticStacker(self): """ Test the galactic coordinate stacker """ ra, dec = np.degrees( np.meshgrid(np.arange(0, 2. * np.pi, 0.1), np.arange(-np.pi, np.pi, 0.1))) ra = np.ravel(ra) dec = np.ravel(dec) data = np.zeros(ra.size, dtype=list(zip(['ra', 'dec'], [float] * 2))) data['ra'] += ra data['dec'] += dec s = stackers.GalacticStacker(raCol='ra', decCol='dec') newData = s.run(data) expectedL, expectedB = _galacticFromEquatorial(np.radians(ra), np.radians(dec)) np.testing.assert_array_equal(newData['gall'], expectedL) np.testing.assert_array_equal(newData['galb'], expectedB) # Check that we have all the quadrants populated q1 = np.where((newData['gall'] < np.pi) & (newData['galb'] < 0.))[0] q2 = np.where((newData['gall'] < np.pi) & (newData['galb'] > 0.))[0] q3 = np.where((newData['gall'] > np.pi) & (newData['galb'] < 0.))[0] q4 = np.where((newData['gall'] > np.pi) & (newData['galb'] > 0.))[0] assert (q1.size > 0) assert (q2.size > 0) assert (q3.size > 0) assert (q4.size > 0)
def testOut(self): """ Check that the metric bundle can generate the expected output """ nside = 8 slicer = slicers.HealpixSlicer(nside=nside) metric = metrics.MeanMetric(col='airmass') sql = 'filter="r"' stacker1 = stackers.RandomDitherFieldPerVisitStacker() stacker2 = stackers.GalacticStacker() map1 = maps.GalCoordsMap() map2 = maps.StellarDensityMap() metricB = metricBundles.MetricBundle(metric, slicer, sql, stackerList=[stacker1, stacker2], mapsList=[map1, map2]) database = os.path.join(getPackageDir('sims_data'), 'OpSimData', 'astro-lsst-01_2014.db') opsdb = db.OpsimDatabaseV4(database=database) resultsDb = db.ResultsDb(outDir=self.outDir) bgroup = metricBundles.MetricBundleGroup({0: metricB}, opsdb, outDir=self.outDir, resultsDb=resultsDb) bgroup.runAll() bgroup.plotAll() bgroup.writeAll() opsdb.close() outThumbs = glob.glob(os.path.join(self.outDir, 'thumb*')) outNpz = glob.glob(os.path.join(self.outDir, '*.npz')) outPdf = glob.glob(os.path.join(self.outDir, '*.pdf')) # By default, make 3 plots for healpix assert (len(outThumbs) == 3) assert (len(outPdf) == 3) assert (len(outNpz) == 1)
def testOut(self): """ Check that the metric bundle can generate the expected output """ nside = 8 slicer = slicers.HealpixSlicer(nside=nside) metric = metrics.MeanMetric(col='airmass') sql = 'filter="r"' stacker1 = stackers.RandomDitherFieldPerVisitStacker() stacker2 = stackers.GalacticStacker() map1 = maps.GalCoordsMap() map2 = maps.StellarDensityMap() metricB = metricBundles.MetricBundle(metric, slicer, sql, stackerList=[stacker1, stacker2]) filepath = os.path.join(os.getenv('SIMS_MAF_DIR'), 'tests/') database = os.path.join(filepath, 'opsimblitz1_1133_sqlite.db') opsdb = db.OpsimDatabase(database=database) resultsDb = db.ResultsDb(outDir=self.outDir) bgroup = metricBundles.MetricBundleGroup({0: metricB}, opsdb, outDir=self.outDir, resultsDb=resultsDb) bgroup.runAll() bgroup.plotAll() bgroup.writeAll() outThumbs = glob.glob(os.path.join(self.outDir, 'thumb*')) outNpz = glob.glob(os.path.join(self.outDir, '*.npz')) outPdf = glob.glob(os.path.join(self.outDir, '*.pdf')) # By default, make 3 plots for healpix assert (len(outThumbs) == 3) assert (len(outPdf) == 3) assert (len(outNpz) == 1)