Search in sources :

Example 1 with Instrument

use of ome.xml.model.Instrument in project bioformats by openmicroscopy.

the class SPWModelMock method makeImage.

private Image makeImage(int index) {
    // <Instrument/> for later linking, etc.
    Instrument instrument = ome.getInstrument(0);
    // Create <Image/>
    Image image = new Image();
    image.setID("Image:" + index);
    CommentAnnotation commentAnnotation = new CommentAnnotation();
    commentAnnotation.setID("Annotation:" + index);
    commentAnnotation.setNamespace(GENERAL_ANNOTATION_NAMESPACE);
    commentAnnotation.setValue("Image:" + index + " annotation.");
    annotations.addCommentAnnotation(commentAnnotation);
    image.linkAnnotation(commentAnnotation);
    // Create <Pixels/>
    Pixels pixels = new Pixels();
    pixels.setID("Pixels:" + index);
    pixels.setSizeX(new PositiveInteger(SIZE_X));
    pixels.setSizeY(new PositiveInteger(SIZE_Y));
    pixels.setSizeZ(new PositiveInteger(SIZE_Z));
    pixels.setSizeC(new PositiveInteger(SIZE_C));
    pixels.setSizeT(new PositiveInteger(SIZE_T));
    pixels.setDimensionOrder(DIMENSION_ORDER);
    pixels.setType(PIXEL_TYPE);
    // Create <BinData/>
    for (int i = 0; i < SIZE_Z * SIZE_C * SIZE_T; i++) {
        BinData binData = new BinData();
        binData.setBigEndian(false);
        binData.setCompression(Compression.NONE);
        binData.setLength(new NonNegativeLong((long) (SIZE_X * SIZE_Y * BYTES_PER_PIXEL)));
        pixels.addBinData(binData);
    }
    // Create <Channel/> under <Pixels/>
    for (int i = 0; i < SIZE_C; i++) {
        Channel channel = new Channel();
        channel.setID("Channel:" + i);
        // Create <LightSourceSettings/> and link to <Channel/>
        LightSourceSettings settings = new LightSourceSettings();
        settings.setID(LIGHTSOURCE_LASER_ID);
        channel.setLightSourceSettings(settings);
        // Create <LightPath/> and link to <Channel/>
        LightPath lightPath = new LightPath();
        lightPath.linkEmissionFilter(instrument.getFilter(0));
        lightPath.linkExcitationFilter(instrument.getFilter(1));
        channel.setLightPath(lightPath);
        pixels.addChannel(channel);
    }
    // Put <Pixels/> under <Image/>
    image.setPixels(pixels);
    // Link <Instrument/> to <Image/>
    image.linkInstrument(instrument);
    // Create <ObjectiveSettings/> and link to <Image/>
    ObjectiveSettings settings = new ObjectiveSettings();
    settings.setID(OBJECTIVE_ID);
    image.setObjectiveSettings(settings);
    return image;
}
Also used : PositiveInteger(ome.xml.model.primitives.PositiveInteger) LightSourceSettings(ome.xml.model.LightSourceSettings) NonNegativeLong(ome.xml.model.primitives.NonNegativeLong) LightPath(ome.xml.model.LightPath) CommentAnnotation(ome.xml.model.CommentAnnotation) BinData(ome.xml.model.BinData) Channel(ome.xml.model.Channel) ObjectiveSettings(ome.xml.model.ObjectiveSettings) Instrument(ome.xml.model.Instrument) Image(ome.xml.model.Image) Pixels(ome.xml.model.Pixels)

Example 2 with Instrument

use of ome.xml.model.Instrument in project bioformats by openmicroscopy.

