2121
2222from __future__ import annotations
2323
24- from typing import TYPE_CHECKING , Any , Iterable , Mapping
25-
2624__all__ = ("RhoStatisticsPlot" ,)
2725
26+ from typing import Any , Iterable , Mapping
27+
2828import numpy as np
2929from lsst .pex .config import ConfigDictField
30+ from matplotlib .figure import Figure
3031
31- from ...interfaces import PlotAction , Vector
32+ from ...interfaces import KeyedData , KeyedDataSchema , PlotAction , Vector
3233from .plotUtils import addPlotInfo
3334from .xyPlot import XYPlot
3435
35- if TYPE_CHECKING :
36- from matplotlib .figure import Figure
37-
38- from ...interfaces import KeyedData , KeyedDataSchema
39-
4036
4137class RhoStatisticsPlot (PlotAction ):
4238 """Make multiple plots of rho statistics.
@@ -46,10 +42,8 @@ class RhoStatisticsPlot(PlotAction):
4642 :ref:`here <rho_definitions>`.
4743 """
4844
49- rhoPlots = ConfigDictField (
45+ rhoPlots = ConfigDictField [ str , XYPlot ] (
5046 doc = "A configurable dict describing the rho statistics to plot." ,
51- keytype = str ,
52- itemtype = XYPlot ,
5347 default = {},
5448 )
5549
@@ -91,15 +85,17 @@ def getInputSchema(self) -> KeyedDataSchema:
9185
9286 def getOutputNames (self ) -> Iterable [str ]:
9387 # Docstring inherited
94- return ("rho3alt" , "rho1" , "rho2" , "rho3" , "rho4" , "rho5" )
88+ for key in self .rhoPlots .keys ():
89+ yield key
9590
9691 def __call__ (self , data : KeyedData , ** kwargs ) -> Mapping [str , Figure ]:
9792 self ._validateInput (data )
9893 return self .makePlot (data , ** kwargs )
9994
10095 def _validateInput (self , data : KeyedData ) -> None :
101- if not set (("rho3alt" , "rho1" , "rho2" , "rho3" , "rho4" , "rho5" )).issubset (data .keys ()):
102- raise ValueError ("Input data must contain rho3alt, rho1, rho2, rho3, rho4, and rho5." )
96+ required = set (self .rhoPlots .keys ())
97+ if not required .issubset (data .keys ()):
98+ raise ValueError (f"Input data must contain { ', ' .join (self .rhoPlots .keys ())} " )
10399
104100 def makePlot (
105101 self , data : KeyedData , plotInfo : Mapping [str , str ] | None = None , ** kwargs : Any
@@ -141,28 +137,20 @@ def makePlot(
141137 :ref:`getting started guide<analysis-tools-getting-started>`.
142138 """
143139 fig_dict : dict [str , Figure ] = {}
144- for rho_name in ( "rho1" , "rho2" , "rho3" , "rho4" , "rho5" ):
140+ for rho_name in self . rhoPlots . keys ( ):
145141 rho : XYPlot = self .rhoPlots [rho_name ]
146-
147142 subdata = {
148143 "x" : data [rho_name ].meanr , # type: ignore
149- "y" : data [rho_name ].xip , # type: ignore
150- "yerr" : np .sqrt (data [rho_name ].varxip ), # type: ignore
151144 "xerr" : None ,
152145 }
146+ if rho_name == "rho3alt" :
147+ subdata ["y" ] = data [rho_name ].xi # type: ignore
148+ subdata ["yerr" ] = np .sqrt (data [rho_name ].varxi )
149+ else :
150+ subdata ["y" ] = data [rho_name ].xip # type: ignore
151+ subdata ["yerr" ] = np .sqrt (data [rho_name ].varxip ) # type: ignore
153152 fig = rho (subdata , ** kwargs )
154153 if plotInfo is not None :
155154 fig_dict [rho_name ] = addPlotInfo (fig , plotInfo )
156155
157- # rho3alt is handled differently because its attributes differ.
158- subdata = {
159- "x" : data ["rho3alt" ].meanr , # type: ignore
160- "y" : data ["rho3alt" ].xi , # type: ignore
161- "yerr" : np .sqrt (data ["rho3alt" ].varxi ), # type: ignore
162- "xerr" : None ,
163- }
164- fig = self .rhoPlots ["rho3alt" ](subdata , ** kwargs ) # type: ignore[misc]
165- if plotInfo is not None :
166- fig_dict ["rho3alt" ] = addPlotInfo (fig , plotInfo )
167-
168156 return fig_dict
0 commit comments