@@ -198,6 +198,45 @@ def reorderAndPadList(inputList, inputKeys, outputKeys, padWith=None):
198
198
return outputList
199
199
200
200
201
+ def reorderRefs (inputRefs , outputSortKeyOrder , dataIdKey ):
202
+ """Reorder inputRefs per outputSortKeyOrder.
203
+
204
+ Any inputRefs which are lists will be resorted per specified key e.g.,
205
+ 'detector.' Only iterables will be reordered, and values can be of type
206
+ `lsst.pipe.base.connections.DeferredDatasetRef` or
207
+ `lsst.daf.butler.core.datasets.ref.DatasetRef`.
208
+
209
+ Returned lists of refs have the same length as the outputSortKeyOrder.
210
+ If an outputSortKey not in the inputRef, then it will be padded with None.
211
+ If an inputRef contains an inputSortKey that is not in the
212
+ outputSortKeyOrder it will be removed.
213
+
214
+ Parameters
215
+ ----------
216
+ inputRefs : `lsst.pipe.base.connections.QuantizedConnection`
217
+ Input references to be reordered and padded.
218
+ outputSortKeyOrder : `iterable`
219
+ Iterable of values to be compared with inputRef's dataId[dataIdKey].
220
+ dataIdKey : `str`
221
+ The data ID key in the dataRefs to compare with the outputSortKeyOrder.
222
+
223
+ Returns
224
+ -------
225
+ inputRefs : `lsst.pipe.base.connections.QuantizedConnection`
226
+ Quantized Connection with sorted DatasetRef values sorted if iterable.
227
+ """
228
+ for connectionName , refs in inputRefs :
229
+ if isinstance (refs , Iterable ):
230
+ if hasattr (refs [0 ], "dataId" ):
231
+ inputSortKeyOrder = [ref .dataId [dataIdKey ] for ref in refs ]
232
+ else :
233
+ inputSortKeyOrder = [handle .datasetRef .dataId [dataIdKey ] for handle in refs ]
234
+ if inputSortKeyOrder != outputSortKeyOrder :
235
+ setattr (inputRefs , connectionName ,
236
+ reorderAndPadList (refs , inputSortKeyOrder , outputSortKeyOrder ))
237
+ return inputRefs
238
+
239
+
201
240
def subBBoxIter (bbox , subregionSize ):
202
241
"""Iterate over subregions of a bbox.
203
242
0 commit comments