Skip to content

Commit 763851a

Browse files
authored
Merge pull request #324 from lsst/tickets/DM-47989
DM-47989: Add unit test for survey-wide healsparse property map task/tool/action
2 parents 845d6a1 + ea7dad9 commit 763851a

4 files changed

Lines changed: 104 additions & 11 deletions

File tree

pipelines/surveyQualityCore.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ tasks:
55
class: lsst.analysis.tools.tasks.PropertyMapSurveyWideAnalysisTask
66
config:
77
connections.outputName: propertyMapSurveyWide
8+
autozoom: true
89
projection: McBryde
910
projectionKwargs:
11+
celestial: true
12+
gridlines: true
1013
# lon_0 should be something close to the center
1114
# (if it’s a sub-survey) or 0 (if it’s the full sky)
1215
lon_0: 0
13-
autozoom: true
1416
colorbarKwargs:
1517
location: top
1618
cmap: viridis

python/lsst/analysis/tools/actions/plot/propertyMapPlot.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,16 +419,16 @@ def makePlot(
419419
propertyName.replace("_", " ")
420420
.replace("psf", "PSF")
421421
.replace("dcr", "DCR")
422-
.replace("dra", "delta-RA")
423-
.replace("ddec", "delta-Dec")
422+
.replace("dra", r"$\Delta$RA")
423+
.replace("ddec", r"$\Delta$Dec")
424424
)
425425
plotInfo["property"] = (
426426
propertyName.replace("_", " ")
427427
.title() # Capitalize and handle edge cases below.
428428
.replace("Psf", "PSF")
429429
.replace("Dcr", "DCR")
430-
.replace("Dra", "delta-RA")
431-
.replace("Ddec", "delta-Dec")
430+
.replace("Dra", r"$\Delta$RA")
431+
.replace("Ddec", r"$\Delta$Dec")
432432
.replace("E1", "e1")
433433
.replace("E2", "e2")
434434
)
@@ -691,7 +691,7 @@ def addPlotInfo(
691691
titleBoxTopLeftCorner = (0.045, 0.89)
692692
title = fig.text(
693693
*titleBoxTopLeftCorner,
694-
f'{plotInfo["plotName"]}: {plotInfo["property"]}',
694+
f'{plotInfo["plotName"]} of {plotInfo["property"]}',
695695
fontsize=19,
696696
transform=fig.transFigure,
697697
ha="left",
@@ -805,16 +805,16 @@ def makePlot(
805805
propertyName.replace("_", " ")
806806
.replace("psf", "PSF")
807807
.replace("dcr", "DCR")
808-
.replace("dra", "delta-RA")
809-
.replace("ddec", "delta-Dec")
808+
.replace("dra", r"$\Delta$RA")
809+
.replace("ddec", r"$\Delta$Dec")
810810
)
811811
plotInfo["property"] = (
812812
propertyName.replace("_", " ")
813813
.title() # Capitalize and handle edge cases below.
814814
.replace("Psf", "PSF")
815815
.replace("Dcr", "DCR")
816-
.replace("Dra", "delta-RA")
817-
.replace("Ddec", "delta-Dec")
816+
.replace("Dra", r"$\Delta$RA")
817+
.replace("Ddec", r"$\Delta$Dec")
818818
.replace("E1", "e1")
819819
.replace("E2", "e2")
820820
)

python/lsst/analysis/tools/tasks/propertyMapAnalysis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ class PropertyMapSurveyWideAnalysisConfig(
103103
projectionKwargs = DictField(
104104
keytype=str,
105105
itemtype=float,
106-
doc="Keyword arguments to use in the projection call, e.g. lon_0 and lat_0 .",
106+
doc="Keyword arguments to use in the projection call, e.g. lon_0. "
107+
"See https://skyproj.readthedocs.io/en/latest/projections.html",
107108
default={},
108109
)
109110

tests/test_propertyMapPlot.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
import matplotlib.pyplot as plt
2828
import numpy as np
2929
import skyproj
30+
from lsst.analysis.tools.atools.healSparsePropertyMap import HealSparsePropertyMapTool
3031
from lsst.analysis.tools.atools.propertyMap import PropertyMapTool
32+
from lsst.analysis.tools.tasks.propertyMapAnalysis import (
33+
PropertyMapSurveyWideAnalysisConfig,
34+
PropertyMapSurveyWideAnalysisTask,
35+
)
3136
from lsst.analysis.tools.tasks.propertyMapTractAnalysis import (
3237
PropertyMapConfig,
3338
PropertyMapTractAnalysisConfig,
@@ -344,6 +349,91 @@ def _validateRGBFractions(self, fig, RGBFraction, rtol=1e-7):
344349
self.assertTrue(len(errors) == 0, msg="\n" + "\n".join(errors))
345350

346351

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+
347437
class MemoryTester(lsst.utils.tests.MemoryTestCase):
348438
pass
349439

0 commit comments

Comments
 (0)