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

Converting between xarray and dataset should convert attrs types better #200

Closed
ctrueden opened this issue May 4, 2022 · 2 comments · Fixed by #233
Closed

Converting between xarray and dataset should convert attrs types better #200

ctrueden opened this issue May 4, 2022 · 2 comments · Fixed by #233
Milestone

Comments

@ctrueden
Copy link
Member

ctrueden commented May 4, 2022

>>> import imagej
>>> ij = imagej.init()
>>> d = ij.io().open('/home/curtis/data/blobs.tif')
>>> d
<java object 'net.imagej.DefaultDataset'>
>>> ij.py.from_java(d)
<xarray.DataArray (row: 254, col: 256)>
array([[ 40,  32,  24, ..., 216, 200, 200],
       [ 56,  40,  24, ..., 232, 216, 216],
       [ 64,  48,  24, ..., 240, 232, 232],
       ...,
       [ 72,  80,  80, ...,  48,  48,  48],
       [ 80,  80,  80, ...,  48,  48,  48],
       [ 96,  88,  80, ...,  48,  48,  48]], dtype=uint8)
Coordinates:
  * row      (row) float64 0.0 1.0 2.0 3.0 4.0 ... 249.0 250.0 251.0 252.0 253.0
  * col      (col) float64 0.0 1.0 2.0 3.0 4.0 ... 251.0 252.0 253.0 254.0 255.0
Attributes:
    rois:                    None
    tables:                  None
    scifio.metadata.image:   io.scif.FieldPrinter@661c46bc\n\t--class io.scif...
    scifio.metadata.global:  io.scif.filters.PlaneSeparatorMetadata@37864b77

Note poor stringification of scifio.metadata.image and scifio.metadata.global data structures above.

See also spatial-image/multiscale-spatial-image#23

@gselzer
Copy link
Contributor

gselzer commented Nov 3, 2022

@ctrueden what does "better" mean in this context? We already call sj.to_python on the properties...
If we're talking about the metadata, what would you want to see? Does xarray offer settings aligning with this metadata?

Do you just want to see a better stringification? Or would you want to convert these properties into dicts?

@ctrueden
Copy link
Member Author

ctrueden commented Nov 4, 2022

what does "better" mean in this context?

Here's what I wrote in the discussion thread of spatial-image/multiscale-spatial-image#23:

My goal with #200 would be to eliminate the need to do this. If a Java-side attribute can't be converted to something Pythonic, I think it's OK to drop it. We could at least make it configurable somehow.

So, behavior in order of priority:

  1. Convert property value into something Pythonic.
  2. Drop properties which cannot be converted.

The remaining question is just: can io.scif.FieldPrinter and io.scif.filters.PlaneSeparatorMetadata be converted? I'm pretty confident that FieldPrinter can be converted; the entire point of that class was to ease printing of key/value pairs. We probably just need to implement a toString() method somewhere on the Java side. For PlaneSeparatorMetadata I don't know off the top of my head; investigation needed.

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 a pull request may close this issue.

2 participants