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

Write block tutorial #696

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

TibbersHao
Copy link

This small PR adds a demonstration of the write_block functionality to the writing tutorial, as suggested in #693.

Key components covered in the code block:

  • Pre-define ArrayStructure
  • Split Chunks
  • Allocate ArrayClient
  • Use write_block with specific index

To follow the flow of the original tutorial, the session has been added right after the demonstration of write_array under the head of "Write data", please feel free to make changes as needed.

Copy link
Contributor

@hyperrealist hyperrealist left a comment

Choose a reason for hiding this comment

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

I think this is a very informative and useful addition to the tutorials. There are some inline comments ranging from copy editing to structural considerations.

docs/source/tutorials/writing.md Outdated Show resolved Hide resolved
docs/source/tutorials/writing.md Outdated Show resolved Hide resolved
ArrayStructure(data_type=BuiltinDtype(endianness='not_applicable', kind=<Kind.integer: 'i'>, itemsize=1), chunks=((1, 1, 1, 1, 1), (32,), (32,)), shape=(5, 32, 32), dims=None, resizable=False)

# Allocate a new array client in tiled
>>> array_client = client.new(structure_family="array", structure=structure, key ="stacked_result", metadata={"color": "yellow", "barcode": 13})
Copy link
Contributor

Choose a reason for hiding this comment

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

Which version of Tiled is this suggested for? With the current most up-to-date Tiled in the main branch I get the following error.

TypeError: Container.new() got an unexpected keyword argument 'structure'

You may want to consider defining array_client the following way instead.

>>> from tiled.structures.data_source import DataSource
>>> data_source = DataSource(structure=structure, structure_family="array")
>>> array_client = client.new(structure_family="array", data_sources=[data_source], key ="stacked_result", metadata={"color": "yellow", "barcode": 13})

Also, PEP8:

Suggested change
>>> array_client = client.new(structure_family="array", structure=structure, key ="stacked_result", metadata={"color": "yellow", "barcode": 13})
>>> array_client = client.new(structure_family="array", structure=structure, key="stacked_result", metadata={"color": "yellow", "barcode": 13})

Finally, for @danielballan, would it be useful to put this part in a utility function and return the client for this particular use case (where we know the eventual array size but don't have the full array yet). Then the user can use that client to write chunks in streaming fashion without having to fiddle with the lower level client.new() method.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. To answer the first part: I am using tiled == 0.1.0a113 at this moment, and it worked out fine on my local end.

I will test the suggested DataSource and see if it's compatible with my pipeline. Will follow up on a new comment.

Copy link
Author

Choose a reason for hiding this comment

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

Follow up: I went through the release notes, the DataSource is introduced in version 0.1.0a115, so within my development environment (0.1.0a113) I was not able to run the suggested code.

To accommodate this, I will add both approaches and comment with notes about tiled version. This could serve as a temporary solution until a more advanced high level version come into the play.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should write the tutorial to the most recent version of tiled, given that it is still in alpha.

docs/source/tutorials/writing.md Show resolved Hide resolved
docs/source/tutorials/writing.md Show resolved Hide resolved
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.

3 participants