Class PrairieReader

All Implemented Interfaces:
Closeable, AutoCloseable, ICompressedTileReader, IFormatHandler, IFormatReader, IMetadataConfigurable, IPyramidHandler

public class PrairieReader extends FormatReader
PrairieReader is the file format reader for Prairie Technologies' TIFF variant.
Author:
Curtis Rueden, Melissa Linkert, Michael Fox
  • Field Details

    • CFG_SUFFIX

      public static final String[] CFG_SUFFIX
    • ENV_SUFFIX

      public static final String[] ENV_SUFFIX
    • XML_SUFFIX

      public static final String[] XML_SUFFIX
    • PRAIRIE_SUFFIXES

      public static final String[] PRAIRIE_SUFFIXES
    • PRAIRIE_TAG_1

      private static final int PRAIRIE_TAG_1
      See Also:
    • PRAIRIE_TAG_2

      private static final int PRAIRIE_TAG_2
      See Also:
    • PRAIRIE_TAG_3

      private static final int PRAIRIE_TAG_3
      See Also:
    • DATE_FORMAT

      private static final String DATE_FORMAT
      See Also:
    • tiff

      private TiffReader tiff
      Helper reader for opening images.
    • xmlFile

      private String xmlFile
      The associated XML files.
    • cfgFile

      private String cfgFile
      The associated XML files.
    • envFile

      private String envFile
      The associated XML files.
    • meta

      private PrairieMetadata meta
      Format-specific metadata.
    • sequences

      private ArrayList<PrairieMetadata.Sequence> sequences
      List of Prairie metadata Sequences, ordered by cycle.
    • channels

      private int[] channels
      List of active channels.
    • framesAreTime

      private boolean[] framesAreTime
      Whether a series uses Frames as time points rather than focal planes (i.e., sizeZ and sizeT values inverted).

      This situation occurs when the series's first Sequence is labeled as a "TSeries" (i.e., PrairieMetadata.Sequence.isTimeSeries() returns true), but there is only one Sequence.

      The array length equals the number of series; i.e., it is a parallel array to FormatReader.core.

    • singleTiffMode

      private boolean singleTiffMode
      Flag indicating that the reader is operating in a mode where grouping of files is disallowed. In the case of Prairie, this happens if a TIFF file is passed to FormatReader.setId(java.lang.String) while FormatReader.isGroupFiles() is false.
  • Constructor Details

    • PrairieReader

      public PrairieReader()
      Constructs a new Prairie TIFF reader.
  • Method Details

    • isSingleFile

      public boolean isSingleFile(String id) throws FormatException, IOException
      Description copied from interface: IFormatReader
      Returns true if the named file is expected to be the only file in the dataset. For single-file formats, always returns true.
      Specified by:
      isSingleFile in interface IFormatReader
      Overrides:
      isSingleFile in class FormatReader
      Throws:
      FormatException
      IOException
    • isThisType

      public boolean isThisType(String name, boolean open)
      Description copied from class: FormatReader
      Checks if a file matches the type of this format reader. Checks filename suffixes against those known for this format. If the suffix check is inconclusive and the open parameter is true, the file is opened and tested with FormatReader.isThisType(RandomAccessInputStream).
      Specified by:
      isThisType in interface IFormatReader
      Overrides:
      isThisType in class FormatReader
      Parameters:
      open - If true, and the file extension is insufficient to determine the file type, the (existing) file is opened for further analysis.
    • isThisType

      public boolean isThisType(loci.common.RandomAccessInputStream stream) throws IOException
      Description copied from interface: IFormatReader
      Checks if the given stream is a valid stream for this file format. The number of bytes read is format-dependent.
      Specified by:
      isThisType in interface IFormatReader
      Overrides:
      isThisType in class FormatReader
      Parameters:
      stream - A RandomAccessInputStream representing the file to check. The first byte in the stream is assumed to be the first byte in the file.
      Returns:
      true if the file represented by the stream can be read by this reader; false otherwise.
      Throws:
      IOException
    • fileGroupOption

      public int fileGroupOption(String id) throws FormatException, IOException
      Description copied from interface: IFormatReader
      Returns an indication of whether the files in a multi-file dataset can be handled individually. This method is only useful for formats and datasets which contain multiple files.
      Specified by:
      fileGroupOption in interface IFormatReader
      Overrides:
      fileGroupOption in class FormatReader
      Parameters:
      id - a file in the multi-file dataset
      Returns:
      an int indicating that we cannot, must, or might group the files. A return value of FormatTools.MUST_GROUP indicates that the files cannot be handled separately; the reader will always detect and read all files in the dataset. FormatTools.CAN_GROUP indicates that the files may be handled separately, but file grouping must then be disabled via IFormatReader.setGroupFiles(boolean). FormatTools.CANNOT_GROUP indicates that the files must be handled separately; the reader will not attempt to read all files in the dataset (this is rare).
      Throws:
      FormatException
      IOException
      See Also:
    • getSeriesUsedFiles

      public String[] getSeriesUsedFiles(boolean noPixels)
      Description copied from interface: IFormatReader
      Returns an array of filenames needed to open the current series. If the 'noPixels' flag is set, then only files that do not contain pixel data will be returned. The first element in the array is expected to be the path passed to IFormatHandler.setId(String), if appropriate based upon 'noPixels'. The remaining elements are expected to be in a consistent order; if a directory listing is necessary to build the list then it should be sorted first.
      Specified by:
      getSeriesUsedFiles in interface IFormatReader
      Overrides:
      getSeriesUsedFiles in class FormatReader
    • getOptimalTileWidth

      public int getOptimalTileWidth()
      Description copied from interface: IFormatReader
      Returns the optimal sub-image width for use with openBytes.
      Specified by:
      getOptimalTileWidth in interface IFormatReader
      Overrides:
      getOptimalTileWidth in class FormatReader
    • getOptimalTileHeight

      public int getOptimalTileHeight()
      Description copied from interface: IFormatReader
      Returns the optimal sub-image height for use with openBytes.
      Specified by:
      getOptimalTileHeight in interface IFormatReader
      Overrides:
      getOptimalTileHeight in class FormatReader
    • openBytes

      public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException
      Description copied from interface: IFormatReader
      Obtains a sub-image of the specified image plane into a pre-allocated byte array.
      Specified by:
      openBytes in interface IFormatReader
      Specified by:
      openBytes in class FormatReader
      Parameters:
      no - the plane index within the current series.
      buf - a pre-allocated buffer.
      x - X coordinate of the upper-left corner of the sub-image
      y - Y coordinate of the upper-left corner of the sub-image
      w - width of the sub-image
      h - height of the sub-image
      Returns:
      the pre-allocated buffer buf for convenience.
      Throws:
      FormatException - if there was a problem parsing the metadata of the file.
      IOException - if there was a problem reading the file.
    • close

      public void close(boolean fileOnly) throws IOException
      Description copied from interface: IFormatReader
      Closes the currently open file. If the flag is set, this is all that happens; if unset, it is equivalent to calling Closeable.close().
      Specified by:
      close in interface IFormatReader
      Overrides:
      close in class FormatReader
      Throws:
      IOException
    • initFile

      protected void initFile(String id) throws FormatException, IOException
      Description copied from class: FormatReader
      Initializes the given file (parsing header information, etc.). Most subclasses should override this method to perform initialization operations such as parsing metadata.
      Overrides:
      initFile in class FormatReader
      Throws:
      FormatException - if a parsing error occurs processing the file.
      IOException - if an I/O error occurs processing the file
    • findMetadataFiles

      private void findMetadataFiles()
    • parsePrairieMetadata

      private void parsePrairieMetadata() throws FormatException, IOException
      This step parses the Prairie metadata files into the Prairie-specific metadata structure, meta.
      Throws:
      FormatException
      IOException
    • populateCoreMetadata

      private void populateCoreMetadata() throws FormatException, IOException
      This step populates the CoreMetadata by extracting relevant values from the parsed meta structure.
      Throws:
      FormatException
      IOException
    • populateOriginalMetadata

      private void populateOriginalMetadata()
      This steps populates the original metadata table (the tables returned by FormatReader.getGlobalMetadata() and FormatReader.getSeriesMetadata()).
    • populateOMEMetadata

      private void populateOMEMetadata() throws FormatException
      This step populates the OME MetadataStore by extracting relevant values from the parsed meta structure.
      Throws:
      FormatException
    • isMinimumMetadata

      private boolean isMinimumMetadata()
      Gets whether to populate only the minimum required metadata.
    • parseDOM

      private Document parseDOM(loci.common.Location file) throws ParserConfigurationException, SAXException, IOException
      Parses a Document from the data in the given file.
      Throws:
      ParserConfigurationException
      SAXException
      IOException
    • warnFrame

      private void warnFrame(PrairieMetadata.Sequence sequence, int index)
      Emits a warning about a missing <Frame>.
    • warnFile

      private void warnFile(PrairieMetadata.Sequence sequence, int index, int channel)
      Emits a warning about a missing <File>.
    • warnFilename

      private void warnFilename(PrairieMetadata.Sequence sequence, int index, int channel)
      Emits a warning about a <File>'s missing filename.
    • getPath

      private String getPath(PrairieMetadata.PFile file)
      Gets the absolute path to the filename of the given PrairieMetadata.PFile.
    • blank

      private byte[] blank(byte[] buf)
      Blanks out and returns the given buffer.
    • pf

      private ome.xml.model.primitives.PositiveFloat pf(Double value, String name)
      Converts the given double to a PositiveFloat, or null if incompatible.
    • find

      private loci.common.Location find(String[] suffix)
      Finds the first file with one of the given suffixes.
    • computeSizeT

      private int computeSizeT(int sequenceCount)
      Scans the parsed metadata to determine the number of actual time points versus the number of actual stage positions. The Prairie file format makes no distinction between the two, referring to both as "Sequences", so we must compare XYZ stage positions to differentiate them.
    • positionsMatch

      private boolean positionsMatch(int sizeT, int sizeP)
      Verifies that stage coordinates match for all (P, Z) across time.
    • sequence

      private PrairieMetadata.Sequence sequence(int s)
      Gets the first sequence associated with the given series.
      Parameters:
      s - The series (i.e., stage position).
      Returns:
      The first associated Sequence.
    • sequence

      private PrairieMetadata.Sequence sequence(int t, int s)
      Gets the sequence associated with the given series and time point.
      Parameters:
      t - The time point.
      s - The series (i.e., stage position).
      Returns:
      The associated Sequence.
    • sequence

      private PrairieMetadata.Sequence sequence(int t, int p, int sizeP)
      Gets the sequence associated with the given time point and stage position.
      Parameters:
      t - The time point.
      p - The stage position.
      sizeP - The number of stage positions.
      Returns:
      The associated Sequence.
    • frameIndex

      private int frameIndex(PrairieMetadata.Sequence sequence, int z, int t, int s)
      Gets the frame index associated with the given (Z, T) position of the specified series.
      Parameters:
      sequence - The sequence from which to extract the frame.
      z - The focal plane.
      t - The time point.
      s - The series (i.e., stage position).
      Returns:
      The frame index which can be passed to PrairieMetadata.Sequence.getFrame(int).
    • equal

      private static boolean equal(ome.units.quantity.Length xPos, ome.units.quantity.Length xInitial)
      Determines whether the two Length values are equal.