use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class Configuration method populateINI.
// -- Helper methods --
private void populateINI(IFormatReader reader) {
IMetadata retrieve = (IMetadata) reader.getMetadataStore();
ini = new IniList();
IniTable globalTable = new IniTable();
putTableName(globalTable, reader, " global");
int seriesCount = reader.getSeriesCount();
globalTable.put(SERIES_COUNT, String.valueOf(seriesCount));
IFormatReader r = reader;
if (r instanceof ImageReader) {
r = ((ImageReader) r).getReader();
} else if (r instanceof ReaderWrapper) {
try {
r = ((ReaderWrapper) r).unwrap();
} catch (FormatException e) {
} catch (IOException e) {
}
}
globalTable.put(READER, TestTools.shortClassName(r));
globalTable.put(TEST, "true");
globalTable.put(MEMORY, String.valueOf(TestTools.getUsedMemory()));
long planeSize = (long) FormatTools.getPlaneSize(reader) * 3;
boolean canOpenImages = planeSize > 0 && TestTools.canFitInMemory(planeSize);
long t0 = System.currentTimeMillis();
if (canOpenImages) {
try {
reader.openBytes(0);
} catch (FormatException e) {
} catch (IOException e) {
}
}
long t1 = System.currentTimeMillis();
globalTable.put(ACCESS_TIME, String.valueOf(t1 - t0));
ini.add(globalTable);
for (int series = 0; series < seriesCount; series++) {
reader.setSeries(series);
IniTable seriesTable = new IniTable();
putTableName(seriesTable, reader, SERIES + series);
seriesTable.put(SIZE_X, String.valueOf(reader.getSizeX()));
seriesTable.put(SIZE_Y, String.valueOf(reader.getSizeY()));
seriesTable.put(SIZE_Z, String.valueOf(reader.getSizeZ()));
seriesTable.put(SIZE_C, String.valueOf(reader.getSizeC()));
seriesTable.put(SIZE_T, String.valueOf(reader.getSizeT()));
seriesTable.put(DIMENSION_ORDER, reader.getDimensionOrder());
seriesTable.put(IS_INTERLEAVED, String.valueOf(reader.isInterleaved()));
seriesTable.put(IS_INDEXED, String.valueOf(reader.isIndexed()));
seriesTable.put(IS_FALSE_COLOR, String.valueOf(reader.isFalseColor()));
seriesTable.put(IS_RGB, String.valueOf(reader.isRGB()));
seriesTable.put(THUMB_SIZE_X, String.valueOf(reader.getThumbSizeX()));
seriesTable.put(THUMB_SIZE_Y, String.valueOf(reader.getThumbSizeY()));
seriesTable.put(PIXEL_TYPE, FormatTools.getPixelTypeString(reader.getPixelType()));
seriesTable.put(IS_LITTLE_ENDIAN, String.valueOf(reader.isLittleEndian()));
seriesTable.put(CHANNEL_COUNT, String.valueOf(retrieve.getChannelCount(series)));
try {
planeSize = DataTools.safeMultiply32(reader.getSizeX(), reader.getSizeY(), reader.getEffectiveSizeC(), FormatTools.getBytesPerPixel(reader.getPixelType()));
canOpenImages = planeSize > 0 && TestTools.canFitInMemory(planeSize);
} catch (IllegalArgumentException e) {
canOpenImages = false;
}
if (canOpenImages) {
try {
byte[] plane = reader.openBytes(0);
seriesTable.put(MD5, TestTools.md5(plane));
} catch (FormatException e) {
// TODO
} catch (IOException e) {
// TODO
}
}
try {
int w = (int) Math.min(TILE_SIZE, reader.getSizeX());
int h = (int) Math.min(TILE_SIZE, reader.getSizeY());
byte[] tile = reader.openBytes(0, 0, 0, w, h);
seriesTable.put(TILE_MD5, TestTools.md5(tile));
} catch (FormatException e) {
// TODO
} catch (IOException e) {
// TODO
}
seriesTable.put(NAME, retrieve.getImageName(series));
seriesTable.put(DESCRIPTION, retrieve.getImageDescription(series));
Length physicalX = retrieve.getPixelsPhysicalSizeX(series);
if (physicalX != null) {
seriesTable.put(PHYSICAL_SIZE_X, physicalX.value().toString());
seriesTable.put(PHYSICAL_SIZE_X_UNIT, physicalX.unit().getSymbol());
}
Length physicalY = retrieve.getPixelsPhysicalSizeY(series);
if (physicalY != null) {
seriesTable.put(PHYSICAL_SIZE_Y, physicalY.value().toString());
seriesTable.put(PHYSICAL_SIZE_Y_UNIT, physicalY.unit().getSymbol());
}
Length physicalZ = retrieve.getPixelsPhysicalSizeZ(series);
if (physicalZ != null) {
seriesTable.put(PHYSICAL_SIZE_Z, physicalZ.value().toString());
seriesTable.put(PHYSICAL_SIZE_Z_UNIT, physicalZ.unit().getSymbol());
}
Time timeIncrement = retrieve.getPixelsTimeIncrement(series);
if (timeIncrement != null) {
seriesTable.put(TIME_INCREMENT, timeIncrement.value().toString());
seriesTable.put(TIME_INCREMENT_UNIT, timeIncrement.unit().getSymbol());
}
Timestamp acquisition = retrieve.getImageAcquisitionDate(series);
if (acquisition != null) {
String date = acquisition.getValue();
if (date != null) {
seriesTable.put(DATE, date);
}
}
for (int c = 0; c < retrieve.getChannelCount(series); c++) {
seriesTable.put(CHANNEL_NAME + c, retrieve.getChannelName(series, c));
try {
seriesTable.put(LIGHT_SOURCE + c, retrieve.getChannelLightSourceSettingsID(series, c));
} catch (NullPointerException e) {
}
try {
int plane = reader.getIndex(0, c, 0);
if (plane < retrieve.getPlaneCount(series)) {
seriesTable.put(EXPOSURE_TIME + c, retrieve.getPlaneExposureTime(series, plane).value().toString());
seriesTable.put(EXPOSURE_TIME_UNIT + c, retrieve.getPlaneExposureTime(series, plane).unit().getSymbol());
}
} catch (NullPointerException e) {
}
Length emWavelength = retrieve.getChannelEmissionWavelength(series, c);
if (emWavelength != null) {
seriesTable.put(EMISSION_WAVELENGTH + c, emWavelength.value().toString());
seriesTable.put(EMISSION_WAVELENGTH_UNIT + c, emWavelength.unit().getSymbol());
}
Length exWavelength = retrieve.getChannelExcitationWavelength(series, c);
if (exWavelength != null) {
seriesTable.put(EXCITATION_WAVELENGTH + c, exWavelength.value().toString());
seriesTable.put(EXCITATION_WAVELENGTH_UNIT + c, exWavelength.unit().getSymbol());
}
try {
seriesTable.put(DETECTOR + c, retrieve.getDetectorSettingsID(series, c));
} catch (NullPointerException e) {
}
}
for (int p = 0; p < reader.getImageCount(); p++) {
try {
Time deltaT = retrieve.getPlaneDeltaT(series, p);
if (deltaT != null) {
seriesTable.put(DELTA_T + p, deltaT.value(UNITS.SECOND).toString());
}
Length xPos = retrieve.getPlanePositionX(series, p);
if (xPos != null) {
seriesTable.put(X_POSITION + p, String.valueOf(xPos.value().doubleValue()));
seriesTable.put(X_POSITION_UNIT + p, xPos.unit().getSymbol());
}
Length yPos = retrieve.getPlanePositionY(series, p);
if (yPos != null) {
seriesTable.put(Y_POSITION + p, String.valueOf(yPos.value().doubleValue()));
seriesTable.put(Y_POSITION_UNIT + p, yPos.unit().getSymbol());
}
Length zPos = retrieve.getPlanePositionZ(series, p);
if (zPos != null) {
seriesTable.put(Z_POSITION + p, String.valueOf(zPos.value().doubleValue()));
seriesTable.put(Z_POSITION_UNIT + p, zPos.unit().getSymbol());
}
} catch (IndexOutOfBoundsException e) {
// only happens if no Plane elements were populated
}
}
ini.add(seriesTable);
}
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class FormatReaderTest method testPlanePositions.
@Test(groups = { "all", "fast", "automated" })
public void testPlanePositions() {
if (config == null)
throw new SkipException("No config tree");
String testName = "PlanePositions";
if (!initFile())
result(testName, false, "initFile");
IMetadata retrieve = (IMetadata) reader.getMetadataStore();
for (int i = 0; i < reader.getSeriesCount(); i++) {
config.setSeries(i);
for (int p = 0; p < reader.getImageCount(); p++) {
Length posX = null;
Length posY = null;
Length posZ = null;
try {
posX = retrieve.getPlanePositionX(i, p);
} catch (IndexOutOfBoundsException e) {
}
try {
posY = retrieve.getPlanePositionY(i, p);
} catch (IndexOutOfBoundsException e) {
}
try {
posZ = retrieve.getPlanePositionZ(i, p);
} catch (IndexOutOfBoundsException e) {
}
Double expectedX = config.getPositionX(p);
Double expectedY = config.getPositionY(p);
Double expectedZ = config.getPositionZ(p);
String expectedXUnit = config.getPositionXUnit(p);
String expectedYUnit = config.getPositionYUnit(p);
String expectedZUnit = config.getPositionZUnit(p);
if (posX == null && expectedX == null) {
} else if (posX == null) {
result(testName, false, "missing X position for series " + i + ", plane " + p);
return;
} else if (expectedX != null && expectedXUnit != null) {
Double x = posX.value().doubleValue();
if (!expectedXUnit.equals(posX.unit().getSymbol())) {
result(testName, false, "X position unit series " + i + ", plane " + p + " (expected " + expectedXUnit + ", actual " + posX.unit().getSymbol() + ")");
return;
}
if (Math.abs(x - expectedX) > Constants.EPSILON) {
result(testName, false, "X position series " + i + ", plane " + p + " (expected " + expectedX + ", actual " + x + ")");
return;
}
}
if (posY == null && expectedY == null) {
} else if (posY == null) {
result(testName, false, "missing Y position for series " + i + ", plane " + p);
return;
} else if (expectedY != null && expectedYUnit != null) {
Double y = posY.value().doubleValue();
if (!expectedYUnit.equals(posY.unit().getSymbol())) {
result(testName, false, "Y position unit series " + i + ", plane " + p + " (expected " + expectedYUnit + ", actual " + posY.unit().getSymbol() + ")");
return;
}
if (Math.abs(y - expectedY) > Constants.EPSILON) {
result(testName, false, "Y position series " + i + ", plane " + p + " (expected " + expectedY + ", actual " + y + ")");
return;
}
}
if (posZ == null && expectedZ == null) {
} else if (posZ == null) {
result(testName, false, "missing Z position for series " + i + ", plane " + p);
return;
} else if (expectedZ != null && expectedZUnit != null) {
Double z = posZ.value().doubleValue();
if (!expectedZUnit.equals(posZ.unit().getSymbol())) {
result(testName, false, "Z position unit series " + i + ", plane " + p + " (expected " + expectedZUnit + ", actual " + posZ.unit().getSymbol() + ")");
return;
}
if (Math.abs(z - expectedZ) > Constants.EPSILON) {
result(testName, false, "Z position series " + i + ", plane " + p + " (expected " + expectedZ + ", actual " + z + ")");
return;
}
}
}
}
result(testName, true);
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class FormatReaderTest method testLightSources.
@Test(groups = { "all", "fast", "automated" })
public void testLightSources() {
if (config == null)
throw new SkipException("No config tree");
String testName = "LightSources";
if (!initFile())
result(testName, false, "initFile");
IMetadata retrieve = (IMetadata) reader.getMetadataStore();
for (int i = 0; i < reader.getSeriesCount(); i++) {
config.setSeries(i);
for (int c = 0; c < config.getChannelCount(); c++) {
String expectedLightSource = config.getLightSource(c);
String realLightSource = null;
try {
realLightSource = retrieve.getChannelLightSourceSettingsID(i, c);
} catch (NullPointerException e) {
}
if (!(expectedLightSource == null && realLightSource == null) && !expectedLightSource.equals(realLightSource)) {
result(testName, false, "Series " + i + " channel " + c + " (expected " + expectedLightSource + ", actual " + realLightSource + ")");
}
}
}
result(testName, true);
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class FormatReaderTest method testDeltaT.
@Test(groups = { "all", "fast", "automated" })
public void testDeltaT() {
if (config == null)
throw new SkipException("No config tree");
String testName = "DeltaT";
if (!initFile())
result(testName, false, "initFile");
IMetadata retrieve = (IMetadata) reader.getMetadataStore();
for (int i = 0; i < reader.getSeriesCount(); i++) {
config.setSeries(i);
// Test image acquisition date
String expectedDate = config.getDate();
String date = null;
if (retrieve.getImageAcquisitionDate(i) != null) {
date = retrieve.getImageAcquisitionDate(i).getValue();
}
if (expectedDate != null && date != null && !expectedDate.equals(date)) {
result(testName, false, "series " + i + " (expected " + expectedDate + ", actual " + date + ")");
return;
}
for (int p = 0; p < reader.getImageCount(); p++) {
Time deltaT = null;
try {
deltaT = retrieve.getPlaneDeltaT(i, p);
} catch (IndexOutOfBoundsException e) {
}
Double expectedDeltaT = config.getDeltaT(p);
if (deltaT == null && expectedDeltaT == null) {
continue;
}
if (deltaT == null) {
result(testName, false, "missing series " + i + ", plane " + p);
return;
}
if (expectedDeltaT != null) {
Double seconds = deltaT.value(UNITS.SECOND).doubleValue();
if (Math.abs(seconds - expectedDeltaT) > Constants.EPSILON) {
result(testName, false, "series " + i + ", plane " + p + " (expected " + expectedDeltaT + ", actual " + seconds + ")");
return;
}
}
}
}
result(testName, true);
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class FormatReaderTest method testPhysicalSizeY.
@Test(groups = { "all", "fast", "automated" })
public void testPhysicalSizeY() {
if (config == null)
throw new SkipException("No config tree");
String testName = "PhysicalSizeY";
if (!initFile())
result(testName, false, "initFile");
IMetadata retrieve = (IMetadata) reader.getMetadataStore();
for (int i = 0; i < reader.getSeriesCount(); i++) {
config.setSeries(i);
Length expectedSize = config.getPhysicalSizeY();
Length realSize = retrieve.getPixelsPhysicalSizeY(i);
if (!isAlmostEqual(realSize, expectedSize)) {
result(testName, false, "Series " + i + " (expected " + expectedSize + ", actual " + realSize + ")");
}
}
result(testName, true);
}
Aggregations