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

Add reset methods for each option #111

Merged
merged 5 commits into from
Nov 30, 2023
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repositories {
dependencies {
implementation 'net.java.dev.jna:jna:5.10.0'
implementation 'dev.zarr:jzarr:0.4.2'
implementation 'info.picocli:picocli:4.2.0'
implementation 'info.picocli:picocli:4.7.5'
implementation 'me.tongfei:progressbar:0.9.0'
implementation 'ome:formats-bsd:7.0.0'
implementation 'com.glencoesoftware:bioformats2raw:0.8.0-rc1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ public class PyramidFromDirectoryWriter implements Callable<Void> {
/** Where to write? */
Path outputFilePath;
Path inputDirectory;
private volatile String logLevel = "WARN";
private volatile String logLevel;
private volatile boolean progressBars = false;
boolean printVersion = false;
CompressionType compression = CompressionType.LZW;
CompressionType compression;
CodecOptions compressionOptions;
boolean legacy = false;
int maxWorkers = Runtime.getRuntime().availableProcessors();
int maxWorkers;
boolean rgb = false;

private List<PyramidSeries> series = new ArrayList<PyramidSeries>();
Expand All @@ -148,7 +148,6 @@ public class PyramidFromDirectoryWriter implements Callable<Void> {
* Construct a writer for performing the pyramid conversion.
*/
public PyramidFromDirectoryWriter() {
tileQueue = new LimitedQueue<Runnable>(maxWorkers);
}

/**
Expand All @@ -159,11 +158,17 @@ public PyramidFromDirectoryWriter() {
@Parameters(
index = "1",
arity = "1",
description = "Relative path to the output OME-TIFF file"
description = "Relative path to the output OME-TIFF file",
defaultValue = Option.NULL_VALUE
)
public void setOutputPath(String output) {
// could be expanded to allow other output locations
outputFilePath = Paths.get(output);
if (output != null) {
outputFilePath = Paths.get(output);
}
else {
outputFilePath = null;
}
}

/**
Expand All @@ -174,11 +179,17 @@ public void setOutputPath(String output) {
@Parameters(
index = "0",
arity = "1",
description = "Directory containing pixel data to convert"
description = "Directory containing pixel data to convert",
defaultValue = Option.NULL_VALUE
)
public void setInputPath(String input) {
// could be expanded to allow other input locations
inputDirectory = Paths.get(input);
if (input != null) {
inputDirectory = Paths.get(input);
}
else {
inputDirectory = null;
}
}

/**
Expand Down Expand Up @@ -208,7 +219,8 @@ public void setLogLevel(String level) {
@Option(
names = {"-p", "--progress"},
description = "Print progress bars during conversion",
help = true
help = true,
defaultValue = "false"
)
public void setProgressBars(boolean useProgressBars) {
progressBars = useProgressBars;
Expand All @@ -223,7 +235,8 @@ public void setProgressBars(boolean useProgressBars) {
@Option(
names = "--version",
description = "Print version information and exit",
help = true
help = true,
defaultValue = "false"
)
public void setPrintVersionOnly(boolean versionOnly) {
printVersion = versionOnly;
Expand Down Expand Up @@ -271,7 +284,8 @@ public void setCompression(CompressionType compressionType) {
@Option(
names = "--quality",
converter = CompressionQualityConverter.class,
description = "Compression quality"
description = "Compression quality",
defaultValue = Option.NULL_VALUE
)
public void setCompressionOptions(CodecOptions options) {
compressionOptions = options;
Expand All @@ -286,7 +300,8 @@ public void setCompressionOptions(CodecOptions options) {
*/
@Option(
names = "--legacy",
description = "Write a Bio-Formats 5.9.x pyramid instead of OME-TIFF"
description = "Write a Bio-Formats 5.9.x pyramid instead of OME-TIFF",
defaultValue = "false"
)
public void setLegacyTIFF(boolean legacyTIFF) {
legacy = legacyTIFF;
Expand All @@ -300,26 +315,36 @@ public void setLegacyTIFF(boolean legacyTIFF) {
@Option(
names = "--split",
description =
"Split output into one OME-TIFF file per OME Image/Zarr group"
"Split output into one OME-TIFF file per OME Image/Zarr group",
defaultValue = "false"
)
public void setSplitTIFFs(boolean split) {
splitBySeries = split;
}

/**
* Set the maximum number of workers to use for converting tiles.
* Defaults to the number of detected CPUs.
* Defaults to 4 or the number of detected CPUs, whichever is smaller.
*
* @param workers maximum worker count
*/
@Option(
names = "--max_workers",
description = "Maximum number of workers (default: ${DEFAULT-VALUE})"
description = "Maximum number of workers (default: ${DEFAULT-VALUE})",
defaultValue = "4"
)
public void setMaxWorkers(int workers) {
if (workers > 0) {
int availableProcessors = Runtime.getRuntime().availableProcessors();
int prevWorkers = getMaxWorkers();
if (workers > availableProcessors) {
maxWorkers = availableProcessors;
}
else if (workers > 0 && workers != maxWorkers) {
maxWorkers = workers;
}
if (prevWorkers != maxWorkers) {
tileQueue = new LimitedQueue<Runnable>(maxWorkers);
}
}

/**
Expand All @@ -332,7 +357,8 @@ public void setMaxWorkers(int workers) {
@Option(
names = "--rgb",
description = "Attempt to write channels as RGB; " +
"channel count must be a multiple of 3"
"channel count must be a multiple of 3",
defaultValue = "false"
)
public void setRGB(boolean isRGB) {
rgb = isRGB;
Expand All @@ -342,13 +368,19 @@ public void setRGB(boolean isRGB) {
* @return path to output data
*/
public String getOutputPath() {
if (outputFilePath == null) {
return null;
}
return outputFilePath.toString();
}

/**
* @return path to input data
*/
public String getInputPath() {
if (inputDirectory == null) {
return null;
}
return inputDirectory.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,68 @@ public void testOptionsAPI() throws Exception {

outputOmeTiff = output.resolve("output.ome.tiff");
PyramidFromDirectoryWriter apiConverter = new PyramidFromDirectoryWriter();
CommandLine cmd = new CommandLine(apiConverter);
cmd.parseArgs();

apiConverter.setInputPath(output.toString());
apiConverter.setOutputPath(outputOmeTiff.toString());
apiConverter.setCompression(CompressionType.UNCOMPRESSED);
apiConverter.setRGB(true);
apiConverter.call();

iteratePixels();
}

/**
* Test resetting options to their default values.
*/
@Test
public void testResetAPI() throws Exception {
input = fake("sizeC", "12", "rgb", "3");
assertBioFormats2Raw();

outputOmeTiff = output.resolve("output.ome.tiff");

// make sure default options are set
PyramidFromDirectoryWriter apiConverter = new PyramidFromDirectoryWriter();
CommandLine cmd = new CommandLine(apiConverter);
cmd.parseArgs();

Assert.assertEquals(apiConverter.getInputPath(), null);
Assert.assertEquals(apiConverter.getOutputPath(), null);
Assert.assertEquals(apiConverter.getCompression(), CompressionType.LZW);
Assert.assertEquals(apiConverter.getRGB(), false);
Assert.assertEquals(apiConverter.getLegacyTIFF(), false);
Assert.assertEquals(apiConverter.getSplitTIFFs(), false);

// override default options, as though to start a conversion
apiConverter.setInputPath(output.toString());
apiConverter.setOutputPath(outputOmeTiff.toString());
apiConverter.setCompression(CompressionType.UNCOMPRESSED);
apiConverter.setRGB(true);

// change our minds and reset the options to defaults again
cmd.parseArgs();

Assert.assertEquals(apiConverter.getInputPath(), null);
Assert.assertEquals(apiConverter.getOutputPath(), null);
Assert.assertEquals(apiConverter.getCompression(), CompressionType.LZW);
Assert.assertEquals(apiConverter.getRGB(), false);
Assert.assertEquals(apiConverter.getLegacyTIFF(), false);
Assert.assertEquals(apiConverter.getSplitTIFFs(), false);

// update options, make sure they were set, and actually convert
apiConverter.setInputPath(output.toString());
apiConverter.setOutputPath(outputOmeTiff.toString());
apiConverter.setCompression(CompressionType.UNCOMPRESSED);
apiConverter.setRGB(true);

Assert.assertEquals(apiConverter.getInputPath(), output.toString());
Assert.assertEquals(apiConverter.getOutputPath(), outputOmeTiff.toString());
Assert.assertEquals(apiConverter.getCompression(),
CompressionType.UNCOMPRESSED);
Assert.assertEquals(apiConverter.getRGB(), true);

apiConverter.call();

iteratePixels();
Expand Down
Loading