Search in sources :

Example 71 with ServiceFactory

use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.

the class PrintTimestamps method main.

public static void main(String[] args) throws Exception {
    // parse command line arguments
    if (args.length < 1) {
        System.err.println("Usage: java PrintTimestamps imageFile [seriesNo]");
        System.exit(1);
    }
    String id = args[0];
    int series = args.length > 1 ? Integer.parseInt(args[1]) : 0;
    // enable debugging
    // FormatReader.debug = true;
    // create OME-XML metadata store of the latest schema version
    ServiceFactory factory = new ServiceFactory();
    OMEXMLService service = factory.getInstance(OMEXMLService.class);
    IMetadata meta = service.createOMEXMLMetadata();
    // or if you want a specific schema version, you can use:
    // IMetadata meta = service.createOMEXMLMetadata(null, "2009-02");
    // meta.createRoot();
    // create format reader
    IFormatReader reader = new ImageReader();
    reader.setMetadataStore(meta);
    // initialize file
    System.out.println("Initializing " + id);
    reader.setId(id);
    int seriesCount = reader.getSeriesCount();
    if (series < seriesCount)
        reader.setSeries(series);
    series = reader.getSeries();
    System.out.println("\tImage series = " + series + " of " + seriesCount);
    printDimensions(reader);
    printGlobalTiming(meta, series);
    printTimingPerTimepoint(meta, series);
    printTimingPerPlane(meta, series);
}
Also used : IMetadata(loci.formats.meta.IMetadata) IFormatReader(loci.formats.IFormatReader) ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) OMEXMLService(loci.formats.services.OMEXMLService)

Example 72 with ServiceFactory

use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.

the class VeecoReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    CoreMetadata m = core.get(0);
    try {
        ServiceFactory factory = new ServiceFactory();
        netcdf = factory.getInstance(NetCDFService.class);
        netcdf.setFile(id);
    } catch (DependencyException e) {
        throw new MissingLibraryException(e);
    }
    Vector<String> variableList = netcdf.getVariableList();
    if (variableList.size() == 0) {
        throw new FormatException("No image data found");
    }
    String imageName = variableList.get(0);
    try {
        image = netcdf.getVariableValue(imageName);
    } catch (ServiceException e) {
        throw new FormatException("Could not retrieve image data", e);
    }
    Hashtable<String, Object> attributes = netcdf.getVariableAttributes(imageName);
    for (String attr : attributes.keySet()) {
        addGlobalMeta(attr, attributes.get(attr));
    }
    if (image instanceof byte[][]) {
        byte[][] byteImage = (byte[][]) image;
        m.sizeX = byteImage[0].length;
        m.sizeY = byteImage.length;
        m.pixelType = FormatTools.INT8;
    } else if (image instanceof short[][]) {
        short[][] shortImage = (short[][]) image;
        m.sizeX = shortImage[0].length;
        m.sizeY = shortImage.length;
        m.pixelType = FormatTools.INT16;
        // set the endianness to use when unpacking pixels
        // NetCDF may not return the pixels with a constant endianness,
        // so this ensures that the reader corrects accordingly (see ticket 12085)
        short nativeMin = 0;
        short nativeMax = 0;
        short swappedMin = 0;
        short swappedMax = 0;
        for (int y = 0; y < shortImage.length; y++) {
            for (int x = 0; x < shortImage[y].length; x++) {
                if (shortImage[y][x] < nativeMin) {
                    nativeMin = shortImage[y][x];
                }
                if (shortImage[y][x] > nativeMax) {
                    nativeMax = shortImage[y][x];
                }
                short swapped = DataTools.swap(shortImage[y][x]);
                if (swapped < swappedMin) {
                    swappedMin = swapped;
                }
                if (swapped > swappedMax) {
                    swappedMax = swapped;
                }
            }
        }
        unpackEndian = nativeMin <= swappedMin && nativeMax >= swappedMax;
    }
    m.sizeZ = 1;
    m.sizeC = 1;
    m.sizeT = 1;
    m.imageCount = m.sizeZ * m.sizeC * m.sizeT;
    m.dimensionOrder = "XYCZT";
    m.littleEndian = false;
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) DependencyException(loci.common.services.DependencyException) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) ServiceException(loci.common.services.ServiceException) MissingLibraryException(loci.formats.MissingLibraryException) NetCDFService(loci.formats.services.NetCDFService)

