use of ome.units.quantity.Length in project bioformats by openmicroscopy.
the class AmiraReader method initFile.
/* (non-Javadoc)
* @see loci.formats.FormatReader#initFile(java.lang.String)
*/
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
in = new RandomAccessInputStream(id);
AmiraParameters parameters = new AmiraParameters(in);
offsetOfFirstStream = in.getFilePointer();
LOGGER.info("Populating metadata hashtable");
addGlobalMeta("Image width", parameters.width);
addGlobalMeta("Image height", parameters.height);
addGlobalMeta("Number of planes", parameters.depth);
addGlobalMeta("Bits per pixel", 8);
LOGGER.info("Populating core metadata");
int channelIndex = 1;
while (parameters.getStreams().get("@" + channelIndex) != null) {
channelIndex++;
}
CoreMetadata m = core.get(0);
m.sizeX = parameters.width;
m.sizeY = parameters.height;
m.sizeZ = parameters.depth;
m.sizeT = 1;
m.sizeC = channelIndex - 1;
m.imageCount = getSizeZ() * getSizeC();
m.littleEndian = parameters.littleEndian;
m.dimensionOrder = "XYZCT";
String streamType = parameters.streamTypes[0].toLowerCase();
if (streamType.equals("byte")) {
m.pixelType = FormatTools.UINT8;
} else if (streamType.equals("short")) {
m.pixelType = FormatTools.INT16;
addGlobalMeta("Bits per pixel", 16);
} else if (streamType.equals("ushort")) {
m.pixelType = FormatTools.UINT16;
addGlobalMeta("Bits per pixel", 16);
} else if (streamType.equals("int")) {
m.pixelType = FormatTools.INT32;
addGlobalMeta("Bits per pixel", 32);
} else if (streamType.equals("float")) {
m.pixelType = FormatTools.FLOAT;
addGlobalMeta("Bits per pixel", 32);
} else {
LOGGER.warn("Assuming data type is byte");
m.pixelType = FormatTools.UINT8;
}
LOGGER.info("Populating metadata store");
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
// The bounding box is the range of the centre of the voxels
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
double pixelWidth = (double) (parameters.x1 - parameters.x0) / (parameters.width - 1);
double pixelHeight = (double) (parameters.y1 - parameters.y0) / (parameters.height - 1);
// TODO - what is correct setting if single slice?
double pixelDepth = (double) (parameters.z1 - parameters.z0) / (parameters.depth - 1);
// Amira does not have a standard form for encoding units, so we just
// have to assume microns for microscopy data
addGlobalMeta("Pixels per meter (X)", 1e6 / pixelWidth);
addGlobalMeta("Pixels per meter (Y)", 1e6 / pixelHeight);
addGlobalMeta("Pixels per meter (Z)", 1e6 / pixelDepth);
Length sizeX = FormatTools.getPhysicalSizeX(pixelWidth);
Length sizeY = FormatTools.getPhysicalSizeY(pixelHeight);
Length sizeZ = FormatTools.getPhysicalSizeZ(pixelDepth);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, 0);
}
}
ascii = parameters.ascii;
ArrayList streamData = (ArrayList) parameters.getStreams().get("@1");
if (streamData.size() > 2) {
compression = (String) streamData.get(2);
}
initPlaneReader();
hasPlaneReader = planeReader != null;
addGlobalMeta("Compression", compression);
Map params = (Map) parameters.getMap().get("Parameters");
if (params != null) {
Map materials = (Map) params.get("Materials");
if (materials != null) {
lut = getLookupTable(materials);
m.indexed = true;
}
}
}
use of ome.units.quantity.Length 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.units.quantity.Length in project bioformats by openmicroscopy.
the class TileStitcher method setId.
/* @see IFormatReader#setId(String) */
@Override
public void setId(String id) throws FormatException, IOException {
super.setId(id);
MetadataStore store = getMetadataStore();
if (!(store instanceof IMetadata) || reader.getSeriesCount() == 1) {
tileX = 1;
tileY = 1;
return;
}
IMetadata meta = (IMetadata) store;
// enough to just ignore HCS data with multiple plates and/or wells
if (meta.getPlateCount() > 1 || (meta.getPlateCount() == 1 && meta.getWellCount(0) > 1)) {
tileX = 1;
tileY = 1;
return;
}
// now make sure that all of the series have the same dimensions
boolean equalDimensions = true;
for (int i = 1; i < meta.getImageCount(); i++) {
if (!meta.getPixelsSizeX(i).equals(meta.getPixelsSizeX(0))) {
equalDimensions = false;
}
if (!meta.getPixelsSizeY(i).equals(meta.getPixelsSizeY(0))) {
equalDimensions = false;
}
if (!meta.getPixelsSizeZ(i).equals(meta.getPixelsSizeZ(0))) {
equalDimensions = false;
}
if (!meta.getPixelsSizeC(i).equals(meta.getPixelsSizeC(0))) {
equalDimensions = false;
}
if (!meta.getPixelsSizeT(i).equals(meta.getPixelsSizeT(0))) {
equalDimensions = false;
}
if (!meta.getPixelsType(i).equals(meta.getPixelsType(0))) {
equalDimensions = false;
}
if (!equalDimensions)
break;
}
if (!equalDimensions) {
tileX = 1;
tileY = 1;
return;
}
ArrayList<TileCoordinate> tiles = new ArrayList<TileCoordinate>();
final List<Length> uniqueX = new ArrayList<Length>();
final List<Length> uniqueY = new ArrayList<Length>();
boolean equalZs = true;
final Length firstZ = meta.getPlanePositionZ(0, meta.getPlaneCount(0) - 1);
for (int i = 0; i < reader.getSeriesCount(); i++) {
TileCoordinate coord = new TileCoordinate();
coord.x = meta.getPlanePositionX(i, meta.getPlaneCount(i) - 1);
coord.y = meta.getPlanePositionY(i, meta.getPlaneCount(i) - 1);
tiles.add(coord);
if (coord.x != null && !uniqueX.contains(coord.x)) {
uniqueX.add(coord.x);
}
if (coord.y != null && !uniqueY.contains(coord.y)) {
uniqueY.add(coord.y);
}
final Length zPos = meta.getPlanePositionZ(i, meta.getPlaneCount(i) - 1);
if (firstZ == null) {
if (zPos != null) {
equalZs = false;
}
} else {
if (!firstZ.equals(zPos)) {
equalZs = false;
}
}
}
tileX = uniqueX.size();
tileY = uniqueY.size();
if (!equalZs) {
LOGGER.warn("Z positions not equal");
}
tileMap = new Integer[tileY][tileX];
final Length[] xCoordinates = uniqueX.toArray(new Length[tileX]);
Arrays.sort(xCoordinates);
final Length[] yCoordinates = uniqueY.toArray(new Length[tileY]);
Arrays.sort(yCoordinates);
for (int row = 0; row < tileMap.length; row++) {
for (int col = 0; col < tileMap[row].length; col++) {
TileCoordinate coordinate = new TileCoordinate();
coordinate.x = xCoordinates[col];
coordinate.y = yCoordinates[row];
for (int tile = 0; tile < tiles.size(); tile++) {
if (tiles.get(tile).equals(coordinate)) {
tileMap[row][col] = tile;
}
}
}
}
}
use of ome.units.quantity.Length in project bioformats by openmicroscopy.
the class ROIHandler method storeRectangle.
/**
* Stores the Rectangle ROI into the specified metadata store.
*
* @param roi The roi to convert.
* @param store The store to handle.
* @param roiNum The roi number
* @param shape The index of the shape.
* @param c The selected channel.
* @param z The selected slice.
* @param t The selected timepoint.
*/
private static void storeRectangle(Roi roi, MetadataStore store, int roiNum, int shape, int c, int z, int t) {
Rectangle bounds = roi.getBounds();
store.setRectangleX(new Double(bounds.x), roiNum, shape);
store.setRectangleY(new Double(bounds.y), roiNum, shape);
store.setRectangleWidth(new Double(bounds.width), roiNum, shape);
store.setRectangleHeight(new Double(bounds.height), roiNum, shape);
if (c >= 0) {
store.setRectangleTheC(unwrap(c), roiNum, shape);
}
if (z >= 0) {
store.setRectangleTheZ(unwrap(z), roiNum, shape);
}
if (t >= 0) {
store.setRectangleTheT(unwrap(t), roiNum, shape);
}
store.setRectangleText(roi.getName(), roiNum, shape);
if (roi.getStrokeWidth() > 0) {
store.setRectangleStrokeWidth(new Length((roi.getStrokeWidth()), UNITS.PIXEL), roiNum, shape);
}
if (roi.getStrokeColor() != null) {
store.setRectangleStrokeColor(toOMExmlColor(roi.getStrokeColor()), roiNum, shape);
}
if (roi.getFillColor() != null) {
store.setRectangleFillColor(toOMExmlColor(roi.getFillColor()), roiNum, shape);
}
}
use of ome.units.quantity.Length in project bioformats by openmicroscopy.
the class ROIHandler method storePoint.
/**
* Stores the Point ROI into the specified metadata store.
*
* @param roi The roi to convert.
* @param store The store to handle.
* @param roiNum The roi number
* @param shape The index of the shape.
* @param c The selected channel.
* @param z The selected slice.
* @param t The selected timepoint.
*/
private static void storePoint(PointRoi roi, MetadataStore store, int roiNum, int shape, int c, int z, int t) {
int[] xCoordinates = roi.getPolygon().xpoints;
int[] yCoordinates = roi.getPolygon().ypoints;
for (int cntr = 0; cntr < xCoordinates.length; cntr++) {
String polylineID = MetadataTools.createLSID("Shape", roiNum, shape + cntr);
store.setPointID(polylineID, roiNum, shape + cntr);
store.setPointX((double) xCoordinates[cntr], roiNum, shape + cntr);
store.setPointY((double) yCoordinates[cntr], roiNum, shape + cntr);
store.setPointText(roi.getName(), roiNum, shape + cntr);
if (c >= 0) {
store.setPointTheC(unwrap(c), roiNum, shape);
}
if (z >= 0) {
store.setPointTheZ(unwrap(z), roiNum, shape);
}
if (t >= 0) {
store.setPointTheT(unwrap(t), roiNum, shape);
}
if (roi.getStrokeWidth() > 0) {
store.setPointStrokeWidth(new Length((roi.getStrokeWidth()), UNITS.PIXEL), roiNum, shape + cntr);
}
if (roi.getStrokeColor() != null) {
store.setPointStrokeColor(toOMExmlColor(roi.getStrokeColor()), roiNum, shape + cntr);
}
if (roi.getFillColor() != null) {
store.setPointFillColor(toOMExmlColor(roi.getFillColor()), roiNum, shape + cntr);
}
}
}
Aggregations