use of ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.
the class FlexReader method populateMetadataStore.
private void populateMetadataStore(MetadataStore store) throws FormatException {
LOGGER.info("Populating MetadataStore");
MetadataTools.populatePixels(store, this, true);
Location currentFile = new Location(getCurrentFile()).getAbsoluteFile();
int[] lengths = new int[] { fieldCount, wellCount, plateCount };
store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
String plateAcqID = MetadataTools.createLSID("PlateAcquisition", 0, 0);
store.setPlateAcquisitionID(plateAcqID, 0, 0);
PositiveInteger maxFieldCount = FormatTools.getMaxFieldCount(fieldCount);
if (maxFieldCount != null) {
store.setPlateAcquisitionMaximumFieldCount(maxFieldCount, 0, 0);
}
plateAcqStartTime = DateTools.formatDate(plateAcqStartTime, "dd.MM.yyyy HH:mm:ss");
if (plateAcqStartTime != null) {
store.setPlateAcquisitionStartTime(new Timestamp(plateAcqStartTime), 0, 0);
}
for (int row = 0; row < wellRows; row++) {
for (int col = 0; col < wellColumns; col++) {
int well = row * wellColumns + col;
store.setWellID(MetadataTools.createLSID("Well", 0, well), 0, well);
store.setWellRow(new NonNegativeInteger(row), 0, well);
store.setWellColumn(new NonNegativeInteger(col), 0, well);
}
}
for (int i = 0; i < getSeriesCount(); i++) {
int[] pos = FormatTools.rasterToPosition(lengths, i);
String imageID = MetadataTools.createLSID("Image", i);
store.setImageID(imageID, i);
int well = wellNumber[pos[1]][0] * wellColumns + wellNumber[pos[1]][1];
char wellRow = (char) ('A' + wellNumber[pos[1]][0]);
store.setImageName("Well " + wellRow + "-" + (wellNumber[pos[1]][1] + 1) + "; Field #" + (pos[0] + 1), i);
if (acquisitionDates.get(i) != null) {
store.setImageAcquisitionDate(acquisitionDates.get(i), i);
}
if (wellRows == 0 && wellColumns == 0) {
well = pos[1];
NonNegativeInteger row = new NonNegativeInteger(wellNumber[pos[1]][0]);
NonNegativeInteger col = new NonNegativeInteger(wellNumber[pos[1]][1]);
String wellID = MetadataTools.createLSID("Well", pos[2], well);
store.setWellID(wellID, pos[2], well);
store.setWellRow(row, pos[2], pos[1]);
store.setWellColumn(col, pos[2], pos[1]);
}
String wellSample = MetadataTools.createLSID("WellSample", pos[2], well, pos[0]);
store.setWellSampleID(wellSample, pos[2], well, pos[0]);
store.setWellSampleIndex(new NonNegativeInteger(i), pos[2], well, pos[0]);
store.setWellSampleImageRef(imageID, pos[2], well, pos[0]);
store.setPlateAcquisitionWellSampleRef(wellSample, 0, 0, i);
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
if (plateName == null)
plateName = currentFile.getParentFile().getName();
if (plateBarcode != null)
plateName = plateBarcode + " " + plateName;
store.setPlateName(plateName, 0);
store.setPlateRowNamingConvention(getNamingConvention("Letter"), 0);
store.setPlateColumnNamingConvention(getNamingConvention("Number"), 0);
for (int i = 0; i < getSeriesCount(); i++) {
int[] pos = FormatTools.rasterToPosition(lengths, i);
store.setImageInstrumentRef(instrumentID, i);
int seriesIndex = i * getImageCount();
if (seriesIndex < objectiveRefs.size()) {
store.setObjectiveSettingsID(objectiveRefs.get(seriesIndex), i);
}
for (int c = 0; c < getEffectiveSizeC(); c++) {
int channelIndex = seriesIndex + c;
if (seriesIndex > 0 && channelNames.length == getEffectiveSizeC() * getSeriesCount()) {
channelIndex = i * getEffectiveSizeC() + c;
}
if (channelNames != null && channelIndex >= channelNames.length) {
channelIndex = c;
}
if (channelNames != null && channelIndex < channelNames.length) {
store.setChannelName(channelNames[channelIndex], i, c);
}
}
if (seriesIndex < lightSourceCombinationRefs.size()) {
String lightSourceCombo = lightSourceCombinationRefs.get(seriesIndex);
List<String> lightSources = lightSourceCombinationIDs.get(lightSourceCombo);
for (int c = 0; c < getEffectiveSizeC(); c++) {
int index = seriesIndex + c;
if (index < cameraRefs.size()) {
store.setDetectorSettingsID(cameraRefs.get(index), i, c);
if (index < binnings.size()) {
store.setDetectorSettingsBinning(getBinning(binnings.get(index)), i, c);
}
}
if (lightSources != null && c < lightSources.size()) {
store.setChannelLightSourceSettingsID(lightSources.get(c), i, c);
} else if (c > 0 && lightSources != null && lightSources.size() == 1) {
lightSourceCombo = lightSourceCombinationRefs.get(seriesIndex + c);
lightSources = lightSourceCombinationIDs.get(lightSourceCombo);
store.setChannelLightSourceSettingsID(lightSources.get(0), i, c);
}
if (index < filterSets.size()) {
FilterGroup group = filterSetMap.get(filterSets.get(index));
if (group != null) {
if (group.emission != null) {
store.setLightPathEmissionFilterRef(group.emission, i, c, 0);
}
if (group.excitation != null) {
store.setLightPathExcitationFilterRef(group.excitation, i, c, 0);
}
if (group.dichroic != null) {
store.setLightPathDichroicRef(group.dichroic, i, c);
}
}
}
}
}
if (seriesIndex < xSizes.size()) {
Length size = FormatTools.getPhysicalSizeX(xSizes.get(seriesIndex));
if (size != null) {
store.setPixelsPhysicalSizeX(size, i);
}
}
if (seriesIndex < ySizes.size()) {
Length size = FormatTools.getPhysicalSizeY(ySizes.get(seriesIndex));
if (size != null) {
store.setPixelsPhysicalSizeY(size, i);
}
}
int well = wellNumber[pos[1]][0] * wellColumns + wellNumber[pos[1]][1];
if (wellRows == 0 && wellColumns == 0) {
well = pos[1];
}
if (pos[0] < xPositions.size()) {
Length l = new Length(xPositions.get(pos[0]), UNITS.REFERENCEFRAME);
store.setWellSamplePositionX(l, pos[2], well, pos[0]);
}
if (pos[0] < yPositions.size()) {
Length l = new Length(yPositions.get(pos[0]), UNITS.REFERENCEFRAME);
store.setWellSamplePositionY(l, pos[2], well, pos[0]);
}
for (int image = 0; image < getImageCount(); image++) {
int plane = i * getImageCount() + image;
int c = getZCTCoords(image)[1];
if (plane < planePositionX.size()) {
store.setPlanePositionX(planePositionX.get(plane), i, image);
}
if (plane < planePositionY.size()) {
store.setPlanePositionY(planePositionY.get(plane), i, image);
}
if (plane < planePositionZ.size()) {
store.setPlanePositionZ(planePositionZ.get(plane), i, image);
}
if (plane - image + c < planeExposureTime.size()) {
if (planeExposureTime.get(plane - image + c) != null) {
store.setPlaneExposureTime(new Time(planeExposureTime.get(plane - image + c), UNITS.SECOND), i, image);
}
}
if (plane < planeDeltaT.size() && planeDeltaT.get(plane) != null) {
store.setPlaneDeltaT(new Time(planeDeltaT.get(plane), UNITS.SECOND), i, image);
}
}
}
}
}
use of ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.
the class FluoviewReader method parseComment.
private void parseComment() {
if (comment != null) {
// this is an INI-style comment, with one key/value pair per line
String[] lines = comment.split("\n");
for (String token : lines) {
token = token.trim();
int eq = token.indexOf('=');
if (eq != -1) {
String key = token.substring(0, eq);
String value = token.substring(eq + 1);
addGlobalMeta(key, value);
if (key.startsWith("Gain Ch")) {
int index = Integer.parseInt(key.substring(7).trim());
if (index > 0 && index <= gains.length) {
gains[index - 1] = value;
}
} else if (key.startsWith("PMT Voltage Ch")) {
int index = Integer.parseInt(key.substring(14).trim());
if (index > 0 && index <= voltages.length) {
voltages[index - 1] = value;
}
} else if (key.startsWith("Offset Ch")) {
int index = Integer.parseInt(key.substring(9).trim());
if (index > 0 && index <= offsets.length) {
offsets[index - 1] = value;
}
} else if (key.equals("Magnification"))
mag = value;
else if (key.equals("System Configuration")) {
detectorManufacturer = value;
} else if (key.equals("Objective Lens"))
objectiveManufacturer = value;
else if (key.startsWith("Channel ") && key.endsWith("Dye")) {
for (int i = 0; i < channelNames.length; i++) {
if (channelNames[i] == null) {
channelNames[i] = value;
break;
}
}
} else if (key.startsWith("Confocal Aperture-Ch")) {
int index = Integer.parseInt(key.substring(20).trim());
if (index > 0 && index <= lensNA.length) {
lensNA[index - 1] = value.substring(0, value.length() - 2);
}
} else if (key.equals("Date")) {
date = value;
} else if (key.equals("Time")) {
date += " " + value;
} else if (key.equals("MontageOffsets")) {
String[] offsets = value.split("\t");
montageOffsets = new double[offsets.length - 1][3];
for (int i = 1; i < offsets.length; i++) {
String[] v = offsets[i].trim().split(",");
for (int j = 0; j < v.length; j++) {
montageOffsets[i - 1][j] = Double.parseDouble(v[j].trim());
}
}
} else if (key.equals("XYFields")) {
String[] offsets = value.split("\t");
fieldOffsets = new double[offsets.length - 1][3];
for (int i = 1; i < offsets.length; i++) {
String[] v = offsets[i].trim().split(",");
for (int j = 0; j < v.length; j++) {
try {
fieldOffsets[i - 1][j] = Double.parseDouble(v[j].trim());
} catch (NumberFormatException e) {
}
}
}
}
} else if (token.startsWith("Z") && token.indexOf(" um ") != -1) {
// looking for "Z - x um in y planes"
String z = token.substring(token.indexOf('-') + 1);
z = z.replaceAll("\\p{Alpha}", "").trim();
int firstSpace = z.indexOf(' ');
double size = Double.parseDouble(z.substring(0, firstSpace));
double nPlanes = Double.parseDouble(z.substring(firstSpace).trim());
voxelZ = size / nPlanes;
}
}
if (date != null) {
date = DateTools.formatDate(date.trim(), new String[] { "dd/MM/yyyy hh:mm:ss a", "MM-dd-yyyy hh:mm:ss", "dd/MM/yyyy H:mm:ss" }, true);
Timestamp timestamp = Timestamp.valueOf(date);
if (timeIndex >= 0 && timestamp != null) {
long ms = timestamp.asInstant().getMillis();
for (int i = 0; i < getImageCount(); i++) {
int[] zct = getZCTCoords(i);
String key = String.format("Timestamp for Z=%2s, C=%2s, T=%2s", zct[0], zct[1], zct[2]);
long stamp = ms + (long) (stamps[timeIndex][i] * 1000);
addGlobalMeta(key, DateTools.convertDate(stamp, DateTools.UNIX, DATE_FORMAT));
}
}
}
int start = comment.indexOf("[Version Info]");
int end = comment.indexOf("[Version Info End]");
if (start != -1 && end != -1 && end > start) {
comment = comment.substring(start + 14, end).trim();
start = comment.indexOf('=') + 1;
end = comment.indexOf("\n");
if (end > start)
comment = comment.substring(start, end).trim();
else
comment = comment.substring(start).trim();
} else
comment = "";
}
}
use of ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.
the class HitachiReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
if (!checkSuffix(id, "txt")) {
String base = id;
if (base.indexOf('.') >= 0) {
base = base.substring(0, base.lastIndexOf("."));
}
id = base + ".txt";
initFile(id);
return;
}
super.initFile(id);
String data = DataTools.readFile(id);
IniParser parser = new IniParser();
parser.setBackslashContinuesLine(false);
IniList ini = parser.parseINI(new BufferedReader(new StringReader(data)));
IniTable image = ini.getTable("SemImageFile");
if (image == null) {
throw new FormatException("Could not find 'SemImageFile' table.");
}
for (String key : image.keySet()) {
addGlobalMeta(key, image.get(key));
}
String imageName = image.get("SampleName");
String pixelsFile = image.get("ImageName");
String date = image.get("Date");
String time = image.get("Time");
Location parent = new Location(id).getAbsoluteFile().getParentFile();
pixelsFile = new Location(parent, pixelsFile).getAbsolutePath();
ClassList<IFormatReader> classes = ImageReader.getDefaultReaderClasses();
Class<? extends IFormatReader>[] classArray = classes.getClasses();
ClassList<IFormatReader> newClasses = new ClassList<IFormatReader>(IFormatReader.class);
for (Class<? extends IFormatReader> c : classArray) {
if (!c.equals(HitachiReader.class)) {
newClasses.addClass(c);
}
}
helperReader = new ImageReader(newClasses);
helperReader.setId(pixelsFile);
core = new ArrayList<CoreMetadata>(helperReader.getCoreMetadataList());
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM);
store.setImageName(imageName, 0);
date = DateTools.formatDate(date + " " + time, DATE_FORMAT);
if (date != null) {
store.setImageAcquisitionDate(new Timestamp(date), 0);
}
populateOMEMetadata(image, store);
}
use of ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.
the class ImaconReader method initMetadataStore.
/* @see BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
super.initMetadataStore();
MetadataStore store = makeFilterMetadata();
if (creationDate != null) {
creationDate = DateTools.formatDate(creationDate, "yyyyMMdd HHmmSSZ");
}
for (int i = 0; i < getSeriesCount(); i++) {
String name = imageName;
if (imageName.length() == 0) {
name = "#" + (i + 1);
} else {
name += " #" + (i + 1);
}
store.setImageName(name, i);
if (creationDate != null) {
store.setImageAcquisitionDate(new Timestamp(creationDate), i);
}
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
if (experimenterName == null)
experimenterName = "";
int nameSpace = experimenterName.indexOf(' ');
String firstName = nameSpace == -1 ? "" : experimenterName.substring(0, nameSpace);
String lastName = nameSpace == -1 ? experimenterName : experimenterName.substring(nameSpace + 1);
String experimenter = MetadataTools.createLSID("Experimenter", 0);
store.setExperimenterID(experimenter, 0);
store.setExperimenterFirstName(firstName, 0);
store.setExperimenterLastName(lastName, 0);
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageExperimenterRef(experimenter, i);
}
}
}
use of ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.
the class FujiReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
if (checkSuffix(id, "inf")) {
infFile = new Location(id).getAbsolutePath();
pixelsFile = infFile.substring(0, infFile.lastIndexOf(".")) + ".img";
} else {
pixelsFile = new Location(id).getAbsolutePath();
infFile = pixelsFile.substring(0, pixelsFile.lastIndexOf(".")) + ".inf";
}
String[] lines = DataTools.readFile(infFile).split("\r{0,1}\n");
int bits = Integer.parseInt(lines[5]);
CoreMetadata m = core.get(0);
m.pixelType = FormatTools.pixelTypeFromBytes(bits / 8, false, false);
m.sizeX = Integer.parseInt(lines[6]);
m.sizeY = Integer.parseInt(lines[7]);
m.sizeC = 1;
m.sizeT = 1;
m.sizeZ = 1;
m.imageCount = getSizeZ() * getSizeC() * getSizeT();
m.dimensionOrder = "XYCZT";
for (String line : lines) {
addGlobalMetaList("Line", line);
}
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
String imageName = lines[1];
String timestamp = lines[10];
timestamp = DateTools.formatDate(timestamp, DATE_FORMAT);
store.setImageName(imageName, 0);
if (timestamp != null) {
store.setImageAcquisitionDate(new Timestamp(timestamp), 0);
}
double physicalWidth = Double.parseDouble(lines[3]);
double physicalHeight = Double.parseDouble(lines[4]);
Length sizeX = FormatTools.getPhysicalSizeX(physicalWidth);
Length sizeY = FormatTools.getPhysicalSizeY(physicalHeight);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
String instrument = lines[13];
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
store.setMicroscopeModel(instrument, 0);
}
}
Aggregations