From 637e2a59fb8331ea1195b4eb11d670aac45bf007 Mon Sep 17 00:00:00 2001 From: Christian Tischer Date: Fri, 17 Jun 2022 11:42:49 +0200 Subject: [PATCH 1/2] Prevent multiple loading of DatasetAttributes in N5OMEZarrImageLoader --- .../zarr/loaders/N5OMEZarrImageLoader.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java index 91c1adaf..8db5d2e2 100644 --- a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java +++ b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java @@ -71,6 +71,7 @@ import java.io.IOException; import java.util.*; import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; import static org.embl.mobie.io.ome.zarr.util.OmeZarrMultiscales.MULTI_SCALE_KEY; @@ -98,6 +99,7 @@ public class N5OMEZarrImageLoader implements ViewerImgLoader, MultiResolutionImg private ZarrAxes zarrAxes; List zarrAxesList; private BlockingFetchQueues> queue; + private ConcurrentHashMap< String, DatasetAttributes > pathToAttributes = new ConcurrentHashMap<>(); /** * The sequenceDescription and viewRegistrations are known already, typically read from xml. @@ -220,8 +222,7 @@ private void initSetups() throws IOException { String pathName = "labels/" + label; multiscales = getMultiscale(pathName); for (OmeZarrMultiscales multiscale : multiscales) { - DatasetAttributes attributes = getDatasetAttributes(multiscale.datasets[0].path); - attributes = getDatasetAttributes(pathName + "/" + multiscale.datasets[0].path); + DatasetAttributes attributes = getDatasetAttributes(pathName + "/" + multiscale.datasets[0].path); setupToMultiscale.put(setupId, multiscale); setupToAttributes.put(setupId, attributes); @@ -244,8 +245,13 @@ private void initSetups() throws IOException { * @return * @throws IOException */ - private DatasetAttributes getDatasetAttributes(String pathName) throws IOException { - return n5.getDatasetAttributes(pathName); + private synchronized DatasetAttributes getDatasetAttributes(String pathName) throws IOException { + if ( ! pathToAttributes.containsKey( pathName ) ) + { + final DatasetAttributes attributes = n5.getDatasetAttributes( pathName ); + pathToAttributes.put( pathName, attributes ); + } + return pathToAttributes.get( pathName ); } /** @@ -510,11 +516,6 @@ private int[] fillBlockSize(DatasetAttributes attributes) { return tmp; } - private SimpleCacheArrayLoader createCacheArrayLoader(final N5Reader n5, final String pathName, int channel, int timepointId, CellGrid grid) throws IOException { - final DatasetAttributes attributes = n5.getDatasetAttributes(pathName); - return new N5OMEZarrCacheArrayLoader<>(n5, pathName, channel, timepointId, attributes, grid, zarrAxes); - } - private class SetupImgLoader, V extends Volatile & NativeType> extends AbstractViewerSetupImgLoader implements MultiResolutionSetupImgLoader { @@ -627,7 +628,7 @@ private > RandomAccessibleInterval prepareCachedImage final int priority = numMipmapLevels() - 1 - level; final CacheHints cacheHints = new CacheHints(loadingStrategy, priority, false); - final SimpleCacheArrayLoader loader = createCacheArrayLoader(n5, pathName, setupToChannel.get(setupId), timepointId, grid); + final SimpleCacheArrayLoader loader = new N5OMEZarrCacheArrayLoader<>(n5, pathName, setupToChannel.get(setupId), timepointId, attributes, grid, zarrAxes); return cache.createImg(grid, timepointId, setupId, level, cacheHints, loader, type); } catch (IOException e) { log.error(String.format( From d34647758cbb1364fff4c7ddaa84662102867b95 Mon Sep 17 00:00:00 2001 From: Christian Tischer Date: Fri, 17 Jun 2022 12:08:47 +0200 Subject: [PATCH 2/2] Change loading strategy to volatile, which appears more reponsive in BDV --- .../embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java index 8db5d2e2..da5b6c87 100644 --- a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java +++ b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5OMEZarrImageLoader.java @@ -566,7 +566,7 @@ private double[][] readMipmapResolutions() throws IOException { @Override public RandomAccessibleInterval getVolatileImage(final int timepointId, final int level, final ImgLoaderHint... hints) { - return prepareCachedImage(timepointId, level, LoadingStrategy.BUDGETED, volatileType); + return prepareCachedImage(timepointId, level, LoadingStrategy.VOLATILE, volatileType); } @Override