use of loci.common.IniList in project bioformats by openmicroscopy.
the class FV1000Reader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
parser.setCommentDelimiter(null);
isOIB = checkSuffix(id, OIB_SUFFIX);
if (isOIB) {
initPOIService();
}
// mappedOIF is used to distinguish between datasets that are being read
// directly (e.g. using ImageJ or showinf), and datasets that are being
// imported through omebf. In the latter case, the necessary directory
// structure is not preserved (only relative file names are stored in
// OMEIS), so we will need to use slightly different logic to build the
// list of associated files.
boolean mappedOIF = !isOIB && !new File(id).getAbsoluteFile().exists();
wavelengths = new ArrayList<Double>();
illuminations = new ArrayList<String>();
channels = new ArrayList<ChannelData>();
planes = new ArrayList<PlaneData>();
String oifName = null;
if (isOIB) {
oifName = mapOIBFiles();
} else {
// make sure we have the OIF file, not a TIFF
if (!checkSuffix(id, OIF_SUFFIX)) {
currentId = findOIFFile(id);
initFile(currentId);
}
oifName = currentId;
}
String oifPath = new Location(oifName).getAbsoluteFile().getAbsolutePath();
if (mappedOIF) {
oifPath = oifName.substring(0, oifName.lastIndexOf(File.separator) + 1);
}
String path = isOIB ? "" : oifPath.substring(0, oifPath.lastIndexOf(File.separator) + 1);
try {
RandomAccessInputStream s = getFile(oifName);
s.close();
} catch (IOException e) {
oifName = oifName.replaceAll(".oif", ".OIF");
}
// parse key/value pairs from the OIF file
code = new String[NUM_DIMENSIONS];
size = new String[NUM_DIMENSIONS];
pixelSize = new Double[NUM_DIMENSIONS];
previewNames = new ArrayList<String>();
SortedMap<Integer, String> previewFileNames = new TreeMap<Integer, String>();
boolean laserEnabled = true;
IniList f = getIniFile(oifName);
IniTable saveInfo = f.getTable("ProfileSaveInfo");
String[] saveKeys = saveInfo.keySet().toArray(new String[saveInfo.size()]);
for (String key : saveKeys) {
String value = saveInfo.get(key).toString();
value = sanitizeValue(value).trim();
if (key.startsWith("IniFileName") && key.indexOf("Thumb") == -1 && !isPreviewName(value)) {
filenames.put(new Integer(key.substring(11)), value);
} else if (key.startsWith("RoiFileName") && key.indexOf("Thumb") == -1 && !isPreviewName(value)) {
try {
roiFilenames.put(new Integer(key.substring(11)), value);
} catch (NumberFormatException e) {
}
} else if (key.equals("PtyFileNameS"))
ptyStart = value;
else if (key.equals("PtyFileNameE"))
ptyEnd = value;
else if (key.equals("PtyFileNameT2"))
ptyPattern = value;
else if (key.indexOf("Thumb") != -1) {
if (thumbId == null)
thumbId = value.trim();
} else if (key.startsWith("LutFileName")) {
lutNames.add(path + value);
} else if (isPreviewName(value)) {
try {
RandomAccessInputStream s = getFile(path + value.trim());
if (s != null) {
s.close();
Integer previewIndex = getPreviewNameIndex(key);
if (previewIndex != null) {
previewFileNames.put(previewIndex, path + value.trim());
} else {
previewNames.add(path + value.trim());
}
}
} catch (FormatException e) {
LOGGER.debug("Preview file not found", e);
} catch (IOException e) {
LOGGER.debug("Preview file not found", e);
}
}
}
// Store sorted list of preview names
previewNames.addAll(previewFileNames.values());
if (filenames.isEmpty())
addPtyFiles();
for (int i = 0; i < NUM_DIMENSIONS; i++) {
IniTable commonParams = f.getTable("Axis " + i + " Parameters Common");
code[i] = commonParams.get("AxisCode");
size[i] = commonParams.get("MaxSize");
double end = Double.parseDouble(commonParams.get("EndPosition"));
double start = Double.parseDouble(commonParams.get("StartPosition"));
pixelSize[i] = end - start;
}
IniTable referenceParams = f.getTable("Reference Image Parameter");
imageDepth = Integer.parseInt(referenceParams.get("ImageDepth"));
pixelSizeX = referenceParams.get("WidthConvertValue");
pixelSizeY = referenceParams.get("HeightConvertValue");
String ripValidBitCounts = referenceParams.get("ValidBitCounts");
if (ripValidBitCounts != null) {
validBits = Integer.parseInt(ripValidBitCounts);
}
int index = 0;
IniTable laser = f.getTable("Laser " + index + " Parameters");
while (laser != null) {
laserEnabled = laser.get("Laser Enable").equals("1");
if (laserEnabled) {
wavelengths.add(new Double(laser.get("LaserWavelength")));
}
creationDate = laser.get("ImageCaputreDate");
if (creationDate == null) {
creationDate = laser.get("ImageCaptureDate");
}
index++;
laser = f.getTable("Laser " + index + " Parameters");
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
index = 1;
IniTable guiChannel = f.getTable("GUI Channel " + index + " Parameters");
while (guiChannel != null) {
ChannelData channel = new ChannelData();
channel.gain = DataTools.parseDouble(guiChannel.get("AnalogPMTGain"));
channel.voltage = DataTools.parseDouble(guiChannel.get("AnalogPMTVoltage"));
channel.barrierFilter = channel.getFilter(guiChannel.get("BF Name"));
channel.active = Integer.parseInt(guiChannel.get("CH Activate")) != 0;
channel.name = guiChannel.get("CH Name");
channel.dyeName = guiChannel.get("DyeName");
channel.emissionFilter = channel.getFilter(guiChannel.get("EmissionDM Name"));
channel.emWave = DataTools.parseDouble(guiChannel.get("EmissionWavelength"));
channel.excitationFilter = channel.getFilter(guiChannel.get("ExcitationDM Name"));
channel.exWave = DataTools.parseDouble(guiChannel.get("ExcitationWavelength"));
channels.add(channel);
index++;
guiChannel = f.getTable("GUI Channel " + index + " Parameters");
}
index = 1;
IniTable channel = f.getTable("Channel " + index + " Parameters");
while (channel != null) {
String illumination = channel.get("LightType");
if (illumination != null)
illumination = illumination.toLowerCase();
if (illumination == null) {
// Ignored
} else if (illumination.indexOf("fluorescence") != -1) {
illumination = "Epifluorescence";
} else if (illumination.indexOf("transmitted") != -1) {
illumination = "Transmitted";
} else
illumination = null;
illuminations.add(illumination);
index++;
channel = f.getTable("Channel " + index + " Parameters");
}
HashMap<String, String> iniMap = f.flattenIntoHashMap();
metadata.putAll(iniMap);
}
LOGGER.info("Initializing helper readers");
if (previewNames.size() > 0) {
final List<String> v = new ArrayList<String>();
for (int i = 0; i < previewNames.size(); i++) {
String ss = previewNames.get(i);
ss = replaceExtension(ss, "pty", "tif");
if (ss.endsWith(".tif"))
v.add(ss);
}
previewNames = v;
if (previewNames.size() > 0) {
core.clear();
core.add(new CoreMetadata());
core.add(new CoreMetadata());
IFDList ifds = null;
CoreMetadata ms1 = core.get(1);
for (String previewName : previewNames) {
RandomAccessInputStream preview = getFile(previewName);
TiffParser tp = new TiffParser(preview);
ifds = tp.getIFDs();
preview.close();
tp = null;
ms1.imageCount += ifds.size();
}
ms1.sizeX = (int) ifds.get(0).getImageWidth();
ms1.sizeY = (int) ifds.get(0).getImageLength();
ms1.sizeZ = 1;
ms1.sizeT = 1;
ms1.sizeC = ms1.imageCount;
ms1.rgb = false;
int bits = ifds.get(0).getBitsPerSample()[0];
while ((bits % 8) != 0) bits++;
bits /= 8;
ms1.pixelType = FormatTools.pixelTypeFromBytes(bits, false, false);
ms1.dimensionOrder = "XYCZT";
ms1.indexed = false;
}
}
CoreMetadata ms0 = core.get(0);
ms0.imageCount = filenames.size();
tiffs = new ArrayList<String>(getImageCount());
thumbReader = new BMPReader();
if (thumbId != null) {
thumbId = replaceExtension(thumbId, "pty", "bmp");
thumbId = sanitizeFile(thumbId, path);
}
LOGGER.info("Reading additional metadata");
// open each INI file (.pty extension) and build list of TIFF files
String tiffPath = null;
ms0.dimensionOrder = "XY";
final Map<String, String> values = new HashMap<String, String>();
final List<String> baseKeys = new ArrayList<String>();
for (int i = 0, ii = 0; ii < getImageCount(); i++, ii++) {
String file = filenames.get(i);
while (file == null) file = filenames.get(++i);
file = sanitizeFile(file, path);
if (file.indexOf(File.separator) != -1) {
tiffPath = file.substring(0, file.lastIndexOf(File.separator));
} else
tiffPath = file;
Location ptyFile = new Location(file);
if (!isOIB && !ptyFile.exists()) {
LOGGER.warn("Could not find .pty file ({}); guessing at the " + "corresponding TIFF file.", file);
String tiff = replaceExtension(file, "pty", "tif");
Location tiffFile = new Location(tiff);
if (tiffFile.exists()) {
tiffs.add(ii, tiffFile.getAbsolutePath());
continue;
} else {
if (!tiffFile.getParentFile().exists()) {
String realOIFName = new Location(currentId).getName();
String basePath = tiffFile.getParentFile().getParent();
if (mappedOIF) {
tiffPath = basePath + File.separator + realOIFName + ".files";
ptyFile = new Location(tiffPath, ptyFile.getName());
file = ptyFile.getAbsolutePath();
} else {
Location newFile = new Location(basePath, realOIFName + ".files");
ptyFile = new Location(newFile, ptyFile.getName());
file = ptyFile.getAbsolutePath();
tiffPath = newFile.getAbsolutePath();
}
}
}
} else if (!isOIB) {
file = ptyFile.getAbsolutePath();
}
IniList pty = getIniFile(file);
IniTable fileInfo = pty.getTable("File Info");
file = sanitizeValue(fileInfo.get("DataName"));
if (!isPreviewName(file)) {
while (file.indexOf("GST") != -1) {
file = removeGST(file);
}
if (isOIB) {
file = tiffPath + File.separator + file;
} else
file = new Location(tiffPath, file).getAbsolutePath();
file = replaceExtension(file, "pty", "tif");
tiffs.add(ii, file);
}
PlaneData plane = new PlaneData();
for (int dim = 0; dim < NUM_DIMENSIONS; dim++) {
IniTable axis = pty.getTable("Axis " + dim + " Parameters");
if (axis == null)
break;
boolean addAxis = Integer.parseInt(axis.get("Number")) > 1;
if (dim == 2) {
if (addAxis && getDimensionOrder().indexOf('C') == -1) {
ms0.dimensionOrder += 'C';
}
} else if (dim == 3) {
if (addAxis && getDimensionOrder().indexOf('Z') == -1) {
ms0.dimensionOrder += 'Z';
}
final Double number = Double.valueOf(axis.get("AbsPositionValue"));
plane.positionZ = new Length(number, UNITS.REFERENCEFRAME);
} else if (dim == 4) {
if (addAxis && getDimensionOrder().indexOf('T') == -1) {
ms0.dimensionOrder += 'T';
}
// divide by 1000, as the position is in milliseconds
// and DeltaT is in seconds
plane.deltaT = Double.parseDouble(axis.get("AbsPositionValue")) / 1000;
} else if (dim == 7) {
try {
String xPos = axis.get("AbsPositionValueX");
if (xPos != null) {
final Double number = Double.valueOf(xPos);
plane.positionX = new Length(number, UNITS.REFERENCEFRAME);
}
} catch (NumberFormatException e) {
}
try {
String yPos = axis.get("AbsPositionValueY");
if (yPos != null) {
final Double number = Double.valueOf(yPos);
plane.positionY = new Length(number, UNITS.REFERENCEFRAME);
}
} catch (NumberFormatException e) {
}
}
}
ms0.bitsPerPixel = validBits;
planes.add(plane);
IniTable acquisition = pty.getTable("Acquisition Parameters Common");
if (acquisition != null) {
magnification = acquisition.get("Magnification");
lensNA = acquisition.get("ObjectiveLens NAValue");
objectiveName = acquisition.get("ObjectiveLens Name");
workingDistance = acquisition.get("ObjectiveLens WDValue");
pinholeSize = acquisition.get("PinholeDiameter");
String validBitCounts = acquisition.get("ValidBitCounts");
if (validBitCounts != null) {
ms0.bitsPerPixel = Integer.parseInt(validBitCounts);
}
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
for (IniTable table : pty) {
String[] keys = table.keySet().toArray(new String[table.size()]);
for (String key : keys) {
values.put("Image " + ii + " : " + key, table.get(key));
if (!baseKeys.contains(key))
baseKeys.add(key);
}
}
}
}
for (String key : baseKeys) {
if (key.equals("DataName") || key.indexOf("FileName") >= 0)
break;
boolean equal = true;
String first = values.get("Image 0 : " + key);
for (int i = 1; i < getImageCount(); i++) {
if (!first.equals(values.get("Image " + i + " : " + key))) {
equal = false;
break;
}
}
if (equal) {
addGlobalMeta(key, first);
} else {
for (int i = 0; i < getImageCount(); i++) {
String k = "Image " + i + " : " + key;
addGlobalMeta(k, values.get(k));
}
}
}
if (tiffs.size() != getImageCount()) {
ms0.imageCount = tiffs.size();
}
usedFiles = new ArrayList<String>();
if (tiffPath != null) {
usedFiles.add(isOIB ? id : oifName);
if (!isOIB) {
Location dir = new Location(tiffPath);
if (!mappedOIF && !dir.exists()) {
throw new FormatException("Required directory " + tiffPath + " was not found.");
}
String[] list = mappedOIF ? Location.getIdMap().keySet().toArray(new String[0]) : dir.list(true);
for (int i = 0; i < list.length; i++) {
if (mappedOIF)
usedFiles.add(list[i]);
else {
String p = new Location(tiffPath, list[i]).getAbsolutePath();
String check = p.toLowerCase();
if (!check.endsWith(".tif") && !check.endsWith(".pty") && !check.endsWith(".roi") && !check.endsWith(".lut") && !check.endsWith(".bmp")) {
continue;
}
usedFiles.add(p);
}
}
}
}
LOGGER.info("Populating metadata");
// calculate axis sizes
int realChannels = 0;
for (int i = 0; i < NUM_DIMENSIONS; i++) {
int ss = Integer.parseInt(size[i]);
if (pixelSize[i] == null)
pixelSize[i] = 1.0;
if (code[i].equals("X"))
ms0.sizeX = ss;
else if (code[i].equals("Y") && ss > 1)
ms0.sizeY = ss;
else if (code[i].equals("Z")) {
if (getSizeY() == 0) {
ms0.sizeY = ss;
} else {
ms0.sizeZ = ss;
// Z size stored in nm
pixelSizeZ = Math.abs((pixelSize[i].doubleValue() / (getSizeZ() - 1)) / 1000);
}
} else if (code[i].equals("T")) {
if (getSizeY() == 0) {
ms0.sizeY = ss;
} else {
ms0.sizeT = ss;
pixelSizeT = Math.abs((pixelSize[i].doubleValue() / (getSizeT() - 1)) / 1000);
}
} else if (ss > 0) {
if (getSizeC() == 0)
ms0.sizeC = ss;
else
ms0.sizeC *= ss;
if (code[i].equals("C"))
realChannels = ss;
}
}
if (getSizeZ() == 0)
ms0.sizeZ = 1;
if (getSizeC() == 0)
ms0.sizeC = 1;
if (getSizeT() == 0)
ms0.sizeT = 1;
if (getImageCount() == getSizeC() && getSizeY() == 1) {
ms0.imageCount *= getSizeZ() * getSizeT();
} else if (getImageCount() == getSizeC()) {
ms0.sizeZ = 1;
ms0.sizeT = 1;
}
if (getSizeZ() * getSizeT() * getSizeC() != getImageCount()) {
int diff = (getSizeZ() * getSizeC() * getSizeT()) - getImageCount();
if (diff == previewNames.size() || diff < 0) {
diff /= getSizeC();
if (getSizeT() > 1 && getSizeZ() == 1)
ms0.sizeT -= diff;
else if (getSizeZ() > 1 && getSizeT() == 1)
ms0.sizeZ -= diff;
} else
ms0.imageCount += diff;
}
if (getSizeC() > 1 && getSizeZ() == 1 && getSizeT() == 1) {
if (getDimensionOrder().indexOf('C') == -1)
ms0.dimensionOrder += 'C';
}
if (getDimensionOrder().indexOf('Z') == -1)
ms0.dimensionOrder += 'Z';
if (getDimensionOrder().indexOf('C') == -1)
ms0.dimensionOrder += 'C';
if (getDimensionOrder().indexOf('T') == -1)
ms0.dimensionOrder += 'T';
ms0.pixelType = FormatTools.pixelTypeFromBytes(imageDepth, false, false);
try {
RandomAccessInputStream thumb = getFile(thumbId);
byte[] b = new byte[(int) thumb.length()];
thumb.read(b);
thumb.close();
Location.mapFile("thumbnail.bmp", new ByteArrayHandle(b));
thumbReader.setId("thumbnail.bmp");
for (int i = 0; i < getSeriesCount(); i++) {
core.get(i).thumbSizeX = thumbReader.getSizeX();
core.get(i).thumbSizeY = thumbReader.getSizeY();
}
thumbReader.close();
Location.mapFile("thumbnail.bmp", null);
} catch (IOException e) {
LOGGER.debug("Could not read thumbnail", e);
} catch (FormatException e) {
LOGGER.debug("Could not read thumbnail", e);
}
// initialize lookup table
lut = new short[getSizeC()][3][65536];
byte[] buffer = new byte[65536 * 4];
int count = (int) Math.min(getSizeC(), lutNames.size());
for (int c = 0; c < count; c++) {
Exception exc = null;
try {
RandomAccessInputStream stream = getFile(lutNames.get(c));
stream.seek(stream.length() - 65536 * 4);
stream.read(buffer);
stream.close();
for (int q = 0; q < buffer.length; q += 4) {
lut[c][0][q / 4] = (short) ((buffer[q + 2] & 0xff) * 257);
lut[c][1][q / 4] = (short) ((buffer[q + 1] & 0xff) * 257);
lut[c][2][q / 4] = (short) ((buffer[q] & 0xff) * 257);
}
} catch (IOException e) {
exc = e;
} catch (FormatException e) {
exc = e;
}
if (exc != null) {
LOGGER.debug("Could not read LUT", exc);
lut = null;
break;
}
}
for (int i = 0; i < getSeriesCount(); i++) {
CoreMetadata ms = core.get(i);
ms.rgb = false;
ms.littleEndian = true;
ms.interleaved = false;
ms.metadataComplete = true;
ms.indexed = lut != null;
ms.falseColor = true;
int nFiles = i == 0 ? tiffs.size() : previewNames.size();
for (int file = 0; file < nFiles; file++) {
RandomAccessInputStream plane = getFile(i == 0 ? tiffs.get(file) : previewNames.get(file));
if (plane == null) {
ifds.add(null);
continue;
}
try {
TiffParser tp = new TiffParser(plane);
IFDList ifd = tp.getIFDs();
ifds.add(ifd);
} finally {
plane.close();
}
}
}
// populate MetadataStore
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, true);
if (creationDate != null) {
creationDate = creationDate.replaceAll("'", "");
creationDate = DateTools.formatDate(creationDate, DATE_FORMAT);
}
for (int i = 0; i < getSeriesCount(); i++) {
// populate Image data
store.setImageName("Series " + (i + 1), i);
if (creationDate != null)
store.setImageAcquisitionDate(new Timestamp(creationDate), i);
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
populateMetadataStore(store, path);
}
}
use of loci.common.IniList in project bioformats by openmicroscopy.
the class FV1000Reader method getIniFile.
private IniList getIniFile(String filename) throws FormatException, IOException {
LOGGER.debug("getIniFile procession: {}", filename);
RandomAccessInputStream stream = getFile(filename);
String data = stream.readString((int) stream.length());
if (!data.startsWith("[")) {
data = data.substring(data.indexOf('['), data.length());
}
data = DataTools.stripString(data);
BufferedReader reader = new BufferedReader(new StringReader(data));
stream.close();
IniList list = parser.parseINI(reader);
// most of the values will be wrapped in double quotes
for (IniTable table : list) {
LOGGER.debug("");
LOGGER.debug("[" + table.get(IniTable.HEADER_KEY) + "]");
String[] keys = table.keySet().toArray(new String[table.size()]);
for (String key : keys) {
String value = sanitizeValue(table.get(key));
LOGGER.debug(key + " = " + value);
table.put(key, value);
}
}
reader.close();
return list;
}
use of loci.common.IniList in project bioformats by openmicroscopy.
the class BDReader method readMetaData.
private IniList readMetaData(String id) throws IOException {
IniParser parser = new IniParser();
RandomAccessInputStream idStream = new RandomAccessInputStream(id);
IniList exp = parser.parseINI(new BufferedReader(new InputStreamReader(idStream, Constants.ENCODING)));
IniList plate = null;
IniList xyz = null;
// Read Plate File
for (String filename : metadataFiles) {
if (checkSuffix(filename, "plt")) {
RandomAccessInputStream stream = new RandomAccessInputStream(filename);
plate = parser.parseINI(new BufferedReader(new InputStreamReader(stream, Constants.ENCODING)));
stream.close();
} else if (checkSuffix(filename, "xyz")) {
RandomAccessInputStream stream = new RandomAccessInputStream(filename);
xyz = parser.parseINI(new BufferedReader(new InputStreamReader(stream, Constants.ENCODING)));
stream.close();
} else if (filename.endsWith("RoiSummary.txt")) {
roiFile = filename;
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
RandomAccessInputStream s = new RandomAccessInputStream(filename);
String line = s.readLine().trim();
while (!line.endsWith(".adf\"")) {
line = s.readLine().trim();
}
plateName = line.substring(line.indexOf(':')).trim();
plateName = plateName.replace('/', File.separatorChar);
plateName = plateName.replace('\\', File.separatorChar);
for (int i = 0; i < 3; i++) {
plateName = plateName.substring(0, plateName.lastIndexOf(File.separator));
}
plateName = plateName.substring(plateName.lastIndexOf(File.separator) + 1);
s.close();
}
}
}
if (plate == null)
throw new IOException("No Plate File");
IniTable plateType = plate.getTable("PlateType");
if (plateName == null) {
plateName = plateType.get("Brand");
}
plateDescription = plateType.get("Brand") + " " + plateType.get("Description");
int nWells = Integer.parseInt(plateType.get("Wells"));
if (nWells == 96) {
wellRows = 8;
wellCols = 12;
} else if (nWells == 384) {
wellRows = 16;
wellCols = 24;
}
for (String filename : rootList) {
String name = new Location(filename).getName();
if (name.startsWith("Well ")) {
wellLabels.add(name.split("\\s|\\.")[1]);
}
}
IniTable imageTable = exp.getTable("Image");
boolean montage = imageTable.get("Montaged").equals("1");
if (montage) {
fieldRows = Integer.parseInt(imageTable.get("TilesY"));
fieldCols = Integer.parseInt(imageTable.get("TilesX"));
} else {
fieldRows = 1;
fieldCols = 1;
}
core.clear();
int coresize = wellLabels.size() * fieldRows * fieldCols;
CoreMetadata ms0 = new CoreMetadata();
core.add(ms0);
for (int i = 1; i < coresize; i++) {
core.add(new CoreMetadata());
}
ms0.sizeC = Integer.parseInt(exp.getTable("General").get("Dyes"));
ms0.bitsPerPixel = Integer.parseInt(exp.getTable("Camera").get("BitdepthUsed"));
IniTable dyeTable = exp.getTable("Dyes");
for (int i = 1; i <= getSizeC(); i++) {
channelNames.add(dyeTable.get(Integer.toString(i)));
}
if (xyz != null) {
IniTable zTable = xyz.getTable("Z1Axis");
boolean zEnabled = "1".equals(zTable.get("Z1AxisEnabled")) && "1".equals(zTable.get("Z1AxisMode"));
if (zEnabled) {
ms0.sizeZ = (int) Double.parseDouble(zTable.get("Z1AxisValue")) + 1;
} else {
ms0.sizeZ = 1;
}
} else {
ms0.sizeZ = 1;
}
// Count Images
ms0.sizeT = 0;
for (String channelName : channelNames) {
int images = 0;
for (String filename : wellList.get(1)) {
if (filename.startsWith(channelName) && filename.endsWith(".tif")) {
images++;
}
}
if (images > getImageCount()) {
ms0.sizeT = images / getSizeZ();
ms0.imageCount = getSizeZ() * getSizeT() * channelNames.size();
}
}
idStream.close();
return exp;
}
use of loci.common.IniList in project bioformats by openmicroscopy.
the class BDReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
// make sure we have the experiment file
id = locateExperimentFile(id);
super.initFile(id);
Location dir = new Location(id).getAbsoluteFile().getParentFile();
rootList = dir.list(true);
Arrays.sort(rootList);
for (int i = 0; i < rootList.length; i++) {
String file = rootList[i];
Location f = new Location(dir, file);
rootList[i] = f.getAbsolutePath();
if (!f.isDirectory()) {
if (checkSuffix(file, META_EXT) && !f.isDirectory()) {
metadataFiles.add(f.getAbsolutePath());
}
} else {
String[] wells = f.list(true);
Arrays.sort(wells);
wellList.add(wells);
for (String well : wells) {
Location wellFile = new Location(f, well);
if (!wellFile.isDirectory()) {
if (checkSuffix(well, META_EXT)) {
metadataFiles.add(wellFile.getAbsolutePath());
}
}
}
}
}
// parse Experiment metadata
IniList experiment = readMetaData(id);
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
objective = experiment.getTable("Geometry").get("Name");
IniTable camera = experiment.getTable("Camera");
binning = camera.get("BinX") + "x" + camera.get("BinY");
parseChannelData(dir);
addGlobalMeta("Objective", objective);
addGlobalMeta("Camera binning", binning);
}
final List<String> uniqueRows = new ArrayList<String>();
final List<String> uniqueColumns = new ArrayList<String>();
for (String well : wellLabels) {
String row = well.substring(0, 1).trim();
String column = well.substring(1).trim();
if (!uniqueRows.contains(row) && row.length() > 0)
uniqueRows.add(row);
if (!uniqueColumns.contains(column) && column.length() > 0) {
uniqueColumns.add(column);
}
}
int nSlices = getSizeZ() == 0 ? 1 : getSizeZ();
int nTimepoints = getSizeT();
int nWells = wellLabels.size();
int nChannels = getSizeC() == 0 ? channelNames.size() : getSizeC();
if (nChannels == 0)
nChannels = 1;
tiffs = getTiffs();
reader = new MinimalTiffReader();
reader.setId(tiffs[0][0]);
int sizeX = reader.getSizeX();
int sizeY = reader.getSizeY();
int pixelType = reader.getPixelType();
boolean rgb = reader.isRGB();
boolean interleaved = reader.isInterleaved();
boolean indexed = reader.isIndexed();
boolean littleEndian = reader.isLittleEndian();
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
IniParser parser = new IniParser();
for (String metadataFile : metadataFiles) {
String filename = new Location(metadataFile).getName();
if (!checkSuffix(metadataFile, new String[] { "txt", "bmp", "adf", "roi" })) {
String data = DataTools.readFile(metadataFile);
IniList ini = parser.parseINI(new BufferedReader(new StringReader(data)));
HashMap<String, String> h = ini.flattenIntoHashMap();
for (String key : h.keySet()) {
addGlobalMeta(filename + " " + key, h.get(key));
}
}
}
}
int coresize = core.size();
core.clear();
for (int i = 0; i < coresize; i++) {
CoreMetadata ms = new CoreMetadata();
core.add(ms);
ms.sizeC = nChannels;
ms.sizeZ = nSlices;
ms.sizeT = nTimepoints;
ms.sizeX = sizeX / fieldCols;
ms.sizeY = sizeY / fieldRows;
ms.pixelType = pixelType;
ms.rgb = rgb;
ms.interleaved = interleaved;
ms.indexed = indexed;
ms.littleEndian = littleEndian;
ms.dimensionOrder = "XYZTC";
ms.imageCount = nSlices * nTimepoints * nChannels;
}
MetadataStore store = makeFilterMetadata();
boolean populatePlanes = getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM;
MetadataTools.populatePixels(store, this, populatePlanes);
String plateAcqID = MetadataTools.createLSID("PlateAcquisition", 0, 0);
store.setPlateAcquisitionID(plateAcqID, 0, 0);
PositiveInteger fieldCount = FormatTools.getMaxFieldCount(fieldRows * fieldCols);
if (fieldCount != null) {
store.setPlateAcquisitionMaximumFieldCount(fieldCount, 0, 0);
}
for (int row = 0; row < wellRows; row++) {
for (int col = 0; col < wellCols; col++) {
int index = row * wellCols + col;
store.setWellID(MetadataTools.createLSID("Well", 0, index), 0, index);
store.setWellRow(new NonNegativeInteger(row), 0, index);
store.setWellColumn(new NonNegativeInteger(col), 0, index);
}
}
for (int i = 0; i < getSeriesCount(); i++) {
int well = i / (fieldRows * fieldCols);
int field = i % (fieldRows * fieldCols);
MetadataTools.setDefaultCreationDate(store, tiffs[well][0], i);
String name = wellLabels.get(well);
String row = name.substring(0, 1);
Integer col = Integer.parseInt(name.substring(1));
int index = (row.charAt(0) - 'A') * wellCols + col - 1;
String wellSampleID = MetadataTools.createLSID("WellSample", 0, index, field);
store.setWellSampleID(wellSampleID, 0, index, field);
store.setWellSampleIndex(new NonNegativeInteger(i), 0, index, field);
String imageID = MetadataTools.createLSID("Image", i);
store.setWellSampleImageRef(imageID, 0, index, field);
store.setImageID(imageID, i);
store.setImageName(name + " Field #" + (field + 1), i);
store.setPlateAcquisitionWellSampleRef(wellSampleID, 0, 0, i);
}
MetadataLevel level = getMetadataOptions().getMetadataLevel();
if (level != MetadataLevel.MINIMUM) {
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
store.setObjectiveID(objectiveID, 0, 0);
if (objective != null) {
String[] tokens = objective.split(" ");
String mag = tokens[0].replaceAll("[xX]", "");
String na = null;
int naIndex = 0;
for (int i = 0; i < tokens.length; i++) {
if (tokens[i].equals("NA")) {
naIndex = i + 1;
na = tokens[naIndex];
break;
}
}
Double magnification = new Double(mag);
store.setObjectiveNominalMagnification(magnification, 0, 0);
if (na != null) {
na = na.substring(0, 1) + "." + na.substring(1);
store.setObjectiveLensNA(new Double(na), 0, 0);
}
if (naIndex + 1 < tokens.length) {
store.setObjectiveManufacturer(tokens[naIndex + 1], 0, 0);
}
}
// populate LogicalChannel data
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageInstrumentRef(instrumentID, i);
store.setObjectiveSettingsID(objectiveID, i);
for (int c = 0; c < getSizeC(); c++) {
store.setChannelName(channelNames.get(c), i, c);
Length emission = FormatTools.getEmissionWavelength(emWave[c]);
Length excitation = FormatTools.getExcitationWavelength(exWave[c]);
if (emission != null) {
store.setChannelEmissionWavelength(emission, i, c);
}
if (excitation != null) {
store.setChannelExcitationWavelength(excitation, i, c);
}
String detectorID = MetadataTools.createLSID("Detector", 0, c);
store.setDetectorID(detectorID, 0, c);
store.setDetectorSettingsID(detectorID, i, c);
store.setDetectorSettingsGain(gain[c], i, c);
store.setDetectorSettingsOffset(offset[c], i, c);
store.setDetectorSettingsBinning(getBinning(binning), i, c);
}
long firstPlane = 0;
for (int p = 0; p < getImageCount(); p++) {
int[] zct = getZCTCoords(p);
store.setPlaneExposureTime(new Time(exposure[zct[1]], UNITS.SECOND), i, p);
String file = getFilename(i, p);
if (file != null) {
long plane = getTimestamp(file);
if (p == 0) {
firstPlane = plane;
}
double timestamp = (plane - firstPlane) / 1000.0;
store.setPlaneDeltaT(new Time(timestamp, UNITS.SECOND), i, p);
}
}
}
store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
store.setPlateRowNamingConvention(getNamingConvention("Letter"), 0);
store.setPlateColumnNamingConvention(getNamingConvention("Number"), 0);
store.setPlateName(plateName, 0);
store.setPlateDescription(plateDescription, 0);
if (level != MetadataLevel.NO_OVERLAYS) {
parseROIs(store);
}
}
}
use of loci.common.IniList in project bioformats by openmicroscopy.
the class ConfigurationTree method parseConfigFile.
public void parseConfigFile(String configFile) throws IOException {
File file = new File(configFile);
if (file.isDirectory()) {
return;
}
String parent = file.getParent();
if (configDir != null) {
parent = relocateToRoot(parent);
}
configFile = file.getAbsolutePath();
String dir = file.getParentFile().getAbsolutePath();
IniParser parser = new IniParser();
parser.setCommentDelimiter(null);
FileInputStream stream = new FileInputStream(configFile);
IniList iniList = parser.parseINI(new BufferedReader(new InputStreamReader(stream, Constants.ENCODING)));
for (IniTable table : iniList) {
String id = table.get(IniTable.HEADER_KEY);
id = id.substring(0, id.lastIndexOf(" "));
id = new File(parent, id).getAbsolutePath();
DefaultMutableTreeNode node = findNode(id, true, configFile);
if (node == null) {
LOGGER.warn("config file '{}' has invalid filename '{}'", configFile, id);
continue;
}
}
}
Aggregations