Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the PixelsService to be runtime configured #5

Merged
merged 5 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package com.glencoesoftware.omero.ms.core;
package com.glencoesoftware.omero.zarr;

import java.net.URI;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package com.glencoesoftware.omero.ms.core;
package com.glencoesoftware.omero.zarr;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package com.glencoesoftware.omero.ms.core;
package com.glencoesoftware.omero.zarr;


import java.io.ByteArrayInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package com.glencoesoftware.omero.ms.core;
package com.glencoesoftware.omero.zarr;

import java.awt.Dimension;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package com.glencoesoftware.omero.ms.core;
package com.glencoesoftware.omero.zarr;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -58,10 +58,10 @@
* @author Chris Allan <[email protected]>
*
*/
public class PixelsService extends ome.io.nio.PixelsService {
public class ZarrPixelsService extends ome.io.nio.PixelsService {

private static final org.slf4j.Logger log =
LoggerFactory.getLogger(PixelsService.class);
LoggerFactory.getLogger(ZarrPixelsService.class);

public static final String NGFF_ENTITY_TYPE = "com.glencoesoftware.ngff:multiscales";
public static final long NGFF_ENTITY_ID = 3;
Expand All @@ -85,7 +85,7 @@ public class PixelsService extends ome.io.nio.PixelsService {
/** Array path vs. ZarrArray cache */
private final AsyncLoadingCache<Path, ZarrArray> zarrArrayCache;

public PixelsService(
public ZarrPixelsService(
String path, boolean isReadOnlyRepo, File memoizerDirectory,
long memoizerWait, FilePathResolver resolver, BackOff backOff,
TileSizes sizes, IQuery iQuery,
Expand All @@ -102,10 +102,10 @@ public PixelsService(
this.iQuery = iQuery;
zarrMetadataCache = Caffeine.newBuilder()
.maximumSize(this.zarrCacheSize)
.buildAsync(PixelsService::getZarrMetadata);
.buildAsync(ZarrPixelsService::getZarrMetadata);
zarrArrayCache = Caffeine.newBuilder()
.maximumSize(this.zarrCacheSize)
.buildAsync(PixelsService::getZarrArray);
.buildAsync(ZarrPixelsService::getZarrArray);
}

/**
Expand Down Expand Up @@ -242,17 +242,35 @@ public String getUri(IObject object) {
}

/**
* Retrieve the {@link Image} for a particular set of pixels.
* Retrieve the {@link Image} for a particular set of pixels. Where
* possible, does not initiate a query.
* @param pixels Pixels set to retrieve the {@link Image} for.
* @return See above.
*/
protected Image getImage(Pixels pixels) {
if (pixels.getImage().isLoaded()) {
// Will likely only be true when operating within a microservice
return pixels.getImage();
}
return iQuery.get(Image.class, pixels.getImage().getId());
}

/**
* Retrieves the series for a given set of pixels. Where possible, does not
* initiate a query.
* @param pixels Set of pixels to return the series for.
* @return The series as specified by the pixels parameters or
* <code>0</code> (the first series).
*/
@Override
protected int getSeries(Pixels pixels) {
if (pixels.getImage().isLoaded()) {
// Will likely only be true when operating within a microservice
return pixels.getImage().getSeries();
}
return super.getSeries(pixels);
}

/**
* Returns a label image NGFF pixel buffer if it exists.
* @param mask Mask to retrieve a pixel buffer for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import java.util.Properties;
import java.util.Set;

import com.glencoesoftware.omero.ms.core.OmeroAmazonS3ClientFactory;
import com.glencoesoftware.omero.ms.core.OmeroS3FileSystem;
import com.glencoesoftware.omero.ms.core.OmeroS3ReadOnlySeekableByteChannel;
import com.glencoesoftware.omero.zarr.OmeroAmazonS3ClientFactory;
import com.glencoesoftware.omero.zarr.OmeroS3FileSystem;
import com.glencoesoftware.omero.zarr.OmeroS3ReadOnlySeekableByteChannel;
import com.google.common.base.Preconditions;
import com.upplication.s3fs.attribute.S3BasicFileAttributes;

Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/blitz/blitz-ZarrPixelBuffer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
Defines the beans for microservices.
</description>

<bean name="/OMERO/Pixels" class="com.glencoesoftware.omero.ms.core.PixelsService"
parent="filesystem">
<alias name="${omero.pixeldata.pixels_service:ZarrPixelsService}" alias="/OMERO/Pixels"/>

<bean name="ZarrPixelsService" class="com.glencoesoftware.omero.zarr.ZarrPixelsService"
parent="filesystem" lazy-init="true">
<!-- note constructor-args from parent bean -->
<constructor-arg value="${omero.pixeldata.memoizer.dir}"/>
<constructor-arg ref="MemoizerWait"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.junit.Before;
import org.junit.Test;

import com.glencoesoftware.omero.zarr.ZarrPixelsService;

import omero.ApiUsageException;
import omero.model.ExternalInfo;
import omero.model.ExternalInfoI;
Expand All @@ -43,7 +45,7 @@

public class PixelsServiceTest {

private PixelsService pixelsService;
private ZarrPixelsService pixelsService;
private String uuid = UUID.randomUUID().toString();
private String imageUri = "/data/ngff/image.zarr";
private String labelUri = imageUri + "/0/labels/" + uuid;
Expand All @@ -58,7 +60,7 @@ public void setUp() throws IOException {
pixelsDir.deleteOnExit();
File memoDir = Files.createTempDirectory("memoizer").toFile();
memoDir.deleteOnExit();
pixelsService = new PixelsService(
pixelsService = new ZarrPixelsService(
pixelsDir.getAbsolutePath(), false, memoDir, 0L, null, null, null, null, 0, 0, 0);
mask = new MaskI();
image = new ImageI();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

import picocli.CommandLine;
import com.glencoesoftware.bioformats2raw.Converter;
import com.glencoesoftware.omero.zarr.ZarrPixelsService;
import com.glencoesoftware.omero.zarr.ZarrPixelBuffer;

import loci.formats.FormatTools;
import loci.formats.in.FakeReader;
Expand All @@ -68,10 +70,10 @@ public ZarrPixelBuffer createPixelBuffer(
pixels, path, maxPlaneWidth, maxPlaneHeight,
Caffeine.newBuilder()
.maximumSize(0)
.buildAsync(PixelsService::getZarrMetadata),
.buildAsync(ZarrPixelsService::getZarrMetadata),
Caffeine.newBuilder()
.maximumSize(0)
.buildAsync(PixelsService::getZarrArray)
.buildAsync(ZarrPixelsService::getZarrArray)
);
}

Expand Down