use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class FormatReaderTest method testSaneOMEXML.
@Test(groups = { "all", "xml", "automated" })
public void testSaneOMEXML() {
String testName = "testSaneOMEXML";
if (!initFile())
result(testName, false, "initFile");
if (!config.hasValidXML()) {
LOGGER.debug("Skipping valid XML test");
result(testName, true);
return;
}
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++) {
// total number of ChannelComponents should match SizeC
int sizeC = retrieve.getPixelsSizeC(i).getValue().intValue();
int nChannelComponents = retrieve.getChannelCount(i);
int samplesPerPixel = retrieve.getChannelSamplesPerPixel(i, 0).getValue();
if (sizeC != nChannelComponents * samplesPerPixel) {
msg = "ChannelComponent";
}
// Z, C and T indices should be populated if PlaneTiming is present
Time deltaT = null;
Time exposure = null;
Integer z = null, c = null, t = null;
if (retrieve.getPlaneCount(i) > 0) {
deltaT = retrieve.getPlaneDeltaT(i, 0);
exposure = retrieve.getPlaneExposureTime(i, 0);
z = retrieve.getPlaneTheZ(i, 0).getValue();
c = retrieve.getPlaneTheC(i, 0).getValue();
t = retrieve.getPlaneTheT(i, 0).getValue();
}
if ((deltaT != null || exposure != null) && (z == null || c == null || t == null)) {
msg = "PlaneTiming";
}
// if CreationDate is before 1990, it's probably invalid
String date = null;
if (retrieve.getImageAcquisitionDate(i) != null) {
date = retrieve.getImageAcquisitionDate(i).getValue();
}
config.setSeries(i);
String configDate = config.getDate();
if (date != null && !date.equals(configDate)) {
date = date.trim();
long acquiredDate = new Timestamp(date).asInstant().getMillis();
long saneDate = new Timestamp("1990-01-01T00:00:00").asInstant().getMillis();
long fileDate = new Location(reader.getCurrentFile()).getAbsoluteFile().lastModified();
if (acquiredDate < saneDate && fileDate >= saneDate) {
msg = "CreationDate (date=" + date + " acquiredDate=" + acquiredDate + " fileDate=" + fileDate + " saneDate=" + saneDate + ")";
}
}
}
} catch (Throwable t) {
LOGGER.info("", t);
msg = t.getMessage();
}
result(testName, msg == null, msg);
}
use of loci.formats.meta.MetadataRetrieve 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.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class FormatReaderTest method testValidXML.
@Test(groups = { "all", "xml", "fast", "automated" })
public void testValidXML() {
if (config == null)
throw new SkipException("No config tree");
String testName = "testValidXML";
if (!initFile())
result(testName, false, "initFile");
if (!config.hasValidXML()) {
LOGGER.debug("Skipping valid XML test");
result(testName, true);
return;
}
String format = config.getReader();
boolean success = true;
try {
MetadataStore store = reader.getMetadataStore();
MetadataRetrieve retrieve = omexmlService.asRetrieve(store);
String xml = omexmlService.getOMEXML(retrieve);
// javax.xml.validation.Validator as used during XML validation
synchronized (configTree) {
success = xml != null && omexmlService.validateOMEXML(xml);
}
} catch (Throwable t) {
LOGGER.info("", t);
success = false;
}
result(testName, success);
try {
close();
} catch (IOException e) {
LOGGER.info("", e);
}
}
use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.
the class FormatReaderTest method writeXML.
@Test(groups = { "config-xml" })
public void writeXML() {
setupReader();
if (!initFile(false))
return;
String file = reader.getCurrentFile();
LOGGER.info("Generating XML: {}", file);
try {
Location l = new Location(file);
File f = new File(l.getParent(), l.getName() + ".ome.xml");
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(f), Constants.ENCODING);
MetadataStore store = reader.getMetadataStore();
MetadataRetrieve retrieve = omexmlService.asRetrieve(store);
String xml = omexmlService.getOMEXML(retrieve);
writer.write(xml);
writer.close();
reader.close();
} catch (Throwable t) {
LOGGER.info("", t);
assert false;
}
}
Aggregations