the class CellWorxReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    if (!checkSuffix(id, "htd")) {
        LOGGER.info("Searching for .htd file");
        String base = new Location(id).getAbsolutePath();
        base = base.substring(0, base.lastIndexOf("_"));
        id = base + ".HTD";
        if (!new Location(id).exists()) {
            Location parent = new Location(id).getAbsoluteFile().getParentFile();
            directoryList = parent.list(true);
            for (String f : directoryList) {
                if (checkSuffix(f, "htd")) {
                    id = new Location(parent, f).getAbsolutePath();
                    LOGGER.info("Found .htd file {}", f);
                    break;
                }
            }
        }
    }
    super.initFile(id);
    try {
        ServiceFactory factory = new ServiceFactory();
        service = factory.getInstance(OMEXMLService.class);
    } catch (DependencyException exc) {
        throw new FormatException("Could not create OME-XML store.", exc);
    }
    String plateData = DataTools.readFile(id);
    String[] lines = plateData.split("\n");
    int xWells = 0, yWells = 0;
    int xFields = 0, yFields = 0;
    String[] wavelengths = null;
    int nTimepoints = 1;
    // determine dataset dimensions
    for (String line : lines) {
        int split = line.indexOf("\",");
        if (split < 1)
            continue;
        String key = line.substring(1, split).trim();
        String value = line.substring(split + 2).trim();
        if (key.equals("XWells")) {
            xWells = Integer.parseInt(value);
        } else if (key.equals("YWells")) {
            yWells = Integer.parseInt(value);
            wellFiles = new String[yWells][xWells][];
            logFiles = new String[yWells][xWells];
        } else if (key.startsWith("WellsSelection")) {
            int row = Integer.parseInt(key.substring(14)) - 1;
            String[] mapping = value.split(",");
            for (int col = 0; col < xWells; col++) {
                if (new Boolean(mapping[col].trim()).booleanValue()) {
                    wellFiles[row][col] = new String[1];
                }
            }
        } else if (key.equals("XSites")) {
            xFields = Integer.parseInt(value);
        } else if (key.equals("YSites")) {
            yFields = Integer.parseInt(value);
            fieldMap = new boolean[yFields][xFields];
        } else if (key.equals("TimePoints")) {
            nTimepoints = Integer.parseInt(value);
        } else if (key.startsWith("SiteSelection")) {
            int row = Integer.parseInt(key.substring(13)) - 1;
            String[] mapping = value.split(",");
            for (int col = 0; col < xFields; col++) {
                fieldMap[row][col] = new Boolean(mapping[col].trim()).booleanValue();
            }
        } else if (key.equals("Waves")) {
            doChannels = new Boolean(value.toLowerCase());
        } else if (key.equals("NWavelengths")) {
            wavelengths = new String[Integer.parseInt(value)];
        } else if (key.startsWith("WaveName")) {
            int index = Integer.parseInt(key.substring(8)) - 1;
            wavelengths[index] = value.replaceAll("\"", "");
        }
    }
    for (int row = 0; row < fieldMap.length; row++) {
        for (int col = 0; col < fieldMap[row].length; col++) {
            if (fieldMap[row][col])
                fieldCount++;
        }
    }
    // find pixels files
    String plateName = new Location(id).getAbsolutePath();
    plateName = plateName.substring(0, plateName.lastIndexOf(".")) + "_";
    int wellCount = 0;
    for (int row = 0; row < wellFiles.length; row++) {
        for (int col = 0; col < wellFiles[row].length; col++) {
            if (wellFiles[row][col] != null) {
                wellCount++;
                char rowLetter = (char) (row + 'A');
                String base = plateName + rowLetter + String.format("%02d", col + 1);
                wellFiles[row][col][0] = base + ".pnl";
                logFiles[row][col] = base + "_scan.log";
                if (!new Location(wellFiles[row][col][0]).exists()) {
                    // using TIFF files instead
                    wellFiles[row][col] = getTiffFiles(plateName, rowLetter, col, wavelengths.length, nTimepoints);
                }
            }
        }
    }
    plateLogFile = plateName + "scan.log";
    String serialNumber = null;
    if (new Location(plateLogFile).exists()) {
        String[] f = DataTools.readFile(plateLogFile).split("\n");
        for (String line : f) {
            if (line.trim().startsWith("Z Map File")) {
                String file = line.substring(line.indexOf(':') + 1);
                file = file.substring(file.lastIndexOf("/") + 1).trim();
                String parent = new Location(id).getAbsoluteFile().getParent();
                zMapFile = new Location(parent, file).getAbsolutePath();
            } else if (line.trim().startsWith("Scanner SN")) {
                serialNumber = line.substring(line.indexOf(':') + 1).trim();
            }
        }
    }
    int seriesCount = fieldCount * wellCount;
    int planeIndex = 0;
    int seriesIndex = 0;
    String file = getFile(seriesIndex, planeIndex);
    while (!new Location(file).exists()) {
        if (planeIndex < nTimepoints * wavelengths.length) {
            planeIndex++;
        } else if (seriesIndex < seriesCount - 1) {
            planeIndex = 0;
            seriesIndex++;
        } else {
            break;
        }
        file = getFile(seriesIndex, planeIndex);
    }
    IFormatReader pnl = getReader(file, true);
    core.clear();
    for (int i = 0; i < seriesCount; i++) {
        CoreMetadata ms = new CoreMetadata();
        core.add(ms);
        setSeries(i);
        ms.littleEndian = pnl.isLittleEndian();
        ms.sizeX = pnl.getSizeX();
        ms.sizeY = pnl.getSizeY();
        ms.pixelType = pnl.getPixelType();
        ms.sizeZ = 1;
        ms.sizeT = nTimepoints;
        ms.sizeC = wavelengths.length;
        ms.imageCount = getSizeZ() * getSizeC() * getSizeT();
        ms.dimensionOrder = "XYCZT";
        ms.rgb = false;
        ms.interleaved = pnl.isInterleaved();
    }
    OMEXMLMetadata readerMetadata = (OMEXMLMetadata) pnl.getMetadataStore();
    OMEXMLMetadataRoot root = (OMEXMLMetadataRoot) readerMetadata.getRoot();
    Instrument instrument = root.getInstrument(0);
    List<Image> images = root.copyImageList();
    OMEXMLMetadataRoot convertRoot = new OMEXMLMetadataRoot();
    convertRoot.addInstrument(instrument);
    for (int i = 0; i < core.size() / images.size(); i++) {
        for (Image img : images) {
            convertRoot.addImage(img);
        }
    }
    OMEXMLMetadata convertMetadata;
    try {
        convertMetadata = service.createOMEXMLMetadata();
    } catch (ServiceException exc) {
        throw new FormatException("Could not create OME-XML store.", exc);
    }
    convertMetadata.setRoot(convertRoot);
    pnl.close();
    MetadataStore store = makeFilterMetadata();
    MetadataConverter.convertMetadata(convertMetadata, store);
    MetadataTools.populatePixels(store, this);
    String plateID = MetadataTools.createLSID("Plate", 0);
    Location plate = new Location(id).getAbsoluteFile();
    store.setPlateID(plateID, 0);
    plateName = plate.getName();
    if (plateName.indexOf('.') > 0) {
        plateName = plateName.substring(0, plateName.lastIndexOf('.'));
    }
    store.setPlateName(plateName, 0);
    store.setPlateRows(new PositiveInteger(wellFiles.length), 0);
    store.setPlateColumns(new PositiveInteger(wellFiles[0].length), 0);
    for (int i = 0; i < core.size(); i++) {
        store.setImageID(MetadataTools.createLSID("Image", i), i);
    }
    String plateAcqID = MetadataTools.createLSID("PlateAcquisition", 0, 0);
    store.setPlateAcquisitionID(plateAcqID, 0, 0);
    PositiveInteger fieldCount = FormatTools.getMaxFieldCount(fieldMap.length * fieldMap[0].length);
    if (fieldCount != null) {
        store.setPlateAcquisitionMaximumFieldCount(fieldCount, 0, 0);
    }
    int nextImage = 0;
    for (int row = 0; row < wellFiles.length; row++) {
        for (int col = 0; col < wellFiles[row].length; col++) {
            int wellIndex = row * wellFiles[row].length + col;
            String wellID = MetadataTools.createLSID("Well", 0, wellIndex);
            store.setWellID(wellID, 0, wellIndex);
            store.setWellColumn(new NonNegativeInteger(col), 0, wellIndex);
            store.setWellRow(new NonNegativeInteger(row), 0, wellIndex);
            int fieldIndex = 0;
            for (int fieldRow = 0; fieldRow < fieldMap.length; fieldRow++) {
                for (int fieldCol = 0; fieldCol < fieldMap[fieldRow].length; fieldCol++) {
                    if (fieldMap[fieldRow][fieldCol] && wellFiles[row][col] != null) {
                        String wellSampleID = MetadataTools.createLSID("WellSample", 0, wellIndex, fieldIndex);
                        store.setWellSampleID(wellSampleID, 0, wellIndex, fieldIndex);
                        String imageID = MetadataTools.createLSID("Image", nextImage);
                        store.setWellSampleImageRef(imageID, 0, wellIndex, fieldIndex);
                        store.setWellSampleIndex(new NonNegativeInteger(nextImage), 0, wellIndex, fieldIndex);
                        store.setPlateAcquisitionWellSampleRef(wellSampleID, 0, 0, nextImage);
                        String well = (char) (row + 'A') + String.format("%02d", col + 1);
                        store.setImageName("Well " + well + " Field #" + (fieldIndex + 1), nextImage);
                        nextImage++;
                        fieldIndex++;
                    }
                }
            }
        }
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        if (serialNumber != null) {
            store.setMicroscopeSerialNumber(serialNumber, 0);
        }
        for (int well = 0; well < wellCount; well++) {
            parseWellLogFile(well, store);
        }
        if (timestamps.size() > 0) {
            store.setPlateAcquisitionStartTime(timestamps.get(0), 0, 0);
            store.setPlateAcquisitionEndTime(timestamps.get(timestamps.size() - 1), 0, 0);
        }
        for (int i = 0; i < core.size(); i++) {
            for (int c = 0; c < getSizeC(); c++) {
                if (c < wavelengths.length && wavelengths[c] != null) {
                    store.setChannelName(wavelengths[c], i, c);
                }
            }
        }
    }
}
Also used : PositiveInteger(ome.xml.model.primitives.PositiveInteger) IFormatReader(loci.formats.IFormatReader) ServiceFactory(loci.common.services.ServiceFactory) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) DependencyException(loci.common.services.DependencyException) Image(ome.xml.model.Image) CoreMetadata(loci.formats.CoreMetadata) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) ServiceException(loci.common.services.ServiceException) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) OMEXMLMetadataRoot(ome.xml.meta.OMEXMLMetadataRoot) Instrument(ome.xml.model.Instrument) Location(loci.common.Location)

