use of loci.formats.MissingLibraryException in project bioformats by openmicroscopy.
the class LegacyND2Reader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
try {
openFile(id);
int numSeries = getNumSeries();
core.clear();
for (int i = 0; i < numSeries; i++) {
CoreMetadata ms = new CoreMetadata();
core.add(ms);
ms.sizeX = getWidth(i);
if (ms.sizeX % 2 != 0)
ms.sizeX++;
ms.sizeY = getHeight(i);
ms.sizeZ = getZSlices(i);
ms.sizeT = getTFrames(i);
ms.sizeC = getChannels(i);
int bytes = getBytesPerPixel(i);
if (bytes % 3 == 0) {
ms.sizeC *= 3;
bytes /= 3;
ms.rgb = true;
} else
ms.rgb = false;
ms.pixelType = FormatTools.pixelTypeFromBytes(bytes, false, true);
ms.imageCount = ms.sizeZ * ms.sizeT;
if (!ms.rgb)
ms.imageCount *= ms.sizeC;
ms.interleaved = true;
ms.littleEndian = true;
ms.dimensionOrder = "XYCZT";
ms.indexed = false;
ms.falseColor = false;
}
} catch (UnsatisfiedLinkError e) {
throw new MissingLibraryException(NO_NIKON_MSG, e);
} catch (Exception e) {
throw new MissingLibraryException(NO_NIKON_MSG, e);
}
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageName("Series " + (i + 1), i);
}
}
use of loci.formats.MissingLibraryException in project bioformats by openmicroscopy.
the class MINCReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
try {
ServiceFactory factory = new ServiceFactory();
netcdf = factory.getInstance(NetCDFService.class);
netcdf.setFile(id);
} catch (DependencyException e) {
throw new MissingLibraryException(e);
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
Vector<String> variableList = netcdf.getVariableList();
for (String variable : variableList) {
Hashtable<String, Object> attributes = netcdf.getVariableAttributes(variable);
String[] keys = attributes.keySet().toArray(new String[0]);
Arrays.sort(keys);
for (String key : keys) {
if (attributes.get(key) instanceof Object[]) {
final StringBuilder sb = new StringBuilder();
Object[] o = (Object[]) attributes.get(key);
for (Object q : o) {
sb.append(q.toString());
}
addGlobalMeta(variable + " " + key, sb.toString());
} else {
addGlobalMeta(variable + " " + key, attributes.get(key));
}
}
}
}
CoreMetadata m = core.get(0);
try {
Object pixels = netcdf.getVariableValue("/image");
if (pixels == null) {
pixels = netcdf.getVariableValue("/minc-2.0/image/0/image");
isMINC2 = true;
}
m.littleEndian = isMINC2;
boolean signed = false;
if (isMINC2) {
Hashtable<String, Object> attrs = netcdf.getVariableAttributes("/minc-2.0/image/0/image");
String unsigned = attrs.get("_Unsigned").toString();
if (!unsigned.startsWith("true")) {
signed = true;
}
} else {
Hashtable<String, Object> attrs = netcdf.getVariableAttributes("/image");
String signtype = attrs.get("signtype").toString();
if (signtype.startsWith("signed")) {
signed = true;
}
}
if (pixels instanceof byte[][][]) {
m.pixelType = signed ? FormatTools.INT8 : FormatTools.UINT8;
pixelData = (byte[][][]) pixels;
} else if (pixels instanceof byte[][][][]) {
byte[][][][] actualPixels = (byte[][][][]) pixels;
m.pixelType = signed ? FormatTools.INT8 : FormatTools.UINT8;
pixelData = new byte[actualPixels.length * actualPixels[0].length][][];
int nextPlane = 0;
for (int t = 0; t < actualPixels.length; t++) {
for (int z = 0; z < actualPixels[t].length; z++) {
pixelData[nextPlane++] = actualPixels[t][z];
}
}
} else if (pixels instanceof short[][][]) {
m.pixelType = signed ? FormatTools.INT16 : FormatTools.UINT16;
short[][][] s = (short[][][]) pixels;
pixelData = new byte[s.length][][];
for (int i = 0; i < s.length; i++) {
pixelData[i] = new byte[s[i].length][];
for (int j = 0; j < s[i].length; j++) {
pixelData[i][j] = DataTools.shortsToBytes(s[i][j], isLittleEndian());
}
}
} else if (pixels instanceof int[][][]) {
m.pixelType = signed ? FormatTools.INT32 : FormatTools.UINT32;
int[][][] s = (int[][][]) pixels;
pixelData = new byte[s.length][][];
for (int i = 0; i < s.length; i++) {
pixelData[i] = new byte[s[i].length][];
for (int j = 0; j < s[i].length; j++) {
pixelData[i][j] = DataTools.intsToBytes(s[i][j], isLittleEndian());
}
}
} else if (pixels instanceof float[][][]) {
m.pixelType = FormatTools.FLOAT;
float[][][] s = (float[][][]) pixels;
pixelData = new byte[s.length][][];
for (int i = 0; i < s.length; i++) {
pixelData[i] = new byte[s[i].length][];
for (int j = 0; j < s[i].length; j++) {
pixelData[i][j] = DataTools.floatsToBytes(s[i][j], isLittleEndian());
}
}
} else if (pixels instanceof double[][][]) {
m.pixelType = FormatTools.DOUBLE;
double[][][] s = (double[][][]) pixels;
pixelData = new byte[s.length][][];
for (int i = 0; i < s.length; i++) {
pixelData[i] = new byte[s[i].length][];
for (int j = 0; j < s[i].length; j++) {
pixelData[i][j] = DataTools.doublesToBytes(s[i][j], isLittleEndian());
}
}
}
} catch (ServiceException e) {
throw new FormatException(e);
}
Length physicalX = null;
Length physicalY = null;
Length physicalZ = null;
Length xPosition = null;
Length yPosition = null;
Length zPosition = null;
if (isMINC2) {
Hashtable<String, Object> attrs = netcdf.getVariableAttributes("/minc-2.0/dimensions/xspace");
m.sizeX = Integer.parseInt(attrs.get("length").toString());
physicalX = getStepSize(attrs);
xPosition = getStart(attrs);
attrs = netcdf.getVariableAttributes("/minc-2.0/dimensions/yspace");
m.sizeY = Integer.parseInt(attrs.get("length").toString());
physicalY = getStepSize(attrs);
yPosition = getStart(attrs);
attrs = netcdf.getVariableAttributes("/minc-2.0/dimensions/zspace");
m.sizeZ = Integer.parseInt(attrs.get("length").toString());
physicalZ = getStepSize(attrs);
zPosition = getStart(attrs);
} else {
m.sizeX = netcdf.getDimension("/xspace");
m.sizeY = netcdf.getDimension("/yspace");
m.sizeZ = netcdf.getDimension("/zspace");
Hashtable<String, Object> attrs = netcdf.getVariableAttributes("/xspace");
physicalX = getStepSize(attrs);
xPosition = getStart(attrs);
attrs = netcdf.getVariableAttributes("/yspace");
physicalY = getStepSize(attrs);
yPosition = getStart(attrs);
attrs = netcdf.getVariableAttributes("/zspace");
physicalZ = getStepSize(attrs);
zPosition = getStart(attrs);
}
try {
m.sizeT = netcdf.getDimension("/time");
} catch (NullPointerException e) {
m.sizeT = 1;
}
m.sizeC = 1;
m.imageCount = getSizeZ() * getSizeT() * getSizeC();
m.rgb = false;
m.indexed = false;
m.dimensionOrder = "XYZCT";
String history = null;
if (isMINC2) {
history = netcdf.getAttributeValue("/minc-2.0/ident");
} else {
history = netcdf.getAttributeValue("/history");
}
addGlobalMeta("Comment", history);
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, xPosition != null || yPosition != null || zPosition != null);
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
store.setImageDescription(history, 0);
if (physicalX != null) {
store.setPixelsPhysicalSizeX(physicalX, 0);
}
if (physicalY != null) {
store.setPixelsPhysicalSizeY(physicalY, 0);
}
if (physicalZ != null) {
store.setPixelsPhysicalSizeZ(physicalZ, 0);
}
for (int i = 0; i < getImageCount(); i++) {
if (xPosition != null) {
store.setPlanePositionX(xPosition, 0, i);
}
if (yPosition != null) {
store.setPlanePositionY(yPosition, 0, i);
}
if (zPosition != null) {
int z = getZCTCoords(i)[0];
Double pos = zPosition.value().doubleValue();
if (physicalZ != null && z > 0) {
pos += z * physicalZ.value().doubleValue();
}
store.setPlanePositionZ(FormatTools.createLength(pos, zPosition.unit()), 0, i);
}
}
}
}
use of loci.formats.MissingLibraryException in project bioformats by openmicroscopy.
the class ImarisHDFReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
try {
ServiceFactory factory = new ServiceFactory();
netcdf = factory.getInstance(NetCDFService.class);
netcdf.setFile(id);
} catch (DependencyException e) {
throw new MissingLibraryException(NetCDFServiceImpl.NO_NETCDF_MSG, e);
}
pixelSizeX = pixelSizeY = pixelSizeZ = 1;
emWave = new ArrayList<String>();
exWave = new ArrayList<String>();
channelMin = new ArrayList<String>();
channelMax = new ArrayList<String>();
gain = new ArrayList<String>();
pinhole = new ArrayList<String>();
channelName = new ArrayList<String>();
microscopyMode = new ArrayList<String>();
colors = new ArrayList<double[]>();
seriesCount = 0;
// read all of the metadata key/value pairs
parseAttributes();
CoreMetadata ms0 = core.get(0);
if (seriesCount > 1) {
for (int i = 1; i < seriesCount; i++) {
core.add(new CoreMetadata());
}
for (int i = 1; i < seriesCount; i++) {
CoreMetadata ms = core.get(i);
String groupPath = "DataSet/ResolutionLevel_" + i + "/TimePoint_0/Channel_0";
ms.sizeX = Integer.parseInt(netcdf.getAttributeValue(groupPath + "/ImageSizeX"));
ms.sizeY = Integer.parseInt(netcdf.getAttributeValue(groupPath + "/ImageSizeY"));
ms.sizeZ = Integer.parseInt(netcdf.getAttributeValue(groupPath + "/ImageSizeZ"));
ms.imageCount = ms.sizeZ * getSizeC() * getSizeT();
ms.sizeC = getSizeC();
ms.sizeT = getSizeT();
ms.thumbnail = true;
if (ms.sizeZ == ms0.sizeZ && ms.sizeC == ms0.sizeC && ms.sizeT == ms0.sizeT) {
// do not assume that all series will have the same dimensions
// if the Z, C or T size is different, then it cannot
// be a subresolution
ms0.resolutionCount++;
}
}
}
ms0.imageCount = getSizeZ() * getSizeC() * getSizeT();
ms0.thumbnail = false;
ms0.dimensionOrder = "XYZCT";
// determine pixel type - this isn't stored in the metadata, so we need
// to check the pixels themselves
int type = -1;
Object pix = getImageData(0, 0, 0, 1, 1);
if (pix instanceof byte[][])
type = FormatTools.UINT8;
else if (pix instanceof short[][])
type = FormatTools.UINT16;
else if (pix instanceof int[][])
type = FormatTools.UINT32;
else if (pix instanceof float[][])
type = FormatTools.FLOAT;
else if (pix instanceof double[][])
type = FormatTools.DOUBLE;
else {
throw new FormatException("Unknown pixel type: " + pix);
}
for (int i = 0; i < core.size(); i++) {
CoreMetadata ms = core.get(i);
ms.pixelType = type;
ms.dimensionOrder = "XYZCT";
ms.rgb = false;
ms.thumbSizeX = 128;
ms.thumbSizeY = 128;
ms.orderCertain = true;
ms.littleEndian = true;
ms.interleaved = false;
ms.indexed = colors.size() >= getSizeC();
}
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
String imageName = new Location(getCurrentFile()).getName();
for (int s = 0; s < getSeriesCount(); s++) {
store.setImageName(imageName + " Resolution Level " + (s + 1), s);
}
if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM) {
return;
}
int cIndex = 0;
for (int s = 0; s < getSeriesCount(); s++) {
setSeries(s);
double px = pixelSizeX, py = pixelSizeY, pz = pixelSizeZ;
if (px == 1)
px = (maxX - minX) / getSizeX();
if (py == 1)
py = (maxY - minY) / getSizeY();
if (pz == 1)
pz = (maxZ - minZ) / getSizeZ();
Length sizeX = FormatTools.getPhysicalSizeX(px);
Length sizeY = FormatTools.getPhysicalSizeY(py);
Length sizeZ = FormatTools.getPhysicalSizeZ(pz);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, s);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, s);
}
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, s);
}
for (int i = 0; i < getSizeC(); i++, cIndex++) {
Float gainValue = null;
Integer pinholeValue = null, emWaveValue = null, exWaveValue;
if (cIndex < gain.size()) {
try {
gainValue = new Float(gain.get(cIndex));
} catch (NumberFormatException e) {
}
}
if (cIndex < pinhole.size()) {
try {
pinholeValue = new Integer(pinhole.get(cIndex));
} catch (NumberFormatException e) {
}
}
if (cIndex < emWave.size()) {
try {
emWaveValue = new Integer(emWave.get(cIndex));
} catch (NumberFormatException e) {
}
}
if (cIndex < exWave.size()) {
try {
exWaveValue = new Integer(exWave.get(cIndex));
} catch (NumberFormatException e) {
}
}
Double minValue = null, maxValue = null;
if (cIndex < channelMin.size()) {
try {
minValue = new Double(channelMin.get(cIndex));
} catch (NumberFormatException e) {
}
}
if (cIndex < channelMax.size()) {
try {
maxValue = new Double(channelMax.get(cIndex));
} catch (NumberFormatException e) {
}
}
if (i < colors.size()) {
double[] color = colors.get(i);
Color realColor = new Color((int) (color[0] * 255), (int) (color[1] * 255), (int) (color[2] * 255), 255);
store.setChannelColor(realColor, s, i);
}
}
}
setSeries(0);
}
use of loci.formats.MissingLibraryException in project bioformats by openmicroscopy.
the class VolocityReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
if (!checkSuffix(id, "mvd2")) {
Location file = new Location(id).getAbsoluteFile();
Location parent = file.getParentFile().getParentFile();
String[] files = parent.list(true);
for (String f : files) {
if (checkSuffix(f, "mvd2")) {
id = new Location(parent, f).getAbsolutePath();
break;
}
}
}
super.initFile(id);
stacks = new ArrayList<Stack>();
extraFiles = new ArrayList<String>();
Location file = new Location(id).getAbsoluteFile();
extraFiles.add(file.getAbsolutePath());
Location parentDir = file.getParentFile();
dir = new Location(parentDir, DATA_DIR);
if (dir.exists()) {
String[] files = dir.list(true);
for (String f : files) {
if (!checkSuffix(f, "aisf") && !checkSuffix(f, "atsf")) {
extraFiles.add(new Location(dir, f).getAbsolutePath());
}
}
}
try {
ServiceFactory factory = new ServiceFactory();
MetakitService reader = factory.getInstance(MetakitService.class);
reader.initialize(id);
sampleTable = reader.getTableData(1);
stringTable = reader.getTableData(2);
reader.close();
} catch (DependencyException e) {
throw new MissingLibraryException("Could not find Metakit library", e);
}
ArrayList<String> stackNames = new ArrayList<String>();
ArrayList<Integer> parentIDs = new ArrayList<Integer>();
for (int i = 0; i < sampleTable.length; i++) {
Integer stringID = (Integer) sampleTable[i][11];
String name = getString(stringID);
int channelIndex = getChildIndex((Integer) sampleTable[i][0], "Channels");
if (i > 0 && (Integer) sampleTable[i][2] == 1 && (channelIndex >= 0 || (sampleTable[i][14] != null && !sampleTable[i][14].equals(0)) || ((byte[]) sampleTable[i][13]).length > 21)) {
if (channelIndex < 0) {
RandomAccessInputStream s = getStream(i);
s.seek(0);
if (s.read() != 'I') {
s.order(false);
}
s.seek(22);
int x = s.readInt();
int y = s.readInt();
int z = s.readInt();
if (x * y * z > 0 && x * y * z < (s.length() * 3)) {
stackNames.add(name);
parentIDs.add((Integer) sampleTable[i][0]);
}
s.close();
} else {
stackNames.add(name);
parentIDs.add((Integer) sampleTable[i][0]);
}
}
}
for (int i = 0; i < parentIDs.size(); i++) {
Stack stack = new Stack();
stack.core = new CoreMetadata();
Integer parent = parentIDs.get(i);
int channelIndex = getChildIndex(parent, "Channels");
if (channelIndex >= 0) {
Integer[] channels = getAllChildren((Integer) sampleTable[channelIndex][0]);
stack.core.sizeC = channels.length;
stack.pixelsFiles = new String[stack.core.sizeC];
stack.channelNames = new String[channels.length];
for (int c = 0; c < channels.length; c++) {
stack.channelNames[c] = getString((Integer) sampleTable[channels[c]][11]);
RandomAccessInputStream data = getStream(channels[c]);
if (data.length() > 22) {
data.seek(22);
int stackID = data.readInt();
Location f = new Location(dir, stackID + ".aisf");
if (!f.exists()) {
f = new Location(dir, DataTools.swap(stackID) + ".aisf");
}
stack.pixelsFiles[c] = f.getAbsolutePath();
} else {
Integer child = getAllChildren((Integer) sampleTable[channels[c]][0])[0];
stack.pixelsFiles[c] = getFile((Integer) sampleTable[child][0], dir);
}
data.close();
}
} else {
stack.pixelsFiles = new String[1];
stack.pixelsFiles[0] = getFile(parent, dir);
if (stack.pixelsFiles[0] == null || !new Location(stack.pixelsFiles[0]).exists()) {
int row = -1;
for (int r = 0; r < sampleTable.length; r++) {
if (sampleTable[r][0].equals(parent)) {
row = r;
break;
}
}
stack.pixelsFiles[0] = EMBEDDED_STREAM;
IRandomAccess data = new ByteArrayHandle((byte[]) sampleTable[row][13]);
Location.mapFile(stack.pixelsFiles[0], data);
}
}
RandomAccessInputStream data = null;
int timestampIndex = getChildIndex(parent, "Timepoint times stream");
if (timestampIndex >= 0) {
data = getStream(timestampIndex);
data.seek(22);
int timestampID = data.readInt();
Location f = new Location(dir, timestampID + ".atsf");
if (!f.exists()) {
f = new Location(dir, DataTools.swap(timestampID) + ".atsf");
}
stack.timestampFile = f.getAbsolutePath();
data.close();
}
int xIndex = getChildIndex(parent, "um/pixel (X)");
if (xIndex >= 0) {
data = getStream(xIndex);
data.seek(SIGNATURE_SIZE);
stack.physicalX = data.readDouble();
data.close();
}
int yIndex = getChildIndex(parent, "um/pixel (Y)");
if (yIndex >= 0) {
data = getStream(yIndex);
data.seek(SIGNATURE_SIZE);
stack.physicalY = data.readDouble();
data.close();
}
int zIndex = getChildIndex(parent, "um/pixel (Z)");
if (zIndex >= 0) {
data = getStream(zIndex);
data.seek(SIGNATURE_SIZE);
stack.physicalZ = data.readDouble();
data.close();
}
timestampIndex = getChildIndex(parent, "TimepointTimes");
if (timestampIndex >= 0) {
data = getStream(timestampIndex);
data.seek(SIGNATURE_SIZE);
data.close();
}
int objectiveIndex = getChildIndex(parent, "Microscope Objective");
if (objectiveIndex >= 0) {
data = getStream(objectiveIndex);
data.seek(SIGNATURE_SIZE);
stack.magnification = data.readDouble();
data.close();
}
int detectorIndex = getChildIndex(parent, "Camera/Detector");
if (detectorIndex >= 0) {
data = getStream(detectorIndex);
data.seek(SIGNATURE_SIZE);
int len = data.readInt();
stack.detector = data.readString(len);
data.close();
}
int descriptionIndex = getChildIndex(parent, "Experiment Description");
if (descriptionIndex >= 0) {
data = getStream(descriptionIndex);
data.seek(SIGNATURE_SIZE);
int len = data.readInt();
stack.description = data.readString(len);
data.close();
}
int xLocationIndex = getChildIndex(parent, "X Location");
if (xLocationIndex >= 0) {
data = getStream(xLocationIndex);
data.seek(SIGNATURE_SIZE);
stack.xLocation = data.readDouble();
data.close();
}
int yLocationIndex = getChildIndex(parent, "Y Location");
if (yLocationIndex >= 0) {
data = getStream(yLocationIndex);
data.seek(SIGNATURE_SIZE);
stack.yLocation = data.readDouble();
data.close();
}
int zLocationIndex = getChildIndex(parent, "Z Location");
if (zLocationIndex >= 0) {
data = getStream(zLocationIndex);
data.seek(SIGNATURE_SIZE);
stack.zLocation = data.readDouble();
data.close();
}
stacks.add(stack);
}
for (int i = 0; i < stacks.size(); i++) {
Stack stack = stacks.get(i);
if (!new Location(stack.pixelsFiles[0]).exists()) {
stacks.remove(i);
i--;
continue;
}
RandomAccessInputStream base = new RandomAccessInputStream(stack.pixelsFiles[0]);
long baseLength = base.length();
base.close();
for (int q = 1; q < stack.pixelsFiles.length; q++) {
if (!new Location(stack.pixelsFiles[q]).exists()) {
continue;
}
base = new RandomAccessInputStream(stack.pixelsFiles[q]);
long length = base.length();
base.close();
if (length > baseLength) {
// split the stack
Stack newStack = new Stack();
newStack.timestampFile = stack.timestampFile;
newStack.core = new CoreMetadata();
newStack.physicalX = stack.physicalX;
newStack.physicalY = stack.physicalY;
newStack.physicalZ = stack.physicalZ;
newStack.magnification = stack.magnification;
newStack.detector = stack.detector;
newStack.description = stack.description;
newStack.xLocation = stack.xLocation;
newStack.yLocation = stack.yLocation;
newStack.zLocation = stack.zLocation;
String[] pixels = stack.pixelsFiles;
newStack.pixelsFiles = new String[pixels.length - q];
System.arraycopy(pixels, q, newStack.pixelsFiles, 0, newStack.pixelsFiles.length);
stack.pixelsFiles = new String[q];
System.arraycopy(pixels, 0, stack.pixelsFiles, 0, q);
String[] channels = stack.channelNames;
newStack.channelNames = new String[channels.length - q];
System.arraycopy(channels, q, newStack.channelNames, 0, newStack.channelNames.length);
stack.channelNames = new String[q];
System.arraycopy(channels, 0, stack.channelNames, 0, q);
newStack.core.sizeC = newStack.channelNames.length;
stack.core.sizeC = stack.channelNames.length;
stacks.add(i + 1, newStack);
stackNames.add(i + 1, stackNames.get(i));
}
}
}
int seriesCount = stacks.size();
core.clear();
for (int i = 0; i < seriesCount; i++) {
Stack stack = stacks.get(i);
CoreMetadata ms = stack.core;
core.add(ms);
setSeries(i);
ms.littleEndian = true;
if (stack.timestampFile != null) {
RandomAccessInputStream s = new RandomAccessInputStream(stack.timestampFile);
s.seek(0);
if (s.read() != 'I') {
ms.littleEndian = false;
}
s.seek(17);
s.order(isLittleEndian());
ms.sizeT = s.readInt();
Double firstStamp = null;
Double[] stamps = new Double[ms.sizeT];
for (int t = 0; t < ms.sizeT; t++) {
// timestamps are stored in microseconds
double timestamp = s.readLong() / 1000000.0;
if (firstStamp == null) {
firstStamp = timestamp;
}
stamps[t] = timestamp - firstStamp;
}
timestamps.add(stamps);
s.close();
} else {
ms.sizeT = 1;
}
ms.rgb = false;
ms.interleaved = true;
ms.dimensionOrder = "XYCZT";
RandomAccessInputStream s = new RandomAccessInputStream(stack.pixelsFiles[0]);
s.order(isLittleEndian());
if (checkSuffix(stack.pixelsFiles[0], "aisf")) {
s.seek(18);
stack.blockSize = s.readShort() * 256;
s.skipBytes(5);
int x = s.readInt();
int y = s.readInt();
int zStart = s.readInt();
int w = s.readInt();
int h = s.readInt();
if (w - x < 0 || h - y < 0 || (w - x) * (h - y) < 0) {
ms.littleEndian = !isLittleEndian();
s.order(isLittleEndian());
s.seek(s.getFilePointer() - 20);
x = s.readInt();
y = s.readInt();
zStart = s.readInt();
w = s.readInt();
h = s.readInt();
}
ms.sizeX = w - x;
ms.sizeY = h - y;
ms.sizeZ = s.readInt() - zStart;
ms.imageCount = getSizeZ() * getSizeC() * getSizeT();
ms.pixelType = FormatTools.INT8;
int planesPerFile = getSizeZ() * getSizeT();
int planeSize = FormatTools.getPlaneSize(this);
int bytesPerPlane = (int) ((s.length() - stack.blockSize) / planesPerFile);
int bytesPerPixel = 0;
while (bytesPerPlane >= planeSize) {
bytesPerPixel++;
bytesPerPlane -= planeSize;
}
if ((bytesPerPixel % 3) == 0) {
ms.sizeC *= 3;
ms.rgb = true;
bytesPerPixel /= 3;
}
ms.pixelType = FormatTools.pixelTypeFromBytes(bytesPerPixel, false, bytesPerPixel > 2);
// full timepoints are padded to have a multiple of 256 bytes
int timepoint = FormatTools.getPlaneSize(this) * getSizeZ();
stack.planePadding = stack.blockSize - (timepoint % stack.blockSize);
if (stack.planePadding == stack.blockSize) {
stack.planePadding = 0;
}
} else {
boolean embedded = Location.getMappedFile(EMBEDDED_STREAM) != null;
s.seek(0);
if (s.read() != 'I') {
ms.littleEndian = false;
s.order(false);
}
s.seek(22);
ms.sizeX = s.readInt();
ms.sizeY = s.readInt();
ms.sizeZ = s.readInt();
ms.sizeC = embedded ? 1 : 4;
ms.imageCount = getSizeZ() * getSizeT();
ms.rgb = ms.sizeC > 1;
ms.pixelType = FormatTools.UINT8;
stack.blockSize = embedded ? (int) s.getFilePointer() : 99;
stack.planePadding = 0;
if (s.length() > ms.sizeX * ms.sizeY * ms.sizeZ * 6) {
ms.pixelType = FormatTools.UINT16;
ms.sizeC = 3;
ms.rgb = true;
}
if (s.length() < (ms.sizeX * ms.sizeY * ms.sizeZ * ms.sizeC)) {
ms.rgb = false;
ms.sizeC = 1;
long pixels = ms.sizeX * ms.sizeY * ms.sizeZ;
double approximateBytes = (double) s.length() / pixels;
int bytes = (int) Math.ceil(approximateBytes);
if (bytes == 0) {
bytes = 1;
} else if (bytes == 3) {
bytes = 2;
}
ms.pixelType = FormatTools.pixelTypeFromBytes(bytes, false, false);
s.seek(70);
stack.blockSize = s.readInt();
stack.clippingData = true;
}
}
s.close();
}
setSeries(0);
for (int i = 0; i < getSeriesCount(); i++) {
setSeries(i);
Stack stack = stacks.get(i);
addSeriesMeta("Name", stackNames.get(i));
addSeriesMeta("Pixel width (in microns)", stack.physicalX);
addSeriesMeta("Pixel height (in microns)", stack.physicalY);
addSeriesMeta("Z step (in microns)", stack.physicalZ);
addSeriesMeta("Objective magnification", stack.magnification);
addSeriesMeta("Camera/Detector", stack.detector);
addSeriesMeta("Description", stack.description);
addSeriesMeta("X Location", stack.xLocation);
addSeriesMeta("Y Location", stack.yLocation);
addSeriesMeta("Z Location", stack.zLocation);
if (stack.channelNames != null) {
for (int c = 0; c < stack.channelNames.length; c++) {
addSeriesMetaList("Channel", stack.channelNames[c]);
}
}
}
setSeries(0);
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, true);
String instrument = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrument, 0);
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageInstrumentRef(instrument, i);
setSeries(i);
Stack stack = stacks.get(i);
store.setImageName(stackNames.get(i), i);
store.setImageDescription(stack.description, i);
if (stack.channelNames != null) {
for (int c = 0; c < getEffectiveSizeC(); c++) {
store.setChannelName(stack.channelNames[c], i, c);
}
}
Length sizeX = FormatTools.getPhysicalSizeX(stack.physicalX);
Length sizeY = FormatTools.getPhysicalSizeY(stack.physicalY);
Length sizeZ = FormatTools.getPhysicalSizeZ(stack.physicalZ);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, i);
}
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, i);
}
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, i);
}
String objective = MetadataTools.createLSID("Objective", 0, i);
store.setObjectiveID(objective, 0, i);
store.setObjectiveNominalMagnification(stack.magnification, 0, i);
store.setObjectiveCorrection(getCorrection("Other"), 0, i);
store.setObjectiveImmersion(getImmersion("Other"), 0, i);
store.setObjectiveSettingsID(objective, i);
String detectorID = MetadataTools.createLSID("Detector", 0, i);
store.setDetectorID(detectorID, 0, i);
store.setDetectorModel(stack.detector, 0, i);
for (int c = 0; c < getEffectiveSizeC(); c++) {
store.setDetectorSettingsID(detectorID, i, c);
}
for (int img = 0; img < getImageCount(); img++) {
int[] coords = getZCTCoords(img);
int z = coords[0];
final Length xLoc = new Length(stack.xLocation, UNITS.REFERENCEFRAME);
final Length yLoc = new Length(stack.yLocation, UNITS.REFERENCEFRAME);
store.setPlanePositionX(xLoc, i, img);
store.setPlanePositionY(yLoc, i, img);
if (stack.physicalZ != null) {
final double zLocNumber = stack.zLocation + z * stack.physicalZ;
final Length zLoc = new Length(zLocNumber, UNITS.REFERENCEFRAME);
store.setPlanePositionZ(zLoc, i, img);
}
if (i < timestamps.size() && coords[2] < timestamps.get(i).length && timestamps.get(i)[coords[2]] != null) {
store.setPlaneDeltaT(new Time(timestamps.get(i)[coords[2]], UNITS.SECOND), i, img);
}
}
}
setSeries(0);
}
use of loci.formats.MissingLibraryException in project bioformats by openmicroscopy.
the class CellH5Reader method initializeJHDFService.
// -- Helper methods --
private void initializeJHDFService(String id) throws IOException, MissingLibraryException {
try {
ServiceFactory factory = new ServiceFactory();
jhdf = factory.getInstance(JHDFService.class);
jhdf.setFile(id);
} catch (DependencyException e) {
throw new MissingLibraryException(JHDFServiceImpl.NO_JHDF_MSG, e);
}
}
Aggregations