use of loci.common.IniList in project bioformats by openmicroscopy.
the class Configuration method pruneINI.
private void pruneINI() {
IniList newIni = new IniList();
for (IniTable table : ini) {
String tableName = table.get(IniTable.HEADER_KEY);
Location file = new Location(dataFile);
if (tableName.startsWith(file.getName() + " ")) {
newIni.add(table);
if (tableName.endsWith("global")) {
globalTable = table;
}
}
}
ini = newIni;
}
use of loci.common.IniList 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);
}
}
Aggregations