use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class BioRadReader method parseNotes.
private boolean parseNotes(MetadataStore store) throws FormatException {
boolean multipleFiles = false;
int nextDetector = 0, nLasers = 0;
for (Note n : noteStrings) {
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
switch(n.type) {
case NOTE_TYPE_USER:
// TODO : this should be an overlay
addGlobalMetaList("Note", n.toString());
break;
case NOTE_TYPE_SCALEBAR:
// TODO : this should be an overlay
// the format of the text is:
// SCALEBAR = <length> <angle>
// where <length> is the length of the scalebar in microns,
// and <angle> is the angle in degrees
addGlobalMetaList("Note", n.toString());
break;
case NOTE_TYPE_ARROW:
// TODO : this should be an overlay
// the format of the text is:
// ARROW = <lx> <ly> <angle> <fill>
// where <lx> and <ly> define the arrow's bounding box,
// <angle> is the angle in degrees and <fill> is either "Fill" or
// "Outline"
addGlobalMetaList("Note", n.toString());
break;
case NOTE_TYPE_VARIABLE:
if (n.p.indexOf('=') >= 0) {
String key = n.p.substring(0, n.p.indexOf('=')).trim();
String value = n.p.substring(n.p.indexOf('=') + 1).trim();
addGlobalMeta(key, value);
if (key.equals("INFO_OBJECTIVE_NAME")) {
store.setObjectiveModel(value, 0, 0);
} else if (key.equals("INFO_OBJECTIVE_MAGNIFICATION")) {
Double mag = Double.parseDouble(value);
store.setObjectiveNominalMagnification(mag, 0, 0);
} else if (key.equals("LENS_MAGNIFICATION")) {
Double magnification = Double.parseDouble(value);
store.setObjectiveNominalMagnification(magnification, 0, 0);
} else if (key.startsWith("SETTING")) {
if (key.indexOf("_DET_") != -1) {
int index = key.indexOf("_DET_") + 5;
if (key.lastIndexOf("_") > index) {
String detectorID = MetadataTools.createLSID("Detector", 0, nextDetector);
store.setDetectorID(detectorID, 0, nextDetector);
store.setDetectorType(getDetectorType("Other"), 0, nextDetector);
if (key.endsWith("OFFSET")) {
if (nextDetector < offset.size()) {
offset.set(nextDetector, Double.parseDouble(value));
} else {
while (nextDetector > offset.size()) {
offset.add(null);
}
offset.add(new Double(value));
}
} else if (key.endsWith("GAIN")) {
if (nextDetector < gain.size()) {
gain.set(nextDetector, Double.parseDouble(value));
} else {
while (nextDetector > gain.size()) {
gain.add(null);
}
gain.add(new Double(value));
}
}
nextDetector++;
}
}
} else {
String[] values = value.split(" ");
if (values.length > 1) {
try {
int type = Integer.parseInt(values[0]);
if (type == 257 && values.length >= 3) {
// found length of axis in um
Double pixelSize = new Double(values[2]);
if (key.equals("AXIS_2")) {
Length size = FormatTools.getPhysicalSizeX(pixelSize);
if (size != null) {
store.setPixelsPhysicalSizeX(size, 0);
}
} else if (key.equals("AXIS_3")) {
Length size = FormatTools.getPhysicalSizeY(pixelSize);
if (size != null) {
store.setPixelsPhysicalSizeY(size, 0);
}
}
}
} catch (NumberFormatException e) {
}
}
}
} else if (n.p.startsWith("AXIS_2")) {
String[] values = n.p.split(" ");
Double pixelSize = new Double(values[3]);
Length size = FormatTools.getPhysicalSizeX(pixelSize);
if (size != null) {
store.setPixelsPhysicalSizeX(size, 0);
}
} else if (n.p.startsWith("AXIS_3")) {
String[] values = n.p.split(" ");
Double pixelSize = new Double(values[3]);
Length size = FormatTools.getPhysicalSizeY(pixelSize);
if (size != null) {
store.setPixelsPhysicalSizeY(size, 0);
}
} else {
addGlobalMetaList("Note", n.toString());
}
break;
case NOTE_TYPE_STRUCTURE:
int structureType = (n.x & 0xff00) >> 8;
int version = (n.x & 0xff);
String[] values = n.p.split(" ");
if (structureType == 1) {
switch(n.y) {
case 1:
for (int i = 0; i < STRUCTURE_LABELS_1.length; i++) {
addGlobalMeta(STRUCTURE_LABELS_1[i], values[i]);
}
Double mag = Double.parseDouble(values[11]);
store.setObjectiveNominalMagnification(mag, 0, 0);
Double sizeZ = new Double(values[14]);
Length size = FormatTools.getPhysicalSizeZ(sizeZ);
if (size != null) {
store.setPixelsPhysicalSizeZ(size, 0);
}
break;
case 2:
for (int i = 0; i < STRUCTURE_LABELS_2.length; i++) {
addGlobalMeta(STRUCTURE_LABELS_2[i], values[i]);
}
double x1 = Double.parseDouble(values[2]);
double x2 = Double.parseDouble(values[4]);
double width = x2 - x1;
width /= getSizeX();
double y1 = Double.parseDouble(values[3]);
double y2 = Double.parseDouble(values[5]);
double height = y2 - y1;
height /= getSizeY();
Length sizeX = FormatTools.getPhysicalSizeX(width);
Length sizeY = FormatTools.getPhysicalSizeY(height);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
break;
case 3:
for (int i = 0; i < 3; i++) {
for (int j = 0; j < STRUCTURE_LABELS_3.length; j++) {
String v = j == STRUCTURE_LABELS_3.length - 1 ? values[12 + i] : values[i * 4 + j];
addGlobalMetaList(STRUCTURE_LABELS_3[j], v);
}
}
break;
case 4:
nLasers = Integer.parseInt(values[0]);
addGlobalMeta("Number of lasers", values[0]);
addGlobalMeta("Number of transmission detectors", values[1]);
addGlobalMeta("Number of PMTs", values[2]);
for (int i = 1; i <= 3; i++) {
int idx = (i + 1) * 3;
addGlobalMetaList("Shutter present for laser", values[i + 2]);
addGlobalMetaList("Neutral density filter for laser", values[idx]);
addGlobalMetaList("Excitation filter for laser", values[idx + 1]);
addGlobalMetaList("Use laser", values[idx + 2]);
}
for (int i = 0; i < nLasers; i++) {
addGlobalMetaList("Neutral density filter name - laser", values[15 + i]);
}
break;
case 5:
String prefix = "Excitation filter name - laser";
for (int i = 0; i < nLasers; i++) {
addGlobalMetaList(prefix, values[i]);
}
break;
case 6:
prefix = "Emission filter name - laser";
for (int i = 0; i < nLasers; i++) {
addGlobalMeta(prefix, values[i]);
}
break;
case 7:
for (int i = 0; i < 2; i++) {
prefix = "Mixer " + i + " - ";
for (int j = 0; j < STRUCTURE_LABELS_4.length; j++) {
addGlobalMeta(prefix + STRUCTURE_LABELS_4[j], values[i * 7 + j]);
}
}
addGlobalMeta("Mixer 0 - low signal on", values[14]);
addGlobalMeta("Mixer 1 - low signal on", values[15]);
break;
case 8:
case 9:
case 10:
addGlobalMeta("Laser name - laser " + (n.y - 7), values[0]);
break;
case 11:
for (int i = 0; i < 3; i++) {
prefix = "Transmission detector " + (i + 1) + " - ";
addGlobalMeta(prefix + "offset", values[i * 3]);
addGlobalMeta(prefix + "gain", values[i * 3 + 1]);
addGlobalMeta(prefix + "black level", values[i * 3 + 2]);
String detectorID = MetadataTools.createLSID("Detector", 0, i);
store.setDetectorID(detectorID, 0, i);
store.setDetectorOffset(new Double(values[i * 3]), 0, i);
store.setDetectorGain(new Double(values[i * 3 + 1]), 0, i);
store.setDetectorType(getDetectorType("Other"), 0, i);
}
break;
case 12:
for (int i = 0; i < 2; i++) {
prefix = "Part number for ";
for (int j = 0; j < STRUCTURE_LABELS_5.length; j++) {
addGlobalMetaList(prefix + STRUCTURE_LABELS_5[j], values[i * 4 + j]);
}
}
break;
case 13:
for (int i = 0; i < STRUCTURE_LABELS_6.length; i++) {
addGlobalMeta(STRUCTURE_LABELS_6[i], values[i]);
}
break;
case 14:
prefix = "Filter Block Name - filter block ";
addGlobalMetaList(prefix, values[0]);
addGlobalMetaList(prefix, values[1]);
break;
case 15:
for (int i = 0; i < 5; i++) {
addGlobalMetaList("Image bands status - band", values[i * 3]);
addGlobalMetaList("Image bands min - band", values[i * 3 + 1]);
addGlobalMetaList("Image bands max - band", values[i * 3 + 2]);
if (store instanceof IMinMaxStore) {
((IMinMaxStore) store).setChannelGlobalMinMax(i, Double.parseDouble(values[i * 3 + 1]), Double.parseDouble(values[i * 3 + 2]), 0);
}
}
break;
case 17:
int year = Integer.parseInt(values[5]) + 1900;
for (int i = 0; i < 5; i++) {
if (values[i].length() == 1)
values[i] = "0" + values[i];
}
// date is in yyyy-MM-dd'T'HH:mm:ss
String date = year + "-" + values[4] + "-" + values[3] + "T" + values[2] + ":" + values[1] + ":" + values[0];
addGlobalMeta("Acquisition date", date);
try {
store.setImageAcquisitionDate(new Timestamp(date), 0);
} catch (Exception e) {
LOGGER.debug("Failed to parse acquisition date", e);
}
break;
case 18:
addGlobalMeta("Mixer 3 - enhanced", values[0]);
for (int i = 1; i <= 3; i++) {
addGlobalMetaList("Mixer 3 - PMT percentage", values[i]);
addGlobalMetaList("Mixer 3 - Transmission percentage", values[i + 3]);
addGlobalMetaList("Mixer 3 - photon counting", values[i + 7]);
}
addGlobalMeta("Mixer 3 - low signal on", values[7]);
addGlobalMeta("Mixer 3 - mode", values[11]);
break;
case 19:
for (int i = 1; i <= 2; i++) {
prefix = "Mixer " + i + " - ";
String photon = prefix + "photon counting ";
addGlobalMetaList(photon, values[i * 4 - 4]);
addGlobalMetaList(photon, values[i * 4 - 3]);
addGlobalMetaList(photon, values[i * 4 - 2]);
addGlobalMeta(prefix + "mode", values[i * 4 - 1]);
}
break;
case 20:
addGlobalMeta("Display mode", values[0]);
addGlobalMeta("Course", values[1]);
addGlobalMeta("Time Course - experiment type", values[2]);
addGlobalMeta("Time Course - kd factor", values[3]);
String experimentID = MetadataTools.createLSID("Experiment", 0);
store.setExperimentID(experimentID, 0);
store.setExperimentType(getExperimentType(values[2]), 0);
break;
case 21:
addGlobalMeta("Time Course - ion name", values[0]);
break;
case 22:
addGlobalMeta("PIC file generated on Isoscan (lite)", values[0]);
for (int i = 1; i <= 3; i++) {
addGlobalMetaList("Photon counting used - PMT", values[i]);
addGlobalMetaList("Hot spot filter used - PMT", values[i + 3]);
addGlobalMetaList("Tx Selector used - TX", values[i + 6]);
}
break;
}
}
break;
default:
// notes for display only
addGlobalMetaList("Note", n.toString());
}
}
if (n.p.indexOf("AXIS") != -1) {
n.p = n.p.replaceAll("=", "");
final List<String> v = new ArrayList<String>();
StringTokenizer tokens = new StringTokenizer(n.p, " ");
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken().trim();
if (token.length() > 0)
v.add(token);
}
String[] values = v.toArray(new String[v.size()]);
String key = values[0];
String noteType = values[1];
int axisType = Integer.parseInt(noteType);
if (axisType == 11 && values.length > 2) {
addGlobalMeta(key + " RGB type (X)", values[2]);
addGlobalMeta(key + " RGB type (Y)", values[3]);
CoreMetadata m = core.get(0);
if (key.equals("AXIS_4")) {
// this is a single section multi-channel dataset
m.sizeC = getImageCount();
m.sizeZ = 1;
m.sizeT = 1;
} else if (key.equals("AXIS_9")) {
multipleFiles = true;
m.sizeC = (int) Double.parseDouble(values[3]);
}
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM && values.length > 2) {
switch(axisType) {
case 1:
addGlobalMeta(key + " distance (X) in microns", values[2]);
addGlobalMeta(key + " distance (Y) in microns", values[3]);
break;
case 3:
addGlobalMeta(key + " angle (X) in degrees", values[2]);
addGlobalMeta(key + " angle (Y) in degrees", values[3]);
break;
case 4:
addGlobalMeta(key + " intensity (X)", values[2]);
addGlobalMeta(key + " intensity (Y)", values[3]);
break;
case 6:
addGlobalMeta(key + " ratio (X)", values[2]);
addGlobalMeta(key + " ratio (Y)", values[3]);
break;
case 7:
addGlobalMeta(key + " log ratio (X)", values[2]);
addGlobalMeta(key + " log ratio (Y)", values[3]);
break;
case 9:
addGlobalMeta(key + " noncalibrated intensity min", values[2]);
addGlobalMeta(key + " noncalibrated intensity max", values[3]);
addGlobalMeta(key + " calibrated intensity min", values[4]);
addGlobalMeta(key + " calibrated intensity max", values[5]);
break;
case 14:
addGlobalMeta(key + " time course type (X)", values[2]);
addGlobalMeta(key + " time course type (Y)", values[3]);
break;
case 15:
String prefix = " inverse sigmoid calibrated intensity ";
addGlobalMeta(key + prefix + "(min)", values[2]);
addGlobalMeta(key + prefix + "(max)", values[3]);
addGlobalMeta(key + prefix + "(beta)", values[4]);
addGlobalMeta(key + prefix + "(Kd)", values[5]);
break;
case 16:
prefix = " log inverse sigmoid calibrated intensity ";
addGlobalMeta(key + prefix + "(min)", values[2]);
addGlobalMeta(key + prefix + "(max)", values[3]);
addGlobalMeta(key + prefix + "(beta)", values[4]);
addGlobalMeta(key + prefix + "(Kd)", values[5]);
break;
}
}
}
}
return multipleFiles;
}
use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class CellH5Reader method parseStructure.
private void parseStructure() throws FormatException {
seriesCount = 0;
core.clear();
// read experiment structure and collect coordinates
String path_to_plate = CellH5Constants.PREFIX_PATH + CellH5Constants.PLATE;
LOGGER.info("Plate :" + path_to_plate);
for (String plate : jhdf.getMember(path_to_plate)) {
String path_to_well = path_to_plate + plate + CellH5Constants.WELL;
LOGGER.info("Well :" + path_to_well);
for (String well : jhdf.getMember(path_to_well)) {
String path_to_site = path_to_well + well + CellH5Constants.SITE;
LOGGER.info("Site :" + path_to_site);
for (String site : jhdf.getMember(path_to_site)) {
CellH5PositionList.add(new CellH5Coordinate(plate, well, site));
}
}
}
if (CellH5PositionList.size() == 0) {
throw new FormatException("No series found in file...");
}
List<String> seriesNames = new ArrayList<String>();
List<String> seriesPlate = new ArrayList<String>();
List<String> seriesWell = new ArrayList<String>();
List<String> seriesSite = new ArrayList<String>();
for (CellH5Coordinate coord : CellH5PositionList) {
if (jhdf.exists(coord.pathToImageData)) {
CoreMetadata m = new CoreMetadata();
core.add(m);
setSeries(seriesCount);
LOGGER.debug(coord.pathToImageData);
int[] ctzyx = jhdf.getShape(coord.pathToImageData);
m.sizeC = ctzyx[0];
m.sizeT = ctzyx[1];
m.sizeZ = ctzyx[2];
m.sizeY = ctzyx[3];
m.sizeX = ctzyx[4];
m.resolutionCount = 1;
m.thumbnail = false;
m.imageCount = getSizeC() * getSizeT() * getSizeZ();
m.dimensionOrder = "XYZTC";
m.rgb = false;
m.thumbSizeX = 128;
m.thumbSizeY = 128;
m.orderCertain = false;
m.littleEndian = true;
m.interleaved = false;
m.indexed = true;
int bpp = jhdf.getElementSize(coord.pathToImageData);
if (bpp == 1) {
m.pixelType = FormatTools.UINT8;
} else if (bpp == 2) {
m.pixelType = FormatTools.UINT16;
} else if (bpp == 4) {
m.pixelType = FormatTools.INT32;
} else {
throw new FormatException("Pixel type not understood. Only 8, " + "16 and 32 bit images supported");
}
seriesNames.add(String.format("P_%s, W_%s_%s", coord.plate, coord.well, coord.site));
seriesPlate.add(coord.plate);
seriesWell.add(coord.well);
seriesSite.add(coord.site);
CellH5PathsToImageData.add(coord.pathToImageData);
seriesCount++;
}
}
for (CellH5Coordinate coord : CellH5PositionList) {
if (jhdf.exists(coord.pathToSegmentationData)) {
CoreMetadata m = new CoreMetadata();
core.add(m);
setSeries(seriesCount);
LOGGER.debug(coord.pathToSegmentationData);
int[] ctzyx = jhdf.getShape(coord.pathToSegmentationData);
m.sizeC = ctzyx[0];
m.sizeT = ctzyx[1];
m.sizeZ = ctzyx[2];
m.sizeY = ctzyx[3];
m.sizeX = ctzyx[4];
m.resolutionCount = 1;
m.thumbnail = false;
m.imageCount = getSizeC() * getSizeT() * getSizeZ();
m.dimensionOrder = "XYZTC";
m.rgb = false;
m.thumbSizeX = 128;
m.thumbSizeY = 128;
m.orderCertain = false;
m.littleEndian = true;
m.interleaved = false;
m.indexed = true;
int bpp = jhdf.getElementSize(coord.pathToSegmentationData);
if (bpp == 1) {
m.pixelType = FormatTools.UINT8;
} else if (bpp == 2) {
m.pixelType = FormatTools.UINT16;
} else if (bpp == 4) {
m.pixelType = FormatTools.INT32;
} else {
throw new FormatException("Pixel type not understood. Only 8, " + "16 and 32 bit images supported");
}
seriesNames.add(String.format("P_%s, W_%s_%s label image", coord.plate, coord.well, coord.site));
seriesPlate.add(coord.plate);
seriesWell.add(coord.well);
seriesSite.add(coord.site);
CellH5PathsToImageData.add(coord.pathToSegmentationData);
seriesCount++;
}
}
if (seriesCount == 0) {
throw new FormatException("No image data found...");
}
store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
for (int s = 0; s < seriesNames.size(); s++) {
String image_id = MetadataTools.createLSID("Image", s);
store.setImageName(seriesNames.get(s), s);
String plate_id = MetadataTools.createLSID("Plate", 0);
store.setPlateID(plate_id, 0);
store.setPlateName(seriesPlate.get(s), 0);
String well_id = MetadataTools.createLSID("Well", 0);
store.setWellID(well_id, 0, 0);
String cellh5WellCoord = seriesWell.get(s);
String wellRowLetter = cellh5WellCoord.substring(0, 1);
String wellColNumber = cellh5WellCoord.substring(1);
int wellRowLetterIndex = "ABCDEFGHIJKLMNOP".indexOf(wellRowLetter);
int wellColNumberIndex = -1;
try {
wellColNumberIndex = Integer.parseInt(wellColNumber);
} catch (NumberFormatException e) {
//
}
if (wellRowLetterIndex > -1 && wellColNumberIndex > 0) {
store.setWellRow(new NonNegativeInteger(wellRowLetterIndex), 0, 0);
store.setWellColumn(new NonNegativeInteger(wellColNumberIndex - 1), 0, 0);
} else {
store.setWellRow(new NonNegativeInteger(0), 0, 0);
store.setWellColumn(new NonNegativeInteger(0), 0, 0);
}
store.setWellExternalIdentifier(cellh5WellCoord, 0, 0);
String site_id = MetadataTools.createLSID("WellSample", 0);
store.setWellSampleID(site_id, 0, 0, 0);
store.setWellSampleIndex(NonNegativeInteger.valueOf(seriesSite.get(s)), 0, 0, 0);
store.setWellSampleImageRef(image_id, 0, 0, 0);
}
setSeries(0);
parseCellObjects();
}
use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class CellSensReader method parseETSFile.
private void parseETSFile(String file, int s) throws FormatException, IOException {
fileMap.put(core.size() - 1, file);
RandomAccessInputStream etsFile = new RandomAccessInputStream(file);
etsFile.order(true);
CoreMetadata ms = core.get(getCoreIndex());
// read the volume header
String magic = etsFile.readString(4).trim();
if (!magic.equals("SIS")) {
throw new FormatException("Unknown magic bytes: " + magic);
}
int headerSize = etsFile.readInt();
int version = etsFile.readInt();
nDimensions.add(etsFile.readInt());
long additionalHeaderOffset = etsFile.readLong();
int additionalHeaderSize = etsFile.readInt();
// reserved
etsFile.skipBytes(4);
long usedChunkOffset = etsFile.readLong();
int nUsedChunks = etsFile.readInt();
// reserved
etsFile.skipBytes(4);
// read the additional header
etsFile.seek(additionalHeaderOffset);
String moreMagic = etsFile.readString(4).trim();
if (!moreMagic.equals("ETS")) {
throw new FormatException("Unknown magic bytes: " + moreMagic);
}
// extra version number
etsFile.skipBytes(4);
int pixelType = etsFile.readInt();
ms.sizeC = etsFile.readInt();
int colorspace = etsFile.readInt();
compressionType.add(etsFile.readInt());
int compressionQuality = etsFile.readInt();
tileX.add(etsFile.readInt());
tileY.add(etsFile.readInt());
int tileZ = etsFile.readInt();
// pixel info hints
etsFile.skipBytes(4 * 17);
byte[] color = new byte[ms.sizeC * FormatTools.getBytesPerPixel(convertPixelType(pixelType))];
etsFile.read(color);
backgroundColor.put(getCoreIndex(), color);
// background color
etsFile.skipBytes(4 * 10 - color.length);
// component order
etsFile.skipBytes(4);
boolean usePyramid = etsFile.readInt() != 0;
ms.rgb = ms.sizeC > 1;
// read the used chunks
etsFile.seek(usedChunkOffset);
tileOffsets.add(new Long[nUsedChunks]);
ArrayList<TileCoordinate> tmpTiles = new ArrayList<TileCoordinate>();
for (int chunk = 0; chunk < nUsedChunks; chunk++) {
etsFile.skipBytes(4);
int dimensions = nDimensions.get(nDimensions.size() - 1);
TileCoordinate t = new TileCoordinate(dimensions);
for (int i = 0; i < dimensions; i++) {
t.coordinate[i] = etsFile.readInt();
}
tileOffsets.get(tileOffsets.size() - 1)[chunk] = etsFile.readLong();
int nBytes = etsFile.readInt();
etsFile.skipBytes(4);
tmpTiles.add(t);
}
int maxResolution = 0;
if (usePyramid) {
for (TileCoordinate t : tmpTiles) {
if (t.coordinate[t.coordinate.length - 1] > maxResolution) {
maxResolution = t.coordinate[t.coordinate.length - 1];
}
}
}
maxResolution++;
int[] maxX = new int[maxResolution];
int[] maxY = new int[maxResolution];
int[] maxZ = new int[maxResolution];
int[] maxC = new int[maxResolution];
int[] maxT = new int[maxResolution];
HashMap<String, Integer> dimOrder = pyramids.get(s).dimensionOrdering;
for (TileCoordinate t : tmpTiles) {
int resolution = usePyramid ? t.coordinate[t.coordinate.length - 1] : 0;
Integer tv = dimOrder.get("T");
Integer zv = dimOrder.get("Z");
Integer cv = dimOrder.get("C");
int tIndex = tv == null ? -1 : tv + 2;
int zIndex = zv == null ? -1 : zv + 2;
int cIndex = cv == null ? -1 : cv + 2;
if (usePyramid && tIndex == t.coordinate.length - 1) {
tv = null;
tIndex = -1;
}
if (usePyramid && zIndex == t.coordinate.length - 1) {
zv = null;
zIndex = -1;
}
int upperLimit = usePyramid ? t.coordinate.length - 1 : t.coordinate.length;
if ((tIndex < 0 || tIndex >= upperLimit) && (zIndex < 0 || zIndex >= upperLimit) && (cIndex < 0 || cIndex >= upperLimit)) {
tIndex--;
zIndex--;
cIndex--;
if (dimOrder.containsKey("T")) {
dimOrder.put("T", tIndex - 2);
}
if (dimOrder.containsKey("Z")) {
dimOrder.put("Z", zIndex - 2);
}
if (dimOrder.containsKey("C")) {
dimOrder.put("C", cIndex - 2);
}
}
if (tv == null && zv == null) {
if (t.coordinate.length > 4 && cv == null) {
cIndex = 2;
dimOrder.put("C", cIndex - 2);
}
if (t.coordinate.length > 4) {
if (cv == null) {
tIndex = 3;
} else {
tIndex = cIndex + 2;
}
if (tIndex < t.coordinate.length) {
dimOrder.put("T", tIndex - 2);
} else {
tIndex = -1;
}
}
if (t.coordinate.length > 5) {
if (cv == null) {
zIndex = 4;
} else {
zIndex = cIndex + 1;
}
if (zIndex < t.coordinate.length) {
dimOrder.put("Z", zIndex - 2);
} else {
zIndex = -1;
}
}
}
if (t.coordinate[0] > maxX[resolution]) {
maxX[resolution] = t.coordinate[0];
}
if (t.coordinate[1] > maxY[resolution]) {
maxY[resolution] = t.coordinate[1];
}
if (tIndex >= 0 && t.coordinate[tIndex] > maxT[resolution]) {
maxT[resolution] = t.coordinate[tIndex];
}
if (zIndex >= 0 && t.coordinate[zIndex] > maxZ[resolution]) {
maxZ[resolution] = t.coordinate[zIndex];
}
if (cIndex >= 0 && t.coordinate[cIndex] > maxC[resolution]) {
maxC[resolution] = t.coordinate[cIndex];
}
}
if (pyramids.get(s).width != null) {
ms.sizeX = pyramids.get(s).width;
}
if (pyramids.get(s).height != null) {
ms.sizeY = pyramids.get(s).height;
}
ms.sizeZ = maxZ[0] + 1;
if (maxC[0] > 0) {
ms.sizeC *= (maxC[0] + 1);
}
ms.sizeT = maxT[0] + 1;
if (ms.sizeZ == 0) {
ms.sizeZ = 1;
}
ms.imageCount = ms.sizeZ * ms.sizeT;
if (maxC[0] > 0) {
ms.imageCount *= (maxC[0] + 1);
}
if (maxY[0] >= 1) {
rows.add(maxY[0] + 1);
} else {
rows.add(1);
}
if (maxX[0] >= 1) {
cols.add(maxX[0] + 1);
} else {
cols.add(1);
}
ArrayList<TileCoordinate> map = new ArrayList<TileCoordinate>();
for (int i = 0; i < tmpTiles.size(); i++) {
map.add(tmpTiles.get(i));
}
tileMap.add(map);
ms.pixelType = convertPixelType(pixelType);
if (usePyramid) {
int finalResolution = 1;
int initialCoreSize = core.size();
for (int i = 1; i < maxResolution; i++) {
CoreMetadata newResolution = new CoreMetadata(ms);
int previousX = core.get(core.size() - 1).sizeX;
int previousY = core.get(core.size() - 1).sizeY;
int maxSizeX = tileX.get(tileX.size() - 1) * (maxX[i] < 1 ? 1 : maxX[i] + 1);
int maxSizeY = tileY.get(tileY.size() - 1) * (maxY[i] < 1 ? 1 : maxY[i] + 1);
newResolution.sizeX = previousX / 2;
if (previousX % 2 == 1 && newResolution.sizeX < maxSizeX) {
newResolution.sizeX++;
} else if (newResolution.sizeX > maxSizeX) {
newResolution.sizeX = maxSizeX;
}
newResolution.sizeY = previousY / 2;
if (previousY % 2 == 1 && newResolution.sizeY < maxSizeY) {
newResolution.sizeY++;
} else if (newResolution.sizeY > maxSizeY) {
newResolution.sizeY = maxSizeY;
}
newResolution.sizeZ = maxZ[i] + 1;
if (maxC[i] > 0 && newResolution.sizeC != (maxC[i] + 1)) {
newResolution.sizeC *= (maxC[i] + 1);
}
newResolution.sizeT = maxT[i] + 1;
if (newResolution.sizeZ == 0) {
newResolution.sizeZ = 1;
}
newResolution.imageCount = newResolution.sizeZ * newResolution.sizeT;
if (maxC[i] > 0) {
newResolution.imageCount *= (maxC[i] + 1);
}
newResolution.metadataComplete = true;
newResolution.dimensionOrder = "XYCZT";
core.add(newResolution);
rows.add(maxY[i] >= 1 ? maxY[i] + 1 : 1);
cols.add(maxX[i] >= 1 ? maxX[i] + 1 : 1);
fileMap.put(core.size() - 1, file);
finalResolution = core.size() - initialCoreSize + 1;
tileX.add(tileX.get(tileX.size() - 1));
tileY.add(tileY.get(tileY.size() - 1));
compressionType.add(compressionType.get(compressionType.size() - 1));
tileMap.add(map);
nDimensions.add(nDimensions.get(nDimensions.size() - 1));
tileOffsets.add(tileOffsets.get(tileOffsets.size() - 1));
backgroundColor.put(core.size() - 1, color);
}
ms.resolutionCount = finalResolution;
}
etsFile.close();
}
use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class ARFReader 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);
// parse file header
LOGGER.info("Reading file header");
byte endian1 = in.readByte();
byte endian2 = in.readByte();
boolean little;
if (endian1 == 1 && endian2 == 0)
little = true;
else if (endian1 == 0 && endian2 == 1)
little = false;
else
throw new FormatException("Undefined endianness");
in.order(little);
// 'AR' signature
in.skipBytes(2);
int version = in.readUnsignedShort();
int width = in.readUnsignedShort();
int height = in.readUnsignedShort();
int bitsPerPixel = in.readUnsignedShort();
int numImages = version == 2 ? in.readUnsignedShort() : 1;
// NB: The next 510 bytes are unused 'application dependent' data,
// followed by raw image data with no padding.
// populate core metadata
CoreMetadata m = core.get(0);
m.sizeX = width;
m.sizeY = height;
m.sizeZ = 1;
m.sizeC = 1;
m.sizeT = numImages;
int bpp = bitsPerPixel / 8;
if ((bitsPerPixel % 8) != 0)
bpp++;
m.pixelType = FormatTools.pixelTypeFromBytes(bpp, false, false);
m.bitsPerPixel = bitsPerPixel;
m.imageCount = numImages;
m.dimensionOrder = "XYCZT";
m.orderCertain = true;
m.littleEndian = little;
m.rgb = false;
m.interleaved = false;
m.indexed = false;
m.metadataComplete = true;
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
// populate original metadata
addGlobalMeta("Endianness", little ? "little" : "big");
addGlobalMeta("Version", version);
addGlobalMeta("Width", width);
addGlobalMeta("Height", height);
addGlobalMeta("Bits per pixel", bitsPerPixel);
addGlobalMeta("Image count", numImages);
}
// populate OME metadata
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
}
use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class AliconaReader 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);
// check that this is a valid AL3D file
LOGGER.info("Verifying Alicona format");
String magicString = in.readString(17);
if (!magicString.trim().equals("AliconaImaging")) {
throw new FormatException("Invalid magic string : " + "expected 'AliconaImaging', got " + magicString);
}
// now we read a series of tags
// each one is 52 bytes - 20 byte key + 30 byte value + 2 byte CRLF
LOGGER.info("Reading tags");
int count = 2;
boolean hasC = false;
String voltage = null, magnification = null, workingDistance = null;
String pntX = null, pntY = null;
int depthOffset = 0;
for (int i = 0; i < count; i++) {
String key = in.readString(20).trim();
String value = in.readString(30).trim();
addGlobalMeta(key, value);
in.skipBytes(2);
if (key.equals("TagCount"))
count += Integer.parseInt(value);
else if (key.equals("Rows"))
m.sizeY = Integer.parseInt(value);
else if (key.equals("Cols"))
m.sizeX = Integer.parseInt(value);
else if (key.equals("NumberOfPlanes")) {
m.imageCount = Integer.parseInt(value);
} else if (key.equals("TextureImageOffset")) {
textureOffset = Integer.parseInt(value);
} else if (key.equals("TexturePtr") && !value.equals("7"))
hasC = true;
else if (key.equals("Voltage"))
voltage = value;
else if (key.equals("Magnification"))
magnification = value;
else if (key.equals("PixelSizeXMeter"))
pntX = value;
else if (key.equals("PixelSizeYMeter"))
pntY = value;
else if (key.equals("WorkingDistance"))
workingDistance = value;
else if (key.equals("DepthImageOffset")) {
depthOffset = Integer.parseInt(value);
}
}
LOGGER.info("Populating metadata");
if (textureOffset != 0) {
numBytes = (int) (in.length() - textureOffset) / (getSizeX() * getSizeY() * getImageCount());
m.sizeC = hasC ? 3 : 1;
m.sizeZ = 1;
m.sizeT = getImageCount() / getSizeC();
m.pixelType = FormatTools.pixelTypeFromBytes(numBytes, false, false);
} else {
textureOffset = depthOffset;
m.pixelType = FormatTools.FLOAT;
m.sizeC = 1;
m.sizeZ = 1;
m.sizeT = 1;
m.imageCount = 1;
}
m.rgb = false;
m.interleaved = false;
m.littleEndian = true;
m.dimensionOrder = "XYCTZ";
m.metadataComplete = true;
m.indexed = false;
m.falseColor = false;
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
// link Image and Instrument
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
store.setImageInstrumentRef(instrumentID, 0);
// used when the dataset was acquired, i.e. detector settings.
if (voltage != null) {
store.setDetectorSettingsVoltage(new ElectricPotential(new Double(voltage), UNITS.VOLT), 0, 0);
// link DetectorSettings to an actual Detector
String detectorID = MetadataTools.createLSID("Detector", 0, 0);
store.setDetectorID(detectorID, 0, 0);
store.setDetectorSettingsID(detectorID, 0, 0);
// set required Detector type
store.setDetectorType(getDetectorType("Other"), 0, 0);
}
if (magnification != null) {
store.setObjectiveCalibratedMagnification(new Double(magnification), 0, 0);
}
if (workingDistance != null) {
store.setObjectiveWorkingDistance(new Length(new Double(workingDistance), UNITS.MICROMETER), 0, 0);
}
store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
// link Objective to an Image using ObjectiveSettings
String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
store.setObjectiveID(objectiveID, 0, 0);
store.setObjectiveSettingsID(objectiveID, 0);
if (pntX != null && pntY != null) {
double pixelSizeX = Double.parseDouble(pntX);
double pixelSizeY = Double.parseDouble(pntY);
Length sizeX = FormatTools.getPhysicalSizeX(pixelSizeX, UNITS.METER);
Length sizeY = FormatTools.getPhysicalSizeY(pixelSizeY, UNITS.METER);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, 0);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, 0);
}
}
}
}
Aggregations