tiled icon indicating copy to clipboard operation
tiled copied to clipboard

Support sub-chunk slicing in the Python client

Open danielballan opened this issue 1 year ago • 2 comments

The Tiled server supporting arbitrary slicing, like:

GET /api/v1/array/full/{path}?slice=..

and

GET /api/v1//array/block/{path}?block=...&slice=...

The Tiled Python client does not take full advantage of this yet. It always grabs whole chunks, and then performs any further (sub-chunk) slicing on the client side. This results in wasted work. The reason for accepting this waste was to keep the implementation simple and solidly correct, in the days of early development.

Now, it makes sense to revisit this and specify the precise slice of interest in the request to the server, such that it only reads and transmits the necessary data. The change must include thorough unit testing, as slicing can involve subtle book-keeping.

The relevant code is:

https://github.com/bluesky/tiled/blob/204676bbb841d252c1413abfe2646c3b7d27a525/tiled/client/array.py#L67-L126

I would guess that the library ndindex may be useful for implementing this correctly. And maybe (maybe!) Slice.as_subindex is the right tool to deal with mapping a slice into a whole array into the coordinate systems of the individual chunks. Needs more investigation.

danielballan avatar Nov 22 '23 21:11 danielballan

This may be of interest to @taxe10.

danielballan avatar Nov 22 '23 21:11 danielballan

I am taking a look at this issue. Slice.as_subindex does look promising, but your link from 2023 seems broken. Here's the new link for reference:

https://quansight-labs.github.io/ndindex/api/internal.html#ndindex.ndindex.NDIndex.as_subindex

hyperrealist avatar Jun 26 '24 02:06 hyperrealist