-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Rotation Functional Index example #8004
Comments
@TomNicholas I haven't looked much at your example yet, but to quickly respond to your questions:
arr = np.array(img_greyscale)
da = xr.DataArray(
data=arr,
dims=['x', 'y'],
# non-rotated pixel coordinates
coords={'x': range(arr.shape[0]), 'y': range(arr.shape[1])},
)
da = da.set_xindex(['x', 'y'], RotationalTransformIndex, angle=-160)
# selection using original (non-rotated coordinates)
da.sel(x=slice(300, 500), y=(600, 800), method="original")
# selection using rotated coordinates
da.sel(x=slice(-400, 0), y=(-600, -400), method="rotated")
# alignment would "just" work if RotationalTransformIndex
# encapsulate two PandasIndex for x and y (meta-index)
xr.align(
da.sel(x=slice(200, 600), method="original"),
da.sel(x=slice(300, 700), method="rotated"),
) It is not very nice using sel's |
@benbovy thanks for responding - I'll have a go at implementing your suggestions. Also I had not seen your example of a 1D functional index from the list in #7041. |
Is your feature request related to a problem?
I'm trying to think of an example that would demonstrate the "functional index" pattern discussed in #3620.
I think a 2D rotation is the simplest example of an analytically-expressible, non-trivial, domain-agnostic case where you might want to back a set of multiple coordinates with a single functional index. It's also nice because there is additional information that must be passed and stored (the angle of the rotation), but that part is very simple, and domain-agnostic. I'm proposing we make this example work and put it in the custom index docs.
I had a go at making that example (notebook here) @benbovy, but I'm confused about a couple of things:
.sel
in such a way that it supports indexing with slices (i.e. to crop my image)Describe the solution you'd like
No response
Describe alternatives you've considered
No response
Additional context
This example is inspired by @jni's use case in napari, where (IIUC) they want to do a lazy functional affine transformation from pixel to physical coordinates, where the simplest example of such a transform might be a linear shear (caused by the imaging focal plane being at an angle to the physical sample).
The text was updated successfully, but these errors were encountered: