-
Notifications
You must be signed in to change notification settings - Fork 8
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 operations to multiscale spatial image #103
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f27f910
add operations
melonora deb167b
add and test operations
melonora e6ba95b
add docstrings
melonora 03a396c
update readme
melonora 501e5f6
Merge branch 'main' into add_operations
melonora 9014bf5
Update README.md
melonora 2ba7fec
Update README.md
melonora b487ba4
Update multiscale_spatial_image/multiscale_spatial_image.py
melonora 7883e79
refer to xarray
melonora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .operations import assign_coords, transpose, reindex_data_arrays | ||
|
||
__all__ = ["assign_coords", "transpose", "reindex_data_arrays"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from multiscale_spatial_image.utils import skip_non_dimension_nodes | ||
from xarray import Dataset | ||
from typing import Any | ||
|
||
|
||
@skip_non_dimension_nodes | ||
def assign_coords(ds: Dataset, *args: Any, **kwargs: Any) -> Dataset: | ||
return ds.assign_coords(*args, **kwargs) | ||
|
||
|
||
@skip_non_dimension_nodes | ||
def transpose(ds: Dataset, *args: Any, **kwargs: Any) -> Dataset: | ||
return ds.transpose(*args, **kwargs) | ||
|
||
|
||
@skip_non_dimension_nodes | ||
def reindex_data_arrays(ds: Dataset, *args: Any, **kwargs: Any) -> Dataset: | ||
return ds["image"].reindex(*args, **kwargs).to_dataset() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pytest | ||
import numpy as np | ||
from spatial_image import to_spatial_image | ||
from multiscale_spatial_image import to_multiscale | ||
|
||
|
||
@pytest.fixture() | ||
def multiscale_data(): | ||
data = np.zeros((3, 200, 200)) | ||
dims = ("c", "y", "x") | ||
scale_factors = [2, 2] | ||
image = to_spatial_image(array_like=data, dims=dims) | ||
return to_multiscale(image, scale_factors=scale_factors) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
def test_transpose(multiscale_data): | ||
multiscale_data = multiscale_data.msi.transpose("y", "x", "c") | ||
|
||
for scale in list(multiscale_data.keys()): | ||
assert multiscale_data[scale]["image"].dims == ("y", "x", "c") | ||
|
||
|
||
def test_reindex_arrays(multiscale_data): | ||
multiscale_data = multiscale_data.msi.reindex_data_arrays({"c": ["r", "g", "b"]}) | ||
for scale in list(multiscale_data.keys()): | ||
assert multiscale_data[scale].c.data.tolist() == ["r", "g", "b"] | ||
|
||
|
||
def test_assign_coords(multiscale_data): | ||
multiscale_data = multiscale_data.msi.assign_coords({"c": ["r", "g", "b"]}) | ||
for scale in list(multiscale_data.keys()): | ||
assert multiscale_data[scale].c.data.tolist() == ["r", "g", "b"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
import numpy as np | ||
from spatial_image import to_spatial_image | ||
from multiscale_spatial_image import skip_non_dimension_nodes, to_multiscale | ||
from multiscale_spatial_image import skip_non_dimension_nodes | ||
|
||
|
||
def test_skip_nodes(): | ||
data = np.zeros((2, 200, 200)) | ||
dims = ("c", "y", "x") | ||
scale_factors = [2, 2] | ||
image = to_spatial_image(array_like=data, dims=dims) | ||
multiscale_img = to_multiscale(image, scale_factors=scale_factors) | ||
|
||
def test_skip_nodes(multiscale_data): | ||
@skip_non_dimension_nodes | ||
def transpose(ds, *args, **kwargs): | ||
return ds.transpose(*args, **kwargs) | ||
|
||
for scale in list(multiscale_img.keys()): | ||
assert multiscale_img[scale]["image"].dims == ("c", "y", "x") | ||
for scale in list(multiscale_data.keys()): | ||
assert multiscale_data[scale]["image"].dims == ("c", "y", "x") | ||
|
||
# applying this function without skipping the root node would fail as the root node does not have dimensions. | ||
result = multiscale_img.map_over_datasets(transpose, "y", "x", "c") | ||
result = multiscale_data.map_over_datasets(transpose, "y", "x", "c") | ||
for scale in list(result.keys()): | ||
assert result[scale]["image"].dims == ("y", "x", "c") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lovely