Skip to content

Commit

Permalink
Merge pull request #1365 from ctrueden/devel/more-prairie-view-5
Browse files Browse the repository at this point in the history
PrairieView 5.2 fixes and improvements
  • Loading branch information
melissalinkert committed Dec 6, 2014
2 parents d8bec8d + 58db168 commit 5c95a23
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 12 deletions.
18 changes: 12 additions & 6 deletions components/formats-bsd/src/loci/formats/in/OMETiffReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.Vector;

import loci.common.DataTools;
import loci.common.DateTools;
import loci.common.Location;
import loci.common.RandomAccessInputStream;
import loci.common.services.DependencyException;
Expand Down Expand Up @@ -202,7 +201,7 @@ else if (description instanceof String) {
try {
String metadataFile = meta.getBinaryOnlyMetadataFile();
if (metadataFile != null) {
return !checkSuffix(metadataFile, "tif") && !checkSuffix(metadataFile, "tiff");
return true;
}
}
catch (NullPointerException e) {
Expand Down Expand Up @@ -437,9 +436,6 @@ protected void initFile(String id) throws FormatException, IOException {
String metadataPath = null;
try {
metadataPath = meta.getBinaryOnlyMetadataFile();
if (checkSuffix(metadataPath, "tif") || checkSuffix(metadataPath, "tiff")) {
metadataPath = null;
}
}
catch (NullPointerException e) {
}
Expand All @@ -450,7 +446,7 @@ protected void initFile(String id) throws FormatException, IOException {
Location path = new Location(dir, metadataPath);
if (path.exists()) {
metadataFile = path.getAbsolutePath();
xml = DataTools.readFile(metadataFile);
xml = readMetadataFile();

try {
meta = service.createOMEXMLMetadata(xml);
Expand Down Expand Up @@ -1004,6 +1000,16 @@ private void setupService() throws FormatException {
}
}

/** Extracts the OME-XML from the current {@link #metadataFile}. */
private String readMetadataFile() throws IOException {
if (checkSuffix(metadataFile, "tif") || checkSuffix(metadataFile, "tiff")) {
// metadata file is an OME-TIFF file; extract OME-XML comment
return new TiffParser(metadataFile).getComment();
}
// assume metadata file is an XML file
return DataTools.readFile(metadataFile);
}

// -- Helper classes --

/** Structure containing details on where to find a particular image plane. */
Expand Down
39 changes: 34 additions & 5 deletions components/formats-gpl/src/loci/formats/in/PrairieMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ private void parseKeys(final Element el, final ValueTable table) {
for (int i=0; i<tokens.length; i++) {
subSubTable.put("" + i, new ValueItem(tokens[i], null));
}
subTable.put(index, subSubTable);
}
}
}
Expand Down Expand Up @@ -380,24 +381,24 @@ private void parsePVStateShard(final Element el, final ValueTable table) {
if (index == null) continue; // invalid <SubindexedValues> element
final ValueTable subSubTable = new ValueTable();
subTable.put(index, subSubTable);
// iterate over <SubindexValue> children
// iterate over <SubindexedValue> children
final NodeList subNodes =
sivElement.getElementsByTagName("SubindexValue");
sivElement.getElementsByTagName("SubindexedValue");
for (int s = 0; s < subNodes.getLength(); s++) {
final Element subElement = el(subNodes, i);
final Element subElement = el(subNodes, s);
final String subindex = attr(subElement, "subindex");
if (subindex == null) continue; // invalid <SubindexedValue> element
final String sValue = attr(subElement, "value");
final String sDescription = attr(subElement, "description");
subSubTable.put(index, new ValueItem(sValue, sDescription));
subSubTable.put(subindex, new ValueItem(sValue, sDescription));
}
}
}
}

/**
* Parses details of the activated channels into the {@link #activeChannels}
* data structure.
* data structure from the "channel" entry of the configuration.
*/
private void parseChannels() {
final Value channels = config.get("channel");
Expand Down Expand Up @@ -567,6 +568,9 @@ public class Sequence {
/** {@code cycle} of this {@code <Sequence>}. */
private Integer cycle;

/** {@code SpectralMode} of this {@code <Sequence>}. */
private boolean spectralMode;

/**
* Creates a new sequence by parsing the given {@code <Sequence>} element.
*/
Expand All @@ -586,6 +590,7 @@ public void parse(final Element sequenceElement) {
if (cycle == null) {
throw new IllegalArgumentException("Sequence missing cycle attribute");
}
spectralMode = b(attr(sequenceElement, "SpectralMode"));

// iterate over all Frame elements
final NodeList frameNodes = sequenceElement.getElementsByTagName("Frame");
Expand Down Expand Up @@ -621,6 +626,10 @@ public int getCycle() {
return cycle;
}

public boolean isSpectralMode() {
return spectralMode;
}

/**
* Gets the minimum index value. Matches the smallest {@code index}
* attribute found, and hence will not necessarily equal {@code 1} (though
Expand Down Expand Up @@ -922,6 +931,12 @@ public class PFile {
/** {@code filename} attribute of this {@code <File>}. */
private String filename;

/** {@code wavelengthMin} attribute of this {@code <File>}. */
private Double waveMin;

/** {@code wavelengthMax} attribute of this {@code <File>}. */
private Double waveMax;

/** Creates a new file by parsing the given {@code <File>} element. */
public PFile(final Frame frame, final Element fileElement) {
this.frame = frame;
Expand All @@ -943,9 +958,13 @@ public void parse(final Element fileElement) {
if (channel == null) {
throw new IllegalArgumentException("File missing channel attribute");
}
activeChannels.add(channel);

channelName = attr(fileElement, "channelName");
filename = attr(fileElement, "filename");

waveMin = d(attr(fileElement, "wavelengthMin"));
waveMax = d(attr(fileElement, "wavelengthMax"));
}

/** Gets the {@code channel} associated with this {@code File}. */
Expand All @@ -963,6 +982,16 @@ public String getFilename() {
return filename;
}

/** Gets the {@code wavelengthMin} associated with this {@code File}. */
public Double getWavelengthMin() {
return waveMin;
}

/** Gets the {@code wavelengthMax} associated with this {@code File}. */
public Double getWavelengthMax() {
return waveMax;
}

}

/**
Expand Down
13 changes: 12 additions & 1 deletion components/formats-gpl/src/loci/formats/in/PrairieReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import loci.formats.tiff.IFD;
import loci.formats.tiff.TiffParser;
import ome.xml.model.primitives.PositiveFloat;
import ome.xml.model.primitives.PositiveInteger;
import ome.xml.model.primitives.Timestamp;

import ome.units.quantity.Length;
Expand Down Expand Up @@ -563,6 +562,18 @@ private void populateOMEMetadata() throws FormatException {
final String channelName = file == null ? null : file.getChannelName();
if (channelName != null) store.setChannelName(channelName, s, c);

// populate emission wavelength
if (file != null) {
final Double waveMin = file.getWavelengthMin();
final Double waveMax = file.getWavelengthMax();
if (waveMin != null && waveMax != null) {
final double waveAvg = (waveMin + waveMax) / 2;
final Length wavelength =
FormatTools.getEmissionWavelength(waveAvg);
store.setChannelEmissionWavelength(wavelength, s, c);
}
}

if (detectorIDs[c] == null) {
// create a Detector for this channel
detectorIDs[c] = MetadataTools.createLSID("Detector", 0, c);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* #%L
* OME Bio-Formats package for reading and converting biological file formats.
* %%
* Copyright (C) 2005 - 2013 Open Microscopy Environment:
* - Board of Regents of the University of Wisconsin-Madison
* - Glencoe Software, Inc.
* - University of Dundee
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/

package loci.formats.utests.in;

import static org.testng.AssertJUnit.assertEquals;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import loci.common.xml.XMLTools;
import loci.formats.in.PrairieMetadata;
import loci.formats.in.PrairieMetadata.Value;
import loci.formats.in.PrairieMetadata.ValueTable;

import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/**
* Unit tests for {@link PrairieMetadata}.
*
* @author Curtis Rueden
*/
public class PrairieMetadataTest {

private static final String OLD_XML =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<PVScan version=\"4.0.0.53\" date=\"3/23/2012 9:47:15 AM\" notes=\"\">" +
" <Sequence type=\"TSeries ZSeries Element\" cycle=\"1\" >" +
" <Frame relativeTime=\"0\" absoluteTime=\"2.06929400000001\" index=\"1\" label=\"CurrentSettings\">" +
" <File channel=\"1\" channelName=\"Ch1\" preAmpID=\"0\" filename=\"TSeries-03232012-0934-006_Cycle001_CurrentSettings_Ch1_000001.tif\" />" +
" <File channel=\"2\" channelName=\"Ch2\" preAmpID=\"1\" filename=\"TSeries-03232012-0934-006_Cycle001_CurrentSettings_Ch2_000001.tif\" />" +
" <ExtraParameters validData=\"True\" />" +
" <PVStateShard>" +
" <Key key=\"linesPerFrame\" permissions=\"Read, Write, Save\" value=\"186\" />" +
" <Key key=\"pmtGain_0\" permissions=\"Write, Save\" value=\"605\" />" +
" <Key key=\"pmtGain_1\" permissions=\"Write, Save\" value=\"604\" />" +
" <Key key=\"pmtGain_2\" permissions=\"Write, Save\" value=\"0\" />" +
" <Key key=\"positionCurrent_XAxis\" permissions=\"Write, Save\" value=\"0.95\" />" +
" <Key key=\"positionCurrent_YAxis\" permissions=\"Write, Save\" value=\"-4.45\" />" +
" <Key key=\"positionCurrent_ZAxis\" permissions=\"Write, Save\" value=\"-9,62.45\" />" +
" </PVStateShard>" +
" </Frame>" +
" </Sequence>" +
"</PVScan>";

private static final String NEW_XML =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<PVScan version=\"5.2.64.400\" date=\"9/23/2014 3:03:37 PM\" notes=\"\">" +
" <PVStateShard>" +
" <PVStateValue key=\"linesPerFrame\" value=\"186\" />" +
" <PVStateValue key=\"pmtGain\">" +
" <IndexedValue index=\"0\" value=\"605\" description=\"Ch1 High Voltage\" />" +
" <IndexedValue index=\"1\" value=\"604\" description=\"Ch2 High Voltage\" />" +
" <IndexedValue index=\"2\" value=\"0\" description=\"Ch3 High Voltage\" />" +
" </PVStateValue>" +
" <PVStateValue key=\"positionCurrent\">" +
" <SubindexedValues index=\"XAxis\">" +
" <SubindexedValue subindex=\"0\" value=\"0.95\" />" +
" </SubindexedValues>" +
" <SubindexedValues index=\"YAxis\">" +
" <SubindexedValue subindex=\"0\" value=\"-4.45\" />" +
" </SubindexedValues>" +
" <SubindexedValues index=\"ZAxis\">" +
" <SubindexedValue subindex=\"0\" value=\"-9\" description=\"Focus\" />" +
" <SubindexedValue subindex=\"1\" value=\"62.45\" description=\"Piezo\" />" +
" </SubindexedValues>" +
" </PVStateValue>" +
" </PVStateShard>" +
" <Sequence type=\"TSeries Timed Element\" cycle=\"1\" time=\"15:03:38.0036337\">" +
" <PVStateShard>" +
" <PVStateValue key=\"positionCurrent\">" +
" <SubindexedValues index=\"XAxis\">" +
" <SubindexedValue subindex=\"0\" value=\"-621.412879412341\" />" +
" </SubindexedValues>" +
" <SubindexedValues index=\"YAxis\">" +
" <SubindexedValue subindex=\"0\" value=\"255.652372573538\" />" +
" </SubindexedValues>" +
" <SubindexedValues index=\"ZAxis\">" +
" <SubindexedValue subindex=\"0\" value=\"28.15\" description=\"Z\" />" +
" <SubindexedValue subindex=\"1\" value=\"111.23\" description=\"ZPiezo\" />" +
" </SubindexedValues>" +
" </PVStateValue>" +
" </PVStateShard>" +
" <Frame relativeTime=\"0\" absoluteTime=\"1.2349999999999\" index=\"1\" parameterSet=\"CurrentSettings\">" +
" <File channel=\"1\" channelName=\"Ch1 Red\" filename=\"TSeries-09232014-1445-011_Cycle00001_Ch1_000001.ome.tif\" />" +
" <ExtraParameters lastGoodFrame=\"0\" />" +
" <PVStateShard />" +
" </Frame>" +
" </Sequence>" +
"</PVScan>";

@Test
public void testParseOldXML() throws ParserConfigurationException,
SAXException, IOException
{
final Document xml = XMLTools.parseDOM(OLD_XML);
final PrairieMetadata meta = new PrairieMetadata(xml, null, null);

final Value positionCurrent =
meta.getSequence(1).getFrame(1).getValue("positionCurrent");

final Value xAxis = positionCurrent.get("XAxis");
assertEquals("0.95", xAxis.value());

final Value yAxis = positionCurrent.get("YAxis");
assertEquals("-4.45", yAxis.value());

final ValueTable zAxis = (ValueTable) positionCurrent.get("ZAxis");
assertEquals("-9", zAxis.get(0).value());
assertEquals("62.45", zAxis.get(1).value());
}

@Test
public void testParseNewXML() throws ParserConfigurationException,
SAXException, IOException
{
final Document xml = XMLTools.parseDOM(NEW_XML);
final PrairieMetadata meta = new PrairieMetadata(xml, null, null);

final ValueTable positionCurrent = (ValueTable)
meta.getSequence(1).getFrame(1).getValue("positionCurrent");

final ValueTable xAxis = (ValueTable) positionCurrent.get("XAxis");
assertEquals("-621.412879412341", xAxis.value());

final ValueTable yAxis = (ValueTable) positionCurrent.get("YAxis");
assertEquals("255.652372573538", yAxis.value());

final ValueTable zAxis = (ValueTable) positionCurrent.get("ZAxis");
assertEquals("28.15", zAxis.get(0).value());
assertEquals("111.23", zAxis.get(1).value());
}
}

0 comments on commit 5c95a23

Please sign in to comment.