Example 3 with Instrument

use of ome.xml.model.Instrument in project bioformats by openmicroscopy.

the class PumpWithLightSourceSettingsTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    Instrument instrument = new Instrument();
    instrument.setID("Instrument:0");
    // Add a Laser with an Arc pump
    Laser laser = new Laser();
    laser.setID("Laser:0");
    Arc pump = new Arc();
    pump.setID("Arc:0");
    laser.linkPump(pump);
    instrument.addLightSource(laser);
    instrument.addLightSource(pump);
    ome.addInstrument(instrument);
    // Add an Image/Pixels with a LightSourceSettings reference to the Pump
    // on one of its channels.
    Image image = new Image();
    image.setID("Image:0");
    Pixels pixels = new Pixels();
    pixels.setID("Pixels:0");
    Channel channel = new Channel();
    channel.setID("Channel:0");
    LightSourceSettings settings = new LightSourceSettings();
    settings.setID("Arc:0");
    channel.setLightSourceSettings(settings);
    pixels.addChannel(channel);
    image.setPixels(pixels);
    ome.addImage(image);
}
Also used : LightSourceSettings(ome.xml.model.LightSourceSettings) Arc(ome.xml.model.Arc) Laser(ome.xml.model.Laser) Channel(ome.xml.model.Channel) Instrument(ome.xml.model.Instrument) Image(ome.xml.model.Image) Pixels(ome.xml.model.Pixels) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with Instrument

