Changeset 6243


Ignore:
Timestamp:
05/06/10 12:33:47 (10 years ago)
Author:
melissa
Message:
  • Fixed timestamp parsing bugs in Andor/Fluoview TIFF reader. Closes #489.
  • Some progress on OME-XML transformation.
Location:
trunk/components
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/build.properties

    r6182 r6243  
    2525component.resources-bin  = loci/formats/bio-formats-logo.png \ 
    2626                           loci/formats/meta/reorder-2008-09.xsl \ 
     27                           loci/formats/meta/2003-FC-to-2008-09.xsl \ 
     28                           loci/formats/meta/2006-LO-to-2008-09.xsl \ 
     29                           loci/formats/meta/2007-06-to-2008-09.xsl \ 
     30                           loci/formats/meta/2008-02-to-2008-09.xsl \ 
     31                           loci/formats/meta/2008-09-to-2009-09.xsl \ 
     32                           loci/formats/meta/2009-09-to-2010-04.xsl \ 
    2733                           loci/formats/utests/2008-09.ome 
    2834component.resources-text = loci/formats/*.txt 
  • trunk/components/bio-formats/src/loci/formats/in/FluoviewReader.java

    r6230 r6243  
    7575  private String date = null; 
    7676  private int timeIndex = -1; 
    77   private long[][] stamps = null; 
     77 
     78  /** Timestamps for each plane, in seconds. */ 
     79  private double[][] stamps = null; 
    7880 
    7981  // hardware settings 
     
    338340    // populate timing data 
    339341    if (timeIndex >= 0) { 
    340       for (int i=0; i<getImageCount(); i++) { 
    341         store.setPlaneDeltaT(new Double(stamps[timeIndex][i] / 1000.0), 0, i); 
    342       } 
     342      for (int s=0; s<getSeriesCount(); s++) { 
     343        setSeries(s); 
     344        for (int i=0; i<getImageCount(); i++) { 
     345          int index = getImageIndex(i); 
     346          store.setPlaneDeltaT(stamps[timeIndex][index], s, i); 
     347        } 
     348      } 
     349      setSeries(0); 
    343350    } 
    344351 
     
    450457 
    451458  private void readStamps() throws FormatException, IOException { 
    452     stamps = new long[8][ifds.size()]; 
     459    stamps = new double[8][ifds.size()]; 
    453460    for (int i=0; i<ifds.size(); i++) { 
    454461      byte[] stamp = shortArrayToBytes(ifds.get(i).getIFDShortArray(MMSTAMP)); 
    455462      RandomAccessInputStream ras = new RandomAccessInputStream(stamp); 
    456  
    457       // each stamp is 8 longs, representing the position on dimensions 3-10 
     463      ras.order(isLittleEndian()); 
     464 
     465      // each stamp is 8 doubles, representing the position on dimensions 3-10 
    458466      for (int j=0; j<8; j++) { 
    459         stamps[j][i] = ras.readLong() / 10000; 
     467        stamps[j][i] = ras.readDouble() / 1000; 
     468 
     469        // correct for clock skew? 
     470        int pow = -1; 
     471        while (Math.pow(2, pow) < stamps[j][i]) { 
     472          stamps[j][i] -= (0.032 * (Math.pow(2, pow < 0 ? 0 : pow))); 
     473          pow++; 
     474        } 
    460475      } 
    461476      ras.close(); 
     
    556571            String key = String.format( 
    557572              "Timestamp for Z=%2s, C=%2s, T=%2s", zct[0], zct[1], zct[2]); 
    558             long stamp = ms + stamps[timeIndex][i]; 
     573            long stamp = ms + (long) (stamps[timeIndex][i] * 1000); 
    559574            addGlobalMeta(key, 
    560575              DateTools.convertDate(stamp, DateTools.UNIX, DATE_FORMAT)); 
  • trunk/components/bio-formats/src/loci/formats/services/OMEXMLServiceImpl.java

    r6234 r6243  
    4040import loci.formats.meta.MetadataStore; 
    4141import loci.formats.ome.OMEXMLMetadata; 
     42import loci.formats.ome.OMEXMLMetadataImpl; 
    4243import ome.xml.OMEXMLFactory; 
    43 import ome.xml.OMEXMLNode; 
     44import ome.xml.r201004.OME; 
     45import ome.xml.r201004.OMEModel; 
     46import ome.xml.r201004.OMEModelImpl; 
     47import ome.xml.r201004.OMEModelObject; 
    4448import ome.xml.r201004.StructuredAnnotations; 
    4549 
     
    4751import org.slf4j.LoggerFactory; 
    4852import org.w3c.dom.Document; 
     53import org.w3c.dom.Element; 
    4954import org.w3c.dom.Node; 
    5055import org.w3c.dom.NodeList; 
     
    5964 * <a href="https://skyking.microscopy.wisc.edu/svn/java/trunk/components/bio-formats/src/loci/formats/services/OMEXMLServiceImpl.java">SVN</a></dd></dl> 
    6065 */ 
    61 public class OMEXMLServiceImpl extends AbstractService 
    62   implements OMEXMLService { 
     66public class OMEXMLServiceImpl extends AbstractService implements OMEXMLService 
     67{ 
    6368 
    6469  /** Logger for this class. */ 
     
    6974  private static Templates reorderXSLT = 
    7075    XMLTools.getStylesheet("/loci/formats/meta/reorder-2008-09.xsl", 
    71                            OMEXMLServiceImpl.class); 
     76    OMEXMLServiceImpl.class); 
    7277 
    7378  /** Stylesheets for updating from previous schema releases. */ 
     
    95100   */ 
    96101  public OMEXMLServiceImpl() { 
    97     checkClassDependency(ome.xml.OMEXMLFactory.class); 
    98     checkClassDependency(ome.xml.OMEXMLNode.class); 
     102    checkClassDependency(ome.xml.r201004.OMEModelObject.class); 
    99103  } 
    100104 
     
    108112  /* @see OMEXMLService#transformToLatestVersion(String) */ 
    109113  public String transformToLatestVersion(String xml) throws ServiceException { 
    110     String version = getOMEXMLVersion(createOMEXMLRoot(xml)); 
     114    String version = getOMEXMLVersion(xml); 
    111115    if (version.equals(getLatestVersion())) return xml; 
    112116 
     
    130134        transformed = XMLTools.transformXML(transformed, UPDATE_200809); 
    131135      } 
    132       return XMLTools.transformXML(transformed, UPDATE_200909); 
     136      transformed = XMLTools.transformXML(transformed, UPDATE_200909); 
     137      return transformed; 
    133138    } 
    134139    catch (IOException e) { 
     
    158163  public OMEXMLMetadata createOMEXMLMetadata(String xml, String version) 
    159164    throws ServiceException { 
    160     OMEXMLNode ome = xml == null ? null : createRoot(xml); 
    161     if (version == null) { 
    162       if (ome == null) { 
    163         // default to newest schema version 
    164         version = getLatestVersion(); 
    165       } 
    166       else { 
    167         // extract schema version from OME root node 
    168         version = ome.getVersion(); 
    169       } 
    170     } 
    171  
    172     // create metadata object of the appropriate schema version 
    173     String metaClass = "loci.formats.ome.OMEXMLMetadataImpl"; 
    174     try { 
    175       Class<? extends OMEXMLMetadata> klass = 
    176         (Class<? extends OMEXMLMetadata>) Class.forName(metaClass); 
    177       OMEXMLMetadata meta = klass.newInstance(); 
    178       // attach OME root node to metadata object 
    179       if (ome != null) meta.setRoot(ome); 
    180       else meta.createRoot(); 
    181       return meta; 
    182     } catch (Exception e) { 
    183       LOGGER.warn("No IMetadata implementation for: {}", version, e); 
    184       return null; 
    185     } 
     165    OMEModelObject ome = 
     166      xml == null ? null : createRoot(transformToLatestVersion(xml)); 
     167 
     168    OMEXMLMetadata meta = new OMEXMLMetadataImpl(); 
     169    if (ome != null) meta.setRoot(ome); 
     170    return meta; 
    186171  } 
    187172 
     
    190175   */ 
    191176  public Object createOMEXMLRoot(String xml) throws ServiceException { 
    192     return createRoot(xml); 
     177    return createRoot(transformToLatestVersion(xml)); 
    193178  } 
    194179 
     
    204189   */ 
    205190  public boolean isOMEXMLRoot(Object o) { 
    206     return o instanceof OMEXMLNode; 
     191    return o instanceof OMEModelObject; 
    207192  } 
    208193 
     
    212197   * classes should not leak out of the interface. 
    213198   * @param xml String of XML to create the root node from. 
    214    * @return An ome.xml.OMEXMLNode subclass root node. 
     199   * @return An ome.xml.r201004.OMEModelObject subclass root node. 
    215200   * @throws IOException If there is an error reading from the string. 
    216201   * @throws SAXException If there is an error parsing the XML. 
     
    218203   * parsing infrastructure. 
    219204   */ 
    220   private OMEXMLNode createRoot(String xml) throws ServiceException { 
     205  private OMEModelObject createRoot(String xml) throws ServiceException { 
    221206    try { 
    222       return OMEXMLFactory.newOMENodeFromSource(transformToLatestVersion(xml)); 
     207      OMEModel model = new OMEModelImpl(); 
     208      OME ome = new OME(XMLTools.parseDOM(xml).getDocumentElement(), model); 
     209      model.resolveReferences(); 
     210      return ome; 
    223211    } 
    224212    catch (Exception e) { 
     
    245233      } 
    246234    } 
    247     else if (o instanceof OMEXMLNode) { 
    248       return ((OMEXMLNode) o).getVersion(); 
     235    else if (o instanceof OMEModelObject) { 
     236      return getLatestVersion(); 
     237    } 
     238    else if (o instanceof String) { 
     239      String xml = (String) o; 
     240      try { 
     241        Element e = XMLTools.parseDOM(xml).getDocumentElement(); 
     242        String namespace = e.getAttribute("xmlns"); 
     243 
     244        return namespace.endsWith("ome.xsd") ? "2003-FC" : 
     245          namespace.substring(namespace.lastIndexOf("/") + 1); 
     246      } 
     247      catch (ParserConfigurationException pce) { } 
     248      catch (SAXException se) { } 
     249      catch (IOException ioe) { } 
    249250    } 
    250251    return null; 
     
    375376  public void convertMetadata(String xml, MetadataStore dest) 
    376377    throws ServiceException { 
    377     OMEXMLNode ome = createRoot(xml); 
     378    OMEModelObject ome = createRoot(transformToLatestVersion(xml)); 
    378379    String rootVersion = getOMEXMLVersion(ome); 
    379380    String storeVersion = getOMEXMLVersion(dest); 
  • trunk/components/common/src/loci/common/xml/XMLTools.java

    r6155 r6243  
    120120  { 
    121121    // Java XML factories are not declared to be thread safe 
    122     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();  
     122    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
    123123    DocumentBuilder db = factory.newDocumentBuilder(); 
    124124    return db.parse(is); 
  • trunk/components/ome-xml/src/ome/xml/OMEXMLFactory.java

    r4940 r6243  
    5353 
    5454  /** Latest OME-XML version namespace. */ 
    55   public static final String LATEST_VERSION = "2008-09"; 
     55  public static final String LATEST_VERSION = "201004"; 
    5656 
    5757  /** Basic skeleton for an OME-XML root node with modern schema. */ 
Note: See TracChangeset for help on using the changeset viewer.