pylabrobot.resources.utils.sort_by_xy_and_chunk_by_x#

pylabrobot.resources.utils.sort_by_xy_and_chunk_by_x(resources: list[R], max_chunk_size: int, sort_chunks_by_size: bool = True) list[list[R]]#

Sort resources spatially and partition them into chunks for channel processing.

Procedure#

  1. Sort all resources by:
    • x ascending

    • y descending within each x

  2. Group resources into chunks based on identical x values.

  3. Split each chunk into sub-chunks of size <= max_chunk_size.

  4. Optionally sort the resulting sub-chunks by their length (smallest -> largest).

Example

>>> sorted_chunks = sort_by_xy_and_chunk_by_x(well_list, max_chunk_size=8)
>>> [
...   list(
...     zip(
...       [r.get_identifier() for r in chunk],
...       [r.get_absolute_location() for r in chunk],
...     )
...   )
...   for chunk in sorted_chunks
... ]
[[('D1', Coordinate(x=450.9, y=402.3, z=164.45)),
  ('H1', Coordinate(x=450.9, y=366.3, z=164.45)), ...],
[('D2', Coordinate(x=459.9, y=402.3, z=164.45)), ...]]
param resources:

List of resources that implement .get_absolute_location(), returning an object with x and y attributes.

param max_chunk_size:

Maximum allowed size for any produced chunk or sub-chunk.

param sort_chunks_by_size:

If True (default), the output list of chunks is sorted by ascending chunk size. If False, chunks retain their original order.

returns:

A list of grouped and sorted resources.

Parameters:
  • resources (list[R])

  • max_chunk_size (int)

  • sort_chunks_by_size (bool)

Return type:

list[list[R]]