zarrAxesList = n5 instanceof N5OmeZarrReader ? ((N5OmeZarrReader) n5).getZarrAxes() :
- n5 instanceof N5S3OmeZarrReader ? ((N5S3OmeZarrReader) n5).getZarrAxes() : null;
-
- multiscale.axes = zarrAxes;
- multiscale.zarrAxisList = zarrAxesList;
-
- setupToMultiscale.put(setupId, multiscale);
- setupToAttributes.put(setupId, attributes);
- setupToPathname.put(setupId, pathName);
- }
- }
- }
- }
-
- /**
- * The dataType, number of channels and number of timepoints are stored
- * in the different pyramid levels (datasets).
- * According to the spec all datasets must be indentical in that sense
- * and we thus fetch this information from level 0.
- *
- * In addition, level 0 contains the information about the size of the full resolution image.
- *
- * @param pathName
- * @return
- * @throws IOException
- */
- private DatasetAttributes getDatasetAttributes(String pathName) throws IOException {
- return n5.getDatasetAttributes(pathName);
- }
-
- /**
- * The primary use case for multiple multiscales at the moment (the one listed in the spec)
- * is multiple different downsamplings.
- * A base image with two multiscales each with a different scale or a different method.
- *
- * I don't know a good logic right now how to deal with different pyramids,
- * thus I just fetch the first one, i.e. multiscales[ 0 ].
- *
- * ??? There's no need for the two multiscales to have the same base though.
- * ??? So it would also allow you to just have two pyramids (in our jargon) in the same zgroup.
- *
- * @param pathName
- * @return
- * @throws IOException
- */
- private OmeZarrMultiscales[] getMultiscale(String pathName) throws IOException {
- OmeZarrMultiscales[] multiscales = n5.getAttribute(pathName, MULTI_SCALE_KEY, OmeZarrMultiscales[].class);
- if (multiscales == null) {
- String location = "";
- if (n5 instanceof N5S3OmeZarrReader) {
- final N5S3OmeZarrReader s3ZarrReader = (N5S3OmeZarrReader) n5;
- s3ZarrReader.setDimensionSeparator("/");
- location += "service endpoint: " + s3ZarrReader.getServiceEndpoint();
- location += "; bucket: " + s3ZarrReader.getBucketName();
- location += "; container path: " + s3ZarrReader.getContainerPath();
- location += "; path: " + pathName;
- location += "; attribute: " + MULTI_SCALE_KEY;
- } else {
- location += " path: " + pathName;
- }
- throw new UnsupportedOperationException("Could not find multiscales at " + location);
- }
- return multiscales;
- }
-
- public AbstractSequenceDescription, ?, ?> getSequenceDescription() {
- //open();
- seq.setImgLoader(Cast.unchecked(this));
- return seq;
- }
-
- public ViewRegistrations getViewRegistrations() {
- return viewRegistrations;
- }
-
- private void open() {
- if (!isOpen) {
- synchronized (this) {
- if (isOpen)
- return;
-
- try {
- int maxNumLevels = 0;
- final List extends BasicViewSetup> setups = seq.getViewSetupsOrdered();
- for (final BasicViewSetup setup : setups) {
- final int setupId = setup.getId();
- final SetupImgLoader, ?> setupImgLoader = createSetupImgLoader(setupId);
- setupImgLoaders.put(setupId, setupImgLoader);
- if (setupImgLoader != null) {
- maxNumLevels = Math.max(maxNumLevels, setupImgLoader.numMipmapLevels());
- }
- }
- if (queue == null) {
- final int numFetcherThreads = Math.max(1, Runtime.getRuntime().availableProcessors());
- queue = new BlockingFetchQueues<>(maxNumLevels, numFetcherThreads);
- fetchers = new FetcherThreads(queue, numFetcherThreads);
- }
- cache = new VolatileGlobalCellCache(queue);
-
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- isOpen = true;
- }
- }
- }
-
- @NotNull
- private ArrayList createViewRegistrations(int setupId, int setupTimePoints) {
- ArrayList viewRegistrations = new ArrayList<>();
- // 3D transform of full resolution level
- AffineTransform3D transform = getAffineTransform3D(setupId, 0);
- for (int t = 0; t < setupTimePoints; t++) {
- viewRegistrations.add(new ViewRegistration(t, setupId, transform));
- }
-
- return viewRegistrations;
- }
-
- private double[] getXYZScale(int setupId, OmeZarrMultiscales.CoordinateTransformations coordinateTransformations) {
- double[] scale = coordinateTransformations.scale;
- double[] xyzScale = null;
- ZarrAxes zarrAxes = setupToMultiscale.get(setupId).axes;
- List zarrAxesList = setupToMultiscale.get(setupId).zarrAxisList;
- if (scale != null && zarrAxesList != null) {
- xyzScale = new double[]{
- scale[zarrAxes.axisIndex("x", false)],
- scale[zarrAxes.axisIndex("y", false)],
- zarrAxes.hasZAxis() ? scale[zarrAxes.axisIndex("z", false)] : 1.0
- };
- }
- return xyzScale;
- }
-
- @NotNull
- private AffineTransform3D getAffineTransform3D(int setupId, int datasetId) {
- OmeZarrMultiscales multiscales = setupToMultiscale.get(setupId);
- AffineTransform3D transform = new AffineTransform3D();
- if (multiscales.datasets[datasetId].coordinateTransformations != null) {
- double[] scale = getXYZScale(setupId, multiscales.datasets[datasetId].coordinateTransformations[0]);
- if (scale != null) {
- transform.scale(scale[0], scale[1], scale[2]);
- }
-
- double[] translation = multiscales.datasets[datasetId].coordinateTransformations[0].translation;
- if (translation != null) {
- transform.translate(translation);
- }
- }
- return transform;
- }
-
- private VoxelDimensions getVoxelDimensions3D(int setupId, int datasetId) {
- OmeZarrMultiscales multiscales = setupToMultiscale.get(setupId);
-
- ZarrAxes zarrAxes = setupToMultiscale.get(setupId).axes;
- List zarrAxesList = setupToMultiscale.get(setupId).zarrAxisList;
- if (multiscales.datasets[datasetId].coordinateTransformations != null && zarrAxesList != null) {
- double[] scale = getXYZScale(setupId, multiscales.datasets[datasetId].coordinateTransformations[0]);
- // get unit of last dimension, under assumption this is the X axis (i.e. a space axis)
- String unit = zarrAxesList.get(zarrAxesList.size() - 1).getUnit();
-
- if (scale != null && unit != null) {
- if (zarrAxes.hasZAxis()) {
- return new FinalVoxelDimensions(unit, scale);
- } else {
- return new FinalVoxelDimensions(unit, new double[]{scale[0], scale[1], 1.0});
- }
- }
- }
-
- return new DefaultVoxelDimensions(3);
- }
-
- private Dimensions getSpatialDimensions(int setupId, DatasetAttributes attributes) {
- final long[] spatialDimensions = new long[3];
- long[] attributeDimensions = attributes.getDimensions();
- Arrays.fill(spatialDimensions, 1);
- ZarrAxes zarrAxes = setupToMultiscale.get(setupId).axes;
- final Map spatialToZarr = zarrAxes.spatialToZarr();
- for (Map.Entry entry : spatialToZarr.entrySet()) {
- spatialDimensions[entry.getKey()] = attributeDimensions[entry.getValue()];
- }
- return new FinalDimensions(spatialDimensions);
- }
-
- private ViewSetup createViewSetup(int setupId) {
- OmeZarrMultiscales multiscale = setupToMultiscale.get(setupId);
- Dimensions dimensions = getSpatialDimensions(setupId, setupToAttributes.get(setupId));
- VoxelDimensions voxelDimensions = getVoxelDimensions3D(setupId, 0);
-
- Tile tile = new Tile(0);
-
- Channel channel;
- if (setupToPathname.get(setupId).contains("labels"))
- channel = new Channel(setupToChannel.get(setupId), "labels");
- else
- channel = new Channel(setupToChannel.get(setupId));
-
- Angle angle = new Angle(0);
- Illumination illumination = new Illumination(0);
- String name = readName(multiscale, setupId);
- //if ( setupToPathname.get( setupId ).contains( "labels" ))
- // viewSetup.setAttribute( new ImageType( ImageType.Type.IntensityImage ) );
- return new ViewSetup(setupId, name, dimensions, voxelDimensions, tile, channel, angle, illumination);
- }
-
- private String readName(OmeZarrMultiscales multiscale, int setupId) {
- if (multiscale.name != null)
- return multiscale.name;
- else
- return "image " + setupId;
- }
-
- /**
- * Clear the cache. Images that were obtained from
- * this loader before {@link #close()} will stop working. Requesting images
- * after {@link #close()} will cause the n5 to be reopened (with a
- * new cache).
- */
- public void close() {
- if (isOpen) {
- synchronized (this) {
- if (!isOpen)
- return;
- if (fetchers != null)
- fetchers.shutdown();
- cache.clearCache();
- isOpen = false;
- }
- }
- }
-
- @Override
- public SetupImgLoader, ?> getSetupImgLoader(final int setupId) {
- open();
- return setupImgLoaders.get(setupId);
- }
-
- private , V extends Volatile & NativeType> SetupImgLoader createSetupImgLoader(final int setupId) throws IOException {
- switch (setupToAttributes.get(setupId).getDataType()) {
- case UINT8:
- return Cast.unchecked(new SetupImgLoader<>(setupId, new UnsignedByteType(), new VolatileUnsignedByteType()));
- case UINT16:
- return Cast.unchecked(new SetupImgLoader<>(setupId, new UnsignedShortType(), new VolatileUnsignedShortType()));
- case UINT32:
- return Cast.unchecked(new SetupImgLoader<>(setupId, new UnsignedIntType(), new VolatileUnsignedIntType()));
- case UINT64:
- return Cast.unchecked(new SetupImgLoader<>(setupId, new UnsignedLongType(), new VolatileUnsignedLongType()));
- case INT8:
- return Cast.unchecked(new SetupImgLoader<>(setupId, new ByteType(), new VolatileByteType()));
- case INT16:
- return Cast.unchecked(new SetupImgLoader<>(setupId, new ShortType(), new VolatileShortType()));
- case INT32:
- return Cast.unchecked(new SetupImgLoader<>(setupId, new IntType(), new VolatileIntType()));
- case INT64:
- return Cast.unchecked(new SetupImgLoader<>(setupId, new LongType(), new VolatileLongType()));
- case FLOAT32:
- return Cast.unchecked(new SetupImgLoader<>(setupId, new FloatType(), new VolatileFloatType()));
- case FLOAT64:
- return Cast.unchecked(new SetupImgLoader<>(setupId, new DoubleType(), new VolatileDoubleType()));
- }
- return null;
- }
-
- @Override
- public CacheControl getCacheControl() {
- open();
- return cache;
- }
-
- // TODO: Add description
- private int[] getBlockSize(int setupId, DatasetAttributes attributes) {
- ZarrAxes zarrAxes = setupToMultiscale.get(setupId).axes;
- if (!zarrAxes.hasZAxis()) {
- return fillBlockSize(attributes);
- } else {
- return Arrays.stream(attributes.getBlockSize()).limit(3).toArray();
- }
- }
-
- private int[] fillBlockSize(DatasetAttributes attributes) {
- int[] tmp = new int[3];
- tmp[0] = Arrays.stream(attributes.getBlockSize()).toArray()[0];
- tmp[1] = Arrays.stream(attributes.getBlockSize()).toArray()[1];
- tmp[2] = 1;
- return tmp;
- }
-
- private SimpleCacheArrayLoader> createCacheArrayLoader(final N5Reader n5, final String pathName, int setupId, int channel, int timepointId, CellGrid grid) throws IOException {
- final DatasetAttributes attributes = n5.getDatasetAttributes(pathName);
- ZarrAxes zarrAxes = setupToMultiscale.get(setupId).axes;
- return new N5OMEZarrCacheArrayLoader<>(n5, pathName, channel, timepointId, attributes, grid, zarrAxes);
- }
-
- private class SetupImgLoader, V extends Volatile & NativeType>
- extends AbstractViewerSetupImgLoader
- implements MultiResolutionSetupImgLoader {
- private final int setupId;
-
- private final double[][] mipmapResolutions;
-
- private final AffineTransform3D[] mipmapTransforms;
-
- public SetupImgLoader(final int setupId, final T type, final V volatileType) throws IOException {
- super(type, volatileType);
- this.setupId = setupId;
- mipmapResolutions = readMipmapResolutions();
- mipmapTransforms = new AffineTransform3D[mipmapResolutions.length];
- for (int level = 0; level < mipmapResolutions.length; level++) {
- mipmapTransforms[level] = MipmapTransforms.getMipmapTransformDefault(mipmapResolutions[level]);
- }
- }
-
- /**
- * @return
- * @throws IOException
- */
- private double[][] readMipmapResolutions() throws IOException {
- OmeZarrMultiscales multiscale = setupToMultiscale.get(setupId);
- double[][] mipmapResolutions = new double[multiscale.datasets.length][];
-
- long[] dimensionsOfLevel0 = getDatasetAttributes(getPathName(setupId, 0)).getDimensions();
- mipmapResolutions[0] = new double[]{1.0, 1.0, 1.0};
-
- for (int level = 1; level < mipmapResolutions.length; level++) {
- long[] dimensions = getDatasetAttributes(getPathName(setupId, level)).getDimensions();
- mipmapResolutions[level] = new double[3];
- for (int d = 0; d < 2; d++) {
- mipmapResolutions[level][d] = Math.round(1.0 * dimensionsOfLevel0[d] / dimensions[d]);
- }
- mipmapResolutions[level][2] = multiscale.axes.hasZAxis() ? Math.round(1.0 * dimensionsOfLevel0[2] / dimensions[2]) : 1.0;
- }
-
- return mipmapResolutions;
- }
-
- @Override
- public RandomAccessibleInterval getVolatileImage(final int timepointId, final int level, final ImgLoaderHint... hints) {
- return prepareCachedImage(timepointId, level, LoadingStrategy.BUDGETED, volatileType);
- }
-
- @Override
- public RandomAccessibleInterval getImage(final int timepointId, final int level, final ImgLoaderHint... hints) {
- return prepareCachedImage(timepointId, level, LoadingStrategy.BLOCKING, type);
- }
-
- @Override
- public Dimensions getImageSize(final int timepointId, final int level) {
- final String pathName = getPathName(setupId, level);
- try {
- final DatasetAttributes attributes = getDatasetAttributes(pathName);
- return new FinalDimensions(attributes.getDimensions());
- } catch (Exception e) {
- throw new RuntimeException("Could not read from " + pathName);
- }
- }
-
- @NotNull
- public String getPathName(int setupId, int level) {
- return setupToPathname.get(setupId) + "/" + setupToMultiscale.get(this.setupId).datasets[level].path;
- }
-
- @Override
- public double[][] getMipmapResolutions() {
- return mipmapResolutions;
- }
-
- @Override
- public AffineTransform3D[] getMipmapTransforms() {
- return mipmapTransforms;
- }
-
- @Override
- public int numMipmapLevels() {
- return mipmapResolutions.length;
- }
-
- @Override
- public VoxelDimensions getVoxelSize(final int timepointId) {
- return null;
- }
-
- /**
- * Create a {@link CellImg} backed by the cache.
- */
- private > RandomAccessibleInterval prepareCachedImage(final int timepointId, final int level, final LoadingStrategy loadingStrategy, final T type) {
- try {
- final String pathName = getPathName(setupId, level);
- final DatasetAttributes attributes = getDatasetAttributes(pathName);
-
- if (logging) {
- System.out.println("Preparing image " + pathName + " of data type " + attributes.getDataType());
- }
-
- // The below dimensions refer to one time point and one channel.
- // That means they are either 2D or 3D.
- long[] dimensions = getSpatialDimensions(setupId, attributes).dimensionsAsLongArray();
- final int[] cellDimensions = getBlockSize(setupId, attributes);
- final CellGrid grid = new CellGrid(dimensions, cellDimensions);
-
- final int priority = numMipmapLevels() - 1 - level;
- final CacheHints cacheHints = new CacheHints(loadingStrategy, priority, false);
-
- final SimpleCacheArrayLoader> loader = createCacheArrayLoader(n5, pathName, setupId, setupToChannel.get(setupId), timepointId, grid);
- return cache.createImg(grid, timepointId, setupId, level, cacheHints, loader, type);
- } catch (IOException e) {
- System.err.println(String.format(
- "image data for timepoint %d setup %d level %d could not be found.%n",
- timepointId, setupId, level));
- return Views.interval(
- new ConstantRandomAccessible<>(type.createVariable(), 3),
- new FinalInterval(1, 1, 1));
- }
- }
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5S3OMEZarrImageLoader.java b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5S3OMEZarrImageLoader.java
deleted file mode 100644
index 1670b41d..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/N5S3OMEZarrImageLoader.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.loaders;
-
-import java.io.IOException;
-
-import org.embl.mobie.io.n5.loaders.S3ImageLoader;
-import org.embl.mobie.io.ome.zarr.readers.N5S3OmeZarrReader;
-import org.embl.mobie.io.util.S3Utils;
-
-import com.amazonaws.services.s3.AmazonS3;
-
-import bdv.cache.SharedQueue;
-import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
-
-public class N5S3OMEZarrImageLoader extends N5OMEZarrImageLoader implements S3ImageLoader {
- private final String serviceEndpoint;
- private final String signingRegion;
- private final String bucketName;
- private final String key;
-
-
- // sequenceDescription has been read from xml
- public N5S3OMEZarrImageLoader(String serviceEndpoint, String signingRegion, String bucketName, String key, String dimensionSeparator, AbstractSequenceDescription, ?, ?> sequenceDescription) throws IOException {
- super(new N5S3ZarrReaderCreator().create(serviceEndpoint, signingRegion, bucketName, key, dimensionSeparator), sequenceDescription);
- this.serviceEndpoint = serviceEndpoint;
- this.signingRegion = signingRegion;
- this.bucketName = bucketName;
- this.key = key;
- }
-
- // sequenceDescription will be read from zarr
- public N5S3OMEZarrImageLoader(String serviceEndpoint, String signingRegion, String bucketName, String key, String dimensionSeparator) throws IOException {
- super(new N5S3ZarrReaderCreator().create(serviceEndpoint, signingRegion, bucketName, key, dimensionSeparator));
- this.serviceEndpoint = serviceEndpoint;
- this.signingRegion = signingRegion;
- this.bucketName = bucketName;
- this.key = key;
- }
-
- public N5S3OMEZarrImageLoader(String serviceEndpoint, String signingRegion, String bucketName, String key, String dimensionSeparator, SharedQueue sharedQueue) throws IOException {
- super(new N5S3ZarrReaderCreator().create(serviceEndpoint, signingRegion, bucketName, key, dimensionSeparator), sharedQueue);
- this.serviceEndpoint = serviceEndpoint;
- this.signingRegion = signingRegion;
- this.bucketName = bucketName;
- this.key = key;
- }
-
- public String getServiceEndpoint() {
- return serviceEndpoint;
- }
-
- public String getSigningRegion() {
- return signingRegion;
- }
-
- public String getBucketName() {
- return bucketName;
- }
-
- public String getKey() {
- return key;
- }
-
- static class N5S3ZarrReaderCreator {
- public N5S3OmeZarrReader create(String serviceEndpoint, String signingRegion, String bucketName, String key, String dimensionSeparator) throws IOException {
- final AmazonS3 s3 = S3Utils.getS3Client(serviceEndpoint, signingRegion, bucketName);
- return new N5S3OmeZarrReader(s3, serviceEndpoint, bucketName, key, dimensionSeparator);
- }
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/xml/XmlIoN5S3ZarrImageLoader.java b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/xml/XmlIoN5S3ZarrImageLoader.java
deleted file mode 100644
index e51d6965..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/xml/XmlIoN5S3ZarrImageLoader.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.loaders.xml;
-
-
-import java.io.File;
-import java.io.IOException;
-
-import org.embl.mobie.io.ome.zarr.loaders.N5S3OMEZarrImageLoader;
-import org.jdom2.Element;
-
-import mpicbg.spim.data.XmlHelpers;
-import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
-import mpicbg.spim.data.generic.sequence.ImgLoaderIo;
-import mpicbg.spim.data.generic.sequence.XmlIoBasicImgLoader;
-
-import static mpicbg.spim.data.XmlKeys.IMGLOADER_FORMAT_ATTRIBUTE_NAME;
-
-@ImgLoaderIo(format = "ome.n5.zarr.s3", type = N5S3OMEZarrImageLoader.class)
-public class XmlIoN5S3ZarrImageLoader implements XmlIoBasicImgLoader {
- public static final String SERVICE_ENDPOINT = "ServiceEndpoint";
- public static final String SIGNING_REGION = "SigningRegion";
- public static final String BUCKET_NAME = "BucketName";
- public static final String KEY = "Key";
-
- @Override
- public Element toXml(final N5S3OMEZarrImageLoader imgLoader, final File basePath) {
- final Element elem = new Element("ImageLoader");
- elem.setAttribute(IMGLOADER_FORMAT_ATTRIBUTE_NAME, "ome.n5.zarr.s3");
- elem.setAttribute("version", "1.0");
- elem.addContent(XmlHelpers.textElement(SERVICE_ENDPOINT, imgLoader.getServiceEndpoint()));
- elem.addContent(XmlHelpers.textElement(SIGNING_REGION, imgLoader.getSigningRegion()));
- elem.addContent(XmlHelpers.textElement(BUCKET_NAME, imgLoader.getBucketName()));
- elem.addContent(XmlHelpers.textElement(KEY, imgLoader.getKey()));
-
- return elem;
- }
-
- @Override
- public N5S3OMEZarrImageLoader fromXml(final Element elem, final File basePath, final AbstractSequenceDescription, ?, ?> sequenceDescription) {
-// final String version = elem.getAttributeValue( "version" );
-
- final String serviceEndpoint = XmlHelpers.getText(elem, SERVICE_ENDPOINT);
- final String signingRegion = XmlHelpers.getText(elem, SIGNING_REGION);
- final String bucketName = XmlHelpers.getText(elem, BUCKET_NAME);
- final String key = XmlHelpers.getText(elem, KEY);
- try {
- return new N5S3OMEZarrImageLoader(serviceEndpoint, signingRegion, bucketName, key, "/", sequenceDescription);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/xml/XmlN5OmeZarrImageLoader.java b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/xml/XmlN5OmeZarrImageLoader.java
deleted file mode 100644
index 4aebec3e..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/xml/XmlN5OmeZarrImageLoader.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.loaders.xml;
-
-import java.io.File;
-
-import org.embl.mobie.io.ome.zarr.loaders.N5OMEZarrImageLoader;
-import org.embl.mobie.io.ome.zarr.readers.N5OmeZarrReader;
-import org.jdom2.Element;
-
-import mpicbg.spim.data.XmlHelpers;
-import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
-import mpicbg.spim.data.generic.sequence.ImgLoaderIo;
-import mpicbg.spim.data.generic.sequence.XmlIoBasicImgLoader;
-
-import static mpicbg.spim.data.XmlKeys.IMGLOADER_FORMAT_ATTRIBUTE_NAME;
-
-@ImgLoaderIo(format = "bdv.ome.zarr", type = N5OMEZarrImageLoader.class)
-public class XmlN5OmeZarrImageLoader implements XmlIoBasicImgLoader {
- public static final String OmeZarr = "ome.zarr";
-
- public static String getDatasetsPathFromXml(final Element parent, final String basePath) {
- final Element elem = parent.getChild(OmeZarr);
- if (elem == null)
- return null;
- final String path = elem.getText();
- final String pathType = elem.getAttributeValue("type");
- final boolean isRelative = null != pathType && pathType.equals("relative");
- if (isRelative) {
- if (basePath == null)
- return null;
- else {
- return new File(basePath).getParent() + File.separator + path;
- }
- } else
- return path;
- }
-
- @Override
- public Element toXml(final N5OMEZarrImageLoader imgLoader, final File basePath) {
- final Element elem = new Element("ImageLoader");
- elem.setAttribute(IMGLOADER_FORMAT_ATTRIBUTE_NAME, "bdv.ome.zarr");
- elem.setAttribute("version", "0.2");
- N5OmeZarrReader reader = (N5OmeZarrReader) imgLoader.n5;
- elem.addContent(XmlHelpers.pathElement(OmeZarr, new File(reader.getBasePath()), basePath));
- return elem;
- }
-
- @Override
- public N5OMEZarrImageLoader fromXml(Element elem, File basePath, AbstractSequenceDescription, ?, ?> sequenceDescription) {
- return null;
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/xml/XmlN5S3OmeZarrImageLoader.java b/src/main/java/org/embl/mobie/io/ome/zarr/loaders/xml/XmlN5S3OmeZarrImageLoader.java
deleted file mode 100644
index 295b7d58..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/loaders/xml/XmlN5S3OmeZarrImageLoader.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.loaders.xml;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.embl.mobie.io.ome.zarr.loaders.N5S3OMEZarrImageLoader;
-import org.jdom2.Element;
-
-import mpicbg.spim.data.XmlHelpers;
-import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
-import mpicbg.spim.data.generic.sequence.ImgLoaderIo;
-import mpicbg.spim.data.generic.sequence.XmlIoBasicImgLoader;
-
-import static mpicbg.spim.data.XmlKeys.IMGLOADER_FORMAT_ATTRIBUTE_NAME;
-
-@ImgLoaderIo(format = "bdv.ome.zarr.s3", type = N5S3OMEZarrImageLoader.class)
-public class XmlN5S3OmeZarrImageLoader implements XmlIoBasicImgLoader {
- public static final String SERVICE_ENDPOINT = "ServiceEndpoint";
- public static final String SIGNING_REGION = "SigningRegion";
- public static final String BUCKET_NAME = "BucketName";
- public static final String KEY = "Key";
-
- @Override
- public Element toXml(final N5S3OMEZarrImageLoader imgLoader, final File basePath) {
- final Element elem = new Element("ImageLoader");
- elem.setAttribute(IMGLOADER_FORMAT_ATTRIBUTE_NAME, "bdv.ome.zarr.s3");
- elem.setAttribute("version", "0.2");
- elem.addContent(XmlHelpers.textElement(SERVICE_ENDPOINT, imgLoader.getServiceEndpoint()));
- elem.addContent(XmlHelpers.textElement(SIGNING_REGION, imgLoader.getSigningRegion()));
- elem.addContent(XmlHelpers.textElement(BUCKET_NAME, imgLoader.getBucketName()));
- elem.addContent(XmlHelpers.textElement(KEY, imgLoader.getKey()));
- return elem;
- }
-
- public Element toXml(String serviceEndpoint, String signingRegion, String bucketName, String key) {
- final Element elem = new Element("ImageLoader");
- elem.setAttribute(IMGLOADER_FORMAT_ATTRIBUTE_NAME, "bdv.ome.zarr.s3");
- elem.addContent(new Element(KEY).addContent(key));
- elem.addContent(new Element(SIGNING_REGION).addContent(signingRegion));
- elem.addContent(new Element(SERVICE_ENDPOINT).addContent(serviceEndpoint));
- elem.addContent(new Element(BUCKET_NAME).addContent(bucketName));
-
- return elem;
- }
-
- @Override
- public N5S3OMEZarrImageLoader fromXml(Element elem, File basePath, AbstractSequenceDescription, ?, ?> sequenceDescription) {
- final String serviceEndpoint = XmlHelpers.getText(elem, SERVICE_ENDPOINT);
- final String signingRegion = XmlHelpers.getText(elem, SIGNING_REGION);
- final String bucketName = XmlHelpers.getText(elem, BUCKET_NAME);
- final String key = XmlHelpers.getText(elem, KEY);
- try {
- return new N5S3OMEZarrImageLoader(serviceEndpoint, signingRegion, bucketName, key, "/", sequenceDescription);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/openers/OMEZarrOpener.java b/src/main/java/org/embl/mobie/io/ome/zarr/openers/OMEZarrOpener.java
deleted file mode 100644
index 44a16f9a..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/openers/OMEZarrOpener.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.openers;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.embl.mobie.io.OpenerLogging;
-import org.embl.mobie.io.ome.zarr.loaders.N5OMEZarrImageLoader;
-import org.embl.mobie.io.ome.zarr.readers.N5OmeZarrReader;
-
-import com.google.gson.GsonBuilder;
-
-import bdv.cache.SharedQueue;
-import mpicbg.spim.data.SpimData;
-import net.imglib2.util.Cast;
-
-public class OMEZarrOpener extends OpenerLogging
-{
- private final String filePath;
-
- public OMEZarrOpener(String filePath) {
- this.filePath = filePath;
- }
-
- public static SpimData openFile(String filePath) throws IOException {
- OMEZarrOpener omeZarrOpener = new OMEZarrOpener(filePath);
- return omeZarrOpener.readFile();
- }
-
- public static SpimData openFile(String filePath, SharedQueue sharedQueue) throws IOException {
- N5OMEZarrImageLoader.logging = logging;
- OMEZarrOpener omeZarrOpener = new OMEZarrOpener(filePath);
- return omeZarrOpener.readFile(sharedQueue);
- }
-
- private SpimData readFile(SharedQueue sharedQueue) throws IOException {
- N5OMEZarrImageLoader.logging = logging;
- N5OmeZarrReader reader = new N5OmeZarrReader(this.filePath, new GsonBuilder());
- N5OMEZarrImageLoader imageLoader = new N5OMEZarrImageLoader(reader, sharedQueue);
- return new SpimData(
- new File(this.filePath),
- Cast.unchecked(imageLoader.getSequenceDescription()),
- imageLoader.getViewRegistrations());
- }
-
- private SpimData readFile() throws IOException {
- N5OMEZarrImageLoader.logging = logging;
- N5OmeZarrReader reader = new N5OmeZarrReader(this.filePath, new GsonBuilder());
- N5OMEZarrImageLoader imageLoader = new N5OMEZarrImageLoader(reader);
- return new SpimData(
- new File(this.filePath),
- Cast.unchecked(imageLoader.getSequenceDescription()),
- imageLoader.getViewRegistrations());
- }
-
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/openers/OMEZarrS3Opener.java b/src/main/java/org/embl/mobie/io/ome/zarr/openers/OMEZarrS3Opener.java
deleted file mode 100644
index efc71b8f..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/openers/OMEZarrS3Opener.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.openers;
-
-import java.io.IOException;
-
-import org.embl.mobie.io.n5.openers.S3Opener;
-import org.embl.mobie.io.ome.zarr.loaders.N5OMEZarrImageLoader;
-import org.embl.mobie.io.ome.zarr.loaders.N5S3OMEZarrImageLoader;
-
-import bdv.cache.SharedQueue;
-import mpicbg.spim.data.SpimData;
-import net.imglib2.util.Cast;
-
-public class OMEZarrS3Opener extends S3Opener {
-
- public OMEZarrS3Opener(String serviceEndpoint, String signingRegion, String bucketName) {
- super(serviceEndpoint, signingRegion, bucketName);
- }
-
- public OMEZarrS3Opener(String url) {
- super(url);
- }
-
- public static SpimData readURL(String url) throws IOException {
- final OMEZarrS3Opener reader = new OMEZarrS3Opener(url);
- return reader.readKey(reader.getKey());
- }
-
- public static SpimData readURL(String url, SharedQueue sharedQueue) throws IOException {
- final OMEZarrS3Opener reader = new OMEZarrS3Opener(url);
- return reader.readKey(reader.getKey(), sharedQueue);
- }
-
- public SpimData readKey(String key, SharedQueue sharedQueue) throws IOException {
- N5OMEZarrImageLoader.logging = logging;
- N5S3OMEZarrImageLoader imageLoader = new N5S3OMEZarrImageLoader(serviceEndpoint, signingRegion, bucketName, key, ".", sharedQueue);
- return new SpimData(null, Cast.unchecked(imageLoader.getSequenceDescription()), imageLoader.getViewRegistrations());
- }
-
- @Override
- public SpimData readKey(String key) throws IOException {
- N5OMEZarrImageLoader.logging = logging;
- N5S3OMEZarrImageLoader imageLoader = new N5S3OMEZarrImageLoader(serviceEndpoint, signingRegion, bucketName, key, ".");
- return new SpimData(null, Cast.unchecked(imageLoader.getSequenceDescription()), imageLoader.getViewRegistrations());
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/readers/N5OmeZarrReader.java b/src/main/java/org/embl/mobie/io/ome/zarr/readers/N5OmeZarrReader.java
deleted file mode 100644
index 31ffe626..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/readers/N5OmeZarrReader.java
+++ /dev/null
@@ -1,395 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-/**
- * Copyright (c) 2019, Stephan Saalfeld
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package org.embl.mobie.io.ome.zarr.readers;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.nio.channels.Channels;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Stream;
-
-import org.embl.mobie.io.ome.zarr.util.N5ZarrImageReader;
-import org.embl.mobie.io.ome.zarr.util.N5ZarrImageReaderHelper;
-import org.embl.mobie.io.ome.zarr.util.OmeZArrayAttributes;
-import org.embl.mobie.io.ome.zarr.util.ZArrayAttributes;
-import org.embl.mobie.io.ome.zarr.util.ZarrAxes;
-import org.embl.mobie.io.ome.zarr.util.ZarrAxis;
-import org.embl.mobie.io.ome.zarr.util.ZarrDatasetAttributes;
-import org.janelia.saalfeldlab.n5.DataBlock;
-import org.janelia.saalfeldlab.n5.DatasetAttributes;
-import org.janelia.saalfeldlab.n5.GsonAttributesParser;
-import org.janelia.saalfeldlab.n5.N5FSReader;
-
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-
-
-
-
-/**
- * @author Stephan Saalfeld <saalfelds@janelia.hhmi.org>
- */
-
-public class N5OmeZarrReader extends N5FSReader implements N5ZarrImageReader {
- protected final boolean mapN5DatasetAttributes;
- final N5ZarrImageReaderHelper n5ZarrImageReaderHelper;
- protected String dimensionSeparator;
- private ZarrAxes zarrAxes;
- private List zarrAxesList;
-
- /**
- * Opens an {@link N5OmeZarrReader} at a given base path with a custom
- * {@link GsonBuilder} to support custom attributes.
- *
- * @param basePath Zarr base path
- * @param gsonBuilder
- * @param dimensionSeparator
- * @param mapN5DatasetAttributes Virtually create N5 dataset attributes (dimensions, blockSize,
- * compression, dataType) for datasets such that N5 code that
- * reads or modifies these attributes directly works as expected.
- * This can lead to name clashes if a zarr container uses these
- * attribute keys for other purposes.
- * @throws IOException
- */
- public N5OmeZarrReader(final String basePath, final GsonBuilder gsonBuilder, final String dimensionSeparator, final boolean mapN5DatasetAttributes) throws IOException {
- super(basePath, N5ZarrImageReader.initGsonBuilder(gsonBuilder));
- this.dimensionSeparator = dimensionSeparator;
- this.mapN5DatasetAttributes = mapN5DatasetAttributes;
- this.n5ZarrImageReaderHelper = new N5ZarrImageReaderHelper(basePath, N5ZarrImageReader.initGsonBuilder(gsonBuilder));
- }
-
- /**
- * Opens an {@link N5OmeZarrReader} at a given base path with a custom
- * {@link GsonBuilder} to support custom attributes.
- *
- * @param basePath Zarr base path
- * @param gsonBuilder
- * @param dimensionSeparator
- * @throws IOException
- */
- public N5OmeZarrReader(final String basePath, final GsonBuilder gsonBuilder, final String dimensionSeparator) throws IOException {
-
- this(basePath, gsonBuilder, dimensionSeparator, true);
- }
-
- /**
- * Opens an {@link N5OmeZarrReader} at a given base path.
- *
- * @param basePath Zarr base path
- * @param dimensionSeparator
- * @param mapN5DatasetAttributes Virtually create N5 dataset attributes (dimensions, blockSize,
- * compression, dataType) for datasets such that N5 code that
- * reads or modifies these attributes directly works as expected.
- * This can lead to name collisions if a zarr container uses these
- * attribute keys for other purposes.
- * @throws IOException
- */
- public N5OmeZarrReader(final String basePath, final String dimensionSeparator, final boolean mapN5DatasetAttributes) throws IOException {
-
- this(basePath, new GsonBuilder(), dimensionSeparator, mapN5DatasetAttributes);
- }
-
- /**
- * Opens an {@link N5OmeZarrReader} at a given base path.
- *
- * @param basePath Zarr base path
- * @param mapN5DatasetAttributes Virtually create N5 dataset attributes (dimensions, blockSize,
- * compression, dataType) for datasets such that N5 code that
- * reads or modifies these attributes directly works as expected.
- * This can lead to name collisions if a zarr container uses these
- * attribute keys for other purposes.
- * @throws IOException
- */
- public N5OmeZarrReader(final String basePath, final boolean mapN5DatasetAttributes) throws IOException {
- this(basePath, new GsonBuilder(), DEFAULT_SEPARATOR, mapN5DatasetAttributes);
- }
-
- /**
- * Opens an {@link N5OmeZarrReader} at a given base path with a custom
- * {@link GsonBuilder} to support custom attributes.
- *
- * Zarray metadata will be virtually mapped to N5 dataset attributes.
- *
- * @param basePath Zarr base path
- * @param gsonBuilder
- * @throws IOException
- */
- public N5OmeZarrReader(final String basePath, final GsonBuilder gsonBuilder) throws IOException {
- this(basePath, gsonBuilder, DEFAULT_SEPARATOR);
- }
-
- /**
- * Opens an {@link N5OmeZarrReader} at a given base path.
- *
- * Zarray metadata will be virtually mapped to N5 dataset attributes.
- *
- * @param basePath Zarr base path
- * @throws IOException
- */
- public N5OmeZarrReader(final String basePath) throws IOException {
-
- this(basePath, new GsonBuilder());
- }
-
- @Override
- public Version getVersion() throws IOException {
-
- final Path path;
- if (groupExists("/")) {
- path = Paths.get(basePath, zgroupFile);
- } else if (datasetExists("/")) {
- path = Paths.get(basePath, zarrayFile);
- } else {
- return VERSION;
- }
-
- if (Files.exists(path)) {
-
- try (final LockedFileChannel lockedFileChannel = LockedFileChannel.openForReading(path)) {
- final HashMap attributes =
- GsonAttributesParser.readAttributes(
- Channels.newReader(
- lockedFileChannel.getFileChannel(),
- StandardCharsets.UTF_8.name()),
- gson);
-
- final Integer zarr_format = GsonAttributesParser.parseAttribute(
- attributes,
- "zarr_format",
- Integer.class,
- gson);
-
- if (zarr_format != null)
- return new Version(zarr_format, 0, 0);
- }
- }
- return VERSION;
- }
-
- /**
- * @return Zarr base path
- */
- @Override
- public String getBasePath() {
-
- return this.basePath;
- }
-
- public boolean groupExists(final String pathName) {
-
- final Path path = Paths.get(basePath, removeLeadingSlash(pathName), zgroupFile);
- return Files.exists(path) && Files.isRegularFile(path);
- }
-
- @Override
- public String getZarrDataBlockString(long[] gridPosition, String dimensionSeparator, boolean isRowMajor) {
- return N5ZarrImageReader.super.getZarrDataBlockString(gridPosition, dimensionSeparator, isRowMajor);
- }
-
- public ZArrayAttributes getZArrayAttributes(final String pathName) throws IOException {
-
- final Path path = Paths.get(basePath, removeLeadingSlash(pathName), zarrayFile);
- OmeZArrayAttributes zArrayAttributes = null;
- if (Files.exists(path)) {
- try (final LockedFileChannel lockedFileChannel = LockedFileChannel.openForReading(path);
- final Reader reader = Channels.newReader(lockedFileChannel.getFileChannel(), StandardCharsets.UTF_8.name())) {
- zArrayAttributes = gson.fromJson(reader, OmeZArrayAttributes.class);
- }
- } else {
- //System.out.println(path + " does not exist.");
- }
- this.dimensionSeparator = zArrayAttributes == null || zArrayAttributes.getDimensionSeparator() == null ?
- DEFAULT_SEPARATOR : zArrayAttributes.getDimensionSeparator();
-
- return zArrayAttributes;
- }
-
- @Override
- public DatasetAttributes getDatasetAttributes(final String pathName) throws IOException {
-
- final ZArrayAttributes zArrayAttributes = getZArrayAttributes(pathName);
- return zArrayAttributes == null ? null : zArrayAttributes.getDatasetAttributes();
- }
-
- @Override
- public boolean datasetExists(final String pathName) throws IOException {
-
- final Path path = Paths.get(basePath, removeLeadingSlash(pathName), zarrayFile);
- return Files.exists(path) && Files.isRegularFile(path) && getDatasetAttributes(pathName) != null;
- }
-
- /**
- * @returns false if the group or dataset does not exist but also if the
- * attempt to access
- */
- @Override
- public boolean exists(final String pathName) {
-
- try {
- return groupExists(pathName) || datasetExists(pathName);
- } catch (final IOException e) {
- e.printStackTrace();
- return false;
- }
- }
-
- /**
- * If {@link #mapN5DatasetAttributes} is set, dataset attributes will
- * override attributes with the same key.
- */
- @Override
- public HashMap getAttributes(final String pathName) throws IOException {
-
- final Path path = Paths.get(basePath, removeLeadingSlash(pathName), zattrsFile);
- final HashMap attributes = new HashMap<>();
- if (Files.exists(path)) {
- try (final LockedFileChannel lockedFileChannel = LockedFileChannel.openForReading(path)) {
- attributes.putAll(
- GsonAttributesParser.readAttributes(
- Channels.newReader(
- lockedFileChannel.getFileChannel(),
- StandardCharsets.UTF_8.name()),
- gson));
- }
- }
-
- try {
- getDimensions(attributes);
- } catch (IllegalArgumentException e) {
- throw new IOException("Error while getting datasets dimensions", e);
- }
-
- if (mapN5DatasetAttributes && datasetExists(pathName)) {
- final DatasetAttributes datasetAttributes = getZArrayAttributes(pathName).getDatasetAttributes();
- n5ZarrImageReaderHelper.putAttributes(attributes, datasetAttributes);
- }
-
- return attributes;
- }
-
- @Override
- public Map> listAttributes(String pathName) throws IOException {
- return super.listAttributes(pathName);
- }
-
- public ZarrAxes getAxes() {
- return this.zarrAxes;
- }
-
- @Override
- public void setAxes(JsonElement axesJson) {
- if (axesJson != null) {
- this.zarrAxes = ZarrAxes.decode(axesJson.toString());
- } else {
- this.zarrAxes = ZarrAxes.TCZYX;
- }
- }
-
- @Override
- public void setAxes(List axes) {
- this.zarrAxesList = axes;
- }
-
- public List getZarrAxes() {
- return this.zarrAxesList;
- }
-
- @Override
- public DataBlock> readBlock(
- final String pathName,
- final DatasetAttributes datasetAttributes,
- final long... gridPosition) throws IOException {
-
- final ZarrDatasetAttributes zarrDatasetAttributes;
- if (datasetAttributes instanceof ZarrDatasetAttributes)
- zarrDatasetAttributes = (ZarrDatasetAttributes) datasetAttributes;
- else
- zarrDatasetAttributes = getZArrayAttributes(pathName).getDatasetAttributes();
-
- Path path = Paths.get(
- basePath,
- removeLeadingSlash(pathName),
- getZarrDataBlockString(
- gridPosition,
- dimensionSeparator,
- zarrDatasetAttributes.isRowMajor()));
- if (!Files.exists(path)) {
- return null;
- }
-
- try (final LockedFileChannel lockedChannel = LockedFileChannel.openForReading(path)) {
- return readBlock(Channels.newInputStream(lockedChannel.getFileChannel()), zarrDatasetAttributes, gridPosition);
- }
- }
-
- @Override
- public String[] list(final String pathName) throws IOException {
-
- final Path path = Paths.get(basePath, removeLeadingSlash(pathName));
- try (final Stream pathStream = Files.list(path)) {
-
- return pathStream
- .filter(Files::isDirectory)
- .map(a -> path.relativize(a).toString())
- .filter(a -> exists(pathName + "/" + a))
- .toArray(String[]::new);
- }
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/readers/N5S3OmeZarrReader.java b/src/main/java/org/embl/mobie/io/ome/zarr/readers/N5S3OmeZarrReader.java
deleted file mode 100644
index 8ea34160..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/readers/N5S3OmeZarrReader.java
+++ /dev/null
@@ -1,301 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-/**
- * Copyright (c) 2019, Stephan Saalfeld
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package org.embl.mobie.io.ome.zarr.readers;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-
-import org.embl.mobie.io.ome.zarr.util.N5ZarrImageReader;
-import org.embl.mobie.io.ome.zarr.util.N5ZarrImageReaderHelper;
-import org.embl.mobie.io.ome.zarr.util.ZArrayAttributes;
-import org.embl.mobie.io.ome.zarr.util.ZarrAxes;
-import org.embl.mobie.io.ome.zarr.util.ZarrAxis;
-import org.embl.mobie.io.ome.zarr.util.ZarrDatasetAttributes;
-import org.janelia.saalfeldlab.n5.DataBlock;
-import org.janelia.saalfeldlab.n5.DatasetAttributes;
-import org.janelia.saalfeldlab.n5.GsonAttributesParser;
-import org.janelia.saalfeldlab.n5.s3.N5AmazonS3Reader;
-
-import com.amazonaws.services.s3.AmazonS3;
-import com.amazonaws.services.s3.model.AmazonS3Exception;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-
-
-
-
-/**
- * Attempt at a diamond inheritance solution for S3+Zarr.
- */
-
-public class N5S3OmeZarrReader extends N5AmazonS3Reader implements N5ZarrImageReader {
-
- final protected boolean mapN5DatasetAttributes;
- private final String serviceEndpoint;
- private final N5ZarrImageReaderHelper n5ZarrImageReaderHelper;
- protected String dimensionSeparator;
- List zarrAxesList = new ArrayList<>();
- private ZarrAxes zarrAxes;
-
- public N5S3OmeZarrReader(AmazonS3 s3, String serviceEndpoint, String bucketName, String containerPath, String dimensionSeparator) throws IOException {
- super(s3, bucketName, containerPath, N5ZarrImageReader.initGsonBuilder(new GsonBuilder()));
- this.serviceEndpoint = serviceEndpoint; // for debugging
- this.dimensionSeparator = dimensionSeparator;
- mapN5DatasetAttributes = true;
- this.n5ZarrImageReaderHelper = new N5ZarrImageReaderHelper(N5ZarrImageReader.initGsonBuilder(new GsonBuilder()));
- }
-
- public ZarrAxes getAxes() {
- return this.zarrAxes;
- }
-
- @Override
- public void setAxes(JsonElement axesJson) {
- if (axesJson != null) {
- this.zarrAxes = ZarrAxes.decode(axesJson.toString());
- } else {
- this.zarrAxes = ZarrAxes.TCZYX;
- }
- }
-
- @Override
- public void setAxes(List axes) {
- this.zarrAxesList = axes;
- }
-
- public List getZarrAxes() {
- return this.zarrAxesList;
- }
-
- public void setDimensionSeparator(String dimensionSeparator) {
- this.dimensionSeparator = dimensionSeparator;
- }
-
- public AmazonS3 getS3() {
- return s3;
- }
-
- public String getBucketName() {
- return bucketName;
- }
-
- public String getContainerPath() {
- return containerPath;
- }
-
- public String getServiceEndpoint() {
- return serviceEndpoint;
- }
-
- /**
- * Helper to encapsulate building the object key for a file like
- * .zarray or .zgroup within any given path.
- *
- * @param pathName
- * @param file One of .zarray, .zgroup or .zattrs
- * @return
- */
- private String objectFile(final String pathName, String file) {
- StringBuilder sb = new StringBuilder();
- sb.append(containerPath);
- String cleaned = removeLeadingSlash(pathName);
- if (!cleaned.isEmpty()) {
- sb.append('/');
- sb.append(cleaned);
- }
- sb.append('/');
- sb.append(file);
- return sb.toString();
- }
-
- // remove getBasePath
-
- @Override
- public Version getVersion() throws IOException {
- HashMap meta;
- meta = readJson(objectFile("", zgroupFile));
- if (meta == null) {
- meta = readJson(objectFile("", zarrayFile));
- }
-
- if (meta != null) {
-
- final Integer zarr_format = GsonAttributesParser.parseAttribute(
- meta,
- "zarr_format",
- Integer.class,
- gson);
-
- if (zarr_format != null)
- return new Version(zarr_format, 0, 0);
- }
-
- return VERSION;
- }
-
- public boolean groupExists(final String pathName) {
- return exists(objectFile(pathName, zgroupFile));
- }
-
- public ZArrayAttributes getZArrayAttributes(final String pathName) throws IOException {
- final String path = objectFile(pathName, zarrayFile);
- HashMap attributes = readJson(path);
-
- if (attributes == null) {
- //System.out.println(path + " does not exist.");
- attributes = new HashMap<>();
- }
-
- JsonElement dimSep = attributes.get("dimension_separator");
- this.dimensionSeparator = dimSep == null ? DEFAULT_SEPARATOR : dimSep.getAsString();
- return n5ZarrImageReaderHelper.getN5DatasetAttributes(attributes);
- }
-
- @Override
- public DatasetAttributes getDatasetAttributes(final String pathName) throws IOException {
- final ZArrayAttributes zArrayAttributes = getZArrayAttributes(pathName);
- return zArrayAttributes == null ? null : zArrayAttributes.getDatasetAttributes();
- }
-
- @Override
- public boolean datasetExists(final String pathName) throws IOException {
- final String path = objectFile(pathName, zarrayFile);
- return readJson(path) != null;
- }
-
- /**
- * If {@link #mapN5DatasetAttributes} is set, dataset attributes will
- * override attributes with the same key.
- */
- @Override
- public HashMap getAttributes(final String pathName) throws IOException {
- final String path = objectFile(pathName, zattrsFile);
- HashMap attributes = readJson(path);
-
- if (attributes == null) {
- attributes = new HashMap<>();
- }
-
- try {
- getDimensions(attributes);
- } catch (IllegalArgumentException e) {
- throw new IOException("Error while getting datasets dimensions", e);
- }
-
- if (mapN5DatasetAttributes) {
- try
- {
- final DatasetAttributes datasetAttributes = getZArrayAttributes( pathName ).getDatasetAttributes();
- n5ZarrImageReaderHelper.putAttributes( attributes, datasetAttributes );
- }
- catch ( Exception e )
- {
- // no datasetAttributes found here
- }
- }
- return attributes;
- }
-
- @Override
- public DataBlock> readBlock(
- final String pathName,
- final DatasetAttributes datasetAttributes,
- final long... gridPosition) throws IOException {
- final ZarrDatasetAttributes zarrDatasetAttributes;
- if (datasetAttributes instanceof ZarrDatasetAttributes)
- zarrDatasetAttributes = (ZarrDatasetAttributes) datasetAttributes;
- else
- zarrDatasetAttributes = getZArrayAttributes(pathName).getDatasetAttributes();
-
- final String dataBlockKey =
- objectFile(pathName,
- getZarrDataBlockString(
- gridPosition,
- dimensionSeparator,
- zarrDatasetAttributes.isRowMajor()));
-
- // Currently exists() appends "/"
- // if (!exists(dataBlockKey))
- // return null;
-
- try {
- try (final InputStream in = this.readS3Object(dataBlockKey)) {
- return readBlock(in, zarrDatasetAttributes, gridPosition);
- }
- } catch (Exception e) {
- return null;
- }
- }
-
- /**
- * Copied from getAttributes but doesn't change the objectPath in any way.
- * CHANGES: returns null rather than empty hash map
- *
- * @param objectPath
- * @return null if the object does not exist, otherwise the loaded attributes.
- */
- public HashMap readJson(String objectPath) {
- try (final InputStream in = this.readS3Object(objectPath)) {
- return GsonAttributesParser.readAttributes(new InputStreamReader(in), gson);
- } catch (Exception e) {
- return null;
- }
- }
-
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/AxesTypes.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/AxesTypes.java
deleted file mode 100644
index 5683b194..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/AxesTypes.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-public enum AxesTypes {
- TIME("time"),
- CHANNEL("channel"),
- SPACE("space");
-
- private final String typeName;
-
- AxesTypes(String typeName) {
- this.typeName = typeName;
- }
-
- public static boolean contains(String test) {
- for (AxesTypes c : AxesTypes.values()) {
- if (c.typeName.equals(test)) {
- return true;
- }
- }
- return false;
- }
-
- public static AxesTypes getAxisType(String axisString) {
- if (axisString.equals("x") || axisString.equals("y") || axisString.equals("z")) {
- return AxesTypes.SPACE;
- } else if (axisString.equals("t")) {
- return AxesTypes.TIME;
- } else if (axisString.equals("c")) {
- return AxesTypes.CHANNEL;
- } else {
- return null;
- }
- }
-
- public String getTypeName() {
- return typeName;
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/N5OMEZarrCacheArrayLoader.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/N5OMEZarrCacheArrayLoader.java
deleted file mode 100644
index 983cf173..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/N5OMEZarrCacheArrayLoader.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Map;
-
-import net.imglib2.img.basictypeaccess.DataAccess;
-import org.embl.mobie.io.n5.util.N5DataTypeSize;
-import org.embl.mobie.io.ome.zarr.loaders.N5OMEZarrImageLoader;
-import org.janelia.saalfeldlab.n5.DataBlock;
-import org.janelia.saalfeldlab.n5.DataType;
-import org.janelia.saalfeldlab.n5.DatasetAttributes;
-import org.janelia.saalfeldlab.n5.N5Reader;
-
-import com.amazonaws.SdkClientException;
-
-import bdv.img.cache.SimpleCacheArrayLoader;
-
-import net.imglib2.img.cell.CellGrid;
-
-public class N5OMEZarrCacheArrayLoader implements SimpleCacheArrayLoader {
- private final N5Reader n5;
- private final String pathName;
- private final int channel;
- private final int timepoint;
- private final DatasetAttributes attributes;
- private final ZarrArrayCreator zarrArrayCreator;
- private final ZarrAxes zarrAxes;
-
- public N5OMEZarrCacheArrayLoader(final N5Reader n5, final String pathName, final int channel, final int timepoint, final DatasetAttributes attributes, CellGrid grid, ZarrAxes zarrAxes) {
- this.n5 = n5;
- this.pathName = pathName; // includes the level
- this.channel = channel;
- this.timepoint = timepoint;
- this.attributes = attributes;
- final DataType dataType = attributes.getDataType();
- this.zarrArrayCreator = new ZarrArrayCreator<>(grid, dataType, zarrAxes);
- this.zarrAxes = zarrAxes;
- }
-
- @Override
- public A loadArray(final long[] gridPosition, int[] cellDimensions) throws IOException {
- DataBlock> block = null;
-
- long[] dataBlockIndices = toZarrChunkIndices(gridPosition);
-
- long start = 0;
- if (N5OMEZarrImageLoader.logging)
- start = System.currentTimeMillis();
-
- try {
- block = n5.readBlock(pathName, attributes, dataBlockIndices);
- } catch (SdkClientException e) {
- System.err.println(e.getMessage()); // this happens sometimes, not sure yet why...
- }
- if (N5OMEZarrImageLoader.logging) {
- if (block != null) {
- final long millis = System.currentTimeMillis() - start;
- final int numElements = block.getNumElements();
- final DataType dataType = attributes.getDataType();
- final float megaBytes = (float) numElements * N5DataTypeSize.getNumBytesPerElement(dataType) / 1000000.0F;
- final float mbPerSecond = megaBytes / (millis / 1000.0F);
- System.out.println(pathName + " " + Arrays.toString(dataBlockIndices) + ": " + "Read " + numElements + " " + dataType + " (" + String.format("%.3f", megaBytes) + " MB) in " + millis + " ms (" + String.format("%.3f", mbPerSecond) + " MB/s).");
- } else
- System.out.println(pathName + " " + Arrays.toString(dataBlockIndices) + ": Missing, returning zeros.");
- }
-
- if (block == null) {
- return (A) zarrArrayCreator.createEmptyArray(gridPosition);
- } else {
- return zarrArrayCreator.createArray(block, gridPosition);
- }
- }
-
- private long[] toZarrChunkIndices(long[] gridPosition) {
-
- long[] chunkInZarr = new long[zarrAxes.getNumDimension()];
-
- // fill in the spatial dimensions
- final Map spatialToZarr = zarrAxes.spatialToZarr();
- for (Map.Entry entry : spatialToZarr.entrySet())
- chunkInZarr[entry.getValue()] = gridPosition[entry.getKey()];
-
- if (zarrAxes.hasChannels())
- chunkInZarr[zarrAxes.channelIndex()] = channel;
-
- if (zarrAxes.hasTimepoints())
- chunkInZarr[zarrAxes.timeIndex()] = timepoint;
-
- return chunkInZarr;
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/N5ZarrImageReader.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/N5ZarrImageReader.java
deleted file mode 100644
index 5475639f..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/N5ZarrImageReader.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.janelia.saalfeldlab.n5.BlockReader;
-import org.janelia.saalfeldlab.n5.ByteArrayDataBlock;
-import org.janelia.saalfeldlab.n5.DataBlock;
-import org.janelia.saalfeldlab.n5.N5Reader;
-import org.janelia.saalfeldlab.n5.zarr.DType;
-import org.janelia.saalfeldlab.n5.zarr.ZarrCompressor;
-import org.janelia.saalfeldlab.n5.zarr.ZarrDatasetAttributes;
-
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-
-public interface N5ZarrImageReader extends N5Reader {
- String DEFAULT_SEPARATOR = ".";
- String zarrayFile = ".zarray";
- String zattrsFile = ".zattrs";
- String zgroupFile = ".zgroup";
- List zarrAxes = new ArrayList<>();
-
-
- static GsonBuilder initGsonBuilder(final GsonBuilder gsonBuilder) {
-
- gsonBuilder.registerTypeAdapter(DType.class, new DType.JsonAdapter());
- gsonBuilder.registerTypeAdapter(ZarrCompressor.class, ZarrCompressor.jsonAdapter);
- gsonBuilder.registerTypeAdapter(ZarrAxes.class, new ZarrAxesAdapter());
- gsonBuilder.registerTypeAdapter(N5Reader.Version.class, new VersionAdapter());
- gsonBuilder.registerTypeAdapter(OmeZarrMultiscales.class, new OmeZarrMultiscalesAdapter());
- gsonBuilder.setPrettyPrinting();
- return gsonBuilder;
- }
-
- default Version getVersion() throws IOException {
- return VERSION;
- }
-
- default String getDimensionSeparator(HashMap attributes) {
- JsonElement dimSep = attributes.get("dimension_separator");
- return dimSep == null ? DEFAULT_SEPARATOR : dimSep.getAsString();
- }
-
- default void getDimensions(HashMap attributes) throws IllegalArgumentException {
- JsonElement multiscales = attributes.get("multiscales");
- if (multiscales == null) {
- return;
- }
- String version = multiscales.getAsJsonArray().get(0).getAsJsonObject().get("version").getAsString();
- if (version.equals("0.3")) {
- JsonElement axes = multiscales.getAsJsonArray().get(0).getAsJsonObject().get("axes");
- setAxes(axes);
- } else if (version.equals("0.4")) {
- JsonArray axes = multiscales.getAsJsonArray().get(0).getAsJsonObject().get("axes").getAsJsonArray();
- int index = 0;
- List zarrAxes = new ArrayList<>();
- for (JsonElement axis : axes) {
- String name = axis.getAsJsonObject().get("name").getAsString();
- String type = axis.getAsJsonObject().get("type").getAsString();
- if (name.isEmpty() || type.isEmpty() || !AxesTypes.contains(type)) {
- throw new IllegalArgumentException("Unsupported multiscales axes: " + name + ", " + type);
- }
- ZarrAxis zarrAxis;
- if (axis.getAsJsonObject().get("unit") != null && axis.getAsJsonObject().get("unit").isJsonPrimitive()) {
- String unit = axis.getAsJsonObject().get("unit").getAsString();
- zarrAxis = new ZarrAxis(index, name, type, unit);
- } else {
- zarrAxis = new ZarrAxis(index, name, type);
- }
- index++;
- zarrAxes.add(zarrAxis);
- }
- setAxes(zarrAxes);
- setAxes(ZarrAxis.convertToJson(zarrAxes));
- } else {
- JsonElement axes = multiscales.getAsJsonArray().get(0).getAsJsonObject().get("axes");
- setAxes(axes);
- }
- }
-
- void setAxes(JsonElement axesJson);
-
- void setAxes(List axes);
-
- ZArrayAttributes getZArrayAttributes(final String pathName) throws IOException;
-
- boolean datasetExists(final String pathName) throws IOException;
-
- boolean groupExists(final String pathName);
-
- /**
- * CHANGE: return String rather than Path, fixed javadoc
- * Constructs the path for a data block in a dataset at a given grid position.
- *
- * The returned path is
- *
- * $datasetPathName/$gridPosition[n]$dimensionSeparator$gridPosition[n-1]$dimensionSeparator[...]$dimensionSeparator$gridPosition[0]
- *
- *
- * This is the file into which the data block will be stored.
- *
- * @param gridPosition
- * @param dimensionSeparator
- * @return
- */
- default String getZarrDataBlockString(
- final long[] gridPosition,
- final String dimensionSeparator,
- final boolean isRowMajor) {
- final StringBuilder pathStringBuilder = new StringBuilder();
- if (isRowMajor) {
- pathStringBuilder.append(gridPosition[gridPosition.length - 1]);
- for (int i = gridPosition.length - 2; i >= 0; --i) {
- pathStringBuilder.append(dimensionSeparator);
- pathStringBuilder.append(gridPosition[i]);
- }
- } else {
- pathStringBuilder.append(gridPosition[0]);
- for (int i = 1; i < gridPosition.length; ++i) {
- pathStringBuilder.append(dimensionSeparator);
- pathStringBuilder.append(gridPosition[i]);
- }
- }
-
- return pathStringBuilder.toString();
- }
-
- /**
- * Reads a {@link DataBlock} from an {@link InputStream}.
- *
- * @param in
- * @param datasetAttributes
- * @param gridPosition
- * @return
- * @throws IOException
- */
- @SuppressWarnings("incomplete-switch")
- default DataBlock> readBlock(
- final InputStream in,
- final ZarrDatasetAttributes datasetAttributes,
- final long... gridPosition) throws IOException {
- final int[] blockSize = datasetAttributes.getBlockSize();
- final DType dType = datasetAttributes.getDType();
-
- final ByteArrayDataBlock byteBlock = dType.createByteBlock(blockSize, gridPosition);
-
- final BlockReader reader = datasetAttributes.getCompression().getReader();
- reader.read(byteBlock, in);
-
- switch (dType.getDataType()) {
- case UINT8:
- case INT8:
- return byteBlock;
- }
-
- /* else translate into target type */
- final DataBlock> dataBlock = dType.createDataBlock(blockSize, gridPosition);
- final ByteBuffer byteBuffer = byteBlock.toByteBuffer();
- byteBuffer.order(dType.getOrder());
- dataBlock.readData(byteBuffer);
-
- return dataBlock;
- }
-
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/N5ZarrImageReaderHelper.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/N5ZarrImageReaderHelper.java
deleted file mode 100644
index 7a278e0d..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/N5ZarrImageReaderHelper.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-
-import org.janelia.saalfeldlab.n5.DataBlock;
-import org.janelia.saalfeldlab.n5.DatasetAttributes;
-import org.janelia.saalfeldlab.n5.N5FSReader;
-import org.janelia.saalfeldlab.n5.zarr.DType;
-import org.janelia.saalfeldlab.n5.zarr.Filter;
-import org.janelia.saalfeldlab.n5.zarr.ZarrCompressor;
-import org.jetbrains.annotations.NotNull;
-
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-import com.google.gson.reflect.TypeToken;
-
-public class N5ZarrImageReaderHelper extends N5FSReader {
-
- public N5ZarrImageReaderHelper(GsonBuilder gsonBuilder) throws IOException {
- super("", gsonBuilder);
- }
-
- public N5ZarrImageReaderHelper(String basePath, GsonBuilder gsonBuilder) throws IOException {
- super(basePath, gsonBuilder);
- }
-
- public ZArrayAttributes getN5DatasetAttributes(@NotNull HashMap attributes) throws IOException {
- if (attributes.isEmpty()) {
- throw new IOException("Empty ZArray attributes");
- }
- return new ZArrayAttributes(
- attributes.get("zarr_format").getAsInt(),
- gson.fromJson(attributes.get("shape"), long[].class),
- gson.fromJson(attributes.get("chunks"), int[].class),
- gson.fromJson(attributes.get("dtype"), DType.class),
- gson.fromJson(attributes.get("compressor"), ZarrCompressor.class),
- attributes.get("fill_value").getAsString(),
- attributes.get("order").getAsCharacter(),
- gson.fromJson(attributes.get("filters"), TypeToken.getParameterized(Collection.class, Filter.class).getType()));
-
- }
-
- public void putAttributes(HashMap attributes, DatasetAttributes datasetAttributes) {
- attributes.put("dimensions", gson.toJsonTree(datasetAttributes.getDimensions()));
- attributes.put("blockSize", gson.toJsonTree(datasetAttributes.getBlockSize()));
- attributes.put("dataType", gson.toJsonTree(datasetAttributes.getDataType()));
- attributes.put("compression", gson.toJsonTree(datasetAttributes.getCompression()));
- }
-
-
- @Override
- public HashMap getAttributes(String pathName) {
- return null;
- }
-
- @Override
- public DataBlock> readBlock(String pathName, DatasetAttributes datasetAttributes, long[] gridPosition) {
- return null;
- }
-
- @Override
- public boolean exists(String pathName) {
- return false;
- }
-
- @Override
- public String[] list(String pathName) throws IOException {
- return new String[0];
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/OmeZArrayAttributes.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/OmeZArrayAttributes.java
deleted file mode 100644
index 8ca0ad78..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/OmeZArrayAttributes.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-import java.util.Collection;
-import java.util.HashMap;
-
-import org.janelia.saalfeldlab.n5.zarr.DType;
-import org.janelia.saalfeldlab.n5.zarr.Filter;
-import org.janelia.saalfeldlab.n5.zarr.ZarrCompressor;
-
-import com.google.gson.annotations.SerializedName;
-
-public class OmeZArrayAttributes extends ZArrayAttributes {
- protected static final String dimensionSeparatorKey = "dimension_separator";
-
- @SerializedName("dimension_separator")
- private final String dimensionSeparator;
-
- public OmeZArrayAttributes(int zarr_format, long[] shape, int[] chunks, DType dtype, ZarrCompressor compressor,
- String fill_value, char order, Collection filters, String dimensionSeparator) {
- super(zarr_format, shape, chunks, dtype, compressor, fill_value, order, filters);
- this.dimensionSeparator = dimensionSeparator;
- }
-
- public String getDimensionSeparator() {
- return dimensionSeparator;
- }
-
- public HashMap asMap() {
-
- final HashMap map = super.asMap();
- map.put(dimensionSeparatorKey, dimensionSeparator);
-
- return map;
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/OmeZarrMultiscales.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/OmeZarrMultiscales.java
deleted file mode 100644
index d25fa53c..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/OmeZarrMultiscales.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-import java.util.List;
-
-import mpicbg.spim.data.sequence.VoxelDimensions;
-
-public class OmeZarrMultiscales {
-
- // key in json for multiscales
- public static final String MULTI_SCALE_KEY = "multiscales";
-
- public transient ZarrAxes axes;
- public List zarrAxisList;
- public Dataset[] datasets;
- public String name;
- public String type;
- public String version;
- public CoordinateTransformations[] coordinateTransformations;
-
- public OmeZarrMultiscales() {
- }
-
- public OmeZarrMultiscales(ZarrAxes axes, String name, String type, String version,
- VoxelDimensions voxelDimensions, double[][] resolutions, String timeUnit,
- double frameInterval) {
- this.version = version;
- this.name = name;
- this.type = type;
- this.axes = axes;
- this.zarrAxisList = axes.toAxesList(voxelDimensions.unit(), timeUnit);
- generateDatasets(voxelDimensions, frameInterval, resolutions);
- }
-
- private void generateDatasets(VoxelDimensions voxelDimensions, double frameInterval, double[][] resolutions) {
-
- Dataset[] datasets = new Dataset[resolutions.length];
- for (int i = 0; i < resolutions.length; i++) {
- Dataset dataset = new Dataset();
-
- CoordinateTransformations coordinateTransformations = new CoordinateTransformations();
- coordinateTransformations.scale = getScale(voxelDimensions, frameInterval, resolutions[i]);
- coordinateTransformations.type = "scale";
-
- dataset.path = "s" + i;
- dataset.coordinateTransformations = new CoordinateTransformations[]{coordinateTransformations};
- datasets[i] = dataset;
- }
- this.datasets = datasets;
- }
-
- private double[] getScale(VoxelDimensions voxelDimensions, double frameInterval, double[] xyzScale) {
- int nDimensions = zarrAxisList.size();
- double[] scale = new double[nDimensions];
- if (axes.timeIndex() != -1) {
- scale[axes.timeIndex()] = frameInterval;
- }
-
- if (axes.channelIndex() != -1) {
- scale[axes.channelIndex()] = 1;
- }
-
- for (int i = 0; i < 3; i++) {
- double dimension = voxelDimensions.dimension(i) * xyzScale[i];
- scale[nDimensions - (i + 1)] = dimension;
- }
-
- return scale;
- }
-
- public static class Dataset {
- public String path;
- public CoordinateTransformations[] coordinateTransformations;
- }
-
- public static class CoordinateTransformations {
- public String type;
- public double[] scale;
- public double[] translation;
- public String path;
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/OmeZarrMultiscalesAdapter.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/OmeZarrMultiscalesAdapter.java
deleted file mode 100644
index 2be02a1c..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/OmeZarrMultiscalesAdapter.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-import java.lang.reflect.Type;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-
-public class OmeZarrMultiscalesAdapter implements JsonSerializer {
-
- @Override
- public JsonElement serialize(OmeZarrMultiscales src, Type typeOfSrc, JsonSerializationContext context) {
- JsonObject obj = new JsonObject();
- obj.add("axes", context.serialize(src.zarrAxisList));
- obj.add("datasets", context.serialize(src.datasets));
- obj.add("name", context.serialize(src.name));
- obj.add("type", context.serialize(src.type));
- obj.add("version", context.serialize(src.version));
- obj.add("coordinateTransformations", context.serialize(src.coordinateTransformations));
- return obj;
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/TransformationTypes.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/TransformationTypes.java
deleted file mode 100644
index 669fef59..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/TransformationTypes.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-public enum TransformationTypes {
- IDENTITY("identity"),
- TRANSLATION("translation"),
- SCALE("scale");
-
- private final String typeName;
-
- TransformationTypes(String typeName) {
- this.typeName = typeName;
- }
-
- public static boolean contains(String test) {
- for (TransformationTypes c : TransformationTypes.values()) {
- if (c.typeName.equals(test)) {
- return true;
- }
- }
- return false;
- }
-
- public String getTypeName() {
- return typeName;
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/UnitTypes.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/UnitTypes.java
deleted file mode 100644
index 5d8fda8f..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/UnitTypes.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-
-import ucar.units.PrefixDBException;
-import ucar.units.SpecificationException;
-import ucar.units.Unit;
-import ucar.units.UnitDBException;
-import ucar.units.UnitFormat;
-import ucar.units.UnitFormatManager;
-import ucar.units.UnitSystemException;
-
-
-public enum UnitTypes {
- ANGSTROM("angstrom"),
- ATTOMETER("attometer"),
- CENTIMETER("centimeter"),
- DECIMETER("decimeter"),
- EXAMETER("exameter"),
- FEMTOMETER("femtometer"),
- FOOT("foot"),
- GIGAMETER("gigameter"),
- HECTOMETER("hectometer"),
- INCH("inch"),
- KILOMETER("kilometer"),
- MEGAMETER("megameter"),
- METER("meter"),
- MICROMETER("micrometer"),
- MILE("mile"),
- MILLIMETER("millimeter"),
- NANOMETER("nanometer"),
- PARSEC("parsec"),
- PETAMETER("petameter"),
- PICOMETER("picometer"),
- TERAMETER("terameter"),
- YARD("yard"),
- YOCTOMETER("yoctometer"),
- YOTTAMETER("yottameter"),
- ZEPTOMETER("zeptometer"),
- ZETTAMETER("zettameter"),
-
- ATTOSECOND("attosecond"),
- CENTISECOND("centisecond"),
- DAY("day"),
- DECISECOND("decisecond"),
- EXASECOND("exasecond"),
- FEMTOSECOND("femtosecond"),
- GIGASECOND("gigasecond"),
- HECTOSECOND("hectosecond"),
- HOUR("hour"),
- KILOSECOND("kilosecond"),
- MEGASECOND("megasecond"),
- MICROSECOND("microsecond"),
- MILLISECOND("millisecond"),
- MINUTE("minute"),
- NANOSECOND("nanosecond"),
- PETASECOND("petasecond"),
- PICOSECOND("picosecond"),
- SECOND("second"),
- TERASECOND("terasecond"),
- YOCTOSECOND("yoctosecond"),
- YOTTASECOND("yottasecond"),
- ZEPTOSECOND("zeptosecond"),
- ZETTASECOND("zettasecond");
-
- private final String typeName;
-
- UnitTypes(String typeName) {
- this.typeName = typeName;
- }
-
- public static boolean contains(String test) {
- for (UnitTypes c : UnitTypes.values()) {
- if (c.typeName.equals(test)) {
- return true;
- }
- }
- return false;
- }
-
- public static UnitTypes convertUnit(String unit) {
- // Convert the mu symbol into "u".
- String unitString = unit.replace("\u00B5", "u");
-
- try {
- UnitFormat unitFormatter = UnitFormatManager.instance();
- Unit inputUnit = unitFormatter.parse(unitString);
-
- for (UnitTypes unitType : UnitTypes.values()) {
- Unit zarrUnit = unitFormatter.parse(unitType.typeName);
- if (zarrUnit.getCanonicalString().equals(inputUnit.getCanonicalString())) {
- System.out.println("Converted unit: " + unit + " to recommended ome-zarr unit: " + unitType.getTypeName());
- return unitType;
- }
- }
- } catch (SpecificationException | UnitDBException | PrefixDBException | UnitSystemException e) {
- e.printStackTrace();
- }
-
- System.out.println(unit + " is not one of the recommended units for ome-zarr");
- return null;
- }
-
- public String getTypeName() {
- return typeName;
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/VersionAdapter.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/VersionAdapter.java
deleted file mode 100644
index 1b0f9b43..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/VersionAdapter.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-
-import java.lang.reflect.Type;
-
-import org.janelia.saalfeldlab.n5.N5Reader;
-
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParseException;
-import com.google.gson.JsonPrimitive;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-
-public class VersionAdapter implements JsonDeserializer, JsonSerializer {
-
- @Override
- public N5Reader.Version deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
- String[] versionElements = json.getAsString().split("\\.");
- int[] versionNumbers = new int[versionElements.length];
-
- for (int i = 0; i < versionNumbers.length; i++) {
- versionNumbers[i] = Integer.parseInt(versionElements[i]);
- }
-
- if (versionNumbers.length > 2) {
- return new N5Reader.Version(versionNumbers[0], versionNumbers[1], versionNumbers[2]);
- } else {
- return new N5Reader.Version(versionNumbers[0], versionNumbers[1], 0);
- }
- }
-
- @Override
- public JsonElement serialize(N5Reader.Version src, Type typeOfSrc, JsonSerializationContext context) {
- return new JsonPrimitive(src.getMajor() + "." + src.getMinor() + "." + src.getPatch());
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZArrayAttributes.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZArrayAttributes.java
deleted file mode 100644
index 4becfb39..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZArrayAttributes.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-
-import org.janelia.saalfeldlab.n5.Compression;
-import org.janelia.saalfeldlab.n5.RawCompression;
-import org.janelia.saalfeldlab.n5.zarr.DType;
-import org.janelia.saalfeldlab.n5.zarr.Filter;
-import org.janelia.saalfeldlab.n5.zarr.Utils;
-import org.janelia.saalfeldlab.n5.zarr.ZarrCompressor;
-
-public class ZArrayAttributes {
-
- protected static final String zarrFormatKey = "zarr_format";
- protected static final String shapeKey = "shape";
- protected static final String chunksKey = "chunks";
- protected static final String dTypeKey = "dtype";
- protected static final String compressorKey = "compressor";
- protected static final String fillValueKey = "fill_value";
- protected static final String orderKey = "order";
- protected static final String filtersKey = "filters";
-
- private final int zarr_format;
- private final long[] shape;
- private final int[] chunks;
- private final DType dtype;
- private final ZarrCompressor compressor;
- private final String fill_value;
- private final char order;
- private final List filters = new ArrayList<>();
-
- public ZArrayAttributes(
- final int zarr_format,
- final long[] shape,
- final int[] chunks,
- final DType dtype,
- final ZarrCompressor compressor,
- final String fill_value,
- final char order,
- final Collection filters) {
-
- this.zarr_format = zarr_format;
- this.shape = shape;
- this.chunks = chunks;
- this.dtype = dtype;
- this.compressor = compressor == null ? new ZarrCompressor.Raw() : compressor;
- this.fill_value = fill_value;
- this.order = order;
- if (filters != null)
- this.filters.addAll(filters);
- }
-
- public ZarrDatasetAttributes getDatasetAttributes() {
- final boolean isRowMajor = order == 'C';
- final long[] dimensions = shape.clone();
- final int[] blockSize = chunks.clone();
-
- if (isRowMajor) {
- Utils.reorder(dimensions);
- Utils.reorder(blockSize);
- }
-
- Compression compression = compressor != null ? compressor.getCompression() : new ZarrCompressor.Raw().getCompression();
-
- return new ZarrDatasetAttributes(
- dimensions,
- blockSize,
- dtype,
- compression,
- isRowMajor,
- fill_value);
- }
-
- public long[] getShape() {
- return shape;
- }
-
- public int getNumDimensions() {
- return shape.length;
- }
-
- public int[] getChunks() {
- return chunks;
- }
-
- public ZarrCompressor getCompressor() {
- return compressor;
- }
-
- public DType getDType() {
- return dtype;
- }
-
- public int getZarrFormat() {
- return zarr_format;
- }
-
- public char getOrder() {
- return order;
- }
-
- public String getFillValue() {
- return fill_value;
- }
-
- public HashMap asMap() {
-
- final HashMap map = new HashMap<>();
-
- map.put(zarrFormatKey, zarr_format);
- map.put(shapeKey, shape);
- map.put(chunksKey, chunks);
- map.put(dTypeKey, dtype.toString());
- map.put(compressorKey, compressor instanceof RawCompression ? null : compressor);
- map.put(fillValueKey, fill_value);
- map.put(orderKey, order);
- map.put(filtersKey, filters);
-
- return map;
- }
-
- public Collection getFilters() {
- return filters;
- }
-
-
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrArrayCreator.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrArrayCreator.java
deleted file mode 100644
index 7c1d72d6..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrArrayCreator.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-import java.util.Arrays;
-
-import org.embl.mobie.io.n5.util.ArrayCreator;
-import org.janelia.saalfeldlab.n5.DataBlock;
-import org.janelia.saalfeldlab.n5.DataType;
-
-import net.imglib2.img.cell.CellGrid;
-import net.imglib2.type.NativeType;
-
-public class ZarrArrayCreator> extends ArrayCreator {
- private final ZarrAxes zarrAxes;
-
- public ZarrArrayCreator(CellGrid cellGrid, DataType dataType, ZarrAxes zarrAxes) {
- super(cellGrid, dataType);
- this.zarrAxes = zarrAxes;
- }
-
- public A createArray(DataBlock> dataBlock, long[] gridPosition) {
- long[] cellDims = getCellDims(gridPosition);
- int n = (int) (cellDims[0] * cellDims[1] * cellDims[2]);
-
- if (zarrAxes.getNumDimension() == 2)
- cellDims = Arrays.stream(cellDims).limit(2).toArray();
-
- return (A) VolatileDoubleArray(dataBlock, cellDims, n);
- }
-
- @Override
- public long[] getCellDims(long[] gridPosition) {
- long[] cellMin = new long[Math.max(zarrAxes.getNumDimension(), 3)];
- int[] cellDims = new int[Math.max(zarrAxes.getNumDimension(), 3)];
-
- if(zarrAxes.hasChannels()) {
- cellDims[zarrAxes.channelIndex()] = 1;
- }
- if(zarrAxes.hasTimepoints()) {
- cellDims[zarrAxes.timeIndex()] = 1;
- }
-
- cellGrid.getCellDimensions(gridPosition, cellMin, cellDims);
- return Arrays.stream(cellDims).mapToLong(i -> i).toArray(); // casting to long for creating ArrayImgs.*
- }
-}
diff --git a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java b/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java
deleted file mode 100644
index f3c47cc4..00000000
--- a/src/main/java/org/embl/mobie/io/ome/zarr/util/ZarrAxes.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*-
- * #%L
- * Readers and writers for image data in MoBIE projects
- * %%
- * Copyright (C) 2021 - 2023 EMBL
- * %%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- * #L%
- */
-package org.embl.mobie.io.ome.zarr.util;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Stream;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.google.common.collect.Lists;
-
-@JsonFormat(shape = JsonFormat.Shape.ARRAY)
-public enum ZarrAxes {
- YX("[\"y\",\"x\"]"),
- CYX("[\"c\",\"y\",\"x\"]"),
- TYX("[\"t\",\"y\",\"x\"]"),
- ZYX("[\"z\",\"y\",\"x\"]"),
- CZYX("[\"c\",\"z\",\"y\",\"x\"]"),
- TZYX("[\"t\",\"z\",\"y\",\"x\"]"),
- TCYX("[\"t\",\"c\",\"y\",\"x\"]"),
- TCZYX("[\"t\",\"c\",\"z\",\"y\",\"x\"]"); // v0.2
-
- private final String axes;
-
- ZarrAxes(String axes) {
- this.axes = axes;
- }
-
- @JsonCreator
- public static ZarrAxes decode(final String axes) {
- return Stream.of(ZarrAxes.values()).filter(targetEnum ->
- targetEnum.axes.equals(axes)).findFirst().orElse(TCZYX);
- }
-
- public List getAxesList() {
- String pattern = "([a-z])";
- List allMatches = new ArrayList<>();
- Matcher m = Pattern.compile(pattern)
- .matcher(axes);
- while (m.find()) {
- allMatches.add(m.group());
- }
- return allMatches;
- }
-
- public List toAxesList(String spaceUnit, String timeUnit) {
- List zarrAxesList = new ArrayList<>();
- List zarrAxesStrings = getAxesList();
-
- String[] units = new String[]{spaceUnit, timeUnit};
-
- // convert to valid ome-zarr units, if possible, otherwise just go ahead with
- // given unit
- for (int i = 0; i < units.length; i++) {
- String unit = units[i];
- if (!UnitTypes.contains(unit)) {
- UnitTypes unitType = UnitTypes.convertUnit(unit);
- if (unitType != null) {
- units[i] = unitType.getTypeName();
- }
- }
- }
-
- for (int i = 0; i < zarrAxesStrings.size(); i++) {
- String axisString = zarrAxesStrings.get(i);
- AxesTypes axisType = AxesTypes.getAxisType(axisString);
-
- String unit;
- if (axisType == AxesTypes.SPACE) {
- unit = units[0];
- } else if (axisType == AxesTypes.TIME) {
- unit = units[1];
- } else {
- unit = null;
- }
-
- zarrAxesList.add(new ZarrAxis(i, axisString, axisType.getTypeName(), unit));
- }
-
- return zarrAxesList;
- }
-
- public boolean hasTimepoints() {
- return this.axes.equals(TCYX.axes) || this.axes.equals(TZYX.axes) || this.axes.equals(TYX.axes) || this.axes.equals(TCZYX.axes);
- }
-
- public boolean hasChannels() {
- return this.axes.equals(CZYX.axes) || this.axes.equals(CYX.axes) || this.axes.equals(TCYX.axes) || this.axes.equals(TCZYX.axes);
- }
-
- // the flag reverseAxes determines whether the index will be given w.r.t.
- // reversedAxes=true corresponds to the java/bdv axis convention
- // reversedAxes=false corresponds to the zarr axis convention
- public int axisIndex(String axisName, boolean reverseAxes) {
- if(reverseAxes) {
- List