Skip to content

Commit

Permalink
Merge pull request #19 from perlman/output-opts
Browse files Browse the repository at this point in the history
Flags to rename and pyramid.n5 and scaler paths
  • Loading branch information
melissalinkert committed Apr 1, 2020
2 parents 5800617 + c6557cb commit f4f7241
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/main/java/com/glencoesoftware/bioformats2raw/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,22 @@ private static Compression getCompressor(
PyramidTiffReader.class, MiraxReader.class
};

@Option(
names = "--pyramid-name",
description = "Name of pyramid n5 (default: ${DEFAULT-VALUE}) " +
"[Can break compatibility with raw2ometiff]"
)
private String pyramidName = "pyramid.n5";

@Option(
names = "--scale-format-string",
description = "Format string for scale paths "+
"[Can break compatibility with raw2ometiff] " +
"(default: ${DEFAULT-VALUE})"
)
private String scaleFormatString = "%d";


/** Scaling implementation that will be used during downsampling. */
private IImageScaler scaler = new SimpleImageScaler();

Expand Down Expand Up @@ -283,6 +299,12 @@ public Void call()
public void convert()
throws FormatException, IOException, InterruptedException
{
if (!pyramidName.equals("pyramid.n5") || !scaleFormatString.equals("%d")) {
LOGGER.info("Output will be incompatible with raw2ometiff " +
"(pyramidName: {}, scaleFormatString: {})",
pyramidName, scaleFormatString);
}

Cache<TilePointer, byte[]> tileCache = CacheBuilder.newBuilder()
.maximumSize(maxCachedTiles)
.build();
Expand Down Expand Up @@ -427,9 +449,9 @@ private byte[] getTileDownsampled(
int resolution, int plane, int xx, int yy, int width, int height)
throws FormatException, IOException, InterruptedException
{
String pathName = "/" + Integer.toString(resolution - 1);
String pathName = "/" + String.format(scaleFormatString, resolution - 1);
N5Reader n5 = new N5FSReader(
outputPath.resolve("pyramid.n5").toString());
outputPath.resolve(pyramidName).toString());
DatasetAttributes datasetAttributes = n5.getDatasetAttributes(pathName);
long[] dimensions = datasetAttributes.getDimensions();

Expand Down Expand Up @@ -506,7 +528,7 @@ private void processTile(
throws EnumerationException, FormatException, IOException,
InterruptedException
{
String pathName = "/" + Integer.toString(resolution);
String pathName = "/" + String.format(scaleFormatString, resolution);
long[] gridPosition = new long[] {
xx / tileWidth, yy / tileHeight, plane
};
Expand Down Expand Up @@ -549,7 +571,7 @@ private void processTile(

// TODO: ZCT
// int[] zct = reader.getZCTCoords(plane);
N5Writer n5 = new N5FSWriter(outputPath.resolve("pyramid.n5").toString());
N5Writer n5 = new N5FSWriter(outputPath.resolve(pyramidName).toString());
Slf4JStopWatch t1 = stopWatch();
try {
n5.writeBlock(
Expand Down Expand Up @@ -634,14 +656,14 @@ public void saveResolutions()
Compression compression = N5Compression.getCompressor(compressionType,
compressionParameter);

N5Writer n5 = new N5FSWriter(outputPath.resolve("pyramid.n5").toString());
N5Writer n5 = new N5FSWriter(outputPath.resolve(pyramidName).toString());
for (int resCounter=0; resCounter<resolutions; resCounter++) {
final int resolution = resCounter;
int scale = (int) Math.pow(PYRAMID_SCALE, resolution);
int scaledWidth = sizeX / scale;
int scaledHeight = sizeY / scale;
n5.createDataset(
"/" + Integer.toString(resolution),
"/" + String.format(scaleFormatString, resolution),
new long[] {scaledWidth, scaledHeight, imageCount},
new int[] {tileWidth, tileHeight, 1},
dataType, compression
Expand Down

0 comments on commit f4f7241

Please sign in to comment.