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

Flags to rename and pyramid.n5 and scaler paths #19

Merged
merged 3 commits into from
Apr 1, 2020
Merged
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
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