Example 73 with ServiceFactory

use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.

the class CellH5Writer method setId.

// -- FormatWriter API methods --
/* @see loci.formats.FormatWriter#setId(String) */
@Override
public void setId(String id) throws FormatException, IOException {
    if (id.equals(currentId))
        return;
    super.setId(id);
    try {
        ServiceFactory factory = new ServiceFactory();
        jhdf = factory.getInstance(JHDFService.class);
        jhdf.setFileForWrite(id);
    } catch (DependencyException e) {
        throw new MissingLibraryException(JHDFServiceImpl.NO_JHDF_MSG, e);
    }
    MetadataRetrieve retrieve = getMetadataRetrieve();
    int sizeX = retrieve.getPixelsSizeX(0).getValue();
    int sizeY = retrieve.getPixelsSizeY(0).getValue();
    int sizeZ = retrieve.getPixelsSizeZ(0).getValue();
    int sizeC = retrieve.getPixelsSizeC(0).getValue();
    int sizeT = retrieve.getPixelsSizeT(0).getValue();
    int type = FormatTools.pixelTypeFromString(retrieve.getPixelsType(0).toString());
    bpp = FormatTools.getBytesPerPixel(type);
    LOGGER.info("CellH5Writer: Found image with dimensions XYZCT {}x{}x{}x{}x{}, and bits per pixel {}", sizeX, sizeY, sizeZ, sizeC, sizeT, bpp);
    String plate = "PLATE_00";
    String well = "WELL_00";
    int site = 1;
    if (retrieve.getPlateCount() > 0) {
        plate = retrieve.getPlateName(0);
        well = retrieve.getWellExternalIdentifier(0, 0);
        site = retrieve.getWellSampleIndex(0, 0, 0).getValue();
        LOGGER.info("CellH5Writer: Found plate information Plate / Well / Site {} / {} / {}", plate, well, site);
    } else {
        LOGGER.info("CellH5Writer: No plate information found. Using default values...");
    }
    jhdf.createGroup(CellH5Constants.DEFINITION + CellH5Reader.CellH5Constants.OBJECT);
    jhdf.createGroup(CellH5Constants.DEFINITION + CellH5Reader.CellH5Constants.FEATURE);
    jhdf.createGroup(CellH5Constants.DEFINITION + CellH5Reader.CellH5Constants.IMAGE);
    outputPath = String.format("/sample/0/plate/%s/experiment/%s/position/%d/image/channel", plate, well, site);
    jhdf.initIntArray(outputPath, new long[] { sizeC, sizeT, sizeZ, sizeY, sizeX }, bpp);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) MissingLibraryException(loci.formats.MissingLibraryException) JHDFService(loci.formats.services.JHDFService) DependencyException(loci.common.services.DependencyException) MetadataRetrieve(loci.formats.meta.MetadataRetrieve)

Example 74 with ServiceFactory

use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.

the class WlzWriter method setId.

