@@ -229,7 +229,7 @@ def cost(scaling_factors):
229229
230230def combine_curves (
231231 curves : Sequence [sc .DataArray ],
232- q_bin_edges : sc .Variable | None = None ,
232+ q_bin_edges : sc .Variable ,
233233) -> sc .DataArray :
234234 '''Combines the given curves by interpolating them
235235 on a 1d grid defined by :code:`q_bin_edges` and averaging
@@ -268,7 +268,8 @@ def combine_curves(
268268 inv_v = 1.0 / v
269269 r_avg = np .nansum (r * inv_v , axis = 0 ) / np .nansum (inv_v , axis = 0 )
270270 v_avg = 1 / np .nansum (inv_v , axis = 0 )
271- return sc .DataArray (
271+
272+ out = sc .DataArray (
272273 data = sc .array (
273274 dims = 'Q' ,
274275 values = r_avg ,
@@ -277,6 +278,28 @@ def combine_curves(
277278 ),
278279 coords = {'Q' : q_bin_edges },
279280 )
281+ if any ('Q_resolution' in c .coords for c in curves ):
282+ # This might need to be revisited. The question about how to combine curves
283+ # with different Q-resolution is not completely resolved.
284+ # However, in practice the difference in Q-resolution between different curves
285+ # is small so it's not likely to make a big difference.
286+ q_res = (
287+ sc .DataArray (
288+ data = c .coords .get (
289+ 'Q_resolution' , sc .scalar (float ('nan' )) * sc .values (c .data .copy ())
290+ ),
291+ coords = {'Q' : c .coords ['Q' ]},
292+ )
293+ for c in curves
294+ )
295+ qs = _interpolate_on_qgrid (q_res , q_bin_edges ).values
296+ qs_avg = np .nansum (qs * inv_v , axis = 0 ) / np .nansum (
297+ ~ np .isnan (qs ) * inv_v , axis = 0
298+ )
299+ out .coords ['Q_resolution' ] = sc .array (
300+ dims = 'Q' , values = qs_avg , unit = next (iter (curves )).coords ['Q_resolution' ].unit
301+ )
302+ return out
280303
281304
282305def orso_datasets_from_measurements (
0 commit comments