use of loci.formats.meta.IMinMaxStore in project bioformats by openmicroscopy.
the class BioRadReader method parseNotes.
private boolean parseNotes(MetadataStore store) throws FormatException {
boolean multipleFiles = false;
int nextDetector = 0, nLasers = 0;
for (Note n : noteStrings) {
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
switch(n.type) {
case NOTE_TYPE_USER:
// TODO : this should be an overlay
addGlobalMetaList("Note", n.toString());
break;
case NOTE_TYPE_SCALEBAR:
// TODO : this should be an overlay
// the format of the text is:
// SCALEBAR = <length> <angle>
// where <length> is the length of the scalebar in microns,
// and <angle> is the angle in degrees
addGlobalMetaList("Note", n.toString());
break;
case NOTE_TYPE_ARROW:
// TODO : this should be an overlay
// the format of the text is:
// ARROW = <lx> <ly> <angle> <fill>
// where <lx> and <ly> define the arrow's bounding box,
// <angle> is the angle in degrees and <fill> is either "Fill" or
// "Outline"
addGlobalMetaList("Note", n.toString());
break;
case NOTE_TYPE_VARIABLE:
if (n.p.indexOf('=') >= 0) {
String key = n.p.substring(0, n.p.indexOf('=')).trim();
String value = n.p.substring(n.p.indexOf('=') + 1).trim();
addGlobalMeta(key, value);
if (key.equals("INFO_OBJECTIVE_NAME")) {
store.setObjectiveModel(value, 0, 0);
} else if (key.equals("INFO_OBJECTIVE_MAGNIFICATION")) {
Double mag = Double.parseDouble(value);
store.setObjectiveNominalMagnification(mag, 0, 0);
} else if (key.equals("LENS_MAGNIFICATION")) {
Double magnification = Double.parseDouble(value);
store.setObjectiveNominalMagnification(magnification, 0, 0);
} else if (key.startsWith("SETTING")) {
if (key.indexOf("_DET_") != -1) {
int index = key.indexOf("_DET_") + 5;
if (key.lastIndexOf("_") > index) {
String detectorID = MetadataTools.createLSID("Detector", 0, nextDetector);
store.setDetectorID(detectorID, 0, nextDetector);
store.setDetectorType(getDetectorType("Other"), 0, nextDetector);
if (key.endsWith("OFFSET")) {
if (nextDetector < offset.size()) {
offset.set(nextDetector, Double.parseDouble(value));
} else {
while (nextDetector > offset.size()) {
offset.add(null);
}
offset.add(new Double(value));
}
} else if (key.endsWith("GAIN")) {
if (nextDetector < gain.size()) {
gain.set(nextDetector, Double.parseDouble(value));
} else {
while (nextDetector > gain.size()) {
gain.add(null);
}
gain.add(new Double(value));
}
}
nextDetector++;
}
}
} else {
String[] values = value.split(" ");
if (values.length > 1) {
try {
int type = Integer.parseInt(values[0]);
if (type == 257 && values.length >= 3) {
// found length of axis in um
Double pixelSize = new Double(values[2]);
if (key.equals("AXIS_2")) {
Length size = FormatTools.getPhysicalSizeX(pixelSize);
if (size != null) {
store.setPixelsPhysicalSizeX(size, 0);
}
} else if (key.equals("AXIS_3")) {
Length size = FormatTools.getPhysicalSizeY(pixelSize);
if (size != null) {
store.setPixelsPhysicalSizeY(size, 0);
}
}
}
} catch (NumberFormatException e) {
}
}
}
} else if (n.p.startsWith("AXIS_2")) {
String[] values = n.p.split(" ");
Double pixelSize = new Double(values[3]);
Length size = FormatTools.getPhysicalSizeX(pixelSize);
if (size != null) {
store.setPixelsPhysicalSizeX(size, 0);
}
} else if (n.p.startsWith("AXIS_3")) {
String[] values = n.p.split(" ");
Double pixelSize = new Double(values[3]);
Length size = FormatTools.getPhysicalSizeY(pixelSize);
if (size != null) {
store.setPixelsPhysicalSizeY(size, 0);
}
} else {
addGlobalMetaList("Note", n.toString());
}
break;
case NOTE_TYPE_STRUCTURE:
int structureType = (n.x & 0xff00) >> 8;
int version = (n.x & 0xff);
String[] values = n.p.split(" ");
if (structureType == 1) {
switch(n.y) {
case 1:
for (int i = 0; i < STRUCTURE_LABELS_1.length; i++) {
addGlobalMeta(STRUCTURE_LABELS_1[i], values[i]);
}
Double mag = Double.parseDouble(values[11]);
store.setObjectiveNominalMagnification(mag, 0, 0);
Double sizeZ = new Double(values[14]);
Length size = FormatTools.getPhysicalSizeZ(sizeZ);
if (size != null) {
store.setPixelsPhysicalSizeZ(size, 0);
}
break;
case 2:
for (int i = 0; i < STRUCTURE_LABELS_2.length; i++) {
addGlobalMeta(STRUCTURE_LABELS_2[i], values[i]);
}
double x1 = Double.parseDouble(values[2]);
double x2 = Double.parseDouble(values[4]);
double width = x2 - x1;
width /= getSizeX();
double y1 = Double.parseDouble(values[3]);
double y2 = Double.parseDouble(values[5]);
double height = y2 - y1;
height /= getSizeY();
Length sizeX = FormatTools.getPhysicalSizeX(width);
Length sizeY = FormatTools.getPhysicalSizeY(height);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
break;
case 3:
for (int i = 0; i < 3; i++) {
for (int j = 0; j < STRUCTURE_LABELS_3.length; j++) {
String v = j == STRUCTURE_LABELS_3.length - 1 ? values[12 + i] : values[i * 4 + j];
addGlobalMetaList(STRUCTURE_LABELS_3[j], v);
}
}
break;
case 4:
nLasers = Integer.parseInt(values[0]);
addGlobalMeta("Number of lasers", values[0]);
addGlobalMeta("Number of transmission detectors", values[1]);
addGlobalMeta("Number of PMTs", values[2]);
for (int i = 1; i <= 3; i++) {
int idx = (i + 1) * 3;
addGlobalMetaList("Shutter present for laser", values[i + 2]);
addGlobalMetaList("Neutral density filter for laser", values[idx]);
addGlobalMetaList("Excitation filter for laser", values[idx + 1]);
addGlobalMetaList("Use laser", values[idx + 2]);
}
for (int i = 0; i < nLasers; i++) {
addGlobalMetaList("Neutral density filter name - laser", values[15 + i]);
}
break;
case 5:
String prefix = "Excitation filter name - laser";
for (int i = 0; i < nLasers; i++) {
addGlobalMetaList(prefix, values[i]);
}
break;
case 6:
prefix = "Emission filter name - laser";
for (int i = 0; i < nLasers; i++) {
addGlobalMeta(prefix, values[i]);
}
break;
case 7:
for (int i = 0; i < 2; i++) {
prefix = "Mixer " + i + " - ";
for (int j = 0; j < STRUCTURE_LABELS_4.length; j++) {
addGlobalMeta(prefix + STRUCTURE_LABELS_4[j], values[i * 7 + j]);
}
}
addGlobalMeta("Mixer 0 - low signal on", values[14]);
addGlobalMeta("Mixer 1 - low signal on", values[15]);
break;
case 8:
case 9:
case 10:
addGlobalMeta("Laser name - laser " + (n.y - 7), values[0]);
break;
case 11:
for (int i = 0; i < 3; i++) {
prefix = "Transmission detector " + (i + 1) + " - ";
addGlobalMeta(prefix + "offset", values[i * 3]);
addGlobalMeta(prefix + "gain", values[i * 3 + 1]);
addGlobalMeta(prefix + "black level", values[i * 3 + 2]);
String detectorID = MetadataTools.createLSID("Detector", 0, i);
store.setDetectorID(detectorID, 0, i);
store.setDetectorOffset(new Double(values[i * 3]), 0, i);
store.setDetectorGain(new Double(values[i * 3 + 1]), 0, i);
store.setDetectorType(getDetectorType("Other"), 0, i);
}
break;
case 12:
for (int i = 0; i < 2; i++) {
prefix = "Part number for ";
for (int j = 0; j < STRUCTURE_LABELS_5.length; j++) {
addGlobalMetaList(prefix + STRUCTURE_LABELS_5[j], values[i * 4 + j]);
}
}
break;
case 13:
for (int i = 0; i < STRUCTURE_LABELS_6.length; i++) {
addGlobalMeta(STRUCTURE_LABELS_6[i], values[i]);
}
break;
case 14:
prefix = "Filter Block Name - filter block ";
addGlobalMetaList(prefix, values[0]);
addGlobalMetaList(prefix, values[1]);
break;
case 15:
for (int i = 0; i < 5; i++) {
addGlobalMetaList("Image bands status - band", values[i * 3]);
addGlobalMetaList("Image bands min - band", values[i * 3 + 1]);
addGlobalMetaList("Image bands max - band", values[i * 3 + 2]);
if (store instanceof IMinMaxStore) {
((IMinMaxStore) store).setChannelGlobalMinMax(i, Double.parseDouble(values[i * 3 + 1]), Double.parseDouble(values[i * 3 + 2]), 0);
}
}
break;
case 17:
int year = Integer.parseInt(values[5]) + 1900;
for (int i = 0; i < 5; i++) {
if (values[i].length() == 1)
values[i] = "0" + values[i];
}
// date is in yyyy-MM-dd'T'HH:mm:ss
String date = year + "-" + values[4] + "-" + values[3] + "T" + values[2] + ":" + values[1] + ":" + values[0];
addGlobalMeta("Acquisition date", date);
try {
store.setImageAcquisitionDate(new Timestamp(date), 0);
} catch (Exception e) {
LOGGER.debug("Failed to parse acquisition date", e);
}
break;
case 18:
addGlobalMeta("Mixer 3 - enhanced", values[0]);
for (int i = 1; i <= 3; i++) {
addGlobalMetaList("Mixer 3 - PMT percentage", values[i]);
addGlobalMetaList("Mixer 3 - Transmission percentage", values[i + 3]);
addGlobalMetaList("Mixer 3 - photon counting", values[i + 7]);
}
addGlobalMeta("Mixer 3 - low signal on", values[7]);
addGlobalMeta("Mixer 3 - mode", values[11]);
break;
case 19:
for (int i = 1; i <= 2; i++) {
prefix = "Mixer " + i + " - ";
String photon = prefix + "photon counting ";
addGlobalMetaList(photon, values[i * 4 - 4]);
addGlobalMetaList(photon, values[i * 4 - 3]);
addGlobalMetaList(photon, values[i * 4 - 2]);
addGlobalMeta(prefix + "mode", values[i * 4 - 1]);
}
break;
case 20:
addGlobalMeta("Display mode", values[0]);
addGlobalMeta("Course", values[1]);
addGlobalMeta("Time Course - experiment type", values[2]);
addGlobalMeta("Time Course - kd factor", values[3]);
String experimentID = MetadataTools.createLSID("Experiment", 0);
store.setExperimentID(experimentID, 0);
store.setExperimentType(getExperimentType(values[2]), 0);
break;
case 21:
addGlobalMeta("Time Course - ion name", values[0]);
break;
case 22:
addGlobalMeta("PIC file generated on Isoscan (lite)", values[0]);
for (int i = 1; i <= 3; i++) {
addGlobalMetaList("Photon counting used - PMT", values[i]);
addGlobalMetaList("Hot spot filter used - PMT", values[i + 3]);
addGlobalMetaList("Tx Selector used - TX", values[i + 6]);
}
break;
}
}
break;
default:
// notes for display only
addGlobalMetaList("Note", n.toString());
}
}
if (n.p.indexOf("AXIS") != -1) {
n.p = n.p.replaceAll("=", "");
final List<String> v = new ArrayList<String>();
StringTokenizer tokens = new StringTokenizer(n.p, " ");
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken().trim();
if (token.length() > 0)
v.add(token);
}
String[] values = v.toArray(new String[v.size()]);
String key = values[0];
String noteType = values[1];
int axisType = Integer.parseInt(noteType);
if (axisType == 11 && values.length > 2) {
addGlobalMeta(key + " RGB type (X)", values[2]);
addGlobalMeta(key + " RGB type (Y)", values[3]);
CoreMetadata m = core.get(0);
if (key.equals("AXIS_4")) {
// this is a single section multi-channel dataset
m.sizeC = getImageCount();
m.sizeZ = 1;
m.sizeT = 1;
} else if (key.equals("AXIS_9")) {
multipleFiles = true;
m.sizeC = (int) Double.parseDouble(values[3]);
}
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM && values.length > 2) {
switch(axisType) {
case 1:
addGlobalMeta(key + " distance (X) in microns", values[2]);
addGlobalMeta(key + " distance (Y) in microns", values[3]);
break;
case 3:
addGlobalMeta(key + " angle (X) in degrees", values[2]);
addGlobalMeta(key + " angle (Y) in degrees", values[3]);
break;
case 4:
addGlobalMeta(key + " intensity (X)", values[2]);
addGlobalMeta(key + " intensity (Y)", values[3]);
break;
case 6:
addGlobalMeta(key + " ratio (X)", values[2]);
addGlobalMeta(key + " ratio (Y)", values[3]);
break;
case 7:
addGlobalMeta(key + " log ratio (X)", values[2]);
addGlobalMeta(key + " log ratio (Y)", values[3]);
break;
case 9:
addGlobalMeta(key + " noncalibrated intensity min", values[2]);
addGlobalMeta(key + " noncalibrated intensity max", values[3]);
addGlobalMeta(key + " calibrated intensity min", values[4]);
addGlobalMeta(key + " calibrated intensity max", values[5]);
break;
case 14:
addGlobalMeta(key + " time course type (X)", values[2]);
addGlobalMeta(key + " time course type (Y)", values[3]);
break;
case 15:
String prefix = " inverse sigmoid calibrated intensity ";
addGlobalMeta(key + prefix + "(min)", values[2]);
addGlobalMeta(key + prefix + "(max)", values[3]);
addGlobalMeta(key + prefix + "(beta)", values[4]);
addGlobalMeta(key + prefix + "(Kd)", values[5]);
break;
case 16:
prefix = " log inverse sigmoid calibrated intensity ";
addGlobalMeta(key + prefix + "(min)", values[2]);
addGlobalMeta(key + prefix + "(max)", values[3]);
addGlobalMeta(key + prefix + "(beta)", values[4]);
addGlobalMeta(key + prefix + "(Kd)", values[5]);
break;
}
}
}
}
return multipleFiles;
}
use of loci.formats.meta.IMinMaxStore in project bioformats by openmicroscopy.
the class DeltavisionReader method initExtraMetadata.
protected void initExtraMetadata() throws FormatException, IOException {
MetadataStore store = makeFilterMetadata();
// --- read in the image header data ---
LOGGER.info("Reading header");
in.seek(16);
int subImageStartX = in.readInt();
int subImageStartY = in.readInt();
int subImageStartZ = in.readInt();
int pixelSamplingX = in.readInt();
int pixelSamplingY = in.readInt();
int pixelSamplingZ = in.readInt();
float pixX = in.readFloat();
float pixY = in.readFloat();
float pixZ = in.readFloat();
float xAxisAngle = in.readFloat();
float yAxisAngle = in.readFloat();
float zAxisAngle = in.readFloat();
int xAxisSeq = in.readInt();
int yAxisSeq = in.readInt();
int zAxisSeq = in.readInt();
float[] minWave = new float[5];
float[] maxWave = new float[5];
minWave[0] = in.readFloat();
maxWave[0] = in.readFloat();
float meanIntensity = in.readFloat();
int spaceGroupNumber = in.readInt();
in.seek(132);
short numSubResSets = in.readShort();
short zAxisReductionQuotient = in.readShort();
for (int i = 1; i <= 3; i++) {
minWave[i] = in.readFloat();
maxWave[i] = in.readFloat();
}
int type = in.readShort();
int lensID = in.readShort();
in.seek(172);
minWave[4] = in.readFloat();
maxWave[4] = in.readFloat();
in.seek(184);
float xTiltAngle = in.readFloat();
float yTiltAngle = in.readFloat();
float zTiltAngle = in.readFloat();
in.skipBytes(2);
short[] waves = new short[5];
for (int i = 0; i < waves.length; i++) {
waves[i] = in.readShort();
}
float xOrigin = in.readFloat();
float yOrigin = in.readFloat();
float zOrigin = in.readFloat();
in.skipBytes(4);
String[] title = new String[10];
for (int i = 0; i < title.length; i++) {
// Make sure that "null" characters are stripped out
title[i] = in.readByteToString(80).replaceAll("\0", "");
}
// --- compute some secondary values ---
String imageType = type < IMAGE_TYPES.length ? IMAGE_TYPES[type] : "unknown";
String imageDesc = title[0];
if (imageDesc != null && imageDesc.length() == 0)
imageDesc = null;
// --- populate original metadata ---
LOGGER.info("Populating original metadata");
addGlobalMeta("Sub-image starting point (X)", subImageStartX);
addGlobalMeta("Sub-image starting point (Y)", subImageStartY);
addGlobalMeta("Sub-image starting point (Z)", subImageStartZ);
addGlobalMeta("Pixel sampling size (X)", pixelSamplingX);
addGlobalMeta("Pixel sampling size (Y)", pixelSamplingY);
addGlobalMeta("Pixel sampling size (Z)", pixelSamplingZ);
addGlobalMeta("X element length (in um)", pixX);
addGlobalMeta("Y element length (in um)", pixY);
addGlobalMeta("Z element length (in um)", pixZ);
addGlobalMeta("X axis angle", xAxisAngle);
addGlobalMeta("Y axis angle", yAxisAngle);
addGlobalMeta("Z axis angle", zAxisAngle);
addGlobalMeta("Column axis sequence", xAxisSeq);
addGlobalMeta("Row axis sequence", yAxisSeq);
addGlobalMeta("Section axis sequence", zAxisSeq);
addGlobalMeta("Image Type", imageType);
addGlobalMeta("Lens ID Number", lensID);
addGlobalMeta("X axis tilt angle", xTiltAngle);
addGlobalMeta("Y axis tilt angle", yTiltAngle);
addGlobalMeta("Z axis tilt angle", zTiltAngle);
for (int i = 0; i < waves.length; i++) {
addGlobalMeta("Wavelength " + (i + 1) + " (in nm)", waves[i]);
}
addGlobalMeta("X origin (in um)", xOrigin);
addGlobalMeta("Y origin (in um)", yOrigin);
addGlobalMeta("Z origin (in um)", zOrigin);
for (String t : title) {
addGlobalMetaList("Title", t);
}
for (int i = 0; i < minWave.length; i++) {
addGlobalMeta("Wavelength " + (i + 1) + " min. intensity", minWave[i]);
addGlobalMeta("Wavelength " + (i + 1) + " max. intensity", maxWave[i]);
}
addGlobalMeta("Wavelength 1 mean intensity", meanIntensity);
addGlobalMeta("Space group number", spaceGroupNumber);
addGlobalMeta("Number of Sub-resolution sets", numSubResSets);
addGlobalMeta("Z axis reduction quotient", zAxisReductionQuotient);
// --- populate OME metadata ---
LOGGER.info("Populating OME metadata");
for (int series = 0; series < getSeriesCount(); series++) {
if (store instanceof IMinMaxStore) {
IMinMaxStore minMaxStore = (IMinMaxStore) store;
for (int i = 0; i < minWave.length; i++) {
if (i < getEffectiveSizeC()) {
minMaxStore.setChannelGlobalMinMax(i, minWave[i], maxWave[i], series);
}
}
}
Double x = new Double(pixX);
Length sizeX = FormatTools.getPhysicalSizeX(x);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, series);
}
Double y = new Double(pixY);
Length sizeY = FormatTools.getPhysicalSizeY(y);
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, series);
}
Double z = new Double(pixZ);
Length sizeZ = FormatTools.getPhysicalSizeZ(z);
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, series);
}
store.setImageDescription(imageDesc, series);
}
populateObjective(store, lensID);
// if matching log file exists, extract key/value pairs from it
boolean logFound = isGroupFiles() ? parseLogFile(store) : false;
if (isGroupFiles())
parseDeconvolutionLog(store);
if (getSeriesCount() == 1) {
xTiles = 1;
yTiles = 1;
backwardsStage = false;
}
for (int series = 0; series < getSeriesCount(); series++) {
int seriesIndex = series;
if (backwardsStage) {
int x = series % xTiles;
int y = series / xTiles;
seriesIndex = (yTiles - y - 1) * xTiles + (xTiles - x - 1);
}
for (int i = 0; i < getImageCount(); i++) {
int[] coords = getZCTCoords(i);
int tIndex = getSeriesCount() * coords[2] + seriesIndex;
DVExtHdrFields hdr = extHdrFields[coords[0]][coords[1]][tIndex];
// plane timing
store.setPlaneDeltaT(new Time(new Double(hdr.timeStampSeconds), UNITS.SECOND), series, i);
store.setPlaneExposureTime(new Time(new Double(extHdrFields[0][coords[1]][0].expTime), UNITS.SECOND), series, i);
// stage position
if (!logFound || getSeriesCount() > 1) {
store.setPlanePositionX(hdr.stageXCoord, series, i);
store.setPlanePositionY(hdr.stageYCoord, series, i);
store.setPlanePositionZ(hdr.stageZCoord, series, i);
}
}
for (int w = 0; w < getSizeC(); w++) {
DVExtHdrFields hdrC = extHdrFields[0][w][series];
Length emission = FormatTools.getEmissionWavelength(new Double(waves[w]));
Length excitation = FormatTools.getExcitationWavelength(new Double(hdrC.exWavelen));
if (emission != null) {
store.setChannelEmissionWavelength(emission, series, w);
}
if (excitation != null) {
store.setChannelExcitationWavelength(excitation, series, w);
}
if (ndFilters[w] == null)
ndFilters[w] = new Double(hdrC.ndFilter);
store.setChannelNDFilter(ndFilters[w], series, w);
}
}
}
Aggregations