use of loci.formats.meta.MetadataStore in project bioformats by openmicroscopy.
the class NikonReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
original = ifds.get(0);
if (cfaPattern != null) {
original.putIFDValue(IFD.COLOR_MAP, (int[]) cfaPattern);
}
ifds.set(0, original);
CoreMetadata m = core.get(0);
m.imageCount = 1;
m.sizeT = 1;
if (ifds.get(0).getSamplesPerPixel() == 1) {
m.interleaved = true;
}
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
}
use of loci.formats.meta.MetadataStore in project bioformats by openmicroscopy.
the class OIRReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
Location current = new Location(id).getAbsoluteFile();
Location parent = current.getParentFile();
ArrayList<String> extraFiles = new ArrayList<String>();
if (parent != null) {
String[] fileList = parent.list();
Arrays.sort(fileList);
String prefix = current.getName();
if (prefix.indexOf(".") > 0) {
prefix = prefix.substring(0, prefix.lastIndexOf("."));
} else if (!checkSuffix(id, "oir")) {
prefix = prefix.substring(0, prefix.lastIndexOf("_"));
}
for (String file : fileList) {
// look for files ending with an underscore plus a 5 digit number
if (file.startsWith(prefix + "_") && file.length() == prefix.length() + 6) {
try {
int index = Integer.parseInt(file.substring(file.lastIndexOf("_") + 1));
if (index != extraFiles.size() + 1) {
LOGGER.warn("Found file {} with index {}; expected index {}", file, index, extraFiles.size() + 1);
}
extraFiles.add(new Location(parent, file).getAbsolutePath());
} catch (NumberFormatException e) {
}
} else if (file.startsWith(prefix) && checkSuffix(file, "oir")) {
current = new Location(parent, file);
currentId = current.getAbsolutePath();
}
}
}
CoreMetadata m = core.get(0);
m.littleEndian = true;
m.sizeZ = 1;
m.sizeC = 1;
m.sizeT = 1;
m.indexed = true;
m.falseColor = true;
try (RandomAccessInputStream s = new RandomAccessInputStream(currentId, BUFFER_SIZE)) {
readPixelsFile(current.getAbsolutePath(), s);
}
for (String file : extraFiles) {
try (RandomAccessInputStream s = new RandomAccessInputStream(file, BUFFER_SIZE)) {
readPixelsFile(file, s);
}
}
m.sizeC *= channels.size();
m.imageCount = getSizeC() * getSizeZ() * getSizeT();
LOGGER.debug("blocks per plane = {}", blocksPerPlane);
LOGGER.debug("number of pixel blocks = {}", pixelBlocks.size());
if (blocksPerPlane * getImageCount() != pixelBlocks.size()) {
// if blocks are missing, set the Z and T dimensions to match the last
// plane for which at least one block exists
int maxZ = 0;
int maxT = 0;
for (String uid : pixelBlocks.keySet()) {
LOGGER.debug(" checking uid = {}", uid);
int thisZ = getZ(uid);
int thisT = getT(uid);
int block = getBlock(uid);
// only count through last full plane
if (block == blocksPerPlane - 1) {
if (thisZ > maxZ) {
maxZ = thisZ;
}
if (thisT > maxT) {
maxT = thisT;
}
if (thisZ < minZ) {
minZ = thisZ;
}
if (thisT < minT) {
minT = thisT;
}
}
}
m.sizeZ = (maxZ - minZ) + 1;
m.sizeT = (maxT - minT) + 1;
m.imageCount = getSizeC() * getSizeZ() * getSizeT();
} else {
minZ = 0;
minT = 0;
}
m.dimensionOrder = "XYC";
if (getSizeZ() == 1 || getSizeT() == 1) {
m.dimensionOrder += "ZT";
} else {
int zIndex = baseName.toLowerCase().indexOf("z");
int tIndex = baseName.toLowerCase().indexOf("t");
if (zIndex < tIndex) {
m.dimensionOrder += "TZ";
} else {
m.dimensionOrder += "ZT";
}
}
pixelUIDs = pixelBlocks.keySet().toArray(new String[pixelBlocks.size()]);
Arrays.sort(pixelUIDs, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
int lastUnderscore1 = s1.lastIndexOf("_");
int lastUnderscore2 = s2.lastIndexOf("_");
Integer block1 = new Integer(s1.substring(lastUnderscore1 + 1));
Integer block2 = new Integer(s2.substring(lastUnderscore2 + 1));
int underscore1 = s1.lastIndexOf("_", lastUnderscore1 - 1);
int underscore2 = s2.lastIndexOf("_", lastUnderscore2 - 1);
String prefix1 = s1.substring(0, underscore1);
String prefix2 = s2.substring(0, underscore2);
String channel1 = s1.substring(underscore1 + 1, lastUnderscore1);
String channel2 = s2.substring(underscore2 + 1, lastUnderscore2);
if (!prefix1.equals(prefix2)) {
return s1.compareTo(s2);
}
if (!channel1.equals(channel2)) {
Integer index1 = -1;
Integer index2 = -2;
for (int i = 0; i < channels.size(); i++) {
if (channels.get(i).id.equals(channel1)) {
index1 = i;
}
if (channels.get(i).id.equals(channel2)) {
index2 = i;
}
}
return index1.compareTo(index2);
}
return block1.compareTo(block2);
}
});
if (LOGGER.isTraceEnabled()) {
for (int i = 0; i < pixelUIDs.length; i++) {
LOGGER.trace("pixel UID #{} = {}", i, pixelUIDs[i]);
}
}
// populate original metadata
Hashtable<String, Object> tmpMeta = new Hashtable<String, Object>();
addMeta("Creation date", acquisitionDate, tmpMeta);
addMeta("Pixel Length X", physicalSizeX, tmpMeta);
addMeta("Pixel Length Y", physicalSizeY, tmpMeta);
addMeta("Z step", physicalSizeZ, tmpMeta);
for (Channel channel : channels) {
String prefix = "Channel " + channel.name + " ";
addMetaList(prefix + "ID", channel.id, tmpMeta);
addMetaList(prefix + "color", channel.color, tmpMeta);
addMetaList(prefix + "pinhole", channel.pinhole, tmpMeta);
addMetaList(prefix + "start wavelength", channel.excitation, tmpMeta);
addMetaList(prefix + "end wavelength", channel.emission, tmpMeta);
addMetaList(prefix + "linked laser index", channel.laserIndex, tmpMeta);
}
for (Objective objective : objectives) {
addMetaList("Objective Lens name", objective.name, tmpMeta);
addMetaList("Objective Lens magnification", objective.magnification, tmpMeta);
addMetaList("Objective Lens na", objective.na, tmpMeta);
addMetaList("Objective Lens wd", objective.wd, tmpMeta);
addMetaList("Objective Lens refractive index", objective.ri, tmpMeta);
addMetaList("Objective Lens immersion", objective.immersion, tmpMeta);
}
for (Laser laser : lasers) {
String prefix = "Laser " + laser.name + " ";
addMetaList(prefix + "ID", laser.id, tmpMeta);
addMetaList(prefix + "data ID", laser.dataId, tmpMeta);
addMetaList(prefix + "power", laser.power, tmpMeta);
addMetaList(prefix + "transmissivity", laser.transmissivity, tmpMeta);
addMetaList(prefix + "wavelength", laser.wavelength, tmpMeta);
}
for (Detector detector : detectors) {
addMetaList("Detector ID", detector.id, tmpMeta);
addMetaList("Detector linked channel ID", detector.channelId, tmpMeta);
addMetaList("Detector voltage", detector.voltage, tmpMeta);
addMetaList("Detector offset", detector.offset, tmpMeta);
addMetaList("Detector gain", detector.gain, tmpMeta);
}
// this ensures that global metadata keys will be sorted before series keys
MetadataTools.merge(tmpMeta, metadata, "- ");
// populate MetadataStore
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
store.setImageInstrumentRef(instrumentID, 0);
for (int i = 0; i < lasers.size(); i++) {
Laser l = lasers.get(i);
String lsid = MetadataTools.createLSID("LightSource", 0, i);
store.setLaserID(lsid, 0, i);
store.setLaserModel(l.id, 0, i);
if (l.wavelength != null) {
store.setLaserWavelength(FormatTools.getWavelength(l.wavelength, null), 0, i);
}
}
for (int i = 0; i < detectors.size(); i++) {
Detector detector = detectors.get(i);
String lsid = MetadataTools.createLSID("Detector", 0, i);
store.setDetectorID(lsid, 0, i);
store.setDetectorOffset(detector.offset, 0, i);
store.setDetectorVoltage(FormatTools.createElectricPotential(detector.voltage, UNITS.VOLT), 0, i);
store.setDetectorGain(detector.gain, 0, i);
}
for (int i = 0; i < objectives.size(); i++) {
Objective objective = objectives.get(i);
String lsid = MetadataTools.createLSID("Objective", 0, i);
store.setObjectiveID(lsid, 0, i);
store.setObjectiveModel(objective.name, 0, i);
store.setObjectiveNominalMagnification(objective.magnification, 0, i);
store.setObjectiveLensNA(objective.na, 0, i);
store.setObjectiveWorkingDistance(FormatTools.createLength(objective.wd, UNITS.MILLIMETRE), 0, i);
store.setObjectiveImmersion(objective.immersion, 0, i);
if (i == 0) {
store.setObjectiveSettingsID(lsid, 0);
store.setObjectiveSettingsRefractiveIndex(objective.ri, 0);
}
}
if (acquisitionDate != null) {
store.setImageAcquisitionDate(acquisitionDate, 0);
}
if (physicalSizeX != null) {
store.setPixelsPhysicalSizeX(physicalSizeX, 0);
}
if (physicalSizeY != null) {
store.setPixelsPhysicalSizeY(physicalSizeY, 0);
}
if (physicalSizeZ != null) {
store.setPixelsPhysicalSizeZ(physicalSizeZ, 0);
}
for (int c = 0; c < channels.size(); c++) {
Channel ch = channels.get(c);
store.setChannelName(ch.name, 0, c);
if (ch.color != null) {
store.setChannelColor(ch.color, 0, c);
}
if (ch.pinhole != null) {
store.setChannelPinholeSize(ch.pinhole, 0, c);
}
if (ch.emission != null) {
store.setChannelEmissionWavelength(ch.emission, 0, c);
}
if (ch.excitation != null) {
store.setChannelExcitationWavelength(ch.excitation, 0, c);
}
for (int d = 0; d < detectors.size(); d++) {
if (detectors.get(d).channelId.equals(ch.id)) {
store.setDetectorSettingsID(MetadataTools.createLSID("Detector", 0, d), 0, c);
}
}
if (ch.laserIndex >= 0 && ch.laserIndex < lasers.size()) {
String laserId = MetadataTools.createLSID("LightSource", 0, ch.laserIndex);
store.setChannelLightSourceSettingsID(laserId, 0, c);
}
}
}
use of loci.formats.meta.MetadataStore in project bioformats by openmicroscopy.
the class OpenlabRawReader 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);
// read the 12 byte file header
LOGGER.info("Verifying Openlab RAW format");
if (!in.readString(4).equals("OLRW")) {
throw new FormatException("Openlab RAW magic string not found.");
}
LOGGER.info("Populating metadata");
CoreMetadata m = core.get(0);
int version = in.readInt();
m.imageCount = in.readInt();
offsets = new int[getImageCount()];
offsets[0] = 12;
in.skipBytes(8);
m.sizeX = in.readInt();
m.sizeY = in.readInt();
in.skipBytes(1);
m.sizeC = in.read();
bytesPerPixel = in.read();
in.skipBytes(1);
long stampMs = in.readLong();
if (stampMs > 0) {
stampMs /= 1000000;
stampMs -= (67 * 365.25 * 24 * 60 * 60);
} else
stampMs = System.currentTimeMillis();
String stamp = DateTools.convertDate(stampMs, DateTools.UNIX);
in.skipBytes(4);
int len = in.read() & 0xff;
String imageName = in.readString(len - 1).trim();
if (getSizeC() <= 1)
m.sizeC = 1;
else
m.sizeC = 3;
int plane = getSizeX() * getSizeY() * bytesPerPixel;
for (int i = 1; i < getImageCount(); i++) {
offsets[i] = offsets[i - 1] + HEADER_SIZE + plane;
}
m.sizeZ = getImageCount();
m.sizeT = 1;
m.rgb = getSizeC() > 1;
m.dimensionOrder = isRGB() ? "XYCZT" : "XYZTC";
m.interleaved = false;
m.littleEndian = false;
m.metadataComplete = true;
m.indexed = false;
m.falseColor = false;
switch(bytesPerPixel) {
case 1:
case 3:
m.pixelType = FormatTools.UINT8;
break;
case 2:
m.pixelType = FormatTools.UINT16;
break;
default:
m.pixelType = FormatTools.FLOAT;
}
addGlobalMeta("Width", getSizeX());
addGlobalMeta("Height", getSizeY());
addGlobalMeta("Bytes per pixel", bytesPerPixel);
addGlobalMeta("Image name", imageName);
addGlobalMeta("Timestamp", stamp);
addGlobalMeta("Version", version);
// The metadata store we're working with.
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
if (stamp != null) {
store.setImageAcquisitionDate(new Timestamp(stamp), 0);
}
store.setImageName(imageName, 0);
}
use of loci.formats.meta.MetadataStore in project bioformats by openmicroscopy.
the class OxfordInstrumentsReader 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);
m.littleEndian = true;
in.order(isLittleEndian());
in.seek(48);
String comment = in.readString(32);
String dateTime = readDate();
in.skipBytes(8);
double xSize = -in.readFloat() + in.readFloat();
in.skipBytes(20);
double ySize = -in.readFloat() + in.readFloat();
in.skipBytes(24);
double zMin = in.readFloat();
double zMax = in.readFloat();
in.skipBytes(864);
m.sizeX = in.readInt();
m.sizeY = in.readInt();
in.skipBytes(28);
if (getSizeX() == 0 && getSizeY() == 0) {
m.sizeX = in.readInt();
m.sizeY = in.readInt();
in.skipBytes(196);
} else
in.skipBytes(204);
m.pixelType = FormatTools.UINT16;
m.sizeZ = 1;
m.sizeC = 1;
m.sizeT = 1;
m.imageCount = 1;
m.rgb = false;
m.indexed = false;
m.dimensionOrder = "XYZCT";
m.interleaved = false;
if (FormatTools.getPlaneSize(this) + in.getFilePointer() > in.length()) {
m.sizeY = 1;
}
int lutSize = in.readInt();
in.skipBytes(lutSize);
headerSize = in.getFilePointer();
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
in.skipBytes(FormatTools.getPlaneSize(this));
int nMetadataStrings = in.readInt();
for (int i = 0; i < nMetadataStrings; i++) {
int length = in.readInt();
String s = in.readString(length);
if (s.indexOf(':') != -1) {
String key = s.substring(0, s.indexOf(':')).trim();
String value = s.substring(s.indexOf(':') + 1).trim();
if (!value.equals("-")) {
addGlobalMeta(key, value);
}
}
}
addGlobalMeta("Description", comment);
addGlobalMeta("Acquisition date", dateTime);
addGlobalMeta("X size (um)", xSize);
addGlobalMeta("Y size (um)", ySize);
addGlobalMeta("Z minimum (um)", zMin);
addGlobalMeta("Z maximum (um)", zMax);
}
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
store.setImageDescription(comment, 0);
if (dateTime != null) {
store.setImageAcquisitionDate(new Timestamp(dateTime), 0);
}
double physicalSizeX = xSize / getSizeX();
double physicalSizeY = ySize / getSizeY();
Length sizeX = FormatTools.getPhysicalSizeX(physicalSizeX);
Length sizeY = FormatTools.getPhysicalSizeY(physicalSizeY);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
}
use of loci.formats.meta.MetadataStore in project bioformats by openmicroscopy.
the class LEOReader method initMetadataStore.
/* @see BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
super.initMetadataStore();
MetadataStore store = makeFilterMetadata();
date = DateTools.formatDate(date, "HH:mm dd-MMM-yyyy");
if (date != null) {
store.setImageAcquisitionDate(new Timestamp(date), 0);
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
Length sizeX = FormatTools.getPhysicalSizeX(xSize);
Length sizeY = FormatTools.getPhysicalSizeY(xSize);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
String instrument = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrument, 0);
store.setImageInstrumentRef(instrument, 0);
store.setObjectiveID(MetadataTools.createLSID("Objective", 0, 0), 0, 0);
store.setObjectiveWorkingDistance(new Length(workingDistance, UNITS.MICROMETER), 0, 0);
store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
}
}
Aggregations