use of ome.xml.model.primitives.Timestamp 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 ome.xml.model.primitives.Timestamp 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 ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.
the class WATOPReader 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());
String comment = null;
MetadataLevel level = getMetadataOptions().getMetadataLevel();
if (level != MetadataLevel.MINIMUM) {
in.seek(49);
comment = in.readString(33);
}
in.seek(211);
int year = in.readInt();
int month = in.readInt();
int day = in.readInt();
int hour = in.readInt();
int min = in.readInt();
String date = year + "-" + month + "-" + day + "T" + hour + ":" + min;
date = DateTools.formatDate(date, "yyyy-MM-dd'T'HH:mm");
in.skipBytes(8);
double xSize = in.readInt() / 100d;
double ySize = in.readInt() / 100d;
double zSize = in.readInt() / 100d;
m.sizeX = in.readInt();
m.sizeY = in.readInt();
if (level != MetadataLevel.MINIMUM) {
double tunnelCurrent = in.readInt() / 1000d;
double sampleVolts = in.readInt() / 1000d;
in.skipBytes(180);
int originalZMax = in.readInt();
int originalZMin = in.readInt();
int zMax = in.readInt();
int zMin = in.readInt();
addGlobalMeta("Comment", comment);
addGlobalMeta("X size (in um)", xSize);
addGlobalMeta("Y size (in um)", ySize);
addGlobalMeta("Z size (in um)", zSize);
addGlobalMeta("Tunnel current (in amps)", tunnelCurrent);
addGlobalMeta("Sample volts", sampleVolts);
addGlobalMeta("Acquisition date", date);
}
m.pixelType = FormatTools.INT16;
m.sizeC = 1;
m.sizeZ = 1;
m.sizeT = 1;
m.imageCount = 1;
m.dimensionOrder = "XYZCT";
m.rgb = false;
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
if (date != null) {
store.setImageAcquisitionDate(new Timestamp(date), 0);
}
if (level != MetadataLevel.MINIMUM) {
store.setImageDescription(comment, 0);
Length sizeX = FormatTools.getPhysicalSizeX((double) xSize / getSizeX());
Length sizeY = FormatTools.getPhysicalSizeY((double) ySize / getSizeY());
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
}
}
use of ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.
the class ObjectBasedOMEModelMock method makePlate.
private Plate makePlate() {
Plate plate = new Plate();
plate.setID(InOutCurrentTest.PLATE_ID);
plate.setRows(InOutCurrentTest.WELL_ROWS);
plate.setColumns(InOutCurrentTest.WELL_COLS);
plate.setRowNamingConvention(InOutCurrentTest.WELL_ROW);
plate.setColumnNamingConvention(InOutCurrentTest.WELL_COL);
TimestampAnnotation plateAnnotation = new TimestampAnnotation();
plateAnnotation.setID(InOutCurrentTest.PLATE_ANNOTATION_ID);
plateAnnotation.setValue(new Timestamp(InOutCurrentTest.PLATE_ANNOTATION_VALUE));
plateAnnotation.setNamespace(InOutCurrentTest.GENERAL_ANNOTATION_NAMESPACE);
plate.linkAnnotation(plateAnnotation);
annotations.addTimestampAnnotation(plateAnnotation);
int wellSampleIndex = 0;
for (int row = 0; row < InOutCurrentTest.WELL_ROWS.getValue(); row++) {
for (int col = 0; col < InOutCurrentTest.WELL_COLS.getValue(); col++) {
Well well = new Well();
well.setID(String.format("Well:%d_%d", row, col));
well.setRow(new NonNegativeInteger(row));
well.setColumn(new NonNegativeInteger(col));
if (row == 0 && col == 0) {
LongAnnotation annotation = new LongAnnotation();
annotation.setID(InOutCurrentTest.WELL_ANNOTATION_ID);
annotation.setValue(InOutCurrentTest.WELL_ANNOTATION_VALUE);
annotation.setNamespace(InOutCurrentTest.GENERAL_ANNOTATION_NAMESPACE);
well.linkAnnotation(annotation);
annotations.addLongAnnotation(annotation);
}
WellSample sample = new WellSample();
sample.setID(String.format("WellSample:%d_%d", row, col));
sample.setIndex(new NonNegativeInteger(wellSampleIndex));
sample.linkImage(ome.getImage(0));
well.addWellSample(sample);
plate.addWell(well);
wellSampleIndex++;
}
}
return plate;
}
use of ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.
the class ColumbusReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
protected void initFile(String id) throws FormatException, IOException {
Location xml = findXML(id);
if (null == xml) {
throw new FormatException("Could not find " + XML_FILE);
}
id = xml.getAbsolutePath();
super.initFile(id);
Location parent = new Location(currentId).getAbsoluteFile().getParentFile();
// parse plate layout and image dimensions from the XML files
String xmlData = DataTools.readFile(id);
MeasurementHandler handler = new MeasurementHandler();
XMLTools.parseXML(xmlData, handler);
String[] parentDirectories = parent.list(true);
Arrays.sort(parentDirectories);
ArrayList<String> timepointDirs = new ArrayList<String>();
for (String file : parentDirectories) {
Location absFile = new Location(parent, file);
if (absFile.isDirectory()) {
timepointDirs.add(absFile.getAbsolutePath());
for (String f : absFile.list(true)) {
if (!checkSuffix(f, "tif")) {
if (!metadataFiles.contains(file + File.separator + f)) {
metadataFiles.add(file + File.separator + f);
}
}
}
}
}
for (int i = 0; i < metadataFiles.size(); i++) {
String metadataFile = metadataFiles.get(i);
int end = metadataFile.indexOf(File.separator);
String timepointPath = end < 0 ? "" : parent + File.separator + metadataFile.substring(0, end);
Location f = new Location(parent + File.separator + metadataFile);
if (!f.exists()) {
metadataFile = metadataFile.substring(end + 1);
f = new Location(parent, metadataFile);
}
String path = f.getAbsolutePath();
metadataFiles.set(i, path);
if (checkSuffix(path, "columbusidx.xml")) {
int timepoint = timepointDirs.indexOf(timepointPath);
if (timepointDirs.size() == 0) {
timepoint = 0;
}
parseImageXML(path, timepoint);
}
}
// process plane list to determine plate size
Comparator<Plane> planeComp = new Comparator<Plane>() {
public int compare(Plane p1, Plane p2) {
if (p1.row != p2.row) {
return p1.row - p2.row;
}
if (p1.col != p2.col) {
return p1.col - p2.col;
}
if (p1.field != p2.field) {
return p1.field - p2.field;
}
if (p1.timepoint != p2.timepoint) {
return p1.timepoint - p2.timepoint;
}
if (p1.channel != p2.channel) {
return p1.channel - p2.channel;
}
return 0;
}
};
Plane[] tmpPlanes = planes.toArray(new Plane[planes.size()]);
Arrays.sort(tmpPlanes, planeComp);
planes.clear();
reader = new MinimalTiffReader();
reader.setId(tmpPlanes[0].file);
core = reader.getCoreMetadataList();
CoreMetadata m = core.get(0);
m.sizeC = 0;
m.sizeT = 0;
ArrayList<Integer> uniqueSamples = new ArrayList<Integer>();
ArrayList<Integer> uniqueRows = new ArrayList<Integer>();
ArrayList<Integer> uniqueCols = new ArrayList<Integer>();
for (Plane p : tmpPlanes) {
planes.add(p);
int sampleIndex = p.row * handler.getPlateColumns() + p.col;
if (!uniqueSamples.contains(sampleIndex)) {
uniqueSamples.add(sampleIndex);
}
if (!uniqueRows.contains(p.row)) {
uniqueRows.add(p.row);
}
if (!uniqueCols.contains(p.col)) {
uniqueCols.add(p.col);
}
// counts are assumed to be non-sparse
if (p.field >= nFields) {
nFields = p.field + 1;
}
if (p.channel >= getSizeC()) {
m.sizeC = p.channel + 1;
}
if (p.timepoint >= getSizeT()) {
m.sizeT = p.timepoint + 1;
}
}
m.sizeZ = 1;
m.imageCount = getSizeZ() * getSizeC() * getSizeT();
m.dimensionOrder = "XYCTZ";
m.rgb = false;
int seriesCount = uniqueSamples.size() * nFields;
for (int i = 1; i < seriesCount; i++) {
core.add(m);
}
// populate the MetadataStore
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, true);
store.setScreenID(MetadataTools.createLSID("Screen", 0), 0);
store.setScreenName(handler.getScreenName(), 0);
store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
store.setPlateName(handler.getPlateName(), 0);
store.setPlateRows(new PositiveInteger(handler.getPlateRows()), 0);
store.setPlateColumns(new PositiveInteger(handler.getPlateColumns()), 0);
String imagePrefix = handler.getPlateName() + " Well ";
int wellSample = 0;
int nextWell = -1;
Timestamp date = new Timestamp(acquisitionDate);
long timestampSeconds = date.asInstant().getMillis() / 1000;
for (Integer row : uniqueRows) {
for (Integer col : uniqueCols) {
if (!uniqueSamples.contains(row * handler.getPlateColumns() + col)) {
continue;
}
nextWell++;
store.setWellID(MetadataTools.createLSID("Well", 0, nextWell), 0, nextWell);
store.setWellRow(new NonNegativeInteger(row), 0, nextWell);
store.setWellColumn(new NonNegativeInteger(col), 0, nextWell);
for (int field = 0; field < nFields; field++) {
Plane p = lookupPlane(row, col, field, 0, 0);
String wellSampleID = MetadataTools.createLSID("WellSample", 0, nextWell, field);
store.setWellSampleID(wellSampleID, 0, nextWell, field);
store.setWellSampleIndex(new NonNegativeInteger(wellSample), 0, nextWell, field);
if (p != null) {
store.setWellSamplePositionX(new Length(p.positionX, UNITS.REFERENCEFRAME), 0, nextWell, field);
store.setWellSamplePositionY(new Length(p.positionY, UNITS.REFERENCEFRAME), 0, nextWell, field);
}
String imageID = MetadataTools.createLSID("Image", wellSample);
store.setImageID(imageID, wellSample);
store.setWellSampleImageRef(imageID, 0, nextWell, field);
store.setImageName(imagePrefix + (char) (row + 'A') + (col + 1) + " Field #" + (field + 1), wellSample);
store.setImageAcquisitionDate(date, wellSample);
if (p != null) {
p.series = wellSample;
store.setPixelsPhysicalSizeX(FormatTools.getPhysicalSizeX(p.sizeX), p.series);
store.setPixelsPhysicalSizeY(FormatTools.getPhysicalSizeY(p.sizeY), p.series);
for (int c = 0; c < getSizeC(); c++) {
p = lookupPlane(row, col, field, 0, c);
if (p != null) {
p.series = wellSample;
store.setChannelName(p.channelName, p.series, p.channel);
if ((int) p.emWavelength > 0) {
store.setChannelEmissionWavelength(FormatTools.getEmissionWavelength(p.emWavelength), p.series, p.channel);
}
if ((int) p.exWavelength > 0) {
store.setChannelExcitationWavelength(FormatTools.getExcitationWavelength(p.exWavelength), p.series, p.channel);
}
store.setChannelColor(p.channelColor, p.series, p.channel);
}
for (int t = 0; t < getSizeT(); t++) {
p = lookupPlane(row, col, field, t, c);
if (p != null) {
p.series = wellSample;
store.setPlaneDeltaT(new Time(p.deltaT - timestampSeconds, UNITS.SECOND), p.series, getIndex(0, c, t));
}
}
}
}
wellSample++;
}
}
}
}
Aggregations