From 6fcb776f9d4e9d51252921161a8851106fa3edea Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Wed, 26 Jul 2023 16:38:42 -0500 Subject: [PATCH 1/2] Add --split-planes option to write one plane per file Fixes #107 --- .../pyramid/PyramidFromDirectoryWriter.java | 177 ++++++++++++++---- .../pyramid/PyramidSeries.java | 2 +- 2 files changed, 142 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/glencoesoftware/pyramid/PyramidFromDirectoryWriter.java b/src/main/java/com/glencoesoftware/pyramid/PyramidFromDirectoryWriter.java index 9665304..318614b 100755 --- a/src/main/java/com/glencoesoftware/pyramid/PyramidFromDirectoryWriter.java +++ b/src/main/java/com/glencoesoftware/pyramid/PyramidFromDirectoryWriter.java @@ -135,6 +135,7 @@ public class PyramidFromDirectoryWriter implements Callable { private List series = new ArrayList(); private Map tiffSavers = new HashMap(); boolean splitBySeries = false; + boolean splitByPlane = false; private ZarrGroup reader = null; @@ -306,6 +307,20 @@ public void setSplitTIFFs(boolean split) { splitBySeries = split; } + /** + * Configure whether to write one OME-TIFF per plane. + * + * @param split true if output should be split into one OME-TIFF per plane + */ + @Option( + names = "--split-planes", + description = + "Split output into one OME-TIFF file per plane" + ) + public void setSplitSinglePlaneTIFFs(boolean split) { + splitByPlane = split; + } + /** * Set the maximum number of workers to use for converting tiles. * Defaults to the number of detected CPUs. @@ -407,6 +422,13 @@ public boolean getSplitTIFFs() { return splitBySeries; } + /** + * @return true if output will be split into one OME-TIFF per plane + */ + public boolean getSplitSinglePlaneTIFFs() { + return splitByPlane; + } + /** * @return maximum number of worker threads */ @@ -475,8 +497,9 @@ public Void call() throws Exception { setupLogger(); // we could support this case later, just keeping it simple for now - if (splitBySeries && legacy) { - throw new IllegalArgumentException("--split not supported with --legacy"); + if ((splitBySeries || splitByPlane) && legacy) { + throw new IllegalArgumentException( + "--split and --split-planes not supported with --legacy"); } try { @@ -1011,12 +1034,9 @@ else if (rgb) { } s.planeCount *= effectiveChannels; - s.describePyramid(reader, metadata); metadata.setTiffDataIFD(new NonNegativeInteger(totalPlanes), s.index, 0); - metadata.setTiffDataPlaneCount( - new NonNegativeInteger(s.planeCount), s.index, 0); for (ResolutionDescriptor descriptor : s.resolutions) { LOG.info("Adding metadata for resolution: {}", @@ -1049,22 +1069,39 @@ else if (rgb) { series.add(s); totalPlanes += s.planeCount; - if (splitBySeries) { + if (splitBySeries && !splitByPlane) { String basePath = getOutputPathPrefix(); // append the series index and file extension basePath += "_s"; seriesPaths.add(Paths.get(basePath + s.index + ".ome.tiff")); // generate one UUID per file - s.uuid = "urn:uuid:" + UUID.randomUUID().toString(); + s.uuid.add("urn:uuid:" + UUID.randomUUID().toString()); + } + else if (splitByPlane) { + String basePath = getOutputPathPrefix(); + // append the series index and file extension + basePath += "_s"; + basePath += s.index; + basePath += "_z"; + for (int t=0; t uuid = new ArrayList(); int index = -1; From 697cf3a69c3ea5bf4e24e93e8e2f695c94d0f26d Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Tue, 1 Aug 2023 14:04:59 -0500 Subject: [PATCH 2/2] Add split plane test cases --- .../raw2ometiff/test/ConversionTest.java | 81 ++++++++++++++++++- 1 file changed, 77 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/glencoesoftware/raw2ometiff/test/ConversionTest.java b/src/test/java/com/glencoesoftware/raw2ometiff/test/ConversionTest.java index 7ff9fbd..ce1b99e 100644 --- a/src/test/java/com/glencoesoftware/raw2ometiff/test/ConversionTest.java +++ b/src/test/java/com/glencoesoftware/raw2ometiff/test/ConversionTest.java @@ -98,17 +98,20 @@ void assertBioFormats2Raw(String...additionalArgs) throws IOException { * @param additionalArgs CLI arguments as needed beyond "input output" */ void assertTool(String...additionalArgs) throws IOException { - assertTool(0, additionalArgs); + assertTool(0, 0, additionalArgs); } /** * Run the PyramidFromDirectoryWriter main method and check for success or * failure. * + * @param seriesCount number of series to expect, if splitting * @param fileCount number of files to expect, if splitting * @param additionalArgs CLI arguments as needed beyond "input output" */ - void assertTool(int fileCount, String...additionalArgs) throws IOException { + void assertTool(int seriesCount, int fileCount, String...additionalArgs) + throws IOException + { List args = new ArrayList(); for (String arg : additionalArgs) { args.add(arg); @@ -122,7 +125,7 @@ void assertTool(int fileCount, String...additionalArgs) throws IOException { if (fileCount == 0) { Assert.assertTrue(Files.exists(outputOmeTiff)); } - else { + else if (seriesCount == fileCount) { String prefix = output.resolve("output").toString(); for (int i=0; i