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 getter and setter for each command line option #97

Merged
merged 4 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -115,93 +115,262 @@ public class PyramidFromDirectoryWriter implements Callable<Void> {
private BlockingQueue<Runnable> tileQueue;
private ExecutorService executor;

/** Where to write? */
Path outputFilePath;
Path inputDirectory;
private volatile String logLevel = "WARN";
private volatile boolean progressBars = false;
boolean printVersion = false;
String compression = "LZW";
Double compressionQuality;
boolean legacy = false;
int maxWorkers = Runtime.getRuntime().availableProcessors();
boolean rgb = false;

private List<PyramidSeries> series = new ArrayList<PyramidSeries>();

private ZarrGroup reader = null;

/** Writer metadata. */
OMEPyramidStore metadata;

private Map<String, Object> plateData = null;

/**
* Construct a writer for performing the pyramid conversion.
*/
public PyramidFromDirectoryWriter() {
tileQueue = new LimitedQueue<Runnable>(maxWorkers);
}

/**
* Where to write?
*
* @param output path to output TIFF
*/
@Parameters(
index = "1",
arity = "1",
description = "Relative path to the output OME-TIFF file"
)
Path outputFilePath;
public void setOutputPath(Path output) {
outputFilePath = output;
}

/** Where to read? */
/**
* Where to read?
*
* @param input path to input Zarr directory
*/
@Parameters(
index = "0",
arity = "1",
description = "Directory containing pixel data to convert"
)
Path inputDirectory;
public void setInputPath(Path input) {
inputDirectory = input;
}

/**
* Set the slf4j logging level. Defaults to "WARN".
*
* @param level logging level
*/
@Option(
names = {"--log-level", "--debug"},
arity = "0..1",
description = "Change logging level; valid values are " +
"OFF, ERROR, WARN, INFO, DEBUG, TRACE and ALL. " +
"(default: ${DEFAULT-VALUE})",
defaultValue = "WARN",
fallbackValue = "DEBUG"
)
private volatile String logLevel = "WARN";
public void setLogLevel(String level) {
logLevel = level;
}

/**
* Configure whether or not progress bars are shown during conversion.
* Progress bars are turned off by default.
*
* @param useProgressBars whether or not to show progress bars
*/
@Option(
names = {"-p", "--progress"},
description = "Print progress bars during conversion",
help = true
)
private volatile boolean progressBars = false;
public void setProgressBars(boolean useProgressBars) {
progressBars = useProgressBars;
}

/**
* Configure whether to print version information and exit
* without converting.
*
* @param versionOnly whether or not to print version information and exit
*/
@Option(
names = "--version",
description = "Print version information and exit",
help = true
)
boolean printVersion = false;
public void setPrintVersionOnly(boolean versionOnly) {
printVersion = versionOnly;
}

/**
* Set the compression type for the output OME-TIFF. Defaults to LZW.
* Valid types are defined in the CompressionTypes class.
*
* @param compressionType compression type
*/
@Option(
names = "--compression",
completionCandidates = CompressionTypes.class,
description = "Compression type for output OME-TIFF file " +
"(${COMPLETION-CANDIDATES}; default: ${DEFAULT-VALUE})"
"(${COMPLETION-CANDIDATES}; default: ${DEFAULT-VALUE})",
defaultValue = "LZW"
)
String compression = "LZW";
public void setCompression(String compressionType) {
compression = compressionType;
}

/**
* Set the compression quality. The interpretation of the quality value
* depends upon the selected compression type.
*
* This value currently only applies to "JPEG-2000 Lossy" compression,
* and corresponds to the encoded bitrate in bits per pixel.
* The quality is a floating point number and must be greater than 0.
* A larger number implies less data loss but also larger file size.
* By default, the quality is set to the largest positive finite double value.
* This is equivalent to lossless compression; to see truly lossy compression,
* the quality should be set to less than the bit depth of the input image.
*
* @param quality compression quality
*/
@Option(
names = "--quality",
description = "Compression quality"
)
Double compressionQuality;
public void setCompressionQuality(Double quality) {
compressionQuality = quality;
}

/**
* Configure whether to write a pyramid OME-TIFF compatible with
* Bio-Formats 6.x (the default), or a legacy pyramid TIFF compatible
* with Bio-Formats 5.9.x.
*
* @param legacyTIFF true if a legacy pyramid TIFF should be written
*/
@Option(
names = "--legacy",
description = "Write a Bio-Formats 5.9.x pyramid instead of OME-TIFF"
)
boolean legacy = false;
public void setLegacyTIFF(boolean legacyTIFF) {
legacy = legacyTIFF;
}

/**
* Set the maximum number of workers to use for converting tiles.
* Defaults to the number of detected CPUs.
*
* @param workers maximum worker count
*/
@Option(
names = "--max_workers",
description = "Maximum number of workers (default: ${DEFAULT-VALUE})"
)
int maxWorkers = Runtime.getRuntime().availableProcessors();
public void setMaxWorkers(int workers) {
maxWorkers = workers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also use a minimal validation check that workers > 0 as in bioformats2raw

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in dda535a.

}

/**
* Write an RGB TIFF, if the input data contains a multiple of 3 channels
* If RGB TIFFs are written, any channel metadata (names, wavelengths, etc.)
* in the input data will be lost.
*
* @param isRGB true if an RGB TIFF should be written
*/
@Option(
names = "--rgb",
description = "Attempt to write channels as RGB; " +
"channel count must be a multiple of 3"
)
boolean rgb = false;
public void setRGB(boolean isRGB) {
rgb = isRGB;
}

private List<PyramidSeries> series = new ArrayList<PyramidSeries>();
/**
* @return path to output data
*/
public Path getOutputPath() {
return outputFilePath;
}

private ZarrGroup reader = null;
/**
* @return path to input data
*/
public Path getInputPath() {
return inputDirectory;
}

/** Writer metadata. */
OMEPyramidStore metadata;
/**
* @return slf4j logging level
*/
public String getLogLevel() {
return logLevel;
}

private Map<String, Object> plateData = null;
/**
* @return true if progress bars are displayed
*/
public boolean getProgressBars() {
return progressBars;
}

/**
* Construct a writer for performing the pyramid conversion.
* @return true if only version info is displayed
*/
public PyramidFromDirectoryWriter() {
tileQueue = new LimitedQueue<Runnable>(maxWorkers);
public boolean getPrintVersionOnly() {
return printVersion;
}

/**
* @return compression type
*/
public String getCompression() {
return compression;
}

/**
* @return compression quality
*/
public Double getCompressionQuality() {
return compressionQuality;
}

/**
* @return true if a legacy pyramid TIFF will be written
* instead of pyramid OME-TIFF
*/
public boolean getLegacyTIFF() {
return legacy;
}

/**
* @return maximum number of worker threads
*/
public int getMaxWorkers() {
return maxWorkers;
}

/**
* @return true if an RGB TIFF should be written
*/
public boolean getRGB() {
return rgb;
}

/**
Expand All @@ -219,6 +388,13 @@ public Void call() throws Exception {
return null;
}

if (inputDirectory == null) {
throw new IllegalArgumentException("Input directory not specified");
}
if (outputFilePath == null) {
throw new IllegalArgumentException("Output path not specified");
}

// Resolve symlinks
inputDirectory = inputDirectory.toRealPath();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,25 @@ public void testSingleImageNoHCS() throws Exception {
}
}

/**
* Test RGB with multiple channels using API instead of command line.
*/
@Test
public void testOptionsAPI() throws Exception {
input = fake("sizeC", "12", "rgb", "3");
assertBioFormats2Raw();

outputOmeTiff = output.resolve("output.ome.tiff");
PyramidFromDirectoryWriter apiConverter = new PyramidFromDirectoryWriter();
apiConverter.setInputPath(output);
apiConverter.setOutputPath(outputOmeTiff);
apiConverter.setCompression("raw");
apiConverter.setRGB(true);
apiConverter.call();

iteratePixels();
}

/**
* Test "--version" with no other arguments.
* Does not test the version values, just makes sure that an exception
Expand Down