use of ome.xml.model.Instrument in project bioformats by openmicroscopy.

the class SPWModelMock method makeInstrument.

private Instrument makeInstrument(boolean makeLightSources) {
    // Create <Instrument/>
    Instrument instrument = new Instrument();
    instrument.setID(INSTRUMENT_ID);
    // Create <Detector/> under <Instrument/>
    Detector detector = new Detector();
    detector.setID(DETECTOR_ID);
    detector.setModel(DETECTOR_MODEL);
    instrument.addDetector(detector);
    if (makeLightSources) {
        // Create <Laser/> under <Instrument/>
        Laser laser = new Laser();
        laser.setID(LIGHTSOURCE_LASER_ID);
        laser.setModel(LIGHTSOURCE_LASER_MODEL);
        laser.setType(LASER_TYPE);
        laser.setPower(new Power(LIGHTSOURCE_LASER_POWER, UNITS.MILLIWATT));
        // with a <Pump/>
        Laser laserPump = new Laser();
        laserPump.setID(LIGHTSOURCE_PUMP_ID);
        laserPump.setModel(LIGHTSOURCE_PUMP_MODEL);
        laserPump.setType(LASER_TYPE);
        laserPump.setPower(new Power(LIGHTSOURCE_PUMP_POWER, UNITS.MILLIWATT));
        laser.linkPump(laserPump);
        instrument.addLightSource(laser);
        instrument.addLightSource(laserPump);
        // Create <Arc/> under <Instrument/>
        Arc arc = new Arc();
        arc.setID(LIGHTSOURCE_ARC_ID);
        arc.setModel(LIGHTSOURCE_ARC_MODEL);
        arc.setType(ARC_TYPE);
        arc.setPower(new Power(LIGHTSOURCE_ARC_POWER, UNITS.MILLIWATT));
        instrument.addLightSource(arc);
        // Create <Filament/> under <Instrument/>
        Filament filament = new Filament();
        filament.setID(LIGHTSOURCE_FILAMENT_ID);
        filament.setModel(LIGHTSOURCE_FILAMENT_MODEL);
        filament.setType(FILAMENT_TYPE);
        filament.setPower(new Power(LIGHTSOURCE_FILAMENT_POWER, UNITS.MILLIWATT));
        instrument.addLightSource(filament);
        // Create <LightEmittingDiode/> under <Instrument/>
        LightEmittingDiode led = new LightEmittingDiode();
        led.setID(LIGHTSOURCE_LED_ID);
        led.setModel(LIGHTSOURCE_LED_MODEL);
        led.setPower(new Power(LIGHTSOURCE_LED_POWER, UNITS.MILLIWATT));
        instrument.addLightSource(led);
    }
    // Create <Dichroic/> under <Instrument/>
    Dichroic dichroic = new Dichroic();
    dichroic.setID(DICHROIC_ID);
    dichroic.setSerialNumber(DICHROIC_SN);
    // Create <FilterSet/> under <Dichroic/>
    FilterSet filterSet = new FilterSet();
    filterSet.setID(FILTERSET_ID);
    filterSet.setLotNumber(FILTERSET_LOT);
    filterSet.linkDichroic(dichroic);
    Filter emFilter = new Filter();
    Filter exFilter = new Filter();
    // Create <Objective/> under <Instrument/>
    Objective objective = new Objective();
    objective.setID(OBJECTIVE_ID);
    objective.setModel(OBJECTIVE_MODEL);
    emFilter.setID(EM_FILTER_ID);
    emFilter.setType(EM_FILTER_TYPE);
    exFilter.setID(EX_FILTER_ID);
    exFilter.setType(EX_FILTER_TYPE);
    instrument.addFilter(emFilter);
    instrument.addFilter(exFilter);
    instrument.addObjective(objective);
    filterSet.linkEmissionFilter(emFilter);
    filterSet.linkExcitationFilter(exFilter);
    filterSet.linkDichroic(dichroic);
    instrument.addFilterSet(filterSet);
    instrument.addDichroic(dichroic);
    return instrument;
}
Also used : LightEmittingDiode(ome.xml.model.LightEmittingDiode) Objective(ome.xml.model.Objective) Detector(ome.xml.model.Detector) Arc(ome.xml.model.Arc) Filament(ome.xml.model.Filament) FilterSet(ome.xml.model.FilterSet) Filter(ome.xml.model.Filter) Laser(ome.xml.model.Laser) Instrument(ome.xml.model.Instrument) Dichroic(ome.xml.model.Dichroic) Power(ome.units.quantity.Power)

