use of loci.common.Location in project bioformats by openmicroscopy.
the class HitachiReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
if (!checkSuffix(id, "txt")) {
String base = id;
if (base.indexOf('.') >= 0) {
base = base.substring(0, base.lastIndexOf("."));
}
id = base + ".txt";
initFile(id);
return;
}
super.initFile(id);
String data = DataTools.readFile(id);
IniParser parser = new IniParser();
parser.setBackslashContinuesLine(false);
IniList ini = parser.parseINI(new BufferedReader(new StringReader(data)));
IniTable image = ini.getTable("SemImageFile");
if (image == null) {
throw new FormatException("Could not find 'SemImageFile' table.");
}
for (String key : image.keySet()) {
addGlobalMeta(key, image.get(key));
}
String imageName = image.get("SampleName");
String pixelsFile = image.get("ImageName");
String date = image.get("Date");
String time = image.get("Time");
Location parent = new Location(id).getAbsoluteFile().getParentFile();
pixelsFile = new Location(parent, pixelsFile).getAbsolutePath();
ClassList<IFormatReader> classes = ImageReader.getDefaultReaderClasses();
Class<? extends IFormatReader>[] classArray = classes.getClasses();
ClassList<IFormatReader> newClasses = new ClassList<IFormatReader>(IFormatReader.class);
for (Class<? extends IFormatReader> c : classArray) {
if (!c.equals(HitachiReader.class)) {
newClasses.addClass(c);
}
}
helperReader = new ImageReader(newClasses);
helperReader.setId(pixelsFile);
core = new ArrayList<CoreMetadata>(helperReader.getCoreMetadataList());
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM);
store.setImageName(imageName, 0);
date = DateTools.formatDate(date + " " + time, DATE_FORMAT);
if (date != null) {
store.setImageAcquisitionDate(new Timestamp(date), 0);
}
populateOMEMetadata(image, store);
}
use of loci.common.Location in project bioformats by openmicroscopy.
the class HitachiReader method isThisType.
/* @see loci.formats.IFormatReader#isThisType(String, boolean) */
@Override
public boolean isThisType(String name, boolean open) {
if (!open) {
return false;
}
String base = name;
if (base.indexOf('.') >= 0) {
base = base.substring(0, base.lastIndexOf("."));
}
if (checkSuffix(name, "txt")) {
Location bmp = new Location(base + ".bmp");
Location jpg = new Location(base + ".jpg");
Location tif = new Location(base + ".tif");
if (!bmp.exists() && !jpg.exists() && !tif.exists()) {
return false;
}
return super.isThisType(name, open);
}
String textFile = base + ".txt";
return new Location(textFile).exists() && isThisType(textFile, open);
}
use of loci.common.Location 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.common.Location in project bioformats by openmicroscopy.
the class InCellReader method openBytes.
/**
* @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
*/
@Override
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
int[] coordinates = getZCTCoords(no);
int well = getWellFromSeries(getSeries());
int field = getFieldFromSeries(getSeries());
int timepoint = oneTimepointPerSeries ? getSeries() % channelsPerTimepoint.size() : coordinates[2];
int image = getIndex(coordinates[0], coordinates[1], 0);
if (imageFiles[well][field][timepoint][image] == null)
return buf;
String filename = imageFiles[well][field][timepoint][image].filename;
if (filename == null || !(new Location(filename).exists()))
return buf;
if (imageFiles[well][field][timepoint][image].isTiff) {
try {
tiffReader.setId(filename);
return tiffReader.openBytes(0, buf, x, y, w, h);
} catch (FormatException e) {
LOGGER.debug("", e);
} catch (IOException e) {
LOGGER.debug("", e);
}
return buf;
}
// pixels are stored in .im files
RandomAccessInputStream s = new RandomAccessInputStream(filename);
if (s.length() > FormatTools.getPlaneSize(this)) {
s.seek(128);
readPlane(s, x, y, w, h, buf);
}
s.close();
return buf;
}
use of loci.common.Location in project bioformats by openmicroscopy.
the class InCellReader method getSeriesUsedFiles.
/* @see loci.formats.IFormatReader#getSeriesUsedFiles(boolean) */
@Override
public String[] getSeriesUsedFiles(boolean noPixels) {
FormatTools.assertId(currentId, true, 1);
final List<String> files = new ArrayList<String>();
files.add(currentId);
files.addAll(metadataFiles);
if (!noPixels && imageFiles != null) {
int well = getWellFromSeries(getSeries());
int field = getFieldFromSeries(getSeries());
for (Image[] timepoints : imageFiles[well][field]) {
for (Image plane : timepoints) {
if (plane != null && plane.filename != null) {
if (new Location(plane.filename).exists()) {
files.add(plane.filename);
}
if (plane.thumbnailFile != null && new Location(plane.thumbnailFile).exists()) {
files.add(plane.thumbnailFile);
}
}
}
}
}
return files.toArray(new String[files.size()]);
}
Aggregations