use of ome.xml.model.primitives.PositiveInteger in project bioformats by openmicroscopy.
the class ObjectBasedOMEModelMock method makeImage.
private Image makeImage() {
// Create <Image/>
Image image = new Image();
image.setID(InOutCurrentTest.IMAGE_ID);
ListAnnotation listAnnotation = new ListAnnotation();
listAnnotation.setID(InOutCurrentTest.IMAGE_LIST_ANNOTATION_ID);
listAnnotation.setNamespace(InOutCurrentTest.GENERAL_ANNOTATION_NAMESPACE);
annotations.addListAnnotation(listAnnotation);
BooleanAnnotation annotation = new BooleanAnnotation();
annotation.setID(InOutCurrentTest.IMAGE_ANNOTATION_ID);
annotation.setValue(InOutCurrentTest.IMAGE_ANNOTATION_VALUE);
annotation.setNamespace(InOutCurrentTest.GENERAL_ANNOTATION_NAMESPACE);
listAnnotation.linkAnnotation(annotation);
image.linkAnnotation(listAnnotation);
annotations.addBooleanAnnotation(annotation);
// Create <Pixels/>
Pixels pixels = new Pixels();
pixels.setID(InOutCurrentTest.PIXELS_ID);
pixels.setSizeX(new PositiveInteger(InOutCurrentTest.SIZE_X));
pixels.setSizeY(new PositiveInteger(InOutCurrentTest.SIZE_Y));
pixels.setSizeZ(new PositiveInteger(InOutCurrentTest.SIZE_Z));
pixels.setSizeC(new PositiveInteger(InOutCurrentTest.SIZE_C));
pixels.setSizeT(new PositiveInteger(InOutCurrentTest.SIZE_T));
pixels.setDimensionOrder(InOutCurrentTest.DIMENSION_ORDER);
pixels.setType(InOutCurrentTest.PIXEL_TYPE);
// Create <TiffData/>
TiffData tiffData = new TiffData();
// Create <UUID/>
UUID uuid = new UUID();
uuid.setValue(InOutCurrentTest.TIFF_DATA_UUID);
tiffData.setUUID(uuid);
pixels.addTiffData(tiffData);
// Create <Channel/> under <Pixels/>
for (int i = 0; i < InOutCurrentTest.SIZE_C; i++) {
Channel channel = new Channel();
channel.setID("Channel:" + i);
if (i == 0) {
XMLAnnotation channelAnnotation = new XMLAnnotation();
channelAnnotation.setID(InOutCurrentTest.CHANNEL_ANNOTATION_ID);
channelAnnotation.setValue(InOutCurrentTest.CHANNEL_ANNOTATION_VALUE);
channelAnnotation.setNamespace(InOutCurrentTest.GENERAL_ANNOTATION_NAMESPACE);
channel.linkAnnotation(channelAnnotation);
annotations.addXMLAnnotation(channelAnnotation);
}
pixels.addChannel(channel);
}
// Put <Pixels/> under <Image/>
image.setPixels(pixels);
return image;
}
use of ome.xml.model.primitives.PositiveInteger 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++;
}
}
}
}
use of ome.xml.model.primitives.PositiveInteger in project bioformats by openmicroscopy.
the class BDReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
// make sure we have the experiment file
id = locateExperimentFile(id);
super.initFile(id);
Location dir = new Location(id).getAbsoluteFile().getParentFile();
rootList = dir.list(true);
Arrays.sort(rootList);
for (int i = 0; i < rootList.length; i++) {
String file = rootList[i];
Location f = new Location(dir, file);
rootList[i] = f.getAbsolutePath();
if (!f.isDirectory()) {
if (checkSuffix(file, META_EXT) && !f.isDirectory()) {
metadataFiles.add(f.getAbsolutePath());
}
} else {
String[] wells = f.list(true);
Arrays.sort(wells);
wellList.add(wells);
for (String well : wells) {
Location wellFile = new Location(f, well);
if (!wellFile.isDirectory()) {
if (checkSuffix(well, META_EXT)) {
metadataFiles.add(wellFile.getAbsolutePath());
}
}
}
}
}
// parse Experiment metadata
IniList experiment = readMetaData(id);
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
objective = experiment.getTable("Geometry").get("Name");
IniTable camera = experiment.getTable("Camera");
binning = camera.get("BinX") + "x" + camera.get("BinY");
parseChannelData(dir);
addGlobalMeta("Objective", objective);
addGlobalMeta("Camera binning", binning);
}
final List<String> uniqueRows = new ArrayList<String>();
final List<String> uniqueColumns = new ArrayList<String>();
for (String well : wellLabels) {
String row = well.substring(0, 1).trim();
String column = well.substring(1).trim();
if (!uniqueRows.contains(row) && row.length() > 0)
uniqueRows.add(row);
if (!uniqueColumns.contains(column) && column.length() > 0) {
uniqueColumns.add(column);
}
}
int nSlices = getSizeZ() == 0 ? 1 : getSizeZ();
int nTimepoints = getSizeT();
int nWells = wellLabels.size();
int nChannels = getSizeC() == 0 ? channelNames.size() : getSizeC();
if (nChannels == 0)
nChannels = 1;
tiffs = getTiffs();
reader = new MinimalTiffReader();
reader.setId(tiffs[0][0]);
int sizeX = reader.getSizeX();
int sizeY = reader.getSizeY();
int pixelType = reader.getPixelType();
boolean rgb = reader.isRGB();
boolean interleaved = reader.isInterleaved();
boolean indexed = reader.isIndexed();
boolean littleEndian = reader.isLittleEndian();
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
IniParser parser = new IniParser();
for (String metadataFile : metadataFiles) {
String filename = new Location(metadataFile).getName();
if (!checkSuffix(metadataFile, new String[] { "txt", "bmp", "adf", "roi" })) {
String data = DataTools.readFile(metadataFile);
IniList ini = parser.parseINI(new BufferedReader(new StringReader(data)));
HashMap<String, String> h = ini.flattenIntoHashMap();
for (String key : h.keySet()) {
addGlobalMeta(filename + " " + key, h.get(key));
}
}
}
}
int coresize = core.size();
core.clear();
for (int i = 0; i < coresize; i++) {
CoreMetadata ms = new CoreMetadata();
core.add(ms);
ms.sizeC = nChannels;
ms.sizeZ = nSlices;
ms.sizeT = nTimepoints;
ms.sizeX = sizeX / fieldCols;
ms.sizeY = sizeY / fieldRows;
ms.pixelType = pixelType;
ms.rgb = rgb;
ms.interleaved = interleaved;
ms.indexed = indexed;
ms.littleEndian = littleEndian;
ms.dimensionOrder = "XYZTC";
ms.imageCount = nSlices * nTimepoints * nChannels;
}
MetadataStore store = makeFilterMetadata();
boolean populatePlanes = getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM;
MetadataTools.populatePixels(store, this, populatePlanes);
String plateAcqID = MetadataTools.createLSID("PlateAcquisition", 0, 0);
store.setPlateAcquisitionID(plateAcqID, 0, 0);
PositiveInteger fieldCount = FormatTools.getMaxFieldCount(fieldRows * fieldCols);
if (fieldCount != null) {
store.setPlateAcquisitionMaximumFieldCount(fieldCount, 0, 0);
}
for (int row = 0; row < wellRows; row++) {
for (int col = 0; col < wellCols; col++) {
int index = row * wellCols + col;
store.setWellID(MetadataTools.createLSID("Well", 0, index), 0, index);
store.setWellRow(new NonNegativeInteger(row), 0, index);
store.setWellColumn(new NonNegativeInteger(col), 0, index);
}
}
for (int i = 0; i < getSeriesCount(); i++) {
int well = i / (fieldRows * fieldCols);
int field = i % (fieldRows * fieldCols);
MetadataTools.setDefaultCreationDate(store, tiffs[well][0], i);
String name = wellLabels.get(well);
String row = name.substring(0, 1);
Integer col = Integer.parseInt(name.substring(1));
int index = (row.charAt(0) - 'A') * wellCols + col - 1;
String wellSampleID = MetadataTools.createLSID("WellSample", 0, index, field);
store.setWellSampleID(wellSampleID, 0, index, field);
store.setWellSampleIndex(new NonNegativeInteger(i), 0, index, field);
String imageID = MetadataTools.createLSID("Image", i);
store.setWellSampleImageRef(imageID, 0, index, field);
store.setImageID(imageID, i);
store.setImageName(name + " Field #" + (field + 1), i);
store.setPlateAcquisitionWellSampleRef(wellSampleID, 0, 0, i);
}
MetadataLevel level = getMetadataOptions().getMetadataLevel();
if (level != MetadataLevel.MINIMUM) {
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
store.setObjectiveID(objectiveID, 0, 0);
if (objective != null) {
String[] tokens = objective.split(" ");
String mag = tokens[0].replaceAll("[xX]", "");
String na = null;
int naIndex = 0;
for (int i = 0; i < tokens.length; i++) {
if (tokens[i].equals("NA")) {
naIndex = i + 1;
na = tokens[naIndex];
break;
}
}
Double magnification = new Double(mag);
store.setObjectiveNominalMagnification(magnification, 0, 0);
if (na != null) {
na = na.substring(0, 1) + "." + na.substring(1);
store.setObjectiveLensNA(new Double(na), 0, 0);
}
if (naIndex + 1 < tokens.length) {
store.setObjectiveManufacturer(tokens[naIndex + 1], 0, 0);
}
}
// populate LogicalChannel data
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageInstrumentRef(instrumentID, i);
store.setObjectiveSettingsID(objectiveID, i);
for (int c = 0; c < getSizeC(); c++) {
store.setChannelName(channelNames.get(c), i, c);
Length emission = FormatTools.getEmissionWavelength(emWave[c]);
Length excitation = FormatTools.getExcitationWavelength(exWave[c]);
if (emission != null) {
store.setChannelEmissionWavelength(emission, i, c);
}
if (excitation != null) {
store.setChannelExcitationWavelength(excitation, i, c);
}
String detectorID = MetadataTools.createLSID("Detector", 0, c);
store.setDetectorID(detectorID, 0, c);
store.setDetectorSettingsID(detectorID, i, c);
store.setDetectorSettingsGain(gain[c], i, c);
store.setDetectorSettingsOffset(offset[c], i, c);
store.setDetectorSettingsBinning(getBinning(binning), i, c);
}
long firstPlane = 0;
for (int p = 0; p < getImageCount(); p++) {
int[] zct = getZCTCoords(p);
store.setPlaneExposureTime(new Time(exposure[zct[1]], UNITS.SECOND), i, p);
String file = getFilename(i, p);
if (file != null) {
long plane = getTimestamp(file);
if (p == 0) {
firstPlane = plane;
}
double timestamp = (plane - firstPlane) / 1000.0;
store.setPlaneDeltaT(new Time(timestamp, UNITS.SECOND), i, p);
}
}
}
store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
store.setPlateRowNamingConvention(getNamingConvention("Letter"), 0);
store.setPlateColumnNamingConvention(getNamingConvention("Number"), 0);
store.setPlateName(plateName, 0);
store.setPlateDescription(plateDescription, 0);
if (level != MetadataLevel.NO_OVERLAYS) {
parseROIs(store);
}
}
}
use of ome.xml.model.primitives.PositiveInteger in project bioformats by openmicroscopy.
the class WriterUtilities method createMetadata.
public static IMetadata createMetadata() throws DependencyException, ServiceException {
ServiceFactory sf = new ServiceFactory();
OMEXMLService service = sf.getInstance(OMEXMLService.class);
IMetadata metadata = service.createOMEXMLMetadata();
metadata.setPixelsDimensionOrder(DimensionOrder.XYZCT, 0);
metadata.setPixelsSizeX(new PositiveInteger(SIZE_X), 0);
metadata.setPixelsSizeY(new PositiveInteger(SIZE_Y), 0);
metadata.setPixelsSizeT(new PositiveInteger(SIZE_T), 0);
metadata.setPixelsSizeZ(new PositiveInteger(SIZE_Z), 0);
metadata.setPixelsSizeC(new PositiveInteger(SIZE_C), 0);
metadata.setPixelsType(PixelType.UINT8, 0);
metadata.setPixelsBinDataBigEndian(true, 0, 0);
metadata.setImageID("Image:1", 0);
metadata.setPixelsID("Pixels:1", 0);
metadata.setChannelID("Channel:1", 0, 0);
metadata.setChannelSamplesPerPixel(new PositiveInteger(1), 0, 0);
return metadata;
}
use of ome.xml.model.primitives.PositiveInteger in project bioformats by openmicroscopy.
the class SPWModelMock method makeImage.
private Image makeImage(int index) {
// <Instrument/> for later linking, etc.
Instrument instrument = ome.getInstrument(0);
// Create <Image/>
Image image = new Image();
image.setID("Image:" + index);
CommentAnnotation commentAnnotation = new CommentAnnotation();
commentAnnotation.setID("Annotation:" + index);
commentAnnotation.setNamespace(GENERAL_ANNOTATION_NAMESPACE);
commentAnnotation.setValue("Image:" + index + " annotation.");
annotations.addCommentAnnotation(commentAnnotation);
image.linkAnnotation(commentAnnotation);
// Create <Pixels/>
Pixels pixels = new Pixels();
pixels.setID("Pixels:" + index);
pixels.setSizeX(new PositiveInteger(SIZE_X));
pixels.setSizeY(new PositiveInteger(SIZE_Y));
pixels.setSizeZ(new PositiveInteger(SIZE_Z));
pixels.setSizeC(new PositiveInteger(SIZE_C));
pixels.setSizeT(new PositiveInteger(SIZE_T));
pixels.setDimensionOrder(DIMENSION_ORDER);
pixels.setType(PIXEL_TYPE);
// Create <BinData/>
for (int i = 0; i < SIZE_Z * SIZE_C * SIZE_T; i++) {
BinData binData = new BinData();
binData.setBigEndian(false);
binData.setCompression(Compression.NONE);
binData.setLength(new NonNegativeLong((long) (SIZE_X * SIZE_Y * BYTES_PER_PIXEL)));
pixels.addBinData(binData);
}
// Create <Channel/> under <Pixels/>
for (int i = 0; i < SIZE_C; i++) {
Channel channel = new Channel();
channel.setID("Channel:" + i);
// Create <LightSourceSettings/> and link to <Channel/>
LightSourceSettings settings = new LightSourceSettings();
settings.setID(LIGHTSOURCE_LASER_ID);
channel.setLightSourceSettings(settings);
// Create <LightPath/> and link to <Channel/>
LightPath lightPath = new LightPath();
lightPath.linkEmissionFilter(instrument.getFilter(0));
lightPath.linkExcitationFilter(instrument.getFilter(1));
channel.setLightPath(lightPath);
pixels.addChannel(channel);
}
// Put <Pixels/> under <Image/>
image.setPixels(pixels);
// Link <Instrument/> to <Image/>
image.linkInstrument(instrument);
// Create <ObjectiveSettings/> and link to <Image/>
ObjectiveSettings settings = new ObjectiveSettings();
settings.setID(OBJECTIVE_ID);
image.setObjectiveSettings(settings);
return image;
}
Aggregations