// -- FormatWriter API methods --
/* @see loci.formats.FormatWriter#setId(String) */
@Override
public void setId(String id) throws FormatException, IOException {
    super.setId(id);
    try {
        ServiceFactory factory = new ServiceFactory();
        wlz = factory.getInstance(WlzService.class);
    } catch (DependencyException e) {
        throw new FormatException(NO_WLZ_MSG, e);
    }
    if (wlz != null) {
        MetadataRetrieve meta = getMetadataRetrieve();
        MetadataTools.verifyMinimumPopulated(meta, series);
        wlz.open(id, "w");
        String stageLabelName = null;
        try {
            stageLabelName = meta.getStageLabelName(0);
        } catch (NullPointerException e) {
        }
        int oX = 0;
        int oY = 0;
        int oZ = 0;
        if ((stageLabelName != null) && stageLabelName.equals(wlz.getWlzOrgLabelName())) {
            final Length stageX = meta.getStageLabelX(0);
            final Length stageY = meta.getStageLabelY(0);
            final Length stageZ = meta.getStageLabelZ(0);
            oX = (int) Math.rint(stageX.value(UNITS.REFERENCEFRAME).doubleValue());
            oY = (int) Math.rint(stageY.value(UNITS.REFERENCEFRAME).doubleValue());
            oZ = (int) Math.rint(stageZ.value(UNITS.REFERENCEFRAME).doubleValue());
        }
        int nX = meta.getPixelsSizeX(series).getValue().intValue();
        int nY = meta.getPixelsSizeY(series).getValue().intValue();
        int nZ = meta.getPixelsSizeZ(series).getValue().intValue();
        int nC = meta.getPixelsSizeC(series).getValue().intValue();
        int nT = meta.getPixelsSizeT(series).getValue().intValue();
        double vX = 1.0;
        double vY = 1.0;
        double vZ = 1.0;
        if (meta.getPixelsPhysicalSizeX(0) != null) {
            vX = meta.getPixelsPhysicalSizeX(0).value(UNITS.MICROMETER).doubleValue();
        }
        if (meta.getPixelsPhysicalSizeY(0) != null) {
            vY = meta.getPixelsPhysicalSizeY(0).value(UNITS.MICROMETER).doubleValue();
        }
        if (meta.getPixelsPhysicalSizeZ(0) != null) {
            vZ = meta.getPixelsPhysicalSizeZ(0).value(UNITS.MICROMETER).doubleValue();
        }
        int gType = FormatTools.pixelTypeFromString(meta.getPixelsType(series).toString());
        wlz.setupWrite(oX, oY, oZ, nX, nY, nZ, nC, nT, vX, vY, vZ, gType);
    }
}
Also used : WlzService(loci.formats.services.WlzService) ServiceFactory(loci.common.services.ServiceFactory) Length(ome.units.quantity.Length) DependencyException(loci.common.services.DependencyException) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) FormatException(loci.formats.FormatException)

Example 75 with ServiceFactory

use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.

the class Upgrade200809Test method setUp.

@BeforeMethod
public void setUp() throws Exception {
    ServiceFactory sf = new ServiceFactory();
    service = sf.getInstance(OMEXMLService.class);
    InputStream s = Upgrade200809Test.class.getResourceAsStream(XML_FILE);
    byte[] b = new byte[s.available()];
    s.read(b);
    s.close();
    xml = new String(b);
    metadata = service.createOMEXMLMetadata(xml);
    ome = (OME) metadata.getRoot();
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) InputStream(java.io.InputStream) OMEXMLService(loci.formats.services.OMEXMLService) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ServiceFactory (loci.common.services.ServiceFactory)94 OMEXMLService (loci.formats.services.OMEXMLService)73 DependencyException (loci.common.services.DependencyException)49 FormatException (loci.formats.FormatException)38 IMetadata (loci.formats.meta.IMetadata)35 ServiceException (loci.common.services.ServiceException)30 ImageReader (loci.formats.ImageReader)23 MissingLibraryException (loci.formats.MissingLibraryException)15 BeforeMethod (org.testng.annotations.BeforeMethod)15 MetadataStore (loci.formats.meta.MetadataStore)14 PositiveInteger (ome.xml.model.primitives.PositiveInteger)14 IOException (java.io.IOException)13 CoreMetadata (loci.formats.CoreMetadata)13 Length (ome.units.quantity.Length)12 Location (loci.common.Location)11 OMEXMLMetadata (loci.formats.ome.OMEXMLMetadata)10 InputStream (java.io.InputStream)9 ArrayList (java.util.ArrayList)8 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)8 BeforeClass (org.testng.annotations.BeforeClass)8