-
Notifications
You must be signed in to change notification settings - Fork 68
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
Intensity Table Concat Processing #1118
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
da247e6
adding todo's and comment about looping
d8122f5
reverting experiement.py"
2fb6fa0
example looping on allen test
cb17b5f
adding travis wait
7de5bd6
upping travis wait time
4db58d9
trying to free up mem in allen test
5a90da7
reverting mem thing
a9fb8a9
moving ecample to 3dsmFish
9816592
reverting tavis wait
84b00f6
regenerated notebooks
fb1764d
:changes
4075652
merge from master
29ff4b8
changes.
b20c92c
good framework to process lists of tables
c52310c
cleanned up
c348597
adding better docs, need better tests
be54805
added tests need to make work for negative coords
97fdc35
fixing lint errors
6499c7a
notebooks
847ef42
small fixes
be5b9e1
review changes
a752373
review comments
4da1a19
merge from master
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import numpy as np | ||
import xarray as xr | ||
|
||
from starfish import IntensityTable | ||
from starfish.test import factories | ||
from starfish.types import Coordinates, Features | ||
from starfish.types._constants import OverlapStrategy | ||
from starfish.util.overlap_utils import ( | ||
Area, | ||
find_overlaps_of_xarrays, | ||
remove_area_of_xarray, | ||
sel_area_of_xarray | ||
) | ||
|
||
|
||
def create_intensity_table_with_coords(area: Area, n_spots: int=10) -> IntensityTable: | ||
""" | ||
Creates a 50X50 intensity table with physical coordinates within | ||
the given Area. | ||
|
||
Parameters | ||
---------- | ||
area: Area | ||
The area of physical space the IntensityTable should be defined over | ||
n_spots: | ||
Number of spots to add to the IntensityTable | ||
""" | ||
codebook = factories.codebook_array_factory() | ||
it = IntensityTable.synthetic_intensities( | ||
codebook, | ||
num_z=1, | ||
height=50, | ||
width=50, | ||
n_spots=n_spots | ||
) | ||
# intensity table 1 has 10 spots, xmin = 0, ymin = 0, xmax = 2, ymax = 1 | ||
it[Coordinates.X.value] = xr.DataArray(np.linspace(area.min_x, area.max_x, n_spots), | ||
dims=Features.AXIS) | ||
it[Coordinates.Y.value] = xr.DataArray(np.linspace(area.min_y, area.max_y, n_spots), | ||
dims=Features.AXIS) | ||
return it | ||
|
||
|
||
def test_find_area_intersection(): | ||
""" | ||
Create various Area objects and verify their intersection are calculated correctly | ||
""" | ||
area1 = Area(min_x=0, max_x=2, min_y=0, max_y=2) | ||
area2 = Area(min_x=1, max_x=2, min_y=1, max_y=3) | ||
intersection = Area.find_intersection(area1, area2) | ||
# intersection should be area with bottom point (1,1) and top point (2,2) | ||
assert intersection == Area(min_x=1, max_x=2, min_y=1, max_y=2) | ||
|
||
area2 = Area(min_x=3, max_x=5, min_y=3, max_y=5) | ||
intersection = Area.find_intersection(area1, area2) | ||
# no intersection | ||
assert intersection is None | ||
|
||
area2 = Area(min_x=0, max_x=5, min_y=3, max_y=5) | ||
intersection = Area.find_intersection(area1, area2) | ||
# area 2 right above area one | ||
assert intersection is None | ||
|
||
# try negatives | ||
area1 = Area(min_x=-1, max_x=1, min_y=0, max_y=2) | ||
area2 = Area(min_x=0, max_x=2, min_y=0, max_y=2) | ||
intersection = Area.find_intersection(area1, area2) | ||
assert intersection == Area(min_x=0, max_x=1, min_y=0, max_y=2) | ||
|
||
area2 = Area(min_x=-3, max_x=-2, min_y=0, max_y=2) | ||
intersection = Area.find_intersection(area1, area2) | ||
assert intersection is None | ||
|
||
|
||
def test_find_overlaps_of_xarrays(): | ||
""" | ||
Create a list of overlapping IntensityTables and verify we identify the correct | ||
overlapping sections | ||
""" | ||
# Create some overlapping intensity tables | ||
it0 = create_intensity_table_with_coords(Area(min_x=0, max_x=1, | ||
min_y=0, max_y=1)) | ||
it1 = create_intensity_table_with_coords(Area(min_x=.5, max_x=2, | ||
min_y=.5, max_y=1.5)) | ||
it2 = create_intensity_table_with_coords(Area(min_x=1.5, max_x=2.5, | ||
min_y=0, max_y=1)) | ||
it3 = create_intensity_table_with_coords(Area(min_x=0, max_x=1, | ||
min_y=1, max_y=2)) | ||
overlaps = find_overlaps_of_xarrays([it0, it1, it2, it3]) | ||
# should have 4 total overlaps | ||
assert len(overlaps) == 4 | ||
# overlap 1 between it0 and it1: | ||
assert (0, 1) in overlaps | ||
# overlap 1 between it0 and it1: | ||
assert (1, 2) in overlaps | ||
# overlap 3 between it1 and it3 | ||
assert (1, 3) in overlaps | ||
# overlap 4 between it0 and it3 | ||
assert (0, 3) in overlaps | ||
|
||
|
||
def test_remove_area_of_xarray(): | ||
""" | ||
Tests removing a section of an IntensityTable defined by its physical area | ||
""" | ||
it = create_intensity_table_with_coords(Area(min_x=0, max_x=2, | ||
min_y=0, max_y=2), n_spots=10) | ||
|
||
area = Area(min_x=1, max_x=2, min_y=1, max_y=3) | ||
# grab some random coord values in this range | ||
removed_x = it.where(it.xc > 1, drop=True)[Coordinates.X.value].data[0] | ||
removed_y = it.where(it.yc > 1, drop=True)[Coordinates.X.value].data[3] | ||
|
||
it = remove_area_of_xarray(it, area) | ||
# assert coords from removed section are no longer in it | ||
assert not np.any(np.isclose(it[Coordinates.X.value], removed_x)) | ||
assert not np.any(np.isclose(it[Coordinates.Y.value], removed_y)) | ||
|
||
|
||
def test_sel_area_of_xarray(): | ||
""" | ||
Tests selecting a section of an IntensityTable defined by its physical area | ||
""" | ||
it = create_intensity_table_with_coords(Area(min_x=0, max_x=2, min_y=0, max_y=2), n_spots=10) | ||
|
||
area = Area(min_x=1, max_x=2, min_y=1, max_y=3) | ||
it = sel_area_of_xarray(it, area) | ||
|
||
# Assert new min/max values | ||
assert min(it[Coordinates.X.value]).data >= 1 | ||
assert max(it[Coordinates.X.value]).data <= 2 | ||
assert min(it[Coordinates.Y.value]).data >= 1 | ||
assert max(it[Coordinates.X.value]).data <= 2 | ||
|
||
|
||
def test_take_max(): | ||
""" | ||
Create two overlapping IntensityTables with differing number of spots and verify that | ||
by concatenating them with the TAKE_MAX strategy we only include spots in the overlapping | ||
section from the IntensityTable that had the most. | ||
""" | ||
it1 = create_intensity_table_with_coords(Area(min_x=0, max_x=2, | ||
min_y=0, max_y=2), n_spots=10) | ||
it2 = create_intensity_table_with_coords(Area(min_x=1, max_x=2, | ||
min_y=1, max_y=3), n_spots=20) | ||
|
||
concatenated = IntensityTable.concatanate_intensity_tables( | ||
[it1, it2], overlap_strategy=OverlapStrategy.TAKE_MAX) | ||
|
||
# The overlap section hits half of the spots from each intensity table, 5 from it1 | ||
# and 10 from i21. It2 wins and the resulting concatenated table should have all the | ||
# spots from it2 (20) and 6 (one on the border) from it1 (6) for a total of 26 spots | ||
assert concatenated.sizes[Features.AXIS] == 26 |
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
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.
wait what? if it hits 5 of the spots from it1, then shouldn't we get a total of 25 spots?
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.
both the sel and remove_area_of_xarray methods are inclusive...so we get one spot in the comparison count and the concatenation...maybe this is wrong?
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.
I would dump the table to make sure it is consistent with your understanding, though I suspect you are correct. :)