use of loci.formats.meta.MetadataStore in project bioformats by openmicroscopy.
the class JPKReader method initMetadataStore.
/* @see loci.formats.BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
super.initMetadataStore();
MetadataStore store = makeFilterMetadata();
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageName("Series " + (i + 1), i);
}
}
use of loci.formats.meta.MetadataStore in project bioformats by openmicroscopy.
the class KhorosReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
in = new RandomAccessInputStream(id);
in.skipBytes(4);
in.order(true);
int dependency = in.readInt();
addGlobalMeta("Comment", in.readString(512));
in.order(dependency == 4 || dependency == 8);
CoreMetadata m = core.get(0);
m.sizeX = in.readInt();
m.sizeY = in.readInt();
in.skipBytes(28);
m.imageCount = in.readInt();
if (getImageCount() == 0)
m.imageCount = 1;
m.sizeC = in.readInt();
int type = in.readInt();
switch(type) {
case 0:
m.pixelType = FormatTools.INT8;
break;
case 1:
m.pixelType = FormatTools.UINT8;
break;
case 2:
m.pixelType = FormatTools.UINT16;
break;
case 4:
m.pixelType = FormatTools.INT32;
break;
case 5:
m.pixelType = FormatTools.FLOAT;
break;
case 9:
m.pixelType = FormatTools.DOUBLE;
break;
default:
throw new FormatException("Unsupported pixel type : " + type);
}
// read lookup table
in.skipBytes(12);
int c = in.readInt();
if (c > 1) {
m.sizeC = c;
int n = in.readInt();
lut = new byte[c][n];
in.skipBytes(436);
for (int i = 0; i < lut.length; i++) {
for (int j = 0; j < lut[0].length; j++) {
lut[i][j] = in.readByte();
}
}
} else
in.skipBytes(440);
offset = in.getFilePointer();
m.sizeZ = getImageCount();
m.sizeT = 1;
m.rgb = getSizeC() > 1;
m.interleaved = false;
m.littleEndian = dependency == 4 || dependency == 8;
m.dimensionOrder = "XYCZT";
m.indexed = lut != null;
m.falseColor = false;
m.metadataComplete = true;
if (isIndexed()) {
m.sizeC = 1;
m.rgb = false;
}
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
}
use of loci.formats.meta.MetadataStore in project bioformats by openmicroscopy.
the class L2DReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
if (!checkSuffix(id, "l2d") && isGroupFiles()) {
// find the corresponding .l2d file
Location parent = new Location(id).getAbsoluteFile().getParentFile();
parent = parent.getParentFile();
String[] list = parent.list();
for (String file : list) {
if (checkSuffix(file, "l2d")) {
initFile(new Location(parent, file).getAbsolutePath());
return;
}
}
throw new FormatException("Could not find .l2d file");
} else if (!isGroupFiles()) {
super.initFile(id);
tiffs = new String[][] { { id } };
TiffReader r = new TiffReader();
r.setMetadataStore(getMetadataStore());
r.setId(id);
core = new ArrayList<CoreMetadata>(r.getCoreMetadataList());
metadataStore = r.getMetadataStore();
final Map<String, Object> globalMetadata = r.getGlobalMetadata();
for (final Map.Entry<String, Object> entry : globalMetadata.entrySet()) {
addGlobalMeta(entry.getKey(), entry.getValue());
}
r.close();
reader = new MinimalTiffReader();
return;
}
super.initFile(id);
String[] scans = getScanNames();
Location parent = new Location(id).getAbsoluteFile().getParentFile();
// remove scan names that do not correspond to existing directories
final List<String> validScans = new ArrayList<String>();
for (String s : scans) {
Location scanDir = new Location(parent, s);
if (scanDir.exists() && scanDir.isDirectory())
validScans.add(s);
}
scans = validScans.toArray(new String[validScans.size()]);
// read metadata from each scan
tiffs = new String[scans.length][];
metadataFiles = new List[scans.length];
core = new ArrayList<CoreMetadata>(scans.length);
String[] comments = new String[scans.length];
String[] wavelengths = new String[scans.length];
String[] dates = new String[scans.length];
String model = null;
tileWidth = new int[scans.length];
tileHeight = new int[scans.length];
core.clear();
for (int i = 0; i < scans.length; i++) {
CoreMetadata ms = new CoreMetadata();
core.add(ms);
setSeries(i);
metadataFiles[i] = new ArrayList<String>();
String scanName = scans[i] + ".scn";
Location scanDir = new Location(parent, scans[i]);
// read .scn file from each scan
String scanPath = new Location(scanDir, scanName).getAbsolutePath();
addDirectory(scanDir.getAbsolutePath(), i);
String scanData = DataTools.readFile(scanPath);
String[] lines = scanData.split("\n");
for (String line : lines) {
if (!line.startsWith("#")) {
String key = line.substring(0, line.indexOf('='));
String value = line.substring(line.indexOf('=') + 1);
addSeriesMeta(key, value);
if (key.equals("ExperimentNames")) {
// TODO : parse experiment metadata - this is typically a list of
// overlay shapes, or analysis data
} else if (key.equals("ImageNames")) {
tiffs[i] = value.split(",");
for (int t = 0; t < tiffs[i].length; t++) {
tiffs[i][t] = new Location(scanDir, tiffs[i][t].trim()).getAbsolutePath();
}
} else if (key.equals("Comments")) {
comments[i] = value;
} else if (key.equals("ScanDate")) {
dates[i] = value;
} else if (key.equals("ScannerName")) {
model = value;
} else if (key.equals("ScanChannels")) {
wavelengths[i] = value;
}
}
}
}
setSeries(0);
reader = new MinimalTiffReader();
MetadataStore store = makeFilterMetadata();
for (int i = 0; i < getSeriesCount(); i++) {
CoreMetadata ms = core.get(i);
ms.imageCount = tiffs[i].length;
ms.sizeC = tiffs[i].length;
ms.sizeT = 1;
ms.sizeZ = 1;
ms.dimensionOrder = "XYCZT";
reader.setId(tiffs[i][0]);
ms.sizeX = reader.getSizeX();
ms.sizeY = reader.getSizeY();
ms.sizeC *= reader.getSizeC();
ms.rgb = reader.isRGB();
ms.indexed = reader.isIndexed();
ms.littleEndian = reader.isLittleEndian();
ms.pixelType = reader.getPixelType();
tileWidth[i] = reader.getOptimalTileWidth();
tileHeight[i] = reader.getOptimalTileHeight();
}
MetadataTools.populatePixels(store, this);
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageName(scans[i], i);
if (dates[i] != null) {
dates[i] = DateTools.formatDate(dates[i], DATE_FORMAT);
if (dates[i] != null) {
store.setImageAcquisitionDate(new Timestamp(dates[i]), i);
}
}
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageInstrumentRef(instrumentID, i);
store.setImageDescription(comments[i], i);
if (wavelengths[i] != null) {
String[] waves = wavelengths[i].split("[, ]");
if (waves.length < getEffectiveSizeC()) {
LOGGER.debug("Expected {} wavelengths; got {} wavelengths.", getEffectiveSizeC(), waves.length);
}
for (int q = 0; q < waves.length; q++) {
String laser = MetadataTools.createLSID("LightSource", 0, q);
store.setLaserID(laser, 0, q);
Double wave = new Double(waves[q].trim());
Length wavelength = FormatTools.getWavelength(wave);
if (wavelength != null) {
store.setLaserWavelength(wavelength, 0, q);
}
store.setLaserType(getLaserType("Other"), 0, q);
store.setLaserLaserMedium(getLaserMedium("Other"), 0, q);
store.setChannelLightSourceSettingsID(laser, i, q);
}
}
}
store.setMicroscopeModel(model, 0);
store.setMicroscopeType(getMicroscopeType("Other"), 0);
}
}
use of loci.formats.meta.MetadataStore in project bioformats by openmicroscopy.
the class SBIGReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
in = new RandomAccessInputStream(id);
CoreMetadata m = core.get(0);
Double sizeX = null, sizeY = null;
String date = null, description = null;
String[] lines = DataTools.readFile(currentId).split("\n");
for (String line : lines) {
line = line.trim();
int eq = line.indexOf('=');
if (eq != -1) {
String key = line.substring(0, eq).trim();
String value = line.substring(eq + 1).trim();
addGlobalMeta(key, value);
if (key.equals("Width")) {
m.sizeX = Integer.parseInt(value);
} else if (key.equals("Height")) {
m.sizeY = Integer.parseInt(value);
} else if (key.equals("Note")) {
description = value;
} else if (key.equals("X_pixel_size")) {
sizeX = new Double(value) * 1000;
} else if (key.equals("Y_pixel_size")) {
sizeY = new Double(value) * 1000;
} else if (key.equals("Date")) {
date = value;
} else if (key.equals("Time")) {
date += " " + value;
}
} else if (line.indexOf("Compressed") != -1) {
compressed = true;
} else if (line.equals("End"))
break;
}
m.pixelType = FormatTools.UINT16;
m.littleEndian = true;
m.rgb = false;
m.sizeZ = 1;
m.sizeC = 1;
m.sizeT = 1;
m.imageCount = 1;
m.dimensionOrder = "XYZCT";
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
if (date != null) {
date = DateTools.formatDate(date, DATE_FORMAT);
if (date != null) {
store.setImageAcquisitionDate(new Timestamp(date), 0);
}
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
Length x = FormatTools.getPhysicalSizeX(sizeX);
Length y = FormatTools.getPhysicalSizeY(sizeY);
if (x != null) {
store.setPixelsPhysicalSizeX(x, 0);
}
if (y != null) {
store.setPixelsPhysicalSizeY(y, 0);
}
store.setImageDescription(description, 0);
}
}
use of loci.formats.meta.MetadataStore in project bioformats by openmicroscopy.
the class SDTReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
in = new RandomAccessInputStream(id);
in.order(true);
LOGGER.info("Reading header");
// read file header information
info = new SDTInfo(in, metadata);
timeBins = info.timeBins;
channels = info.channels;
addGlobalMeta("time bins", timeBins);
addGlobalMeta("channels", channels);
double timeBase = 1e9 * info.tacR / info.tacG;
addGlobalMeta("time base", timeBase);
LOGGER.info("Populating metadata");
CoreMetadata m = core.get(0);
int timepoints = info.timepoints;
if (timepoints == 0) {
timepoints = 1;
}
m.sizeX = info.width;
m.sizeY = info.height;
m.sizeZ = 1;
m.sizeT = intensity ? timepoints : timeBins * timepoints;
m.sizeC = channels;
m.dimensionOrder = "XYZTC";
m.pixelType = FormatTools.UINT16;
m.rgb = false;
m.littleEndian = true;
m.imageCount = m.sizeZ * m.sizeC * m.sizeT;
m.indexed = false;
m.falseColor = false;
m.metadataComplete = true;
if (intensity) {
m.moduloT.parentType = FormatTools.SPECTRA;
} else {
m.moduloT.type = FormatTools.LIFETIME;
m.moduloT.parentType = FormatTools.SPECTRA;
m.moduloT.typeDescription = "TCSPC";
m.moduloT.start = 0;
timeBase *= 1000;
m.moduloT.step = timeBase / timeBins;
m.moduloT.end = m.moduloT.step * (m.sizeT - 1);
m.moduloT.unit = "ps";
}
for (int i = 1; i < info.allBlockOffsets.length; i++) {
CoreMetadata p = new CoreMetadata(m);
core.add(p);
int planeSize = m.sizeX * m.sizeY * FormatTools.getBytesPerPixel(m.pixelType);
if (info.allBlockLengths[i] != planeSize * m.imageCount) {
if (info.mcstaPoints * planeSize == info.allBlockLengths[i]) {
p.sizeT = info.mcstaPoints;
p.moduloT.end = p.moduloT.step * (p.sizeT - 1);
p.imageCount = p.sizeZ * p.sizeC * p.sizeT;
}
}
}
// Arbitrarily chosen size limit for buffer
int sizeThreshold = 512 * 512 * 512;
// default No of bins in buffer
blockLength = 2048;
while (blockLength * m.sizeX * m.sizeY > sizeThreshold) {
blockLength = blockLength / 2;
}
if (blockLength > timeBins) {
blockLength = timeBins;
}
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
}
Aggregations