use of ome.units.quantity.ElectricPotential in project bioformats by openmicroscopy.
the class MicromanagerReader method populateMetadata.
private void populateMetadata() throws FormatException, IOException {
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, true);
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
for (int i = 0; i < positions.size(); i++) {
Position p = positions.get(i);
if (p.time != null) {
String date = DateTools.formatDate(p.time, DATE_FORMAT);
if (date != null) {
store.setImageAcquisitionDate(new Timestamp(date), i);
}
}
if (positions.size() > 1) {
Location parent = new Location(p.metadataFile).getParentFile();
store.setImageName(parent.getName(), i);
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
store.setImageDescription(p.comment, i);
// link Instrument and Image
store.setImageInstrumentRef(instrumentID, i);
for (int c = 0; c < p.channels.length; c++) {
store.setChannelName(p.channels[c], i, c);
}
Length sizeX = FormatTools.getPhysicalSizeX(p.pixelSize);
Length sizeY = FormatTools.getPhysicalSizeY(p.pixelSize);
Length sizeZ = FormatTools.getPhysicalSizeZ(p.sliceThickness);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, i);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, i);
}
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, i);
}
int nextStamp = 0;
for (int q = 0; q < getImageCount(); q++) {
store.setPlaneExposureTime(p.exposureTime, i, q);
String tiff = positions.get(getSeries()).getFile(q);
if (tiff != null && new Location(tiff).exists() && nextStamp < p.timestamps.length && p.timestamps[nextStamp] != null) {
store.setPlaneDeltaT(new Time(p.timestamps[nextStamp++], UNITS.MILLISECOND), i, q);
}
if (p.positions != null && q < p.positions.length) {
if (p.positions[q][0] != null) {
store.setPlanePositionX(new Length(p.positions[q][0], UNITS.MICROMETER), i, q);
}
if (p.positions[q][1] != null) {
store.setPlanePositionY(new Length(p.positions[q][1], UNITS.MICROMETER), i, q);
}
if (p.positions[q][2] != null) {
store.setPlanePositionZ(new Length(p.positions[q][2], UNITS.MICROMETER), i, q);
}
}
}
String serialNumber = p.detectorID;
p.detectorID = MetadataTools.createLSID("Detector", 0, i);
for (int c = 0; c < p.channels.length; c++) {
store.setDetectorSettingsBinning(getBinning(p.binning), i, c);
store.setDetectorSettingsGain(new Double(p.gain), i, c);
if (c < p.voltage.size()) {
store.setDetectorSettingsVoltage(new ElectricPotential(p.voltage.get(c), UNITS.VOLT), i, c);
}
store.setDetectorSettingsID(p.detectorID, i, c);
}
store.setDetectorID(p.detectorID, 0, i);
if (p.detectorModel != null) {
store.setDetectorModel(p.detectorModel, 0, i);
}
if (serialNumber != null) {
store.setDetectorSerialNumber(serialNumber, 0, i);
}
if (p.detectorManufacturer != null) {
store.setDetectorManufacturer(p.detectorManufacturer, 0, i);
}
if (p.cameraMode == null)
p.cameraMode = "Other";
store.setDetectorType(getDetectorType(p.cameraMode), 0, i);
store.setImagingEnvironmentTemperature(new Temperature(p.temperature, UNITS.CELSIUS), i);
}
}
}
use of ome.units.quantity.ElectricPotential in project bioformats by openmicroscopy.
the class FluoviewReader method initMetadataStore.
/* @see loci.formats.in.BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
super.initMetadataStore();
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, true);
if (date != null) {
store.setImageAcquisitionDate(new Timestamp(date), 0);
}
if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM) {
return;
}
if (ifds.get(0).get(MMHEADER) == null) {
initAlternateMetadataStore();
return;
}
store.setImageDescription(comment, 0);
// link Instrument and Image
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
store.setImageInstrumentRef(instrumentID, 0);
// populate timing data
if (timeIndex >= 0) {
for (int s = 0; s < getSeriesCount(); s++) {
setSeries(s);
for (int i = 0; i < getImageCount(); i++) {
int index = getImageIndex(i);
store.setPlaneDeltaT(new Time(stamps[timeIndex][index], UNITS.SECOND), s, i);
}
}
setSeries(0);
}
// populate Dimensions
for (int i = 0; i < getSeriesCount(); i++) {
Length sizeX = FormatTools.getPhysicalSizeX(voxelX);
Length sizeY = FormatTools.getPhysicalSizeY(voxelY);
Length sizeZ = FormatTools.getPhysicalSizeZ(voxelZ);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, i);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, i);
}
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, i);
}
store.setPixelsTimeIncrement(new Time(voxelT, UNITS.SECOND), i);
int montage = getMontage(i);
int field = getField(i);
double posX = 0d, posY = 0d, posZ = 0d;
if (montageOffsets != null && montage < montageOffsets.length) {
if (montageOffsets[montage].length > 0) {
posX += montageOffsets[montage][0];
}
if (montageOffsets[montage].length > 1) {
posY += montageOffsets[montage][1];
}
if (montageOffsets[montage].length > 2) {
posZ += montageOffsets[montage][2];
}
}
if (fieldOffsets != null && field < fieldOffsets.length) {
if (fieldOffsets[field].length > 0) {
posX += fieldOffsets[field][0];
}
if (fieldOffsets[field].length > 1) {
posY += fieldOffsets[field][1];
}
if (fieldOffsets[field].length > 2) {
posZ += fieldOffsets[field][2];
}
}
for (int image = 0; image < getImageCount(); image++) {
final Length xl = new Length(posX, UNITS.REFERENCEFRAME);
final Length yl = new Length(posY, UNITS.REFERENCEFRAME);
Length zl = new Length(posZ, UNITS.REFERENCEFRAME);
if (zPositions != null && zPositions.length > image) {
zl = new Length(zPositions[image], UNITS.MICROMETER);
}
store.setPlanePositionX(xl, i, image);
store.setPlanePositionY(yl, i, image);
store.setPlanePositionZ(zl, i, image);
}
}
if (channelNames != null) {
for (int i = 0; i < getSizeC(); i++) {
if (channelNames[i] != null) {
store.setChannelName(channelNames[i].trim(), 0, i);
}
}
}
for (int i = 0; i < getSizeC(); i++) {
if (voltages != null && voltages[i] != null) {
store.setDetectorSettingsVoltage(new ElectricPotential(new Double(voltages[i]), UNITS.VOLT), 0, i);
}
if (gains != null && gains[i] != null) {
store.setDetectorSettingsGain(new Double(gains[i]), 0, i);
}
if (offsets != null && offsets[i] != null) {
store.setDetectorSettingsOffset(new Double(offsets[i]), 0, i);
}
store.setDetectorType(getDetectorType("Other"), 0, i);
if (detectorManufacturer != null) {
store.setDetectorManufacturer(detectorManufacturer, 0, i);
}
// link DetectorSettings to an actual Detector
String detectorID = MetadataTools.createLSID("Detector", 0, i);
store.setDetectorID(detectorID, 0, i);
store.setDetectorSettingsID(detectorID, 0, i);
}
if (mag != null && mag.toLowerCase().endsWith("x")) {
mag = mag.substring(0, mag.length() - 1);
} else if (mag == null)
mag = "1";
store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
if (objectiveManufacturer != null) {
String[] objectiveData = objectiveManufacturer.split(" ");
store.setObjectiveModel(objectiveData[0], 0, 0);
if (objectiveData.length > 2) {
store.setObjectiveImmersion(getImmersion(objectiveData[2]), 0, 0);
}
}
if (mag != null) {
store.setObjectiveCalibratedMagnification(new Double(mag), 0, 0);
}
if (lensNA != null) {
for (int i = 0; i < getSizeC(); i++) {
if (lensNA[i] != null) {
store.setObjectiveLensNA(new Double(lensNA[i]), 0, i);
}
}
}
// link Objective to Image using ObjectiveSettings
String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
store.setObjectiveID(objectiveID, 0, 0);
store.setObjectiveSettingsID(objectiveID, 0);
}
use of ome.units.quantity.ElectricPotential in project bioformats by openmicroscopy.
the class NikonElementsTiffReader method initMetadataStore.
/* @see BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
super.initMetadataStore();
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, true);
String date = handler.getDate();
if (date != null) {
store.setImageAcquisitionDate(new Timestamp(date), 0);
}
if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM) {
return;
}
Length sizeX = FormatTools.getPhysicalSizeX(handler.getPixelSizeX());
Length sizeY = FormatTools.getPhysicalSizeY(handler.getPixelSizeY());
Length sizeZ = FormatTools.getPhysicalSizeZ(handler.getPixelSizeZ());
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, 0);
}
String instrument = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrument, 0);
store.setImageInstrumentRef(instrument, 0);
ArrayList<Double> exposureTimes = handler.getExposureTimes();
ArrayList<Length> posX = handler.getXPositions();
ArrayList<Length> posY = handler.getYPositions();
ArrayList<Length> posZ = handler.getZPositions();
for (int i = 0; i < getImageCount(); i++) {
int c = getZCTCoords(i)[1];
if (c < exposureTimes.size() && exposureTimes.get(c) != null) {
store.setPlaneExposureTime(new Time(exposureTimes.get(c), UNITS.SECOND), 0, i);
}
if (i < posX.size()) {
store.setPlanePositionX(posX.get(i), 0, i);
}
if (i < posY.size()) {
store.setPlanePositionY(posY.get(i), 0, i);
}
if (i < posZ.size()) {
store.setPlanePositionZ(posZ.get(i), 0, i);
}
}
String detector = MetadataTools.createLSID("Detector", 0, 0);
store.setDetectorID(detector, 0, 0);
store.setDetectorModel(handler.getCameraModel(), 0, 0);
store.setDetectorType(getDetectorType("Other"), 0, 0);
ArrayList<String> channelNames = handler.getChannelNames();
ArrayList<String> modality = handler.getModalities();
ArrayList<String> binning = handler.getBinnings();
ArrayList<Double> speed = handler.getSpeeds();
ArrayList<Double> gain = handler.getGains();
ArrayList<Double> temperature = handler.getTemperatures();
ArrayList<Double> exWave = handler.getExcitationWavelengths();
ArrayList<Double> emWave = handler.getEmissionWavelengths();
ArrayList<Integer> power = handler.getPowers();
ArrayList<Hashtable<String, String>> rois = handler.getROIs();
Double pinholeSize = handler.getPinholeSize();
for (int c = 0; c < getEffectiveSizeC(); c++) {
if (pinholeSize != null) {
store.setChannelPinholeSize(new Length(pinholeSize, UNITS.MICROMETER), 0, c);
}
if (c < channelNames.size()) {
store.setChannelName(channelNames.get(c), 0, c);
}
if (c < modality.size()) {
store.setChannelAcquisitionMode(getAcquisitionMode(modality.get(c)), 0, c);
}
if (c < emWave.size()) {
Length em = FormatTools.getEmissionWavelength(emWave.get(c));
if (em != null) {
store.setChannelEmissionWavelength(em, 0, c);
}
}
if (c < exWave.size()) {
Length ex = FormatTools.getExcitationWavelength(exWave.get(c));
if (ex != null) {
store.setChannelExcitationWavelength(ex, 0, c);
}
}
if (c < binning.size()) {
store.setDetectorSettingsBinning(getBinning(binning.get(c)), 0, c);
}
if (c < gain.size()) {
store.setDetectorSettingsGain(gain.get(c), 0, c);
}
if (c < speed.size()) {
store.setDetectorSettingsReadOutRate(new Frequency(speed.get(c), UNITS.HERTZ), 0, c);
}
store.setDetectorSettingsID(detector, 0, c);
}
if (temperature.size() > 0) {
store.setImagingEnvironmentTemperature(new Temperature(temperature.get(0), UNITS.CELSIUS), 0);
}
Double voltage = handler.getVoltage();
if (voltage != null) {
store.setDetectorSettingsVoltage(new ElectricPotential(voltage, UNITS.VOLT), 0, 0);
}
Double na = handler.getNumericalAperture();
if (na != null)
store.setObjectiveLensNA(na, 0, 0);
Double mag = handler.getMagnification();
if (mag != null)
store.setObjectiveCalibratedMagnification(mag, 0, 0);
store.setObjectiveModel(handler.getObjectiveModel(), 0, 0);
String immersion = handler.getImmersion();
if (immersion == null)
immersion = "Other";
store.setObjectiveImmersion(getImmersion(immersion), 0, 0);
String correction = handler.getCorrection();
if (correction == null || correction.length() == 0)
correction = "Other";
store.setObjectiveCorrection(getCorrection(correction), 0, 0);
String objective = MetadataTools.createLSID("Objective", 0, 0);
store.setObjectiveID(objective, 0, 0);
store.setObjectiveSettingsID(objective, 0);
Double refractiveIndex = handler.getRefractiveIndex();
if (refractiveIndex != null) {
store.setObjectiveSettingsRefractiveIndex(refractiveIndex, 0);
}
if (getMetadataOptions().getMetadataLevel() == MetadataLevel.NO_OVERLAYS) {
return;
}
handler.populateROIs(store);
}
use of ome.units.quantity.ElectricPotential in project bioformats by openmicroscopy.
the class LeicaHandler method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
if (attributes.getLength() > 0 && !qName.equals("Element") && !qName.equals("Attachment") && !qName.equals("LMSDataContainerHeader")) {
nameStack.push(qName);
}
int oldSeriesCount = numDatasets;
Hashtable h = getSeriesHashtable(numDatasets);
if (qName.equals("LDM_Block_Sequential_Master")) {
canParse = false;
} else if (qName.startsWith("LDM")) {
linkedInstruments = true;
}
if (!canParse)
return;
final StringBuilder key = new StringBuilder();
final Iterator<String> nameStackIterator = nameStack.descendingIterator();
while (nameStackIterator.hasNext()) {
final String k = nameStackIterator.next();
key.append(k);
key.append("|");
}
String suffix = attributes.getValue("Identifier");
String value = attributes.getValue("Variant");
if (suffix == null)
suffix = attributes.getValue("Description");
if (level != MetadataLevel.MINIMUM) {
if (suffix != null && value != null) {
storeKeyValue(h, key.toString() + suffix, value);
} else {
for (int i = 0; i < attributes.getLength(); i++) {
String name = attributes.getQName(i);
storeKeyValue(h, key.toString() + name, attributes.getValue(i));
}
}
}
if (qName.equals("Element")) {
elementName = attributes.getValue("Name");
} else if (qName.equals("Collection")) {
collection = elementName;
} else if (qName.equals("Image")) {
if (!linkedInstruments && level != MetadataLevel.MINIMUM) {
int c = 0;
for (Detector d : detectors) {
String id = MetadataTools.createLSID("Detector", numDatasets, detectorChannel);
store.setDetectorID(id, numDatasets, detectorChannel);
try {
DetectorTypeEnumHandler handler = new DetectorTypeEnumHandler();
store.setDetectorType((DetectorType) handler.getEnumeration(d.type), numDatasets, detectorChannel);
} catch (EnumerationException e) {
}
store.setDetectorModel(d.model, numDatasets, detectorChannel);
store.setDetectorZoom(d.zoom, numDatasets, detectorChannel);
store.setDetectorOffset(d.offset, numDatasets, detectorChannel);
store.setDetectorVoltage(new ElectricPotential(d.voltage, UNITS.VOLT), numDatasets, detectorChannel);
if (c < numChannels) {
if (d.active) {
store.setDetectorSettingsOffset(d.offset, numDatasets, c);
store.setDetectorSettingsID(id, numDatasets, c);
c++;
}
}
detectorChannel++;
}
int filter = 0;
for (int i = 0; i < nextFilter; i++) {
while (filter < detectors.size() && !detectors.get(filter).active) {
filter++;
}
if (filter >= detectors.size() || filter >= nextFilter)
break;
String id = MetadataTools.createLSID("Filter", numDatasets, filter);
if (i < numChannels && detectors.get(filter).active) {
String lsid = MetadataTools.createLSID("Channel", numDatasets, i);
store.setChannelID(lsid, numDatasets, i);
store.setLightPathEmissionFilterRef(id, numDatasets, i, 0);
}
filter++;
}
}
core.add(new CoreMetadata());
numDatasets++;
laserCount = 0;
linkedInstruments = false;
detectorChannel = 0;
detectors.clear();
lasers.clear();
nextFilter = 0;
String name = elementName;
if (collection != null)
name = collection + "/" + name;
store.setImageName(name, numDatasets);
h = getSeriesHashtable(numDatasets);
storeKeyValue(h, "Image name", name);
storeSeriesHashtable(numDatasets, h);
String instrumentID = MetadataTools.createLSID("Instrument", numDatasets);
store.setInstrumentID(instrumentID, numDatasets);
store.setImageInstrumentRef(instrumentID, numDatasets);
numChannels = 0;
extras = 1;
} else if (qName.equals("Attachment") && level != MetadataLevel.MINIMUM) {
if ("ContextDescription".equals(attributes.getValue("Name"))) {
store.setImageDescription(attributes.getValue("Content"), numDatasets);
}
} else if (qName.equals("ChannelDescription")) {
count++;
numChannels++;
lutNames.add(attributes.getValue("LUTName"));
String bytesInc = attributes.getValue("BytesInc");
int bytes = bytesInc == null ? 0 : Integer.parseInt(bytesInc);
if (bytes > 0) {
bytesPerAxis.put(new Integer(bytes), "C");
}
} else if (qName.equals("DimensionDescription")) {
int len = Integer.parseInt(attributes.getValue("NumberOfElements"));
int id = Integer.parseInt(attributes.getValue("DimID"));
double physicalLen = Double.parseDouble(attributes.getValue("Length"));
String unit = attributes.getValue("Unit");
int nBytes = Integer.parseInt(attributes.getValue("BytesInc"));
physicalLen /= len;
if (unit.equals("Ks")) {
physicalLen /= 1000;
} else if (unit.equals("m")) {
physicalLen *= 1000000;
}
Double physicalSize = new Double(physicalLen);
CoreMetadata coreMeta = core.get(core.size() - 1);
switch(id) {
case // X axis
1:
coreMeta.sizeX = len;
coreMeta.rgb = (nBytes % 3) == 0;
if (coreMeta.rgb)
nBytes /= 3;
switch(nBytes) {
case 1:
coreMeta.pixelType = FormatTools.UINT8;
break;
case 2:
coreMeta.pixelType = FormatTools.UINT16;
break;
case 4:
coreMeta.pixelType = FormatTools.FLOAT;
break;
}
physicalSizeX = physicalSize.doubleValue();
Length sizeX = FormatTools.getPhysicalSizeX(physicalSize);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, numDatasets);
}
break;
case // Y axis
2:
if (coreMeta.sizeY != 0) {
if (coreMeta.sizeZ == 1) {
coreMeta.sizeZ = len;
bytesPerAxis.put(new Integer(nBytes), "Z");
} else if (coreMeta.sizeT == 1) {
coreMeta.sizeT = len;
bytesPerAxis.put(new Integer(nBytes), "T");
}
} else {
coreMeta.sizeY = len;
physicalSizeY = physicalSize.doubleValue();
Length sizeY = FormatTools.getPhysicalSizeY(physicalSize);
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, numDatasets);
}
}
break;
case // Z axis
3:
if (coreMeta.sizeY == 0) {
// XZ scan - swap Y and Z
coreMeta.sizeY = len;
coreMeta.sizeZ = 1;
physicalSizeY = physicalSize.doubleValue();
Length sizeY = FormatTools.getPhysicalSizeY(physicalSize);
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, numDatasets);
}
bytesPerAxis.put(new Integer(nBytes), "Y");
} else {
coreMeta.sizeZ = len;
bytesPerAxis.put(new Integer(nBytes), "Z");
}
break;
case // T axis
4:
if (coreMeta.sizeY == 0) {
// XT scan - swap Y and T
coreMeta.sizeY = len;
coreMeta.sizeT = 1;
physicalSizeY = physicalSize.doubleValue();
Length sizeY = FormatTools.getPhysicalSizeY(physicalSize);
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, numDatasets);
}
bytesPerAxis.put(new Integer(nBytes), "Y");
} else {
coreMeta.sizeT = len;
bytesPerAxis.put(new Integer(nBytes), "T");
}
break;
default:
extras *= len;
}
count++;
} else if (qName.equals("ScannerSettingRecord") && level != MetadataLevel.MINIMUM) {
String id = attributes.getValue("Identifier");
if (id == null)
id = "";
if (id.equals("SystemType")) {
store.setMicroscopeModel(value, numDatasets);
store.setMicroscopeType(MicroscopeType.OTHER, numDatasets);
} else if (id.equals("dblPinhole")) {
pinhole = new Double(Double.parseDouble(value) * 1000000);
} else if (id.equals("dblZoom")) {
zoom = new Double(value);
} else if (id.equals("dblStepSize")) {
double zStep = Double.parseDouble(value) * 1000000;
Length sizeZ = FormatTools.getPhysicalSizeZ(zStep);
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, numDatasets);
}
} else if (id.equals("nDelayTime_s")) {
Double timeIncrement = new Double(value);
if (timeIncrement != null) {
store.setPixelsTimeIncrement(new Time(timeIncrement, UNITS.SECOND), numDatasets);
}
} else if (id.equals("CameraName")) {
store.setDetectorModel(value, numDatasets, 0);
} else if (id.indexOf("WFC") == 1) {
int c = 0;
try {
c = Integer.parseInt(id.replaceAll("\\D", ""));
} catch (NumberFormatException e) {
}
Channel channel = channels.get(numDatasets + "-" + c);
if (channel == null)
channel = new Channel();
if (id.endsWith("ExposureTime") && c < numChannels) {
try {
Double exposureTime = new Double(value);
if (exposureTime != null) {
store.setPlaneExposureTime(new Time(exposureTime, UNITS.SECOND), numDatasets, c);
}
} catch (IndexOutOfBoundsException e) {
}
} else if (id.endsWith("Gain")) {
channel.gain = new Double(value);
String detectorID = MetadataTools.createLSID("Detector", numDatasets, 0);
channel.detector = detectorID;
store.setDetectorID(detectorID, numDatasets, 0);
store.setDetectorType(DetectorType.CCD, numDatasets, 0);
} else if (id.endsWith("WaveLength")) {
Double exWave = new Double(value);
Length ex = FormatTools.getExcitationWavelength(exWave);
if (ex != null) {
channel.exWave = ex;
}
} else // NB: "UesrDefName" is not a typo.
if (id.endsWith("UesrDefName") && !value.equals("None")) {
channel.name = value;
}
channels.put(numDatasets + "-" + c, channel);
}
} else if (qName.equals("FilterSettingRecord") && level != MetadataLevel.MINIMUM) {
String object = attributes.getValue("ObjectName");
String attribute = attributes.getValue("Attribute");
String objectClass = attributes.getValue("ClassName");
String variant = attributes.getValue("Variant");
CoreMetadata coreMeta = core.get(numDatasets);
if (attribute.equals("NumericalAperture")) {
store.setObjectiveLensNA(new Double(variant), numDatasets, 0);
} else if (attribute.equals("OrderNumber")) {
store.setObjectiveSerialNumber(variant, numDatasets, 0);
} else if (objectClass.equals("CDetectionUnit")) {
if (attribute.equals("State")) {
Detector d = new Detector();
String data = attributes.getValue("data");
if (data == null)
data = attributes.getValue("Data");
d.channel = data == null ? 0 : Integer.parseInt(data);
d.type = "PMT";
d.model = object;
d.active = variant.equals("Active");
d.zoom = zoom;
detectors.add(d);
} else if (attribute.equals("HighVoltage")) {
Detector d = detectors.get(detectors.size() - 1);
d.voltage = new Double(variant);
} else if (attribute.equals("VideoOffset")) {
Detector d = detectors.get(detectors.size() - 1);
d.offset = new Double(variant);
}
} else if (attribute.equals("Objective")) {
StringTokenizer tokens = new StringTokenizer(variant, " ");
boolean foundMag = false;
final StringBuilder model = new StringBuilder();
while (!foundMag) {
String token = tokens.nextToken();
int x = token.indexOf('x');
if (x != -1) {
foundMag = true;
Double mag = Double.parseDouble(token.substring(0, x));
String na = token.substring(x + 1);
store.setObjectiveNominalMagnification(mag, numDatasets, 0);
store.setObjectiveLensNA(new Double(na), numDatasets, 0);
} else {
model.append(token);
model.append(" ");
}
}
String immersion = "Other";
if (tokens.hasMoreTokens()) {
immersion = tokens.nextToken();
if (immersion == null || immersion.trim().equals("")) {
immersion = "Other";
}
}
try {
ImmersionEnumHandler handler = new ImmersionEnumHandler();
store.setObjectiveImmersion((Immersion) handler.getEnumeration(immersion), numDatasets, 0);
} catch (EnumerationException e) {
}
String correction = "Other";
if (tokens.hasMoreTokens()) {
correction = tokens.nextToken();
if (correction == null || correction.trim().equals("")) {
correction = "Other";
}
}
try {
CorrectionEnumHandler handler = new CorrectionEnumHandler();
store.setObjectiveCorrection((Correction) handler.getEnumeration(correction), numDatasets, 0);
} catch (EnumerationException e) {
}
store.setObjectiveModel(model.toString().trim(), numDatasets, 0);
} else if (attribute.equals("RefractionIndex")) {
String id = MetadataTools.createLSID("Objective", numDatasets, 0);
store.setObjectiveID(id, numDatasets, 0);
store.setObjectiveSettingsID(id, numDatasets);
store.setObjectiveSettingsRefractiveIndex(new Double(variant), numDatasets);
} else if (attribute.equals("XPos")) {
int c = coreMeta.rgb || coreMeta.sizeC == 0 ? 1 : coreMeta.sizeC;
int nPlanes = coreMeta.imageCount;
final Double posXn = Double.valueOf(variant);
final Length posXl = new Length(posXn, UNITS.REFERENCEFRAME);
for (int image = 0; image < nPlanes; image++) {
store.setPlanePositionX(posXl, numDatasets, image);
}
if (numChannels == 0)
xPos.add(posXl);
} else if (attribute.equals("YPos")) {
int c = coreMeta.rgb || coreMeta.sizeC == 0 ? 1 : coreMeta.sizeC;
int nPlanes = coreMeta.imageCount;
final Double posYn = Double.valueOf(variant);
final Length posYl = new Length(posYn, UNITS.REFERENCEFRAME);
for (int image = 0; image < nPlanes; image++) {
store.setPlanePositionY(posYl, numDatasets, image);
}
if (numChannels == 0)
yPos.add(posYl);
} else if (attribute.equals("ZPos")) {
int c = coreMeta.rgb || coreMeta.sizeC == 0 ? 1 : coreMeta.sizeC;
int nPlanes = coreMeta.imageCount;
final Double posZn = Double.valueOf(variant);
final Length posZl = new Length(posZn, UNITS.REFERENCEFRAME);
for (int image = 0; image < nPlanes; image++) {
store.setPlanePositionZ(posZl, numDatasets, image);
}
if (numChannels == 0)
zPos.add(posZl);
} else if (objectClass.equals("CSpectrophotometerUnit")) {
Double v = null;
try {
v = Double.parseDouble(variant);
} catch (NumberFormatException e) {
}
if (attributes.getValue("Description").endsWith("(left)")) {
String id = MetadataTools.createLSID("Filter", numDatasets, nextFilter);
store.setFilterID(id, numDatasets, nextFilter);
store.setFilterModel(object, numDatasets, nextFilter);
Length in = FormatTools.getCutIn(v);
if (in != null) {
store.setTransmittanceRangeCutIn(in, numDatasets, nextFilter);
}
} else if (attributes.getValue("Description").endsWith("(right)")) {
Length out = FormatTools.getCutOut(v);
if (out != null) {
store.setTransmittanceRangeCutOut(out, numDatasets, nextFilter);
nextFilter++;
}
}
}
} else if (qName.equals("Detector") && level != MetadataLevel.MINIMUM) {
String v = attributes.getValue("Gain");
Double gain = v == null ? null : new Double(v);
v = attributes.getValue("Offset");
Double offset = v == null ? null : new Double(v);
boolean active = "1".equals(attributes.getValue("IsActive"));
if (active) {
// find the corresponding MultiBand and Detector
MultiBand m = null;
Detector detector = null;
Laser laser = lasers.isEmpty() ? null : lasers.get(lasers.size() - 1);
String c = attributes.getValue("Channel");
int channel = c == null ? 0 : Integer.parseInt(c);
for (MultiBand mb : multiBands) {
if (mb.channel == channel) {
m = mb;
break;
}
}
for (Detector d : detectors) {
if (d.channel == channel) {
detector = d;
break;
}
}
String id = MetadataTools.createLSID("Detector", numDatasets, nextChannel);
if (m != null) {
String channelID = MetadataTools.createLSID("Channel", numDatasets, nextChannel);
store.setChannelID(channelID, numDatasets, nextChannel);
store.setChannelName(m.dyeName, numDatasets, nextChannel);
String filter = MetadataTools.createLSID("Filter", numDatasets, nextFilter);
store.setFilterID(filter, numDatasets, nextFilter);
Length in = FormatTools.getCutIn(m.cutIn);
Length out = FormatTools.getCutOut(m.cutOut);
if (in != null) {
store.setTransmittanceRangeCutIn(in, numDatasets, nextFilter);
}
if (out != null) {
store.setTransmittanceRangeCutOut(out, numDatasets, nextFilter);
}
store.setLightPathEmissionFilterRef(filter, numDatasets, nextChannel, 0);
nextFilter++;
store.setDetectorID(id, numDatasets, nextChannel);
store.setDetectorType(DetectorType.PMT, numDatasets, nextChannel);
store.setDetectorSettingsGain(gain, numDatasets, nextChannel);
store.setDetectorSettingsOffset(offset, numDatasets, nextChannel);
store.setDetectorSettingsID(id, numDatasets, nextChannel);
}
store.setDetectorID(id, numDatasets, nextChannel);
if (detector != null) {
store.setDetectorSettingsGain(gain, numDatasets, nextChannel);
store.setDetectorSettingsOffset(offset, numDatasets, nextChannel);
store.setDetectorSettingsID(id, numDatasets, nextChannel);
try {
DetectorTypeEnumHandler handler = new DetectorTypeEnumHandler();
store.setDetectorType((DetectorType) handler.getEnumeration(detector.type), numDatasets, nextChannel);
} catch (EnumerationException e) {
}
store.setDetectorModel(detector.model, numDatasets, nextChannel);
store.setDetectorZoom(detector.zoom, numDatasets, nextChannel);
store.setDetectorOffset(detector.offset, numDatasets, nextChannel);
store.setDetectorVoltage(new ElectricPotential(detector.voltage, UNITS.VOLT), numDatasets, nextChannel);
}
if (laser != null && laser.intensity < 100) {
store.setChannelLightSourceSettingsID(laser.id, numDatasets, nextChannel);
store.setChannelLightSourceSettingsAttenuation(new PercentFraction((float) laser.intensity / 100f), numDatasets, nextChannel);
Length wavelength = FormatTools.getExcitationWavelength(laser.wavelength);
if (wavelength != null) {
store.setChannelExcitationWavelength(wavelength, numDatasets, nextChannel);
}
}
nextChannel++;
}
} else if (qName.equals("LaserLineSetting") && level != MetadataLevel.MINIMUM) {
Laser l = new Laser();
String lineIndex = attributes.getValue("LineIndex");
String qual = attributes.getValue("Qualifier");
l.index = lineIndex == null ? 0 : Integer.parseInt(lineIndex);
int qualifier = qual == null ? 0 : Integer.parseInt(qual);
l.index += (2 - (qualifier / 10));
if (l.index < 0)
l.index = 0;
l.id = MetadataTools.createLSID("LightSource", numDatasets, l.index);
l.wavelength = new Double(attributes.getValue("LaserLine"));
while (l.index > laserCount) {
String lsid = MetadataTools.createLSID("LightSource", numDatasets, laserCount);
store.setLaserID(lsid, numDatasets, laserCount);
laserCount++;
}
store.setLaserID(l.id, numDatasets, l.index);
laserCount++;
Length wavelength = FormatTools.getWavelength(l.wavelength);
if (wavelength != null) {
store.setLaserWavelength(wavelength, numDatasets, l.index);
}
store.setLaserType(LaserType.OTHER, numDatasets, l.index);
store.setLaserLaserMedium(LaserMedium.OTHER, numDatasets, l.index);
String intensity = attributes.getValue("IntensityDev");
l.intensity = intensity == null ? 0d : Double.parseDouble(intensity);
if (l.intensity > 0) {
l.intensity = 100d - l.intensity;
lasers.add(l);
}
} else if (qName.equals("TimeStamp") && numDatasets >= 0) {
String stampHigh = attributes.getValue("HighInteger");
String stampLow = attributes.getValue("LowInteger");
long high = stampHigh == null ? 0 : Long.parseLong(stampHigh);
long low = stampLow == null ? 0 : Long.parseLong(stampLow);
long ms = DateTools.getMillisFromTicks(high, low);
if (count == 0) {
String date = DateTools.convertDate(ms, DateTools.COBOL);
Timestamp timestamp = Timestamp.valueOf(date);
if (timestamp != null && timestamp.asInstant().getMillis() < System.currentTimeMillis()) {
store.setImageAcquisitionDate(new Timestamp(date), numDatasets);
}
firstStamp = ms;
store.setPlaneDeltaT(new Time(0.0, UNITS.SECOND), numDatasets, count);
} else if (level != MetadataLevel.MINIMUM) {
CoreMetadata coreMeta = core.get(numDatasets);
int nImages = coreMeta.sizeZ * coreMeta.sizeT * coreMeta.sizeC;
if (count < nImages) {
ms -= firstStamp;
store.setPlaneDeltaT(new Time(ms / 1000.0, UNITS.SECOND), numDatasets, count);
}
}
count++;
} else if (qName.equals("RelTimeStamp") && level != MetadataLevel.MINIMUM) {
CoreMetadata coreMeta = core.get(numDatasets);
int nImages = coreMeta.sizeZ * coreMeta.sizeT * coreMeta.sizeC;
if (count < nImages) {
Double time = new Double(attributes.getValue("Time"));
if (time != null) {
store.setPlaneDeltaT(new Time(time, UNITS.SECOND), numDatasets, count++);
}
}
} else if (qName.equals("Annotation") && level != MetadataLevel.MINIMUM) {
roi = new ROI();
String type = attributes.getValue("type");
if (type != null)
roi.type = Integer.parseInt(type);
String color = attributes.getValue("color");
if (color != null)
roi.color = Integer.parseInt(color);
roi.name = attributes.getValue("name");
roi.fontName = attributes.getValue("fontName");
roi.fontSize = attributes.getValue("fontSize");
roi.transX = parseDouble(attributes.getValue("transTransX"));
roi.transY = parseDouble(attributes.getValue("transTransY"));
roi.scaleX = parseDouble(attributes.getValue("transScalingX"));
roi.scaleY = parseDouble(attributes.getValue("transScalingY"));
roi.rotation = parseDouble(attributes.getValue("transRotation"));
String linewidth = attributes.getValue("linewidth");
if (linewidth != null)
roi.linewidth = Integer.parseInt(linewidth);
roi.text = attributes.getValue("text");
} else if (qName.equals("Vertex") && level != MetadataLevel.MINIMUM) {
String x = attributes.getValue("x");
String y = attributes.getValue("y");
if (x != null) {
x = x.replaceAll(",", ".");
roi.x.add(new Double(x));
}
if (y != null) {
y = y.replaceAll(",", ".");
roi.y.add(new Double(y));
}
} else if (qName.equals("ROI")) {
alternateCenter = true;
} else if (qName.equals("MultiBand") && level != MetadataLevel.MINIMUM) {
MultiBand m = new MultiBand();
m.dyeName = attributes.getValue("DyeName");
m.channel = Integer.parseInt(attributes.getValue("Channel"));
m.cutIn = (double) Math.round(Double.parseDouble(attributes.getValue("LeftWorld")));
m.cutOut = (double) Math.round(Double.parseDouble(attributes.getValue("RightWorld")));
multiBands.add(m);
} else if (qName.equals("ChannelInfo")) {
int index = Integer.parseInt(attributes.getValue("Index"));
channels.remove(numDatasets + "-" + index);
} else
count = 0;
if (numDatasets == oldSeriesCount)
storeSeriesHashtable(numDatasets, h);
}
Aggregations