Skip to content
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

WIP: Array Views #867

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft

WIP: Array Views #867

wants to merge 16 commits into from

Conversation

genematx
Copy link
Contributor

This adds a mechanism for creating views of arrays in Tiled. The source for a view could be either an array or a column of a table already registered in Tiled. the view is represented as its own DataSource with possibly several Assets pointing to a location of the source in the Tiled catalog tree, e.g. tiled://X/Y/image or tiled://X/Y/table/column_1. There is a possibility to use additional parameters to slice or reshape (TBD?) the original array and present only a subset of its values as a view. Likewise, multiple arrays (declared in separate assets) can be concatenated into a single view (TBD?).

Checklist

  • Add a Changelog entry
  • Add the ticket number which this PR closes to the comment section

@genematx genematx requested a review from danielballan January 27, 2025 15:50
segments = asset.data_uri.lstrip("tiled://").split('/')
root, *rest = segments

def deserialize_ndslice(ser_ndslice):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: this could be moved to utils or better to a method on NDSlice class.


from ..structures.array import ArrayStructure

def serialize_ndslice(ndslice):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above; to be moved to utils or an NDSlice method.

substructures[-1]['chunks'] = out_chunks
assets.append(Asset(data_uri=f"tiled://{links[0]}", is_directory=False, parameter='data_uri'))

# TODO: combine substructures if tehre are multiple sub-arrays that are concatenated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we can concatenate several subarrays into a single view. Not sure if it's needed or useful, but seems like a sensible generalization.


ndslice = deserialize_ndslice(data_source.parameters['slices'][0])

adapter = ArrayAdapter.from_array(adapter.read(slice=ndslice))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly use ArrayViewAdapter, although it's probably unnecessary...

@danielballan
Copy link
Member

Capturing notes on discussion:

  • Management.view is a good way to denote view-ness. 👍
  • Using a mimetype is nice because it gives us room to try other approaches to views in the future, with different mimetypes. 👍
  • For now, we may restrict that a view target (a slice of) a single node, never combining the data from multiple nodes. These "multi-views" could be added later, either by extending the existing adapter or (perhaps better) by adding an additional mimetype.
  • It may make sense to create ArrayViewAdapter which takes a slice parameter, so that the parameters in the database match the signature of the Adapter, as usual.

@@ -52,8 +54,8 @@ def from_array(
cls,
array: NDArray[Any],
*,
shape: Optional[Tuple[int, ...]] = None,
chunks: Optional[Tuple[Tuple[int, ...], ...]] = None,
# shape: Optional[Tuple[int, ...]] = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we never use these...🤔

@@ -139,7 +163,7 @@ def read_block(
"""
# Slice the whole array to get this block.
slice_, _ = slice_and_shape_from_block_and_chunks(block, self._structure.chunks)
array = self._array[slice_]
array = self._array[tuple(slice_)]
Copy link
Contributor Author

@genematx genematx Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_array[...] requires a tuple; even though NDSlice is a subclass of tuple, it doesn't work here. Probably there's a better way to define NDSlice so it can be accepted right away (if we want to go this route at all, of course)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants