Search in sources :

Example 11 with IniTable

use of loci.common.IniTable in project bioformats by openmicroscopy.

the class ConfigurationTree method parseConfigFile.

public void parseConfigFile(String configFile) throws IOException {
    File file = new File(configFile);
    if (file.isDirectory()) {
        return;
    }
    String parent = file.getParent();
    if (configDir != null) {
        parent = relocateToRoot(parent);
    }
    configFile = file.getAbsolutePath();
    String dir = file.getParentFile().getAbsolutePath();
    IniParser parser = new IniParser();
    parser.setCommentDelimiter(null);
    FileInputStream stream = new FileInputStream(configFile);
    IniList iniList = parser.parseINI(new BufferedReader(new InputStreamReader(stream, Constants.ENCODING)));
    for (IniTable table : iniList) {
        String id = table.get(IniTable.HEADER_KEY);
        id = id.substring(0, id.lastIndexOf(" "));
        id = new File(parent, id).getAbsolutePath();
        DefaultMutableTreeNode node = findNode(id, true, configFile);
        if (node == null) {
            LOGGER.warn("config file '{}' has invalid filename '{}'", configFile, id);
            continue;
        }
    }
}
Also used : IniParser(loci.common.IniParser) InputStreamReader(java.io.InputStreamReader) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) IniList(loci.common.IniList) IniTable(loci.common.IniTable) BufferedReader(java.io.BufferedReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 12 with IniTable

use of loci.common.IniTable in project bioformats by openmicroscopy.

the class FV1000Reader method parseROIFile.

private int parseROIFile(String filename, MetadataStore store, int nextROI, int plane) throws FormatException, IOException {
    int[] coordinates = getZCTCoords(plane);
    IniList roiFile = null;
    try {
        roiFile = getIniFile(filename);
    } catch (FormatException e) {
        LOGGER.debug("Could not parse ROI file {}", filename, e);
        return nextROI;
    } catch (IOException e) {
        LOGGER.debug("Could not parse ROI file {}", filename, e);
        return nextROI;
    }
    boolean validROI = false;
    int shape = -1;
    int shapeType = -1;
    String[] xc = null, yc = null;
    int divide = 0;
    int fontSize = 0, lineWidth = 0, angle = 0;
    String fontName = null, name = null;
    for (IniTable table : roiFile) {
        String tableName = table.get(IniTable.HEADER_KEY);
        if (tableName.equals("ROIBase FileInformation")) {
            try {
                String roiName = table.get("Name").replaceAll("\"", "");
                validROI = Integer.parseInt(roiName) > 1;
            } catch (NumberFormatException e) {
                validROI = false;
            }
            if (!validROI)
                continue;
        } else if (tableName.equals("ROIBase Body")) {
            shapeType = Integer.parseInt(table.get("SHAPE"));
            divide = Integer.parseInt(table.get("DIVIDE"));
            String[] fontAttributes = table.get("FONT").split(",");
            fontName = fontAttributes[0];
            fontSize = Integer.parseInt(fontAttributes[1]);
            Length font = FormatTools.getFontSize(fontSize);
            lineWidth = Integer.parseInt(table.get("LINEWIDTH"));
            name = table.get("NAME");
            angle = Integer.parseInt(table.get("ANGLE"));
            xc = table.get("X").split(",");
            yc = table.get("Y").split(",");
            int x = Integer.parseInt(xc[0]);
            int width = xc.length > 1 ? Integer.parseInt(xc[1]) - x : 0;
            int y = Integer.parseInt(yc[0]);
            int height = yc.length > 1 ? Integer.parseInt(yc[1]) - y : 0;
            if (width + x <= getSizeX() && height + y <= getSizeY()) {
                shape++;
                final Integer zIndex = coordinates[0];
                final Integer tIndex = coordinates[2];
                if (shape == 0) {
                    nextROI++;
                    if (shapeType == POINT || shapeType == GRID || shapeType == RECTANGLE || shapeType == LINE || shapeType == CIRCLE || shapeType == ELLIPSE || shapeType == POLYGON || shapeType == FREE_SHAPE || shapeType == POLYLINE || shapeType == FREE_LINE) {
                        String roiID = MetadataTools.createLSID("ROI", nextROI);
                        store.setROIID(roiID, nextROI);
                        store.setImageROIRef(roiID, 0, nextROI);
                    }
                }
                String shapeID = MetadataTools.createLSID("Shape", nextROI, shape);
                if (shapeType == POINT) {
                    store.setPointID(shapeID, nextROI, shape);
                    store.setPointTheZ(new NonNegativeInteger(zIndex), nextROI, shape);
                    store.setPointTheT(new NonNegativeInteger(tIndex), nextROI, shape);
                    if (font != null) {
                        store.setPointFontSize(font, nextROI, shape);
                    }
                    Length l = new Length((double) lineWidth, UNITS.PIXEL);
                    store.setPointStrokeWidth(l, nextROI, shape);
                    store.setPointX(new Double(xc[0]), nextROI, shape);
                    store.setPointY(new Double(yc[0]), nextROI, shape);
                } else if (shapeType == GRID || shapeType == RECTANGLE) {
                    if (shapeType == RECTANGLE)
                        divide = 1;
                    width /= divide;
                    height /= divide;
                    for (int row = 0; row < divide; row++) {
                        for (int col = 0; col < divide; col++) {
                            double realX = x + col * width;
                            double realY = y + row * height;
                            shapeID = MetadataTools.createLSID("Shape", nextROI, shape);
                            store.setRectangleID(shapeID, nextROI, shape);
                            store.setRectangleX(realX, nextROI, shape);
                            store.setRectangleY(realY, nextROI, shape);
                            store.setRectangleWidth((double) width, nextROI, shape);
                            store.setRectangleHeight((double) height, nextROI, shape);
                            store.setRectangleTheZ(new NonNegativeInteger(zIndex), nextROI, shape);
                            store.setRectangleTheT(new NonNegativeInteger(tIndex), nextROI, shape);
                            if (font != null) {
                                store.setRectangleFontSize(font, nextROI, shape);
                            }
                            Length l = new Length((double) lineWidth, UNITS.PIXEL);
                            store.setRectangleStrokeWidth(l, nextROI, shape);
                            double centerX = realX + (width / 2);
                            double centerY = realY + (height / 2);
                            store.setRectangleTransform(getRotationTransform(angle), nextROI, shape);
                            if (row < divide - 1 || col < divide - 1)
                                shape++;
                        }
                    }
                } else if (shapeType == LINE) {
                    store.setLineID(shapeID, nextROI, shape);
                    store.setLineX1((double) x, nextROI, shape);
                    store.setLineY1((double) y, nextROI, shape);
                    store.setLineX2((double) (x + width), nextROI, shape);
                    store.setLineY2((double) (y + height), nextROI, shape);
                    store.setLineTheZ(new NonNegativeInteger(zIndex), nextROI, shape);
                    store.setLineTheT(new NonNegativeInteger(tIndex), nextROI, shape);
                    if (font != null) {
                        store.setLineFontSize(font, nextROI, shape);
                    }
                    Length l = new Length((double) lineWidth, UNITS.PIXEL);
                    store.setLineStrokeWidth(l, nextROI, shape);
                    int centerX = x + (width / 2);
                    int centerY = y + (height / 2);
                    store.setLineTransform(getRotationTransform(angle), nextROI, shape);
                } else if (shapeType == CIRCLE || shapeType == ELLIPSE) {
                    double rx = width / 2;
                    double ry = shapeType == CIRCLE ? rx : height / 2;
                    store.setEllipseID(shapeID, nextROI, shape);
                    store.setEllipseX(x + rx, nextROI, shape);
                    store.setEllipseY(y + ry, nextROI, shape);
                    store.setEllipseRadiusX(rx, nextROI, shape);
                    store.setEllipseRadiusY(ry, nextROI, shape);
                    store.setEllipseTheZ(new NonNegativeInteger(zIndex), nextROI, shape);
                    store.setEllipseTheT(new NonNegativeInteger(tIndex), nextROI, shape);
                    if (font != null) {
                        store.setEllipseFontSize(font, nextROI, shape);
                    }
                    Length l = new Length((double) lineWidth, UNITS.PIXEL);
                    store.setEllipseStrokeWidth(l, nextROI, shape);
                    store.setEllipseTransform(getRotationTransform(angle), nextROI, shape);
                } else if (shapeType == POLYGON || shapeType == FREE_SHAPE || shapeType == POLYLINE || shapeType == FREE_LINE) {
                    final StringBuilder points = new StringBuilder();
                    for (int point = 0; point < xc.length; point++) {
                        points.append(xc[point]);
                        points.append(",");
                        points.append(yc[point]);
                        if (point < xc.length - 1)
                            points.append(" ");
                    }
                    if (shapeType == POLYLINE || shapeType == FREE_LINE) {
                        store.setPolylineID(shapeID, nextROI, shape);
                        store.setPolylinePoints(points.toString(), nextROI, shape);
                        store.setPolylineTransform(getRotationTransform(angle), nextROI, shape);
                        store.setPolylineTheZ(new NonNegativeInteger(zIndex), nextROI, shape);
                        store.setPolylineTheT(new NonNegativeInteger(tIndex), nextROI, shape);
                        if (font != null) {
                            store.setPolylineFontSize(font, nextROI, shape);
                        }
                        Length l = new Length((double) lineWidth, UNITS.PIXEL);
                        store.setPolylineStrokeWidth(l, nextROI, shape);
                    } else {
                        store.setPolygonID(shapeID, nextROI, shape);
                        store.setPolygonPoints(points.toString(), nextROI, shape);
                        store.setPolygonTransform(getRotationTransform(angle), nextROI, shape);
                        store.setPolygonTheZ(new NonNegativeInteger(zIndex), nextROI, shape);
                        store.setPolygonTheT(new NonNegativeInteger(tIndex), nextROI, shape);
                        if (font != null) {
                            store.setPolygonFontSize(font, nextROI, shape);
                        }
                        Length l = new Length((double) lineWidth, UNITS.PIXEL);
                        store.setPolygonStrokeWidth(l, nextROI, shape);
                    }
                } else {
                    if (shape == 0)
                        nextROI--;
                    shape--;
                }
            }
        }
    }
    return nextROI;
}
Also used : IniList(loci.common.IniList) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) IOException(java.io.IOException) FormatException(loci.formats.FormatException) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) Length(ome.units.quantity.Length) IniTable(loci.common.IniTable)

Example 13 with IniTable

use of loci.common.IniTable in project bioformats by openmicroscopy.

the class BDReader method parseChannelData.

private void parseChannelData(Location dir) throws IOException {
    emWave = new double[channelNames.size()];
    exWave = new double[channelNames.size()];
    exposure = new double[channelNames.size()];
    gain = new double[channelNames.size()];
    offset = new double[channelNames.size()];
    for (int c = 0; c < channelNames.size(); c++) {
        Location dyeFile = new Location(dir, channelNames.get(c) + ".dye");
        RandomAccessInputStream stream = new RandomAccessInputStream(dyeFile.getAbsolutePath());
        IniList dye = new IniParser().parseINI(new BufferedReader(new InputStreamReader(stream, Constants.ENCODING)));
        IniTable numerator = dye.getTable("Numerator");
        String em = numerator.get("Emission");
        em = em.substring(0, em.indexOf(' '));
        emWave[c] = Double.parseDouble(em);
        String ex = numerator.get("Excitation");
        ex = ex.substring(0, ex.lastIndexOf(" "));
        if (ex.indexOf(' ') != -1) {
            ex = ex.substring(ex.lastIndexOf(" ") + 1);
        }
        exWave[c] = Double.parseDouble(ex);
        exposure[c] = Double.parseDouble(numerator.get("Exposure"));
        gain[c] = Double.parseDouble(numerator.get("Gain"));
        offset[c] = Double.parseDouble(numerator.get("Offset"));
        stream.close();
    }
}
Also used : IniParser(loci.common.IniParser) InputStreamReader(java.io.InputStreamReader) IniList(loci.common.IniList) IniTable(loci.common.IniTable) BufferedReader(java.io.BufferedReader) RandomAccessInputStream(loci.common.RandomAccessInputStream) Location(loci.common.Location)

Example 14 with IniTable

use of loci.common.IniTable in project bioformats by openmicroscopy.

the class MetadataRatings method updateRatings.

// -- API methods --
public void updateRatings() throws IOException {
    for (IniTable table : formats) {
        String readerName = table.get("reader");
        String opennessRating = table.get("opennessRating");
        String pixelsRating = table.get("pixelsRating");
        String pyramid = table.get("pyramid");
        int opennessIndex = DataTools.indexOf(RATINGS, opennessRating.toLowerCase());
        int pixelsIndex = DataTools.indexOf(RATINGS, pixelsRating.toLowerCase());
        int metadataIndex = (int) Math.min(opennessIndex, pixelsIndex);
        for (IniTable metadataTable : metadata) {
            if (metadataTable.get(IniTable.HEADER_KEY).equals(readerName)) {
                String instrument = metadataTable.get("Instrument.ID");
                String instrumentRef = metadataTable.get("Image.InstrumentRef");
                String emission = metadataTable.get("Channel.EmissionWavelength");
                String excitation = metadataTable.get("Channel.ExcitationWavelength");
                if ((instrument != null && instrument.equalsIgnoreCase("yes") && instrumentRef != null && instrumentRef.equalsIgnoreCase("yes")) || (emission != null && emission.equalsIgnoreCase("yes")) || (excitation != null && excitation.equalsIgnoreCase("yes"))) {
                    metadataIndex++;
                }
                if (pyramid == null || !pyramid.equalsIgnoreCase("yes")) {
                    // look for SPW metadata
                    for (String key : metadataTable.keySet()) {
                        if (key.startsWith("Plate.") || key.startsWith("Screen.") || key.startsWith("Well.")) {
                            String value = metadataTable.get(key);
                            if (value != null && value.equalsIgnoreCase("yes")) {
                                metadataIndex++;
                            }
                        }
                    }
                } else {
                    metadataIndex++;
                }
            }
        }
        if (pixelsIndex >= opennessIndex && metadataIndex > pixelsIndex) {
            metadataIndex = pixelsIndex;
        }
        if (metadataIndex >= RATINGS.length) {
            metadataIndex = RATINGS.length - 1;
        }
        String rating = RATINGS[metadataIndex];
        String firstLetter = rating.substring(0, 1).toUpperCase();
        rating = firstLetter + rating.substring(1);
        table.put("metadataRating", rating);
    }
    // replace metadata ratings as needed, without altering the key/value pair order
    BufferedReader reader = IniParser.openTextResource(FORMATS, MetadataRatings.class);
    ArrayList<String> lines = new ArrayList<String>();
    int ratingIndex = -1;
    while (true) {
        String line = reader.readLine();
        if (line == null) {
            break;
        }
        lines.add(line);
        line = line.trim();
        if (line.startsWith("reader =")) {
            String name = line.substring(line.indexOf("=") + 1).trim();
            String rating = null;
            for (IniTable table : formats) {
                if (name.equals(table.get("reader"))) {
                    rating = table.get("metadataRating");
                    break;
                }
            }
            if (ratingIndex >= 0) {
                lines.set(ratingIndex, "metadataRating = " + rating);
            }
        } else if (line.startsWith("metadataRating =")) {
            ratingIndex = lines.size() - 1;
        }
    }
    reader.close();
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), Constants.ENCODING));
    for (String line : lines) {
        out.write(line);
        out.write("\n");
    }
    out.close();
}
Also used : IniTable(loci.common.IniTable) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Example 15 with IniTable

use of loci.common.IniTable in project bioformats by openmicroscopy.

the class FormatPageAutogen method writeFormatPages.

// -- API Methods --
public void writeFormatPages() throws Exception {
    File doc = new File("../../docs/sphinx/formats/");
    if (!doc.exists()) {
        boolean success = doc.mkdir();
        if (!success) {
            throw new IOException("Could not create " + doc.getAbsolutePath());
        }
    }
    VelocityEngine engine = VelocityTools.createEngine();
    for (IniTable table : data) {
        VelocityContext context = VelocityTools.createContext();
        String format = table.get(IniTable.HEADER_KEY);
        context.put("format", format);
        if (table.containsKey("extensions")) {
            context.put("extensions", table.get("extensions"));
        }
        if (table.containsKey("indexExtensions")) {
            context.put("indexExtensions", table.get("indexExtensions"));
        } else if (table.containsKey("extensions")) {
            context.put("indexExtensions", table.get("extensions"));
        }
        context.put("owner", table.get("owner"));
        context.put("developer", table.get("developer"));
        context.put("bsd", table.get("bsd"));
        context.put("export", table.get("export"));
        context.put("pyramid", table.get("pyramid"));
        if (table.containsKey("versions")) {
            context.put("versions", table.get("versions"));
        } else {
            context.put("versions", "");
        }
        context.put("pixelsRating", table.get("pixelsRating"));
        context.put("metadataRating", table.get("metadataRating"));
        context.put("opennessRating", table.get("opennessRating"));
        context.put("presenceRating", table.get("presenceRating"));
        context.put("utilityRating", table.get("utilityRating"));
        context.put("reader", table.get("reader"));
        context.put("writer", table.get("writer"));
        context.put("mif", table.get("mif"));
        context.put("notes", table.get("notes"));
        context.put("privateSpecification", table.get("privateSpecification"));
        context.put("options", table.get("options"));
        context.put("readerextlink", table.get("bsd").equals("no") ? "bfreader" : "bsd-reader");
        context.put("writerextlink", table.get("bsd").equals("no") ? "bfwriter" : "bsd-writer");
        if (table.containsKey("software")) {
            String[] software = table.get("software").split("\n");
            context.put("software", software);
        }
        if (table.containsKey("weHave")) {
            String[] weHave = table.get("weHave").split("\n");
            context.put("weHave", weHave);
        }
        if (table.containsKey("weWant")) {
            String[] weWant = table.get("weWant").split("\n");
            context.put("weWant", weWant);
        }
        if (table.containsKey("samples")) {
            String[] samples = table.get("samples").split("\n");
            context.put("samples", samples);
        }
        if (table.containsKey("notes")) {
            String[] notes = table.get("notes").split("\n");
            context.put("notes", notes);
        }
        if (table.containsKey("reader")) {
            String[] reader = table.get("reader").split(", ");
            context.put("reader", reader);
        }
        String filename = getPageName(format, table.get("pagename"));
        if (table.containsKey("metadataPage")) {
            String page = table.get("metadataPage");
            if (page.length() > 0) {
                context.put("metadataPage", page.split(", "));
            }
        } else {
            String[] page = { filename.substring(filename.indexOf(File.separator) + 1) + "-metadata" };
            context.put("metadataPage", page);
        }
        VelocityTools.processTemplate(engine, context, TEMPLATE, "../../docs/sphinx/" + filename + ".rst");
    }
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) VelocityContext(org.apache.velocity.VelocityContext) IniTable(loci.common.IniTable) IOException(java.io.IOException) File(java.io.File)

Aggregations

IniTable (loci.common.IniTable)20 IniList (loci.common.IniList)16 BufferedReader (java.io.BufferedReader)12 IniParser (loci.common.IniParser)11 Location (loci.common.Location)9 CoreMetadata (loci.formats.CoreMetadata)9 FormatException (loci.formats.FormatException)7 IOException (java.io.IOException)6 StringReader (java.io.StringReader)6 RandomAccessInputStream (loci.common.RandomAccessInputStream)6 Length (ome.units.quantity.Length)6 File (java.io.File)5 InputStreamReader (java.io.InputStreamReader)5 MetadataStore (loci.formats.meta.MetadataStore)5 ArrayList (java.util.ArrayList)4 Time (ome.units.quantity.Time)3 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)3 Timestamp (ome.xml.model.primitives.Timestamp)3 FileInputStream (java.io.FileInputStream)2 DependencyException (loci.common.services.DependencyException)2