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

add methods to read and write serializable objects as datablocks #73

Merged
merged 8 commits into from
Sep 17, 2020

Conversation

axtimwalde
Copy link
Collaborator

  • introduces DataType.OBJECT that maps to bytes
  • introduces block mode 2 because serialized objects do not have a blocksize or
    number of dimensions

change api for writing blocks to take compressor instead of full
dataset attributes

TODO reconsider this API change because with full dataset attributes, we
can introduce type 2 blocks without blocksize fields for serializable
objects
introduce mode 2 for object datablocks
This is more flexible for generic types using e.g. Google's TypeToken
@joshmoore
Copy link

@axtimwalde: oddly enough I found myself wanting to read a complex type via n5(-zarr) this morning:

colormap-like array-type
  "dtype": [
    [
      "label-value",
      "<i8"
    ],
    [
      "r",
      "<i8"
    ],
    [
      "g",
      "<i8"
    ],
    [
      "b",
      "<i8"
    ],
    [
      "a",
      "<i8"
    ],
    [
      "my-type",
      "<U20"
    ],
    [
      "my-id",
      "<i8"
    ],
    [
      "description",
      "<U200"
    ]
  ],
sample python code
import numpy as np
import zarr

t = [
    ("label-value", int),
    ("r", int),
    ("g", int),
    ("b", int),
    ("a", int),
    ("object-type", "U20"),
    ("object-id", int),
    ("description", "U200")]

data = list()
for x in range(100):
    data.append((1, 100, 100, 100, 100, "Mask", 123456, "some text here"))
    data.append((2, 200, 200, 200, 200, "Mask", 567896, "some more text"))
a = np.array(data, dtype=t)

z = zarr.open("s.zarr")
z.array(name="a", data=a, chunks=(10,))

Is this generally the type of Object you are looking to support here?

@axtimwalde
Copy link
Collaborator Author

No, I think we would have to support this in n5-imglib2 as complex types are just two other types. This is meant for serializing something big into a block, i.e. I need it for an array of sets of point matches.

@axtimwalde
Copy link
Collaborator Author

You can already store arbitrarily many values into a block. It is one of the places where the zarr and n5 specs have never converged. Let me see what we can do for complex types or generally multi-primitive value types in n5-imglib2.

@axtimwalde axtimwalde merged commit 2fd6ef7 into master Sep 17, 2020
@axtimwalde
Copy link
Collaborator Author

@joshmoore, looking at this again, I am not sure about the best way to support the full dtype language for arbitrary structs in Java as we're not dynamically resolving type information. So far, data of unknown dtype specifications will be opened as byte[] which, in principle, enables interpreting it on the fly with either ImgLib2's ByteArray access or via something similar with ByteBuffer. If you're staying inside the Java language, you can indeed save collections of complex types with this block-serializer but that, in turn, is not very useful when reading from Python.

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