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 dimension renaming support to to_dataset() method #304

Open
elevans opened this issue May 10, 2024 · 2 comments
Open

Add dimension renaming support to to_dataset() method #304

elevans opened this issue May 10, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@elevans
Copy link
Member

elevans commented May 10, 2024

We can do better here and detect what the input image is and take the appropriate steps to re-order the dataset. If you try to re-order an imglib2 image with to_dataset(img, dim_order=['X', 'Y', 'Channel']) only the first two dimensions will be appropriately assigned. All other dimensions are discarded and unknown is assigned as the dimension label.

@elevans elevans added the enhancement New feature or request label May 10, 2024
@elevans elevans self-assigned this May 10, 2024
@ctrueden
Copy link
Member

To be clear: in the case of img being an Img, there is no "reordering" happening, but rather dimensional assignment to match the given dim_order. So this case should IMHO be easy to do. The trickier one is if you call to_dataset on something that is already an ImgPlus or Dataset—then what? Is the user expecting the dimensions to be swapped around? Or just relabeled? (When passing an xarray, what do we do? I forgot.)

@elevans elevans changed the title Add dimension re-ordering support to to_dataset() method Add dimension renaming support to to_dataset() method Dec 27, 2024
@elevans
Copy link
Member Author

elevans commented Dec 27, 2024

@ctrueden Great point on being clear about what we mean here! You are correct in that we are doing no reordering here, but instead we are renaming dimensions while preserving the array shape and the associated axis coordinates. I better defined the renaming behavior in this commit (73f4c35) were I added a missing docstring parameter for dim_order.

I recreated the same behavior, more or less, for net.imagej.DefaultDatasets on this pyimagej branch. This implementation of dimension renaming follows the same behavior as the imagej.convert._rename_xarray_dims() function, preserving shape and coordinates. I need to expand the renaming to include EnumeratedAxis, not just DefaultLinearAxis, some tests and a new section in the documentation. But so far I'm happy with it. This will allow users to easily fix Datasets that have Channel and Time confused (something I run into frequently).

Once I have this ready, I'll create a PR for it. It'd be nice to include this in 1.6.0.

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

No branches or pull requests

2 participants