use of ome.units.quantity.Time in project bioformats by openmicroscopy.
the class DeltavisionReader method initExtraMetadata.
protected void initExtraMetadata() throws FormatException, IOException {
MetadataStore store = makeFilterMetadata();
// --- read in the image header data ---
LOGGER.info("Reading header");
in.seek(16);
int subImageStartX = in.readInt();
int subImageStartY = in.readInt();
int subImageStartZ = in.readInt();
int pixelSamplingX = in.readInt();
int pixelSamplingY = in.readInt();
int pixelSamplingZ = in.readInt();
float pixX = in.readFloat();
float pixY = in.readFloat();
float pixZ = in.readFloat();
float xAxisAngle = in.readFloat();
float yAxisAngle = in.readFloat();
float zAxisAngle = in.readFloat();
int xAxisSeq = in.readInt();
int yAxisSeq = in.readInt();
int zAxisSeq = in.readInt();
float[] minWave = new float[5];
float[] maxWave = new float[5];
minWave[0] = in.readFloat();
maxWave[0] = in.readFloat();
float meanIntensity = in.readFloat();
int spaceGroupNumber = in.readInt();
in.seek(132);
short numSubResSets = in.readShort();
short zAxisReductionQuotient = in.readShort();
for (int i = 1; i <= 3; i++) {
minWave[i] = in.readFloat();
maxWave[i] = in.readFloat();
}
int type = in.readShort();
int lensID = in.readShort();
in.seek(172);
minWave[4] = in.readFloat();
maxWave[4] = in.readFloat();
in.seek(184);
float xTiltAngle = in.readFloat();
float yTiltAngle = in.readFloat();
float zTiltAngle = in.readFloat();
in.skipBytes(2);
short[] waves = new short[5];
for (int i = 0; i < waves.length; i++) {
waves[i] = in.readShort();
}
float xOrigin = in.readFloat();
float yOrigin = in.readFloat();
float zOrigin = in.readFloat();
in.skipBytes(4);
String[] title = new String[10];
for (int i = 0; i < title.length; i++) {
// Make sure that "null" characters are stripped out
title[i] = in.readByteToString(80).replaceAll("\0", "");
}
// --- compute some secondary values ---
String imageType = type < IMAGE_TYPES.length ? IMAGE_TYPES[type] : "unknown";
String imageDesc = title[0];
if (imageDesc != null && imageDesc.length() == 0)
imageDesc = null;
// --- populate original metadata ---
LOGGER.info("Populating original metadata");
addGlobalMeta("Sub-image starting point (X)", subImageStartX);
addGlobalMeta("Sub-image starting point (Y)", subImageStartY);
addGlobalMeta("Sub-image starting point (Z)", subImageStartZ);
addGlobalMeta("Pixel sampling size (X)", pixelSamplingX);
addGlobalMeta("Pixel sampling size (Y)", pixelSamplingY);
addGlobalMeta("Pixel sampling size (Z)", pixelSamplingZ);
addGlobalMeta("X element length (in um)", pixX);
addGlobalMeta("Y element length (in um)", pixY);
addGlobalMeta("Z element length (in um)", pixZ);
addGlobalMeta("X axis angle", xAxisAngle);
addGlobalMeta("Y axis angle", yAxisAngle);
addGlobalMeta("Z axis angle", zAxisAngle);
addGlobalMeta("Column axis sequence", xAxisSeq);
addGlobalMeta("Row axis sequence", yAxisSeq);
addGlobalMeta("Section axis sequence", zAxisSeq);
addGlobalMeta("Image Type", imageType);
addGlobalMeta("Lens ID Number", lensID);
addGlobalMeta("X axis tilt angle", xTiltAngle);
addGlobalMeta("Y axis tilt angle", yTiltAngle);
addGlobalMeta("Z axis tilt angle", zTiltAngle);
for (int i = 0; i < waves.length; i++) {
addGlobalMeta("Wavelength " + (i + 1) + " (in nm)", waves[i]);
}
addGlobalMeta("X origin (in um)", xOrigin);
addGlobalMeta("Y origin (in um)", yOrigin);
addGlobalMeta("Z origin (in um)", zOrigin);
for (String t : title) {
addGlobalMetaList("Title", t);
}
for (int i = 0; i < minWave.length; i++) {
addGlobalMeta("Wavelength " + (i + 1) + " min. intensity", minWave[i]);
addGlobalMeta("Wavelength " + (i + 1) + " max. intensity", maxWave[i]);
}
addGlobalMeta("Wavelength 1 mean intensity", meanIntensity);
addGlobalMeta("Space group number", spaceGroupNumber);
addGlobalMeta("Number of Sub-resolution sets", numSubResSets);
addGlobalMeta("Z axis reduction quotient", zAxisReductionQuotient);
// --- populate OME metadata ---
LOGGER.info("Populating OME metadata");
for (int series = 0; series < getSeriesCount(); series++) {
if (store instanceof IMinMaxStore) {
IMinMaxStore minMaxStore = (IMinMaxStore) store;
for (int i = 0; i < minWave.length; i++) {
if (i < getEffectiveSizeC()) {
minMaxStore.setChannelGlobalMinMax(i, minWave[i], maxWave[i], series);
}
}
}
Double x = new Double(pixX);
Length sizeX = FormatTools.getPhysicalSizeX(x);
if (sizeX != null) {
store.setPixelsPhysicalSizeX(sizeX, series);
}
Double y = new Double(pixY);
Length sizeY = FormatTools.getPhysicalSizeY(y);
if (sizeY != null) {
store.setPixelsPhysicalSizeY(sizeY, series);
}
Double z = new Double(pixZ);
Length sizeZ = FormatTools.getPhysicalSizeZ(z);
if (sizeZ != null) {
store.setPixelsPhysicalSizeZ(sizeZ, series);
}
store.setImageDescription(imageDesc, series);
}
populateObjective(store, lensID);
// if matching log file exists, extract key/value pairs from it
boolean logFound = isGroupFiles() ? parseLogFile(store) : false;
if (isGroupFiles())
parseDeconvolutionLog(store);
if (getSeriesCount() == 1) {
xTiles = 1;
yTiles = 1;
backwardsStage = false;
}
for (int series = 0; series < getSeriesCount(); series++) {
int seriesIndex = series;
if (backwardsStage) {
int x = series % xTiles;
int y = series / xTiles;
seriesIndex = (yTiles - y - 1) * xTiles + (xTiles - x - 1);
}
for (int i = 0; i < getImageCount(); i++) {
int[] coords = getZCTCoords(i);
int tIndex = getSeriesCount() * coords[2] + seriesIndex;
DVExtHdrFields hdr = extHdrFields[coords[0]][coords[1]][tIndex];
// plane timing
store.setPlaneDeltaT(new Time(new Double(hdr.timeStampSeconds), UNITS.SECOND), series, i);
store.setPlaneExposureTime(new Time(new Double(extHdrFields[0][coords[1]][0].expTime), UNITS.SECOND), series, i);
// stage position
if (!logFound || getSeriesCount() > 1) {
store.setPlanePositionX(hdr.stageXCoord, series, i);
store.setPlanePositionY(hdr.stageYCoord, series, i);
store.setPlanePositionZ(hdr.stageZCoord, series, i);
}
}
for (int w = 0; w < getSizeC(); w++) {
DVExtHdrFields hdrC = extHdrFields[0][w][series];
Length emission = FormatTools.getEmissionWavelength(new Double(waves[w]));
Length excitation = FormatTools.getExcitationWavelength(new Double(hdrC.exWavelen));
if (emission != null) {
store.setChannelEmissionWavelength(emission, series, w);
}
if (excitation != null) {
store.setChannelExcitationWavelength(excitation, series, w);
}
if (ndFilters[w] == null)
ndFilters[w] = new Double(hdrC.ndFilter);
store.setChannelNDFilter(ndFilters[w], series, w);
}
}
}
use of ome.units.quantity.Time in project bioformats by openmicroscopy.
the class PlugInBioFormatsImporter method readImage.
public void readImage() {
final ViewUserInterface mipav = ViewUserInterface.getReference();
// prompt user to choose a file
if (chooser == null) {
chooser = GUITools.buildFileChooser(reader);
chooser.setCurrentDirectory(new File(Preferences.getImageDirectory()));
}
JFrame parent = mipav.getMainFrame();
int rval = chooser.showOpenDialog(parent);
// user canceled
if (rval != JFileChooser.APPROVE_OPTION)
return;
final File file = chooser.getSelectedFile();
// load the image in a separate thread
Thread importerThread = new Thread("BioFormats-Importer") {
public void run() {
String name = file.getName();
String dir = file.getParent();
// open file using Bio-Formats
setMessage(mipav, "Importing " + name + "...", true);
String id = file.getPath();
try {
long tic = System.currentTimeMillis();
IMetadata store;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
store = service.createOMEXMLMetadata();
} catch (DependencyException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
} catch (ServiceException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
}
reader.setMetadataStore(store);
reader.setId(id);
// MIPAV assumes 4-D data in XYZT order
reader.setOutputOrder("XYZTC");
// harvest some core metadata
int imageCount = reader.getImageCount();
boolean little = reader.isLittleEndian();
int pixelType = reader.getPixelType();
int bpp = FormatTools.getBytesPerPixel(pixelType);
boolean floating = FormatTools.isFloatingPoint(pixelType);
int sizeX = reader.getSizeX();
int sizeY = reader.getSizeY();
int sizeZ = reader.getSizeZ();
int sizeT = reader.getSizeT();
int sizeC = reader.getSizeC();
String imageName = store.getImageName(0);
if (sizeC > 1) {
throw new FormatException("Multichannel data is unsupported at the moment");
}
// compute MIPAV buffer type
int mipavType;
switch(pixelType) {
case FormatTools.INT8:
mipavType = ModelStorageBase.BYTE;
break;
case FormatTools.UINT8:
mipavType = ModelStorageBase.UBYTE;
break;
case FormatTools.INT16:
mipavType = ModelStorageBase.SHORT;
break;
case FormatTools.UINT16:
mipavType = ModelStorageBase.USHORT;
break;
case FormatTools.INT32:
mipavType = ModelStorageBase.INTEGER;
break;
case FormatTools.UINT32:
mipavType = ModelStorageBase.UINTEGER;
break;
case FormatTools.FLOAT:
mipavType = ModelStorageBase.FLOAT;
break;
case FormatTools.DOUBLE:
mipavType = ModelStorageBase.DOUBLE;
break;
default:
throw new FormatException("Unsupported pixel type: " + pixelType);
}
// harvest physical resolution
Length dimPhysSizeX = store.getPixelsPhysicalSizeX(0);
Length dimPhysSizeY = store.getPixelsPhysicalSizeY(0);
Length dimPhysSizeZ = store.getPixelsPhysicalSizeZ(0);
Time dimTimeInc = store.getPixelsTimeIncrement(0);
float physSizeX = dimPhysSizeX == null ? 1.0f : dimPhysSizeX.value(UNITS.MICROMETER).floatValue();
float physSizeY = dimPhysSizeY == null ? 1.0f : dimPhysSizeY.value(UNITS.MICROMETER).floatValue();
float physSizeZ = dimPhysSizeZ == null ? 1.0f : dimPhysSizeZ.value(UNITS.MICROMETER).floatValue();
float timeInc = dimTimeInc == null ? 1.0f : dimTimeInc.value(UNITS.SECOND).floatValue();
// compute dimensional extents
int[] dimExtents = { sizeX, sizeY, sizeZ, sizeT };
float[] res = { physSizeX, physSizeY, physSizeZ, timeInc };
int[] units = { FileInfoBase.MICROMETERS, FileInfoBase.MICROMETERS, FileInfoBase.MICROMETERS, FileInfoBase.SECONDS };
// create MIPAV image object
ModelImage modelImage = new ModelImage(mipavType, dimExtents, imageName);
// import planes into MIPAV image
byte[] buf = new byte[bpp * sizeX * sizeY];
for (int i = 0; i < imageCount; i++) {
setMessage(mipav, "Reading plane #" + (i + 1) + "/" + imageCount, false);
reader.openBytes(i, buf);
// convert byte array to appropriate primitive type
int offset = i * buf.length;
Object array = DataTools.makeDataArray(buf, bpp, floating, little);
// assign data to MIPAV image object
switch(mipavType) {
case ModelStorageBase.BYTE:
case ModelStorageBase.UBYTE:
modelImage.importData(offset, (byte[]) array, false);
break;
case ModelStorageBase.SHORT:
case ModelStorageBase.USHORT:
modelImage.importData(offset, (short[]) array, false);
break;
case ModelStorageBase.INTEGER:
case ModelStorageBase.UINTEGER:
modelImage.importData(offset, (int[]) array, false);
break;
case ModelStorageBase.FLOAT:
modelImage.importData(offset, (float[]) array, false);
break;
case ModelStorageBase.DOUBLE:
modelImage.importData(offset, (double[]) array, false);
break;
default:
throw new FormatException("Unknown buffer type: " + mipavType);
}
}
setMessage(mipav, "Finishing import...", true);
// create a FileInfo object for each image plane
FileInfoBase[] fileInfo = new FileInfoBase[imageCount];
for (int i = 0; i < imageCount; i++) {
// HACK: Use FileInfoImageXML since FileInfoBase is abstract.
fileInfo[i] = new FileInfoImageXML(name, dir, FileUtility.XML);
fileInfo[i].setExtents(dimExtents);
fileInfo[i].setResolutions(res);
fileInfo[i].setUnitsOfMeasure(units);
fileInfo[i].setDataType(mipavType);
}
modelImage.setFileInfo(fileInfo);
// scale color range and display MIPAV image
modelImage.calcMinMax();
new ViewJFrameImage(modelImage);
long toc = System.currentTimeMillis();
long time = toc - tic;
long avg = time / imageCount;
setMessage(mipav, name + ": Read " + imageCount + " planes in " + (time / 1000f) + " seconds (" + avg + " ms/plane)", true);
} catch (FormatException exc) {
exc.printStackTrace();
MipavUtil.displayError("An error occurred parsing the file: " + exc.getMessage());
} catch (IOException exc) {
exc.printStackTrace();
MipavUtil.displayError("An I/O error occurred reading the file: " + exc.getMessage());
}
}
};
importerThread.start();
}
use of ome.units.quantity.Time in project bioformats by openmicroscopy.
the class BaseZeissReader method parseMainTags.
// -- Internal FormatReader API methods --
void parseMainTags(int image, MetadataStore store, ArrayList<Tag> tags) throws FormatException, IOException {
int effectiveSizeC = 0;
try {
effectiveSizeC = getEffectiveSizeC();
} catch (ArithmeticException e) {
}
for (Tag t : tags) {
String key = t.getKey();
String value = t.getValue();
try {
if (key.equals("Image Channel Index")) {
cIndex = Integer.parseInt(value);
addGlobalMetaList(key, cIndex);
continue;
} else if (key.equals("ImageWidth")) {
int v = Integer.parseInt(value);
if (getSizeX() == 0 || v < getSizeX()) {
core.get(0).sizeX = v;
}
if (realWidth == 0 && v > realWidth)
realWidth = v;
} else if (key.equals("ImageHeight")) {
int v = Integer.parseInt(value);
if (getSizeY() == 0 || v < getSizeY())
core.get(0).sizeY = v;
if (realHeight == 0 || v > realHeight)
realHeight = v;
}
if (cIndex != -1)
key += " " + cIndex;
if (!key.startsWith("Camera Acquisition Time") && !key.startsWith("ImageRelativeTime")) {
String metavalue = value;
if (key.endsWith("Date")) {
try {
metavalue = DateTools.convertDate(parseTimestamp(value), DateTools.UNIX, DateTools.ISO8601_FORMAT_MS);
} catch (Exception e) {
}
}
addGlobalMeta(key, metavalue);
}
if (key.startsWith("ImageTile") && !(store instanceof DummyMetadata)) {
if (!tiles.containsKey(new Integer(value))) {
tiles.put(Integer.valueOf(value), 1);
} else {
int v = tiles.get(new Integer(value)).intValue() + 1;
tiles.put(new Integer(value), new Integer(v));
}
}
if (key.startsWith("MultiChannel Color")) {
if (cIndex >= 0 && cIndex < effectiveSizeC) {
if (channelColors == null || effectiveSizeC > channelColors.length) {
channelColors = new int[effectiveSizeC];
}
if (channelColors[cIndex] == 0) {
channelColors[cIndex] = Integer.parseInt(value);
}
} else if (cIndex == effectiveSizeC && channelColors != null && channelColors[0] == 0) {
System.arraycopy(channelColors, 1, channelColors, 0, channelColors.length - 1);
channelColors[cIndex - 1] = Integer.parseInt(value);
} else if (channelColors != null && channelColors[0] > 0 && channelColors.length > 1) {
int c = 1;
while (c < channelColors.length - 1 && channelColors[c] != 0) {
c++;
}
if (channelColors[c] == 0) {
channelColors[c] = Integer.parseInt(value);
}
}
} else if (key.startsWith("Scale Factor for X") && physicalSizeX == null) {
physicalSizeX = Double.parseDouble(value);
} else if (key.startsWith("Scale Factor for Y") && physicalSizeY == null) {
physicalSizeY = Double.parseDouble(value);
} else if (key.startsWith("Scale Factor for Z") && physicalSizeZ == null) {
physicalSizeZ = Double.parseDouble(value);
} else if (key.startsWith("Number Rows") && rowCount == 0) {
rowCount = parseInt(value);
} else if (key.startsWith("Number Columns") && colCount == 0) {
colCount = parseInt(value);
} else if (key.startsWith("NumberOfRawImages") && rawCount == 0) {
rawCount = parseInt(value);
} else if (key.startsWith("Emission Wavelength")) {
if (cIndex != -1) {
Double wave = new Double(value);
Length emission = FormatTools.getEmissionWavelength(wave);
if (emission != null) {
emWavelength.put(cIndex, emission);
}
}
} else if (key.startsWith("Excitation Wavelength")) {
if (cIndex != -1) {
Double wave = new Double(Double.parseDouble(value));
Length excitation = FormatTools.getExcitationWavelength(wave);
if (excitation != null) {
exWavelength.put(cIndex, excitation);
}
}
} else if (key.startsWith("Channel Name")) {
if (cIndex != -1) {
channelName.put(cIndex, value);
}
} else if (key.startsWith("Exposure Time [ms]")) {
if (exposureTime.get(new Integer(cIndex)) == null) {
double exp = Double.parseDouble(value) / 1000;
exposureTime.put(new Integer(cIndex), String.valueOf(exp));
}
} else if (key.startsWith("User Name")) {
String[] username = value.split(" ");
if (username.length >= 2) {
String id = MetadataTools.createLSID("Experimenter", 0);
store.setExperimenterID(id, 0);
store.setExperimenterFirstName(username[0], 0);
store.setExperimenterLastName(username[username.length - 1], 0);
}
} else if (key.equals("User company")) {
String id = MetadataTools.createLSID("Experimenter", 0);
store.setExperimenterID(id, 0);
store.setExperimenterInstitution(value, 0);
} else if (key.startsWith("Objective Magnification")) {
Double magnification = Double.parseDouble(value);
store.setObjectiveNominalMagnification(magnification, 0, 0);
} else if (key.startsWith("Objective ID")) {
store.setObjectiveID("Objective:" + value, 0, 0);
store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
} else if (key.startsWith("Objective N.A.")) {
store.setObjectiveLensNA(new Double(value), 0, 0);
} else if (key.startsWith("Objective Name")) {
String[] tokens = value.split(" ");
for (int q = 0; q < tokens.length; q++) {
int slash = tokens[q].indexOf('/');
if (slash != -1 && slash - q > 0) {
Double mag = Double.parseDouble(tokens[q].substring(0, slash - q));
String na = tokens[q].substring(slash + 1);
store.setObjectiveNominalMagnification(mag, 0, 0);
store.setObjectiveLensNA(new Double(na), 0, 0);
store.setObjectiveCorrection(getCorrection(tokens[q - 1]), 0, 0);
break;
}
}
} else if (key.startsWith("Objective Working Distance")) {
store.setObjectiveWorkingDistance(new Length(new Double(value), UNITS.MICROMETER), 0, 0);
} else if (key.startsWith("Objective Immersion Type")) {
String immersion = "Other";
switch(Integer.parseInt(value)) {
// case 1: no immersion
case 2:
immersion = "Oil";
break;
case 3:
immersion = "Water";
break;
}
store.setObjectiveImmersion(getImmersion(immersion), 0, 0);
} else if (key.startsWith("Stage Position X")) {
final Double number = Double.valueOf(value);
stageX.put(image, new Length(number, UNITS.REFERENCEFRAME));
addGlobalMetaList("X position for position", value);
} else if (key.startsWith("Stage Position Y")) {
final Double number = Double.valueOf(value);
stageY.put(image, new Length(number, UNITS.REFERENCEFRAME));
addGlobalMetaList("Y position for position", value);
} else if (key.startsWith("Orca Analog Gain")) {
detectorGain.put(cIndex, new Double(value));
} else if (key.startsWith("Orca Analog Offset")) {
detectorOffset.put(cIndex, new Double(value));
} else if (key.startsWith("Comments")) {
imageDescription = value;
} else if (key.startsWith("Acquisition Date")) {
acquisitionDate = new Timestamp(DateTools.convertDate(parseTimestamp(value), DateTools.UNIX, DateTools.ISO8601_FORMAT_MS));
} else if (image >= 0 && key.startsWith("Camera Acquisition Time")) {
// Note Double variant for TIFF XML.
String date = DateTools.convertDate(parseTimestamp(value), DateTools.UNIX, DateTools.ISO8601_FORMAT_MS);
addSeriesMetaList(key, date);
if (timepoint != 0) {
// First timepoint is duplicated for some reason.
timestamps.put(timepoint - 1, date);
} else {
timestamps.put(timepoint, date);
}
timepoint++;
} else if (image >= 0 && key.startsWith("ImageRelativeTime")) {
Time time = new Time(Double.parseDouble(value), UNITS.DAY);
String timestr = time.value().toString() + " " + time.unit().getSymbol();
addSeriesMetaList(key, timestr);
}
} catch (NumberFormatException e) {
}
}
}
use of ome.units.quantity.Time in project bioformats by openmicroscopy.
the class FakeReaderTest method testPlaneMetadata.
@Test
public void testPlaneMetadata() throws Exception {
File fakeIni = mkIni("foo.fake.ini", "sizeC=2", "[series_0]", "ExposureTime_0=100.0", "ExposureTimeUnit_0=ms", "ExposureTime_1=50.0", "ExposureTimeUnit_1=ns", "PositionX_0=10.0", "PositionY_0=20.0", "PositionZ_0=30.0", "PositionXUnit_0=mm", "PositionYUnit_0=mm", "PositionZUnit_0=mm", "PositionX_1=5.0", "PositionY_1=10.0", "PositionZ_1=15.0", "PositionXUnit_1=nm", "PositionYUnit_1=nm", "PositionZUnit_1=nm");
reader.setId(fakeIni.getAbsolutePath());
m = service.asRetrieve(reader.getMetadataStore());
assertEquals(m.getPixelsSizeC(0).getNumberValue(), 2);
assertEquals(m.getPlaneExposureTime(0, 0), new Time(100.0, UNITS.MILLISECOND));
assertEquals(m.getPlaneExposureTime(0, 1), new Time(50.0, UNITS.NANOSECOND));
assertEquals(m.getPlanePositionX(0, 0), new Length(10.0, UNITS.MM));
assertEquals(m.getPlanePositionY(0, 0), new Length(20.0, UNITS.MM));
assertEquals(m.getPlanePositionZ(0, 0), new Length(30.0, UNITS.MM));
assertEquals(m.getPlanePositionX(0, 1), new Length(5.0, UNITS.NM));
assertEquals(m.getPlanePositionY(0, 1), new Length(10.0, UNITS.NM));
assertEquals(m.getPlanePositionZ(0, 1), new Length(15.0, UNITS.NM));
}
use of ome.units.quantity.Time in project bioformats by openmicroscopy.
the class ZeissCZIReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
parser = XMLTools.createBuilder();
// switch to the master file if this is part of a multi-file dataset
int lastDot = id.lastIndexOf(".");
String base = lastDot < 0 ? id : id.substring(0, lastDot);
if (base.endsWith(")") && isGroupFiles()) {
LOGGER.info("Checking for master file");
int lastFileSeparator = base.lastIndexOf(File.separator);
int end = base.lastIndexOf(" (");
if (end < 0 || end < lastFileSeparator) {
end = base.lastIndexOf("(");
}
if (end > 0 && end > lastFileSeparator) {
base = base.substring(0, end) + ".czi";
if (new Location(base).exists()) {
LOGGER.info("Initializing master file {}", base);
initFile(base);
return;
}
}
}
CoreMetadata ms0 = core.get(0);
ms0.littleEndian = true;
pixels = new HashMap<Integer, String>();
segments = new ArrayList<Segment>();
planes = new ArrayList<SubBlock>();
readSegments(id);
// check if we have the master file in a multi-file dataset
// file names are not stored in the files; we have to rely on a
// specific naming convention:
//
// master_file.czi
// master_file (1).czi
// master_file (2).czi
// ...
//
// the number of files is also not stored, so we have to manually check
// for all files with a matching name
Location file = new Location(id).getAbsoluteFile();
base = file.getName();
lastDot = base.lastIndexOf(".");
if (lastDot >= 0) {
base = base.substring(0, lastDot);
}
Location parent = file.getParentFile();
String[] list = parent.list(true);
for (String f : list) {
if (f.startsWith(base + "(") || f.startsWith(base + " (")) {
String part = f.substring(f.lastIndexOf("(") + 1, f.lastIndexOf(")"));
try {
pixels.put(Integer.parseInt(part), new Location(parent, f).getAbsolutePath());
} catch (NumberFormatException e) {
LOGGER.debug("{} not included in multi-file dataset", f);
}
}
}
Integer[] keys = pixels.keySet().toArray(new Integer[pixels.size()]);
Arrays.sort(keys);
for (Integer key : keys) {
readSegments(pixels.get(key));
}
calculateDimensions();
if (planes.size() == 0) {
throw new FormatException("Pixel data could not be found; this file may be corrupted");
}
int firstX = planes.get(0).x;
int firstY = planes.get(0).y;
if (getSizeC() == 0) {
ms0.sizeC = 1;
}
if (getSizeZ() == 0) {
ms0.sizeZ = 1;
}
if (getSizeT() == 0) {
ms0.sizeT = 1;
}
if (getImageCount() == 0) {
ms0.imageCount = ms0.sizeZ * ms0.sizeT;
}
int originalC = getSizeC();
convertPixelType(planes.get(0).directoryEntry.pixelType);
// remove any invalid SubBlocks
int bpp = FormatTools.getBytesPerPixel(getPixelType());
if (isRGB()) {
bpp *= (getSizeC() / originalC);
}
int fullResBlockCount = planes.size();
for (int i = 0; i < planes.size(); i++) {
long planeSize = (long) planes.get(i).x * planes.get(i).y * bpp;
int compression = planes.get(i).directoryEntry.compression;
if (compression == UNCOMPRESSED || compression == JPEGXR) {
long size = planes.get(i).dataSize;
if (size < planeSize || planeSize >= Integer.MAX_VALUE || size < 0) {
// check for reduced resolution in the pyramid
DimensionEntry[] entries = planes.get(i).directoryEntry.dimensionEntries;
int pyramidType = planes.get(i).directoryEntry.pyramidType;
if ((pyramidType == 1 || pyramidType == 2 || compression == JPEGXR) && (compression == JPEGXR || size == entries[0].storedSize * entries[1].storedSize * bpp)) {
int scale = planes.get(i).x / entries[0].storedSize;
if (scale == 1 || (((scale % 2) == 0 || (scale % 3) == 0) && allowAutostitching())) {
if (scale > 1 && scaleFactor == 0) {
scaleFactor = scale % 2 == 0 ? 2 : 3;
}
planes.get(i).coreIndex = 0;
while (scale > 1) {
scale /= scaleFactor;
planes.get(i).coreIndex++;
}
if (planes.get(i).coreIndex > maxResolution) {
maxResolution = planes.get(i).coreIndex;
}
} else {
LOGGER.trace("removing block #{}; calculated size = {}, recorded size = {}, scale = {}", i, planeSize, size, scale);
planes.remove(i);
i--;
}
} else {
LOGGER.trace("removing block #{}; calculated size = {}, recorded size = {}", i, planeSize, size);
planes.remove(i);
i--;
}
fullResBlockCount--;
} else {
scanDim = (int) (size / planeSize);
}
} else {
byte[] pixels = planes.get(i).readPixelData();
if (pixels.length < planeSize || planeSize >= Integer.MAX_VALUE) {
LOGGER.trace("removing block #{}; calculated size = {}, decoded size = {}", i, planeSize, pixels.length);
planes.remove(i);
i--;
} else {
scanDim = (int) (pixels.length / planeSize);
}
}
}
if (getSizeZ() == 0) {
ms0.sizeZ = 1;
}
if (getSizeC() == 0) {
ms0.sizeC = 1;
}
if (getSizeT() == 0) {
ms0.sizeT = 1;
}
// set modulo annotations
// rotations -> modulo Z
// illuminations -> modulo C
// phases -> modulo T
LOGGER.trace("rotations = {}", rotations);
LOGGER.trace("illuminations = {}", illuminations);
LOGGER.trace("phases = {}", phases);
LOGGER.trace("positions = {}", positions);
LOGGER.trace("acquisitions = {}", acquisitions);
LOGGER.trace("mosaics = {}", mosaics);
LOGGER.trace("angles = {}", angles);
ms0.moduloZ.step = ms0.sizeZ;
ms0.moduloZ.end = ms0.sizeZ * (rotations - 1);
ms0.moduloZ.type = FormatTools.ROTATION;
ms0.sizeZ *= rotations;
ms0.moduloC.step = ms0.sizeC;
ms0.moduloC.end = ms0.sizeC * (illuminations - 1);
ms0.moduloC.type = FormatTools.ILLUMINATION;
ms0.moduloC.parentType = FormatTools.CHANNEL;
ms0.sizeC *= illuminations;
ms0.moduloT.step = ms0.sizeT;
ms0.moduloT.end = ms0.sizeT * (phases - 1);
ms0.moduloT.type = FormatTools.PHASE;
ms0.sizeT *= phases;
// finish populating the core metadata
int seriesCount = positions * acquisitions * angles;
int originalMosaicCount = mosaics;
if (maxResolution == 0) {
seriesCount *= mosaics;
} else {
prestitched = true;
}
ms0.imageCount = getSizeZ() * (isRGB() ? getSizeC() / 3 : getSizeC()) * getSizeT();
LOGGER.trace("Size Z = {}", getSizeZ());
LOGGER.trace("Size C = {}", getSizeC());
LOGGER.trace("Size T = {}", getSizeT());
LOGGER.trace("is RGB = {}", isRGB());
LOGGER.trace("calculated image count = {}", ms0.imageCount);
LOGGER.trace("number of available planes = {}", planes.size());
LOGGER.trace("prestitched = {}", prestitched);
LOGGER.trace("scanDim = {}", scanDim);
int calculatedSeries = fullResBlockCount / getImageCount();
if (((mosaics == seriesCount) || (positions == seriesCount)) && ((seriesCount == calculatedSeries) || (maxResolution > 0 && seriesCount * mosaics == calculatedSeries)) && prestitched != null && prestitched) {
boolean equalTiles = true;
for (SubBlock plane : planes) {
if (plane.x != planes.get(0).x || plane.y != planes.get(0).y) {
equalTiles = false;
break;
}
}
if ((getSizeX() > planes.get(0).x || (getSizeX() == planes.get(0).x && calculatedSeries == seriesCount * mosaics * positions)) && !equalTiles && allowAutostitching()) {
// image was fused; treat the mosaics as a single image
seriesCount = 1;
positions = 1;
acquisitions = 1;
mosaics = 1;
angles = 1;
} else {
int newX = planes.get(planes.size() - 1).x;
int newY = planes.get(planes.size() - 1).y;
if (allowAutostitching() && (ms0.sizeX < newX || ms0.sizeY < newY)) {
prestitched = true;
mosaics = 1;
} else {
prestitched = maxResolution > 0;
}
ms0.sizeX = newX;
ms0.sizeY = newY;
}
} else if (!allowAutostitching() && calculatedSeries > seriesCount) {
ms0.sizeX = firstX;
ms0.sizeY = firstY;
prestitched = true;
}
if (ms0.imageCount * seriesCount > planes.size() * scanDim && planes.size() > 0) {
if (planes.size() != ms0.imageCount && planes.size() != ms0.sizeT && (planes.size() % (seriesCount * getSizeZ())) == 0) {
if (!isGroupFiles() && planes.size() == (ms0.imageCount * seriesCount) / positions) {
seriesCount /= positions;
positions = 1;
}
} else if (planes.size() == ms0.sizeT || planes.size() == ms0.imageCount || (!isGroupFiles() && positions > 1)) {
positions = 1;
acquisitions = 1;
mosaics = 1;
angles = 1;
seriesCount = 1;
} else if (seriesCount > mosaics && mosaics > 1 && prestitched != null && prestitched) {
seriesCount /= mosaics;
mosaics = 1;
}
}
ms0.dimensionOrder = "XYCZT";
ArrayList<Integer> pixelTypes = new ArrayList<Integer>();
pixelTypes.add(planes.get(0).directoryEntry.pixelType);
if (maxResolution == 0) {
for (SubBlock plane : planes) {
if (!pixelTypes.contains(plane.directoryEntry.pixelType)) {
pixelTypes.add(plane.directoryEntry.pixelType);
}
plane.pixelTypeIndex = pixelTypes.indexOf(plane.directoryEntry.pixelType);
}
if (seriesCount * pixelTypes.size() > 1) {
core.clear();
for (int j = 0; j < pixelTypes.size(); j++) {
for (int i = 0; i < seriesCount; i++) {
CoreMetadata add = new CoreMetadata(ms0);
if (pixelTypes.size() > 1) {
int newC = originalC / pixelTypes.size();
add.sizeC = newC;
add.imageCount = add.sizeZ * add.sizeT;
add.rgb = false;
convertPixelType(add, pixelTypes.get(j));
}
core.add(add);
}
}
}
}
if (seriesCount > 1 || maxResolution > 0) {
core.clear();
for (int i = 0; i < seriesCount; i++) {
CoreMetadata add = new CoreMetadata(ms0);
add.resolutionCount = maxResolution + 1;
core.add(add);
for (int r = 0; r < maxResolution; r++) {
CoreMetadata resolution = new CoreMetadata(add);
resolution.resolutionCount = 1;
core.add(resolution);
}
}
}
assignPlaneIndices();
if (maxResolution > 0) {
tileWidth = new int[core.size()];
tileHeight = new int[core.size()];
for (int s = 0; s < core.size(); ) {
if (s > 0) {
core.get(s).sizeX = 0;
core.get(s).sizeY = 0;
calculateDimensions(s, true);
}
if (originalMosaicCount > 1) {
// calculate total stitched size if the image was not fused
int minRow = Integer.MAX_VALUE;
int maxRow = Integer.MIN_VALUE;
int minCol = Integer.MAX_VALUE;
int maxCol = Integer.MIN_VALUE;
int x = 0, y = 0;
int lastX = 0, lastY = 0;
for (SubBlock plane : planes) {
if (plane.coreIndex != s) {
continue;
}
if (x == 0 && y == 0) {
x = plane.x;
y = plane.y;
}
if (plane.row < minRow) {
minRow = plane.row;
}
if (plane.row > maxRow) {
maxRow = plane.row;
}
if (plane.col < minCol) {
minCol = plane.col;
}
if (plane.col > maxCol) {
maxCol = plane.col;
}
if (plane.x > tileWidth[s]) {
tileWidth[s] = plane.x;
}
if (plane.y > tileHeight[s]) {
tileHeight[s] = plane.y;
}
if (plane.row == maxRow && plane.col == maxCol) {
lastX = plane.x;
lastY = plane.y;
}
}
// don't overwrite the dimensions if stitching already occurred
if (core.get(s).sizeX == x && core.get(s).sizeY == y) {
core.get(s).sizeX = (lastX + maxCol) - minCol;
core.get(s).sizeY = (lastY + maxRow) - minRow;
}
}
boolean keepMissingPyramid = false;
for (int r = 0; r < core.get(s).resolutionCount; r++) {
boolean hasValidPlane = false;
for (SubBlock plane : planes) {
if (plane.coreIndex == s + r) {
hasValidPlane = true;
break;
}
}
if (!hasValidPlane && r > 0 && !keepMissingPyramid) {
core.remove(s + r);
core.get(s).resolutionCount--;
// adjust the core indexes of any subsequent planes
for (SubBlock plane : planes) {
if (plane.coreIndex > s + r) {
plane.coreIndex--;
}
}
r--;
} else {
int div = (int) Math.pow(scaleFactor, r);
if (r == 0 && s > 0 && core.get(s).sizeX == 1) {
core.get(s).sizeX = core.get(s - maxResolution).sizeX;
core.get(s).sizeY = core.get(s - maxResolution).sizeY;
} else {
core.get(s + r).sizeX = core.get(s).sizeX / div;
core.get(s + r).sizeY = core.get(s).sizeY / div;
}
tileWidth[s + r] = tileWidth[s] / div;
tileHeight[s + r] = tileHeight[s] / div;
}
if (r == 0 && !hasValidPlane) {
keepMissingPyramid = true;
}
}
s += core.get(s).resolutionCount;
}
}
// check for PALM data; requires planes to split into separate series
String firstXML = null;
boolean canSkipXML = true;
String currentPath = new Location(currentId).getAbsolutePath();
boolean isPALM = false;
if (planes.size() <= 2 && getImageCount() <= 2) {
for (Segment segment : segments) {
String path = new Location(segment.filename).getAbsolutePath();
if (currentPath.equals(path) && segment instanceof Metadata) {
segment.fillInData();
String xml = ((Metadata) segment).xml;
xml = XMLTools.sanitizeXML(xml);
if (firstXML == null && canSkipXML) {
firstXML = xml;
}
if (canSkipXML && firstXML.equals(xml)) {
isPALM = checkPALM(xml);
} else if (!firstXML.equals(xml)) {
canSkipXML = false;
}
((Metadata) segment).clearXML();
}
}
}
if (isPALM) {
LOGGER.debug("Detected PALM data");
core.get(0).sizeC = 1;
core.get(0).imageCount = core.get(0).sizeZ * core.get(0).sizeT;
for (int i = 0; i < planes.size(); i++) {
SubBlock p = planes.get(i);
int storedX = p.directoryEntry.dimensionEntries[0].storedSize;
int storedY = p.directoryEntry.dimensionEntries[1].storedSize;
if (p.planeIndex >= getImageCount()) {
if (core.size() == 1) {
CoreMetadata second = new CoreMetadata(core.get(0));
core.add(second);
}
p.coreIndex = 1;
p.planeIndex -= (planes.size() / 2);
core.get(1).sizeX = storedX;
core.get(1).sizeY = storedY;
} else {
core.get(0).sizeX = storedX;
core.get(0).sizeY = storedY;
}
}
if (core.size() == 2) {
// prevent misidentification of PALM data; each plane should be a different size
if (core.get(0).sizeX == core.get(1).sizeX && core.get(0).sizeY == core.get(1).sizeY) {
isPALM = false;
core.remove(1);
core.get(0).sizeC = 2;
core.get(0).imageCount *= getSizeC();
for (int i = 0; i < planes.size(); i++) {
SubBlock p = planes.get(i);
if (p.coreIndex == 1) {
p.coreIndex = 0;
p.planeIndex += (planes.size() / 2);
}
}
}
}
}
// find and add attached label/overview images
readAttachments();
// populate the OME metadata
store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, true);
firstXML = null;
canSkipXML = true;
for (Segment segment : segments) {
String path = new Location(segment.filename).getAbsolutePath();
if (currentPath.equals(path) && segment instanceof Metadata) {
segment.fillInData();
String xml = ((Metadata) segment).xml;
xml = XMLTools.sanitizeXML(xml);
if (firstXML == null && canSkipXML) {
firstXML = xml;
}
if (canSkipXML && firstXML.equals(xml)) {
translateMetadata(xml);
} else if (!firstXML.equals(xml)) {
canSkipXML = false;
}
((Metadata) segment).clearXML();
} else if (segment instanceof Attachment) {
AttachmentEntry entry = ((Attachment) segment).attachment;
String name = entry.name.trim();
if (name.equals("TimeStamps")) {
segment.fillInData();
RandomAccessInputStream s = new RandomAccessInputStream(((Attachment) segment).attachmentData);
try {
s.order(isLittleEndian());
s.seek(8);
while (s.getFilePointer() + 8 <= s.length()) {
timestamps.add(s.readDouble());
}
} finally {
s.close();
}
}
}
segment.close();
}
if (rotationLabels != null) {
ms0.moduloZ.labels = rotationLabels;
ms0.moduloZ.end = ms0.moduloZ.start;
}
if (illuminationLabels != null) {
ms0.moduloC.labels = illuminationLabels;
ms0.moduloC.end = ms0.moduloC.start;
}
if (phaseLabels != null) {
ms0.moduloT.labels = phaseLabels;
ms0.moduloT.end = ms0.moduloT.start;
}
for (int i = 0; i < planes.size(); i++) {
SubBlock p = planes.get(i);
Coordinate c = new Coordinate(p.coreIndex, p.planeIndex, getImageCount());
ArrayList<Integer> indices = new ArrayList<Integer>();
if (indexIntoPlanes.containsKey(c)) {
indices = indexIntoPlanes.get(c);
}
indices.add(i);
indexIntoPlanes.put(c, indices);
// Add series metadata : populate position list
int nameWidth = String.valueOf(getSeriesCount()).length();
for (DimensionEntry dimension : p.directoryEntry.dimensionEntries) {
if (dimension == null) {
continue;
}
switch(dimension.dimension.charAt(0)) {
case 'S':
setCoreIndex(p.coreIndex);
int seriesId = p.coreIndex + 1;
// add padding to make sure the original metadata table is organized properly in ImageJ
String sIndex = String.format("Positions|Series %0" + nameWidth + "d|", seriesId);
addSeriesMetaList(sIndex, dimension.start);
break;
}
}
setCoreIndex(0);
}
if (channels.size() > 0 && channels.get(0).color != null && !isRGB()) {
for (int i = 0; i < seriesCount; i++) {
core.get(i).indexed = true;
}
}
String experimenterID = MetadataTools.createLSID("Experimenter", 0);
store.setExperimenterID(experimenterID, 0);
store.setExperimenterEmail(userEmail, 0);
store.setExperimenterFirstName(userFirstName, 0);
store.setExperimenterInstitution(userInstitution, 0);
store.setExperimenterLastName(userLastName, 0);
store.setExperimenterMiddleName(userMiddleName, 0);
store.setExperimenterUserName(userName, 0);
String name = new Location(getCurrentFile()).getName();
if (imageName != null && imageName.trim().length() > 0) {
name = imageName;
}
store.setInstrumentID(MetadataTools.createLSID("Instrument", 0), 0);
int indexLength = String.valueOf(getSeriesCount()).length();
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageInstrumentRef(MetadataTools.createLSID("Instrument", 0), i);
if (acquiredDate != null) {
store.setImageAcquisitionDate(new Timestamp(acquiredDate), i);
} else if (planes.get(0).timestamp != null) {
long timestamp = (long) (planes.get(0).timestamp * 1000);
String date = DateTools.convertDate(timestamp, DateTools.UNIX);
store.setImageAcquisitionDate(new Timestamp(date), i);
}
if (experimenterID != null) {
store.setImageExperimenterRef(experimenterID, i);
}
if (timeIncrement != null) {
store.setPixelsTimeIncrement(timeIncrement, i);
}
String imageIndex = String.valueOf(i + 1);
while (imageIndex.length() < indexLength) {
imageIndex = "0" + imageIndex;
}
int extraIndex = i - (getSeriesCount() - extraImages.size());
if (extraIndex < 0) {
if (hasFlattenedResolutions()) {
store.setImageName(name + " #" + imageIndex, i);
} else if (positions == 1) {
store.setImageName("", i);
} else {
store.setImageName("Scene #" + i, i);
}
} else if (extraIndex == 0) {
store.setImageName("label image", i);
} else if (extraIndex == 1) {
store.setImageName("macro image", i);
} else {
store.setImageName("thumbnail image", i);
}
// label and macro images
if (extraIndex >= 0) {
continue;
}
if (description != null && description.length() > 0) {
store.setImageDescription(description, i);
}
if (airPressure != null) {
store.setImagingEnvironmentAirPressure(new Pressure(new Double(airPressure), UNITS.MILLIBAR), i);
}
if (co2Percent != null) {
store.setImagingEnvironmentCO2Percent(PercentFraction.valueOf(co2Percent), i);
}
if (humidity != null) {
store.setImagingEnvironmentHumidity(PercentFraction.valueOf(humidity), i);
}
if (temperature != null) {
store.setImagingEnvironmentTemperature(new Temperature(new Double(temperature), UNITS.CELSIUS), i);
}
if (objectiveSettingsID != null) {
store.setObjectiveSettingsID(objectiveSettingsID, i);
if (correctionCollar != null) {
store.setObjectiveSettingsCorrectionCollar(new Double(correctionCollar), i);
}
if (medium != null) {
store.setObjectiveSettingsMedium(getMedium(medium), i);
}
if (refractiveIndex != null) {
store.setObjectiveSettingsRefractiveIndex(new Double(refractiveIndex), i);
}
}
Double startTime = null;
if (acquiredDate != null) {
Timestamp t = Timestamp.valueOf(acquiredDate);
if (t != null)
startTime = t.asInstant().getMillis() / 1000d;
}
for (int plane = 0; plane < getImageCount(); plane++) {
Coordinate coordinate = new Coordinate(i, plane, getImageCount());
ArrayList<Integer> index = indexIntoPlanes.get(coordinate);
if (index == null) {
continue;
}
SubBlock p = planes.get(index.get(0));
if (startTime == null) {
startTime = p.timestamp;
}
if (p.stageX != null) {
store.setPlanePositionX(p.stageX, i, plane);
} else if (positionsX != null && i < positionsX.length && positionsX[i] != null) {
store.setPlanePositionX(positionsX[i], i, plane);
} else {
store.setPlanePositionX(new Length(p.col, UNITS.REFERENCEFRAME), i, plane);
}
if (p.stageY != null) {
store.setPlanePositionY(p.stageY, i, plane);
} else if (positionsY != null && i < positionsY.length && positionsY[i] != null) {
store.setPlanePositionY(positionsY[i], i, plane);
} else {
store.setPlanePositionY(new Length(p.row, UNITS.REFERENCEFRAME), i, plane);
}
if (p.stageZ != null) {
store.setPlanePositionZ(p.stageZ, i, plane);
} else if (positionsZ != null && i < positionsZ.length) {
int zIndex = getZCTCoords(plane)[0];
if (positionsZ[i] != null) {
if (zStep != null) {
double value = positionsZ[i].value(zStep.unit()).doubleValue();
if (zStep != null) {
value += zIndex * zStep.value().doubleValue();
}
Length pos = new Length(value, zStep.unit());
store.setPlanePositionZ(pos, i, plane);
} else {
store.setPlanePositionZ(positionsZ[i], i, plane);
}
}
}
if (p.timestamp != null) {
store.setPlaneDeltaT(new Time(p.timestamp - startTime, UNITS.SECOND), i, plane);
} else if (plane < timestamps.size() && timestamps.size() == getImageCount()) {
// only use the plane index if there is one timestamp per plane
if (timestamps.get(plane) != null) {
store.setPlaneDeltaT(new Time(timestamps.get(plane), UNITS.SECOND), i, plane);
}
} else if (getZCTCoords(plane)[2] < timestamps.size()) {
// otherwise use the timepoint index, to prevent incorrect timestamping of channels
int t = getZCTCoords(plane)[2];
if (timestamps.get(t) != null) {
store.setPlaneDeltaT(new Time(timestamps.get(t), UNITS.S), i, plane);
}
}
if (p.exposureTime != null) {
store.setPlaneExposureTime(new Time(p.exposureTime, UNITS.SECOND), i, plane);
} else {
int channel = getZCTCoords(plane)[1];
if (channel < channels.size() && channels.get(channel).exposure != null) {
store.setPlaneExposureTime(new Time(channels.get(channel).exposure, UNITS.SECOND), i, plane);
}
}
}
for (int c = 0; c < getEffectiveSizeC(); c++) {
if (c < channels.size()) {
if (isPALM && i < channels.size()) {
store.setChannelName(channels.get(i).name, i, c);
} else {
store.setChannelName(channels.get(c).name, i, c);
}
store.setChannelFluor(channels.get(c).fluor, i, c);
if (channels.get(c).filterSetRef != null) {
store.setChannelFilterSetRef(channels.get(c).filterSetRef, i, c);
}
String color = channels.get(c).color;
if (color != null && !isRGB()) {
color = color.replaceAll("#", "");
if (color.length() > 6) {
color = color.substring(2, color.length());
}
try {
// shift by 8 to allow alpha in the final byte
store.setChannelColor(new Color((Integer.parseInt(color, 16) << 8) | 0xff), i, c);
} catch (NumberFormatException e) {
LOGGER.warn("", e);
}
}
String emWave = channels.get(c).emission;
if (emWave != null) {
Double wave = new Double(emWave);
Length em = FormatTools.getEmissionWavelength(wave);
if (em != null) {
store.setChannelEmissionWavelength(em, i, c);
}
}
String exWave = channels.get(c).excitation;
if (exWave != null) {
Double wave = new Double(exWave);
Length ex = FormatTools.getExcitationWavelength(wave);
if (ex != null) {
store.setChannelExcitationWavelength(ex, i, c);
}
}
if (channels.get(c).illumination != null) {
store.setChannelIlluminationType(channels.get(c).illumination, i, c);
}
if (channels.get(c).pinhole != null) {
store.setChannelPinholeSize(new Length(new Double(channels.get(c).pinhole), UNITS.MICROMETER), i, c);
}
if (channels.get(c).acquisitionMode != null) {
store.setChannelAcquisitionMode(channels.get(c).acquisitionMode, i, c);
}
}
if (c < detectorRefs.size()) {
String detector = detectorRefs.get(c);
store.setDetectorSettingsID(detector, i, c);
if (c < binnings.size()) {
store.setDetectorSettingsBinning(getBinning(binnings.get(c)), i, c);
}
if (c < channels.size()) {
store.setDetectorSettingsGain(channels.get(c).gain, i, c);
}
}
if (c < channels.size()) {
if (hasDetectorSettings) {
store.setDetectorSettingsGain(channels.get(c).gain, i, c);
}
}
}
}
// not needed by further calls on the reader
segments = null;
}
Aggregations