-
Notifications
You must be signed in to change notification settings - Fork 125
Create sort_by_xy_and_chunk_by_x Proposal
#790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Create sort_by_xy_and_chunk_by_x Proposal
#790
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a new utility function sort_by_xy_and_chunk_by_x that provides a common sorting pattern for dynamic automation processes involving spatial resources. The function sorts resources by x-coordinate (ascending) and y-coordinate (descending), groups them by x-coordinate, splits large groups into smaller chunks, and optionally sorts these chunks by size.
Key Changes:
- Added
sort_by_xy_and_chunk_by_xfunction to handle multi-dimensional sorting and chunking of resources - Imported
groupbyfrom itertools and addedAnyto typing imports
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
|
||
| def sort_by_xy_and_chunk_by_x( | ||
| resources: list[Any], | ||
| max_chunk_size: int, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might make sense to have max_chunk_size be optional as well. I could imagine wanting to just get a separate chunk for each unique x coordinate (as is I would just enter an arbitrarily large chunk size if I wanted to do this).
|
do you think we should sort and chunk in 2 separate functions? |
|
One thing that could be nice to add here (possibly in a future PR) is a "fuzz factor" that would allow you to set a tolerance within which to still group locations by X. Use case: If you have individually taught plate positions for maximum accuracy on your STAR, but you'd still like to be able to use all channels together in cases where a small difference in x (say, less than a few tenths of a mm) wouldn't matter for channel access. In this use case, I could imagine doing something like:
Or (using pseudocode, but this is already possible in PLR):
|
Yes I think this would make sense! Output of sort then would just be a list instead of a list of lists |
I'm sure: the STAR firmware has to be given the exact same x-coordinates for a single command if the channels are supposed to interact with the resource (i.e. pickup/drop from Or do you mean the sorting would add |
Interesting, because I don't want to reinvent |
the goal of this function would be to find which resources can be accessed in parallel on robots without variable x-span. so I think the resolution parameter makes sense so users can match it to what their specific robot supports. (side question: why do you "teach plate positions" to less than 0.1mm resolution on a star? the STAR firmware runs on 0.1mm units for every command so anything smaller than that is always rounded to the nearest 0.1) |
yes, I guess given that you just say sorted(
resources,
key=lambda r: (r.get_absolute_location().x, -r.get_absolute_location().y),
)and that sorting, grouping are similarly simple functions, it might become a little verbose to say chunk(
group_by(
sorted(
resources,
key=lambda r: (r.get_absolute_location().x, -r.get_absolute_location().y),
),
key=lambda r: r.get_absolute_location().x,
),
chunk_size=8,
)every single time but still having functions like that which are just a tiny bit simpler than standard python syntax could be nice utilities, and then the function for me personally I like explicit code but I can see it being repetitive to not have |
|
https://docs.python.org/3/library/itertools.html#itertools.batched is only available in 3.12+... |
Yes good point, I imagine we'd want to average the x location for the group before sending the command. I could see how that's getting a little more into the weeds with implicit logic than we might like. Even if we added an optional tolerance or resolution parameter, I'd think the default behavior would be to require the same x-coordinate to be grouped together unless a resolution is specified. |
Yep correct, have never taught positions to less than 0.1 mm resolution. I said "less than a few tenths of a mm" but in reality I think this could be useful for larger differences -- really depends on the well geometry. Flat bottom 96 well plates could probably be ~2mm off in X and still be accessed at the same time. |
One of the most common sorting sequences for dynamic automation processes I came across.
Not hung up on the name though - please let me know whether you can think of a better one :)