Example 5 with Instrument

use of ome.xml.model.Instrument in project bioformats by openmicroscopy.

the class GenericExcitationMapTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    Instrument instrument = new Instrument();
    instrument.setID("Instrument:0");
    // Add a GenericExcitationSource with an Map
    GenericExcitationSource geSource = new GenericExcitationSource();
    geSource.setID("LightSource:0");
    List<MapPair> dataMap = new ArrayList<MapPair>();
    dataMap.add(new MapPair("a", "1"));
    dataMap.add(new MapPair("d", "2"));
    dataMap.add(new MapPair("c", "3"));
    dataMap.add(new MapPair("b", "4"));
    dataMap.add(new MapPair("e", "5"));
    dataMap.add(new MapPair("c", "6"));
    assertEquals(6, dataMap.size());
    geSource.setMap(dataMap);
    instrument.addLightSource(geSource);
    ome.addInstrument(instrument);
    // Add an Image/Pixels with a LightSourceSettings reference to the
    // GenericExcitationSource on one of its channels.
    Image image = new Image();
    image.setID("Image:0");
    Pixels pixels = new Pixels();
    pixels.setID("Pixels:0");
    Channel channel = new Channel();
    channel.setID("Channel:0");
    LightSourceSettings settings = new LightSourceSettings();
    settings.setID("LightSource:0");
    channel.setLightSourceSettings(settings);
    pixels.addChannel(channel);
    image.setPixels(pixels);
    ome.addImage(image);
}
Also used : MapPair(ome.xml.model.MapPair) LightSourceSettings(ome.xml.model.LightSourceSettings) GenericExcitationSource(ome.xml.model.GenericExcitationSource) Channel(ome.xml.model.Channel) Instrument(ome.xml.model.Instrument) ArrayList(java.util.ArrayList) Image(ome.xml.model.Image) Pixels(ome.xml.model.Pixels) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

Instrument (ome.xml.model.Instrument)9 Image (ome.xml.model.Image)6 Arc (ome.xml.model.Arc)4 Laser (ome.xml.model.Laser)4 Channel (ome.xml.model.Channel)3 Filament (ome.xml.model.Filament)3 LightEmittingDiode (ome.xml.model.LightEmittingDiode)3 LightSourceSettings (ome.xml.model.LightSourceSettings)3 Pixels (ome.xml.model.Pixels)3 BeforeClass (org.testng.annotations.BeforeClass)3 Power (ome.units.quantity.Power)2 OMEXMLMetadataRoot (ome.xml.meta.OMEXMLMetadataRoot)2 CommentAnnotation (ome.xml.model.CommentAnnotation)2 Detector (ome.xml.model.Detector)2 Dichroic (ome.xml.model.Dichroic)2 Filter (ome.xml.model.Filter)2 FilterSet (ome.xml.model.FilterSet)2 Objective (ome.xml.model.Objective)2 PositiveInteger (ome.xml.model.primitives.PositiveInteger)2 Test (org.testng.annotations.Test)2