use of loci.formats.FileStitcher in project bioformats by openmicroscopy.
the class WrapperTest method createWrappers.
@DataProvider(name = "wrappers")
public Object[][] createWrappers() {
Location.mapId(TEST_FILE, TEST_FILE);
Object[][] wrappers = new Object[][] { { new ChannelFiller() }, { new ChannelMerger() }, { new ChannelSeparator() }, { new DimensionSwapper() }, { new FileStitcher() }, { new ImageReader() }, { new MinMaxCalculator() }, { new Memoizer() } };
for (int i = 0; i < wrappers.length; i++) {
IFormatReader reader = (IFormatReader) wrappers[i][0];
try {
reader.setId(TEST_FILE);
} catch (FormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return wrappers;
}
use of loci.formats.FileStitcher in project bioformats by openmicroscopy.
the class FormatReaderTest method testSaneUsedFiles.
@Test(groups = { "all", "type", "automated" })
public void testSaneUsedFiles() {
if (!initFile())
return;
String file = reader.getCurrentFile();
String testName = "testSaneUsedFiles";
boolean success = true;
String msg = null;
try {
String[] base = reader.getUsedFiles();
if (base.length == 1) {
if (!base[0].equals(file))
success = false;
} else {
Arrays.sort(base);
IFormatReader r = /*config.noStitching() ? new ImageReader() :*/
new FileStitcher();
int maxFiles = (int) Math.min(base.length, 100);
if (DataTools.indexOf(reader.getDomains(), FormatTools.HCS_DOMAIN) >= 0 || file.toLowerCase().endsWith(".czi")) {
maxFiles = (int) Math.min(maxFiles, 10);
}
for (int i = 0; i < maxFiles && success; i++) {
// than one dataset
if (reader.getFormat().equals("InCell 1000/2000")) {
if (!base[i].toLowerCase().endsWith(".xdce") && !base[i].toLowerCase().endsWith(".xml")) {
continue;
}
}
// Volocity datasets can only be detected with the .mvd2 file
if (file.toLowerCase().endsWith(".mvd2") && !base[i].toLowerCase().endsWith(".mvd2")) {
continue;
}
// 'fid' and 'acqp' files
if ((file.toLowerCase().endsWith("fid") || file.toLowerCase().endsWith("acqp")) && !base[i].toLowerCase().endsWith("fid") && !base[i].toLowerCase().endsWith("acqp") && reader.getFormat().equals("Bruker")) {
continue;
}
// CellR datasets cannot be detected with a TIFF file
if (reader.getFormat().equals("Olympus APL") && base[i].toLowerCase().endsWith("tif")) {
continue;
}
// Micromanager datasets cannot be detected with an OME-TIFF file
if (reader.getFormat().equals("Micro-Manager") && (base[i].toLowerCase().endsWith(".ome.tiff") || base[i].toLowerCase().endsWith(".ome.tif"))) {
continue;
}
// DICOM companion files may not be detected
if (reader.getFormat().equals("DICOM") && !base[i].equals(file)) {
continue;
}
// QuickTime resource forks are not detected
if (reader.getFormat().equals("QuickTime") && !base[i].equals(file)) {
continue;
}
// SVS files in AFI datasets are detected as SVS
if (reader.getFormat().equals("Aperio AFI") && base[i].toLowerCase().endsWith(".svs")) {
continue;
}
if (reader.getFormat().equals("BD Pathway") && (base[i].endsWith(".adf") || base[i].endsWith(".txt")) || base[i].endsWith(".roi")) {
continue;
}
// Hamamatsu VMS datasets cannot be detected with non-.vms files
if (reader.getFormat().equals("Hamamatsu VMS") && !base[i].toLowerCase().endsWith(".vms")) {
continue;
}
if (reader.getFormat().equals("CellVoyager")) {
continue;
}
if (reader.getFormat().equals("Leica Image File Format")) {
continue;
}
// pattern datasets can only be detected with the pattern file
if (reader.getFormat().equals("File pattern")) {
continue;
}
r.setId(base[i]);
String[] comp = r.getUsedFiles();
// are not grouped. This is expected behavior; see ticket #3701.
if (base[i].toLowerCase().endsWith(".lsm") && comp.length == 1) {
r.close();
continue;
}
// will give different results.
if (file.toLowerCase().endsWith(".dv") && base[i].toLowerCase().endsWith(".log")) {
r.close();
continue;
}
// used file count from the text file.
if (reader.getFormat().equals("Hitachi")) {
r.close();
continue;
}
// separately
if (reader.getFormat().equals("Trestle")) {
r.close();
continue;
}
// TIFF files in CellR datasets are detected separately
if (reader.getFormat().equals("Olympus APL") && base[i].toLowerCase().endsWith(".tif")) {
r.close();
continue;
}
// TIFF files in Li-Cor datasets are detected separately
if (reader.getFormat().equals("Li-Cor L2D") && !base[i].toLowerCase().endsWith("l2d")) {
r.close();
continue;
}
// TIFF files in Prairie datasets may be detected as OME-TIFF
if (reader.getFormat().equals("Prairie TIFF") && base[i].toLowerCase().endsWith(".tif") && r.getFormat().equals("OME-TIFF")) {
r.close();
continue;
}
if (reader.getFormat().equals("Hamamatsu NDPIS") && r.getFormat().equals("Hamamatsu NDPI")) {
r.close();
continue;
}
if (base[i].endsWith(".bmp") && reader.getFormat().equals("BD Pathway")) {
r.close();
continue;
}
if (comp.length != base.length) {
success = false;
msg = base[i] + " (file list length was " + comp.length + "; expected " + base.length + ")";
}
if (success)
Arrays.sort(comp);
// a test failure (which we can do nothing about).
if (file.toLowerCase().endsWith(".nhdr") || base[i].toLowerCase().endsWith(".nhdr")) {
r.close();
continue;
}
for (int j = 0; j < comp.length && success; j++) {
if (!comp[j].equals(base[j])) {
if (base[j].equals(new Location(comp[j]).getCanonicalPath())) {
continue;
}
success = false;
msg = base[i] + "(file @ " + j + " was '" + comp[j] + "', expected '" + base[j] + "')";
}
}
r.close();
}
}
} catch (Throwable t) {
LOGGER.info("", t);
success = false;
}
result(testName, success, msg);
}
use of loci.formats.FileStitcher in project bioformats by openmicroscopy.
the class FormatReaderTest method testUnflattenedSubimagePixelsHashes.
/*
@Test(groups = {"all", "pixels"})
public void testReorderedPixelsHashes() {
if (config == null) throw new SkipException("No config tree");
String testName = "testReorderedPixelsHashes";
if (!initFile()) result(testName, false, "initFile");
boolean success = true;
String msg = null;
try {
for (int i=0; i<reader.getSeriesCount() && success; i++) {
reader.setSeries(i);
config.setSeries(i);
for (int j=0; j<3; j++) {
int index = (int) (Math.random() * reader.getImageCount());
reader.openBytes(index);
}
String md5 = TestTools.md5(reader.openBytes(0));
String expected1 = config.getMD5();
String expected2 = config.getAlternateMD5();
if (!md5.equals(expected1) && !md5.equals(expected2)) {
success = false;
msg = expected1 == null && expected2 == null ? "no configuration" :
"series " + i;
}
}
}
catch (Throwable t) {
LOGGER.info("", t);
success = false;
}
result(testName, success, msg);
}
*/
@Test(groups = { "all", "pixels", "automated" })
public void testUnflattenedSubimagePixelsHashes() {
if (config == null)
throw new SkipException("No config tree");
String testName = "testUnflattenedSubimagePixelsHashes";
if (!initFile())
result(testName, false, "initFile");
boolean success = true;
String msg = null;
try {
IFormatReader resolutionReader = new BufferedImageReader(new FileStitcher());
resolutionReader.setFlattenedResolutions(false);
resolutionReader.setNormalized(true);
resolutionReader.setOriginalMetadataPopulated(false);
resolutionReader.setMetadataFiltered(true);
resolutionReader.setId(id);
// check the MD5 of the first plane in each resolution
for (int i = 0; i < resolutionReader.getSeriesCount() && success; i++) {
resolutionReader.setSeries(i);
for (int r = 0; r < resolutionReader.getResolutionCount() && success; r++) {
resolutionReader.setResolution(r);
config.setSeries(resolutionReader.getCoreIndex());
int w = (int) Math.min(Configuration.TILE_SIZE, resolutionReader.getSizeX());
int h = (int) Math.min(Configuration.TILE_SIZE, resolutionReader.getSizeY());
String expected1 = config.getTileMD5();
String expected2 = config.getTileAlternateMD5();
String md5 = null;
try {
md5 = TestTools.md5(resolutionReader.openBytes(0, 0, 0, w, h));
} catch (Throwable e) {
if (TestTools.isOutOfMemory(e)) {
result(testName, true, "Image too large");
return;
}
LOGGER.warn("", e);
}
if (md5 == null && expected1 == null && expected2 == null) {
success = true;
} else if (!md5.equals(expected1) && !md5.equals(expected2) && (expected1 != null || expected2 != null)) {
success = false;
msg = "series " + i + ", resolution " + r;
}
}
}
resolutionReader.close();
} catch (Throwable t) {
LOGGER.info("", t);
success = false;
}
result(testName, success, msg);
}
use of loci.formats.FileStitcher in project bioformats by openmicroscopy.
the class FormatReaderTest method testOMEXML.
@Test(groups = { "all", "xml", "fast", "automated" })
public void testOMEXML() {
String testName = "testOMEXML";
if (!initFile())
result(testName, false, "initFile");
String msg = null;
try {
MetadataRetrieve retrieve = (MetadataRetrieve) reader.getMetadataStore();
boolean success = omexmlService.isOMEXMLMetadata(retrieve);
if (!success)
msg = TestTools.shortClassName(retrieve);
for (int i = 0; i < reader.getSeriesCount() && msg == null; i++) {
reader.setSeries(i);
String type = FormatTools.getPixelTypeString(reader.getPixelType());
if (reader.getSizeX() != retrieve.getPixelsSizeX(i).getValue().intValue()) {
msg = "SizeX";
}
if (reader.getSizeY() != retrieve.getPixelsSizeY(i).getValue().intValue()) {
msg = "SizeY";
}
if (reader.getSizeZ() != retrieve.getPixelsSizeZ(i).getValue().intValue()) {
msg = "SizeZ";
}
if (reader.getSizeC() != retrieve.getPixelsSizeC(i).getValue().intValue()) {
msg = "SizeC";
}
if (reader.getSizeT() != retrieve.getPixelsSizeT(i).getValue().intValue()) {
msg = "SizeT";
}
// NB: OME-TIFF files do not have a BinData element under Pixels
IFormatReader r = reader.unwrap();
if (r instanceof FileStitcher)
r = ((FileStitcher) r).getReader();
if (r instanceof ReaderWrapper)
r = ((ReaderWrapper) r).unwrap();
if (!(r instanceof OMETiffReader)) {
boolean littleEndian = false;
if (retrieve.getPixelsBigEndian(i) != null) {
littleEndian = !retrieve.getPixelsBigEndian(i).booleanValue();
} else if (retrieve.getPixelsBinDataCount(i) == 0) {
littleEndian = !retrieve.getPixelsBinDataBigEndian(i, 0).booleanValue();
}
if (reader.isLittleEndian() != littleEndian) {
msg = "BigEndian";
}
}
if (!reader.getDimensionOrder().equals(retrieve.getPixelsDimensionOrder(i).toString())) {
msg = "DimensionOrder";
}
if (!type.equalsIgnoreCase(retrieve.getPixelsType(i).toString())) {
msg = "PixelType";
}
}
} catch (Throwable t) {
LOGGER.info("", t);
msg = t.getMessage();
}
result(testName, msg == null, msg);
}
use of loci.formats.FileStitcher in project bioformats by openmicroscopy.
the class FormatReaderTest method testRequiredDirectories.
@Test(groups = { "all", "type", "automated" })
public void testRequiredDirectories() {
if (!initFile())
return;
if (reader.getFormat().equals("Woolz") || reader.getFormat().startsWith("CellH5")) {
throw new SkipException(SKIP_MESSAGE);
}
String testName = "testRequiredDirectories";
String file = reader.getCurrentFile();
LOGGER.debug("testRequiredDirectories({})", file);
int directories = -1;
try {
directories = reader.getRequiredDirectories(reader.getUsedFiles());
} catch (Exception e) {
LOGGER.warn("Could not retrieve directory count", e);
}
LOGGER.debug("directories = {}", directories);
if (directories < 0) {
result(testName, false, "Invalid directory count (" + directories + ")");
} else {
// make sure the directory count is not too small
// we can't reliably test for the directory count being too large,
// since a different fileset in the same format may need more directories
String[] usedFiles = reader.getUsedFiles();
String[] newFiles = new String[usedFiles.length];
// find the common parent
String commonParent = new Location(usedFiles[0]).getAbsoluteFile().getParent();
for (int i = 1; i < usedFiles.length; i++) {
while (!usedFiles[i].startsWith(commonParent)) {
commonParent = commonParent.substring(0, commonParent.lastIndexOf(File.separator));
}
}
LOGGER.debug("commonParent = {}", commonParent);
// remove extra directories
String split = File.separatorChar == '\\' ? "\\\\" : File.separator;
LOGGER.debug("split = {}", split);
String[] f = commonParent.split(split);
StringBuilder toRemove = new StringBuilder();
for (int i = 0; i < f.length - directories - 1; i++) {
toRemove.append(f[i]);
if (i < f.length - directories - 2) {
toRemove.append(split);
}
}
// map new file names and verify that setId still works
String newFile = null;
for (int i = 0; i < usedFiles.length; i++) {
newFiles[i] = usedFiles[i].replaceAll(toRemove.toString(), "");
LOGGER.debug("mapping {} to {}", newFiles[i], usedFiles[i]);
Location.mapId(newFiles[i], usedFiles[i]);
if (usedFiles[i].equals(file)) {
newFile = newFiles[i];
}
}
if (newFile == null) {
newFile = newFiles[0];
}
LOGGER.debug("newFile = {}", newFile);
IFormatReader check = new FileStitcher();
try {
check.setId(newFile);
int nFiles = check.getUsedFiles().length;
result(testName, nFiles == usedFiles.length, "Found " + nFiles + "; expected " + usedFiles.length);
} catch (Exception e) {
LOGGER.info("Initialization failed", e);
result(testName, false, e.getMessage());
} finally {
try {
check.close();
} catch (IOException e) {
LOGGER.warn("Could not close reader", e);
}
for (int i = 0; i < newFiles.length; i++) {
Location.mapId(newFiles[i], null);
}
}
}
}
Aggregations