|
27 | 27 | import matplotlib.pyplot as plt |
28 | 28 | import numpy as np |
29 | 29 | import skyproj |
| 30 | +from lsst.analysis.tools.atools.healSparsePropertyMap import HealSparsePropertyMapTool |
30 | 31 | from lsst.analysis.tools.atools.propertyMap import PropertyMapTool |
| 32 | +from lsst.analysis.tools.tasks.propertyMapAnalysis import ( |
| 33 | + PropertyMapSurveyWideAnalysisConfig, |
| 34 | + PropertyMapSurveyWideAnalysisTask, |
| 35 | +) |
31 | 36 | from lsst.analysis.tools.tasks.propertyMapTractAnalysis import ( |
32 | 37 | PropertyMapConfig, |
33 | 38 | PropertyMapTractAnalysisConfig, |
@@ -344,6 +349,91 @@ def _validateRGBFractions(self, fig, RGBFraction, rtol=1e-7): |
344 | 349 | self.assertTrue(len(errors) == 0, msg="\n" + "\n".join(errors)) |
345 | 350 |
|
346 | 351 |
|
| 352 | +class PropertyMapSurveyWideAnalysisTaskTestCase(lsst.utils.tests.TestCase): |
| 353 | + """PropertyMapTractAnalysisTask test case. |
| 354 | +
|
| 355 | + Notes |
| 356 | + ----- |
| 357 | + This is a basic functionality test to verify the internal workings of the |
| 358 | + task. |
| 359 | + """ |
| 360 | + |
| 361 | + def setUp(self): |
| 362 | + # Create a temporary directory to test in. |
| 363 | + self.testDir = makeTestTempDir(ROOT) |
| 364 | + |
| 365 | + # Create a butler in the test directory. |
| 366 | + Butler.makeRepo(self.testDir) |
| 367 | + butler = Butler(self.testDir, run="testrun") |
| 368 | + |
| 369 | + # Make a dummy dataId. |
| 370 | + dataId = {"band": "i", "skymap": "hsc_rings_v1", "tract": 1915} |
| 371 | + dataId = DataCoordinate.standardize(dataId, universe=butler.dimensions) |
| 372 | + |
| 373 | + # Configure the maps to be plotted. |
| 374 | + config = PropertyMapSurveyWideAnalysisConfig() |
| 375 | + |
| 376 | + # Set configurations sent to skyproj. |
| 377 | + config.autozoom = True |
| 378 | + config.projection = "Mollweide" |
| 379 | + config.projectionKwargs = {"celestial": True, "gridlines": True, "lon_0": 0} |
| 380 | + config.colorbarKwargs = {"location": "top", "cmap": "viridis"} |
| 381 | + |
| 382 | + # The entries in the 'atools' namespace must exactly match the dataset |
| 383 | + # type. |
| 384 | + config.atools.deepCoadd_exposure_time_consolidated_map_sum = HealSparsePropertyMapTool() |
| 385 | + config.atools.deepCoadd_psf_maglim_consolidated_map_weighted_mean = HealSparsePropertyMapTool() |
| 386 | + config.atools.goodSeeingCoadd_dcr_dra_consolidated_map_weighted_mean = HealSparsePropertyMapTool() |
| 387 | + |
| 388 | + # Generate a list of dataset type names. |
| 389 | + names = [name for name in config.atools.fieldNames] |
| 390 | + |
| 391 | + # Mock up corresponding HealSparseMaps and register them with the |
| 392 | + # butler. |
| 393 | + inputs = {} |
| 394 | + for name, value in zip(names, np.linspace(1, 10, len(names))): |
| 395 | + hspMap = hsp.HealSparseMap.make_empty(nside_coverage=32, nside_sparse=4096, dtype=np.float32) |
| 396 | + hspMap[0:10000] = value |
| 397 | + hspMap[100000:110000] = value + 1 |
| 398 | + hspMap[500000:510000] = value + 2 |
| 399 | + datasetType = DatasetType(name, [], "HealSparseMap", universe=butler.dimensions) |
| 400 | + butler.registry.registerDatasetType(datasetType) |
| 401 | + dataRef = butler.put(hspMap, datasetType) |
| 402 | + # Keys in inputs are designed to reflect the task's connection |
| 403 | + # names. |
| 404 | + inputs[name] = DeferredDatasetHandle(butler=butler, ref=dataRef, parameters=None) |
| 405 | + |
| 406 | + # Initialize the task and set class attributes for subsequent use. |
| 407 | + task = PropertyMapSurveyWideAnalysisTask() |
| 408 | + self.config = config |
| 409 | + self.plotInfo = task.parsePlotInfo(inputs, dataId, list(inputs.keys())) |
| 410 | + self.data = inputs |
| 411 | + |
| 412 | + for tool in self.config.atools: |
| 413 | + tool.finalize() |
| 414 | + |
| 415 | + def tearDown(self): |
| 416 | + del self.data |
| 417 | + del self.config |
| 418 | + del self.plotInfo |
| 419 | + removeTestTempDir(self.testDir) |
| 420 | + del self.testDir |
| 421 | + |
| 422 | + def test_PropertyMapSurveyWideAnalysisTask(self): |
| 423 | + plt.rcParams.update(plt.rcParamsDefault) |
| 424 | + for tool in self.config.atools: |
| 425 | + # Run the task via butler using the tool. |
| 426 | + result = tool(data=self.data, plotConfig=self.config, plotInfo=self.plotInfo) |
| 427 | + key = tool.process.buildActions.data.mapKey + "_PropertyMapSurveyWidePlot" |
| 428 | + fig = result[key] |
| 429 | + |
| 430 | + # Check that the output is a matplotlib figure. |
| 431 | + self.assertTrue(isinstance(fig, plt.Figure), msg=f"Figure {key} is not a matplotlib figure.") |
| 432 | + |
| 433 | + # Assert the number of axes in the figure. At least not empty. |
| 434 | + self.assertEqual(len(fig.axes), 3) |
| 435 | + |
| 436 | + |
347 | 437 | class MemoryTester(lsst.utils.tests.MemoryTestCase): |
348 | 438 | pass |
349 | 439 |
|
|
0 commit comments