@@ -105,6 +105,18 @@ def _repeat_variable_argument(n, arg):
105105 )
106106
107107
108+ def _try_to_create_theta_grid_if_missing (bins , da ):
109+ if (
110+ 'theta' not in bins
111+ and 'theta' not in da .dims
112+ and 'sample_rotation' in da .coords
113+ and 'detector_rotation' in da .coords
114+ ):
115+ bins ['theta' ] = theta_grid (
116+ nu = da .coords ['detector_rotation' ], mu = da .coords ['sample_rotation' ]
117+ )
118+
119+
108120def wavelength_theta_figure (
109121 da : sc .DataArray | Sequence [sc .DataArray ],
110122 * ,
@@ -169,19 +181,15 @@ def wavelength_theta_figure(
169181 da , wavelength_bins , theta_bins , strict = True
170182 ):
171183 bins = {}
184+
172185 if wavelength_bin is not None :
173186 bins ['wavelength' ] = wavelength_bin
174187
175188 if theta_bin is not None :
176189 bins ['theta' ] = theta_bin
177- elif (
178- 'theta' not in d .dims
179- and 'sample_rotation' in d .coords
180- and 'detector_rotation' in d .coords
181- ):
182- bins ['theta' ] = theta_grid (
183- nu = d .coords ['detector_rotation' ], mu = d .coords ['sample_rotation' ]
184- )
190+
191+ _try_to_create_theta_grid_if_missing (bins , d )
192+
185193 hs .append (_reshape_array_to_expected_shape (d , ('theta' , 'wavelength' ), ** bins ))
186194
187195 kwargs .setdefault ('cbar' , True )
@@ -246,20 +254,15 @@ def q_theta_figure(
246254 hs = []
247255 for d , q_bin , theta_bin in zip (da , q_bins , theta_bins , strict = True ):
248256 bins = {}
257+
249258 if q_bin is not None :
250259 bins ['Q' ] = q_bin
251260
252261 if theta_bin is not None :
253262 bins ['theta' ] = theta_bin
254- else :
255- if (
256- 'theta' not in d .dims
257- and 'sample_rotation' in d .coords
258- and 'detector_rotation' in d .coords
259- ):
260- bins ['theta' ] = theta_grid (
261- nu = d .coords ['detector_rotation' ], mu = d .coords ['sample_rotation' ]
262- )
263+
264+ _try_to_create_theta_grid_if_missing (bins , d )
265+
263266 hs .append (_reshape_array_to_expected_shape (d , ('theta' , 'Q' ), ** bins ))
264267
265268 kwargs .setdefault ('cbar' , True )
0 commit comments