use of ome.xml.model.enums.EnumerationException in project bioformats by openmicroscopy.
the class ImportProcess method initializeDimOrder.
/**
* Performed following ImportStep.DIM_ORDER notification.
*/
private void initializeDimOrder() {
final int seriesCount = getSeriesCount();
final String stackOrder = getStackOrder();
for (int s = 0; s < seriesCount; s++) {
reader.setSeries(s);
// set input order
String dimOrder = options.getInputOrder(s);
if (dimOrder != null)
dimensionSwapper.swapDimensions(dimOrder);
// set output order
getDimensionSwapper().setOutputOrder(stackOrder);
try {
DimensionOrder order = DimensionOrder.fromString(stackOrder);
getOMEMetadata().setPixelsDimensionOrder(order, s);
} catch (EnumerationException e) {
}
}
}
use of ome.xml.model.enums.EnumerationException in project bioformats by openmicroscopy.
the class FormatTools method getPhysicalSize.
public static Length getPhysicalSize(Double value, String unit) {
if (value != null && value != 0 && value < Double.POSITIVE_INFINITY) {
if (unit != null) {
try {
UnitsLength ul = UnitsLength.fromString(unit);
int ordinal = ul.ordinal();
Length returnLength = UnitsLength.create(value, ul);
if (returnLength.value().doubleValue() > Constants.EPSILON && returnLength.value().doubleValue() < Double.POSITIVE_INFINITY) {
return returnLength;
}
// Using UnitsLength.values().length - 2 as a boundary so as not to include Pixel and Reference Frame as convertible units
while (returnLength.value().doubleValue() < Constants.EPSILON && ordinal < (UnitsLength.values().length - 3)) {
ordinal++;
ul = UnitsLength.values()[ordinal];
Length tempLength = UnitsLength.create(0, ul);
returnLength = UnitsLength.create(returnLength.value(tempLength.unit()), ul);
}
if (returnLength.value().doubleValue() > Constants.EPSILON && returnLength.value().doubleValue() < Double.POSITIVE_INFINITY) {
return returnLength;
} else {
LOGGER.debug("Expected positive value for PhysicalSize; got {}", value);
return null;
}
} catch (EnumerationException e) {
}
}
return new Length(value, UNITS.MICROMETER);
}
LOGGER.debug("Expected positive value for PhysicalSize; got {}", value);
return null;
}
use of ome.xml.model.enums.EnumerationException in project bioformats by openmicroscopy.
the class MetadataTools method populatePixelsOnly.
public static void populatePixelsOnly(MetadataStore store, int series, boolean littleEndian, String dimensionOrder, String pixelType, int sizeX, int sizeY, int sizeZ, int sizeC, int sizeT, int samplesPerPixel) {
store.setPixelsID(createLSID("Pixels", series), series);
store.setPixelsBigEndian(!littleEndian, series);
try {
store.setPixelsDimensionOrder(DimensionOrder.fromString(dimensionOrder), series);
} catch (EnumerationException e) {
LOGGER.warn("Invalid dimension order: " + dimensionOrder, e);
}
try {
store.setPixelsType(PixelType.fromString(pixelType), series);
} catch (EnumerationException e) {
LOGGER.warn("Invalid pixel type: " + pixelType, e);
}
store.setPixelsSizeX(new PositiveInteger(sizeX), series);
store.setPixelsSizeY(new PositiveInteger(sizeY), series);
store.setPixelsSizeZ(new PositiveInteger(sizeZ), series);
store.setPixelsSizeC(new PositiveInteger(sizeC), series);
store.setPixelsSizeT(new PositiveInteger(sizeT), series);
int effSizeC = sizeC / samplesPerPixel;
for (int i = 0; i < effSizeC; i++) {
store.setChannelID(createLSID("Channel", series, i), series, i);
store.setChannelSamplesPerPixel(new PositiveInteger(samplesPerPixel), series, i);
}
}
use of ome.xml.model.enums.EnumerationException in project bioformats by openmicroscopy.
the class Configuration method getPhysicalSizeX.
public Length getPhysicalSizeX() {
String physicalSize = currentTable.get(PHYSICAL_SIZE_X);
String sizeXUnits = currentTable.get(PHYSICAL_SIZE_X_UNIT);
try {
UnitsLength xUnits = sizeXUnits == null ? UnitsLength.MICROMETER : UnitsLength.fromString(sizeXUnits);
return physicalSize == null ? null : UnitsLength.create(new Double(physicalSize), xUnits);
} catch (NumberFormatException e) {
} catch (EnumerationException e) {
}
return null;
}
use of ome.xml.model.enums.EnumerationException in project bioformats by openmicroscopy.
the class FileExportSPW method initializeMetadata.
/**
* Populate the minimum amount of metadata required to export a Plate.
*
* @param width
* the width (in pixels) of the image
* @param height
* the height (in pixels) of the image
* @param pixelType
* the pixel type of the image; @see loci.formats.FormatTools
*/
private IMetadata initializeMetadata(int width, int height, int pixelType) {
Exception exception = null;
try {
// create the OME-XML metadata storage object
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
OMEXMLMetadata meta = service.createOMEXMLMetadata();
meta.createRoot();
int plateIndex = 0;
// count of images
int series = 0;
int well = 0;
// Create Minimal 2x2 Plate
meta.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
meta.setPlateRowNamingConvention(NamingConvention.LETTER, 0);
meta.setPlateColumnNamingConvention(NamingConvention.NUMBER, 0);
meta.setPlateRows(new PositiveInteger(rows), 0);
meta.setPlateColumns(new PositiveInteger(cols), 0);
meta.setPlateName("First test Plate", 0);
PositiveInteger pwidth = new PositiveInteger(width);
PositiveInteger pheight = new PositiveInteger(height);
char rowChar = 'A';
for (int row = 0; row < rows; row++) {
for (int column = 0; column < cols; column++) {
// set up well
String wellID = MetadataTools.createLSID("Well:", well);
meta.setWellID(wellID, plateIndex, well);
meta.setWellRow(new NonNegativeInteger(row), plateIndex, well);
meta.setWellColumn(new NonNegativeInteger(column), plateIndex, well);
for (int fov = 0; fov < fovPerWell; fov++) {
// Create Image
String imageName = rowChar + ":" + Integer.toString(column + 1) + ":FOV:" + Integer.toString(fov + 1);
String imageID = MetadataTools.createLSID("Image", well, fov);
meta.setImageID(imageID, series);
meta.setImageName(imageName, series);
String pixelsID = MetadataTools.createLSID("Pixels", row, well, fov);
meta.setPixelsID(pixelsID, series);
// specify that the pixel data is stored in big-endian format
// change 'TRUE' to 'FALSE' to specify little-endian format
meta.setPixelsBinDataBigEndian(Boolean.TRUE, series, 0);
// specify that the image is stored in ZCT order
meta.setPixelsDimensionOrder(DimensionOrder.XYZCT, series);
// specify the pixel type of the image
meta.setPixelsType(PixelType.fromString(FormatTools.getPixelTypeString(pixelType)), series);
// specify the dimensions of the image
meta.setPixelsSizeX(pwidth, series);
meta.setPixelsSizeY(pheight, series);
meta.setPixelsSizeZ(new PositiveInteger(1), series);
meta.setPixelsSizeC(new PositiveInteger(1), series);
meta.setPixelsSizeT(new PositiveInteger(sizeT), series);
// define each channel and specify the number of samples in the
// channel the number of samples is 3 for RGB images and 1 otherwise
String channelID = MetadataTools.createLSID("Channel", well, fov);
meta.setChannelID(channelID, series, 0);
meta.setChannelSamplesPerPixel(new PositiveInteger(1), series, 0);
// set sample
String wellSampleID = MetadataTools.createLSID("WellSample", well, fov);
meta.setWellSampleID(wellSampleID, 0, well, fov);
// NB sampleIndex here == series ie the image No
meta.setWellSampleIndex(new NonNegativeInteger(series), 0, well, fov);
meta.setWellSampleImageRef(imageID, 0, well, fov);
// add FLIM ModuloAlongT annotation if required
// CoreMetadata modlo = createModuloAnn();
// meta.addModuloAlong(meta, modlo, series);
series++;
}
// end of samples
well++;
}
rowChar++;
}
return meta;
} catch (DependencyException e) {
exception = e;
} catch (ServiceException e) {
exception = e;
} catch (EnumerationException e) {
exception = e;
}
System.err.println("Failed to populate OME-XML metadata object.");
exception.printStackTrace();
return null;
}
Aggregations