-
Notifications
You must be signed in to change notification settings - Fork 5
Switch from PixelBuffer to Zarr metadata and array cache #3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
import org.junit.Test; | ||
|
||
import com.bc.zarr.ZarrArray; | ||
import com.github.benmanes.caffeine.cache.Caffeine; | ||
|
||
import loci.formats.FormatTools; | ||
import loci.formats.in.FakeReader; | ||
|
@@ -47,6 +48,20 @@ | |
|
||
public class ZarrPixelBufferTest extends AbstractZarrPixelBufferTest { | ||
|
||
public ZarrPixelBuffer createPixelBuffer( | ||
Pixels pixels, Path path, | ||
Integer maxPlaneWidth, Integer maxPlaneHeight) throws IOException { | ||
return new ZarrPixelBuffer( | ||
pixels, path, maxPlaneWidth, maxPlaneHeight, | ||
Caffeine.newBuilder() | ||
.maximumSize(0) | ||
.buildAsync(PixelsService::getZarrMetadata), | ||
Caffeine.newBuilder() | ||
.maximumSize(0) | ||
.buildAsync(PixelsService::getZarrArray) | ||
); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I'll port similar changes to the This raises the question of whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. I'm not sure the utility now to be honest. |
||
|
||
@Test | ||
public void testGetChunks() throws IOException { | ||
int sizeT = 1; | ||
|
@@ -60,7 +75,7 @@ public void testGetChunks() throws IOException { | |
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "uint16", resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
int[][] chunks = zpbuf.getChunks(); | ||
int[][] expectedChunks = new int[][] { | ||
new int[] {1, 1, 1, 512, 1024}, | ||
|
@@ -88,7 +103,7 @@ public void testGetDatasets() throws IOException { | |
sizeT, sizeC, sizeZ, sizeY, sizeX, "uint16", | ||
resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
List<Map<String,String>> datasets = zpbuf.getDatasets(); | ||
List<Map<String,String>> expectedDatasets = getDatasets(3); | ||
for (int i = 0; i < datasets.size(); i++) { | ||
|
@@ -110,7 +125,7 @@ public void testGetResolutionDescriptions() throws IOException { | |
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "uint16", resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
List<List<Integer>> expected = new ArrayList<List<Integer>>(); | ||
expected.add(Arrays.asList(new Integer[] {2048, 512})); | ||
expected.add(Arrays.asList(new Integer[] {1024, 256})); | ||
|
@@ -158,7 +173,7 @@ public void testGetTile() throws IOException, InvalidRangeException { | |
} | ||
test.write(data, new int[] {2,3,4,5,6}, new int[] {0,0,0,0,0}); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
PixelData pixelData = zpbuf.getTile(0, 0, 0, 0, 0, 2, 2); | ||
ByteBuffer bb = pixelData.getData(); | ||
bb.order(ByteOrder.BIG_ENDIAN); | ||
|
@@ -242,7 +257,7 @@ public void testGetTimepointStackPlaneRowCol() | |
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "int32", resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 2048, 2048)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 2048, 2048)) { | ||
for (int t = 0; t < sizeT; t++) { | ||
// Assert timepoint | ||
byte[] timepoint = zpbuf.getTimepoint(t).getData().array(); | ||
|
@@ -309,7 +324,7 @@ public void testGetTileLargerThanImage() | |
} | ||
test.write(data, new int[] {2,3,4,5,6}, new int[] {0,0,0,0,0}); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
zpbuf.setResolutionLevel(0); | ||
PixelData pixelData = zpbuf.getTile(0, 0, 0, 0, 0, 10, 10); | ||
ByteBuffer bb = pixelData.getData(); | ||
|
@@ -337,7 +352,7 @@ public void testTileExceedsMax() throws IOException, InvalidRangeException { | |
resolutions); | ||
|
||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 32, 32)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 32, 32)) { | ||
PixelData pixelData = zpbuf.getTile(0, 0, 0, 0, 0, 32, 33); | ||
Assert.assertNull(pixelData); | ||
} | ||
|
@@ -356,7 +371,7 @@ public void testCheckBoundsValidZeros() throws IOException { | |
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "uint16", resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
zpbuf.checkBounds(0, 0, 0, 0, 0); | ||
} | ||
} | ||
|
@@ -374,7 +389,7 @@ public void testCheckBoundsValidEnd() throws IOException { | |
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "uint16", resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
zpbuf.checkBounds(2047, 511, 2, 1, 0); | ||
} | ||
} | ||
|
@@ -392,7 +407,7 @@ public void testCheckBoundsOutOfRange() throws IOException { | |
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "uint16", resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
zpbuf.checkBounds(2048, 511, 2, 1, 0); | ||
} | ||
} | ||
|
@@ -410,7 +425,7 @@ public void testCheckBounds() throws IOException { | |
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "uint16", resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
zpbuf.checkBounds(-1, 0, 0, 0, 0); | ||
} | ||
} | ||
|
@@ -428,7 +443,7 @@ public void testGetTileSize() throws IOException { | |
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "uint16", resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
Dimension tileSize = zpbuf.getTileSize(); | ||
Assert.assertEquals(1024, tileSize.getWidth(), 0.1); | ||
Assert.assertEquals(1024, tileSize.getHeight(), 0.1); | ||
|
@@ -449,7 +464,7 @@ public void testUint16() throws IOException { | |
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "uint16", resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
Assert.assertEquals(FormatTools.UINT16, zpbuf.getPixelsType()); | ||
Assert.assertEquals(false, zpbuf.isSigned()); | ||
Assert.assertEquals(false, zpbuf.isFloat()); | ||
|
@@ -471,7 +486,7 @@ public void testFloat() throws IOException { | |
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "float", resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
Assert.assertEquals(FormatTools.FLOAT, zpbuf.getPixelsType()); | ||
Assert.assertEquals(true, zpbuf.isSigned()); | ||
Assert.assertEquals(true, zpbuf.isFloat()); | ||
|
@@ -493,7 +508,7 @@ public void testSizes() throws IOException { | |
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "uint16", resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
// Plane size | ||
Assert.assertEquals( | ||
sizeX * sizeY * bytesPerPixel, | ||
|
@@ -534,7 +549,7 @@ public void testSetResolutionLevelOutOfBounds() throws IOException { | |
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "uint16", resolutions); | ||
try (ZarrPixelBuffer zpbuf = | ||
new ZarrPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
createPixelBuffer(pixels, output.resolve("0"), 1024, 1024)) { | ||
zpbuf.setResolutionLevel(3); | ||
} | ||
} | ||
|
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.
In the same spirit as the work we did with @melissalinkert on
bioformats2raw/raw2ometiff
, I was considering switching to the more activezarr-developers/jzarr
fork on this repository as wellThis might be an opportunity to discuss any API improvements we should consider as a preamble of this update.
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.
Opened as zarr-developers/jzarr#19. I think it makes sense to switch to that fork for testing as soon as possible.