Class MetamorphReader

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

public class MetamorphReader extends BaseTiffReader
Reader is the file format reader for Metamorph STK files.
Author:
Eric Kjellman egkjellman at wisc.edu, Melissa Linkert melissa at glencoesoftware.com, Curtis Rueden ctrueden at wisc.edu, Sebastien Huart Sebastien dot Huart at curie.fr
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
      Logger for this class.
    • SHORT_DATE_FORMAT

      public static final String SHORT_DATE_FORMAT
      See Also:
    • LONG_DATE_FORMAT

      public static final String LONG_DATE_FORMAT
      See Also:
    • ND_SUFFIX

      public static final String[] ND_SUFFIX
    • STK_SUFFIX

      public static final String[] STK_SUFFIX
    • WELL_COORDS

      public static final Pattern WELL_COORDS
    • METAMORPH_ID

      private static final int METAMORPH_ID
      See Also:
    • UIC1TAG

      private static final int UIC1TAG
      See Also:
    • UIC2TAG

      private static final int UIC2TAG
      See Also:
    • UIC3TAG

      private static final int UIC3TAG
      See Also:
    • UIC4TAG

      private static final int UIC4TAG
      See Also:
    • NDINFOFILE_VER1

      private static final String NDINFOFILE_VER1
      See Also:
    • NDINFOFILE_VER2

      private static final String NDINFOFILE_VER2
      See Also:
    • ND_ENCODING

      private static final String ND_ENCODING
      See Also:
    • imageName

      private String imageName
      The TIFF's name
    • imageCreationDate

      private String imageCreationDate
      The TIFF's creation date
    • emWavelength

      private long[] emWavelength
      The TIFF's emWavelength
    • isHCS

      private boolean isHCS
    • stageLabels

      private String[] stageLabels
    • wave

      private double[] wave
    • binning

      private String binning
    • zoom

      private double zoom
    • stepSize

      private double stepSize
    • exposureTime

      private Double exposureTime
    • waveNames

      private List<String> waveNames
    • stageNames

      private List<String> stageNames
    • internalStamps

      private long[] internalStamps
    • zDistances

      private double[] zDistances
    • stageX

      private ome.units.quantity.Length[] stageX
    • stageY

      private ome.units.quantity.Length[] stageY
    • zStart

      private double zStart
    • sizeX

      private Double sizeX
    • sizeY

      private Double sizeY
    • tempZ

      private double tempZ
    • validZ

      private boolean validZ
    • gain

      private Double gain
    • mmPlanes

      private int mmPlanes
    • stkReaders

      private MetamorphReader[][] stkReaders
    • stks

      private String[][] stks
      List of STK files in the dataset.
    • ndFilename

      private String ndFilename
    • canLookForND

      private boolean canLookForND
    • firstSeriesChannels

      private boolean[] firstSeriesChannels
    • bizarreMultichannelAcquisition

      private boolean bizarreMultichannelAcquisition
    • openFiles

      private int openFiles
    • hasStagePositions

      private boolean hasStagePositions
    • hasChipOffsets

      private boolean hasChipOffsets
    • hasAbsoluteZ

      private boolean hasAbsoluteZ
    • hasAbsoluteZValid

      private boolean hasAbsoluteZValid
  • Constructor Details

    • MetamorphReader

      public MetamorphReader()
      Constructs a new Metamorph reader.
  • Method Details

    • getDomains

      public String[] getDomains()
      Description copied from interface: IFormatReader
      Returns the list of domains represented by the current file.
      Specified by:
      getDomains in interface IFormatReader
      Overrides:
      getDomains in class FormatReader
    • 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 MinimalTiffReader
      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
    • 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
    • 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
    • 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
      Overrides:
      openBytes in class MinimalTiffReader
      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.
      See Also:
    • 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 MinimalTiffReader
      Throws:
      IOException
    • initFile

      protected void initFile(String id) throws FormatException, IOException
      Description copied from class: SubResolutionFormatReader
      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 BaseTiffReader
      Throws:
      FormatException - if a parsing error occurs processing the file.
      IOException - if an I/O error occurs processing the file
    • initStandardMetadata

      protected void initStandardMetadata() throws FormatException, IOException
      Description copied from class: BaseTiffReader
      Parses standard metadata. NOTE: Absolutely no calls to the metadata store should be made in this method or methods that override this method. Data will be overwritten if you do so.
      Overrides:
      initStandardMetadata in class BaseTiffReader
      Throws:
      FormatException
      IOException
    • getRealSTKFile

      private String getRealSTKFile(loci.common.Location l)
      Check that the given STK file exists. If it does, then return the absolute path. If it does not, then apply various formatting rules until an existing file is found.
      Returns:
      the absolute path of an STK file, or null if no STK file is found.
    • getFirstComment

      private String getFirstComment(int i) throws IOException
      Returns the TIFF comment from the first IFD of the first STK file in the given series.
      Throws:
      IOException
    • getComment

      private String getComment(int i, int no) throws IOException
      Throws:
      IOException
    • makeImageName

      private String makeImageName(int i)
      Create an appropriate name for the given series.
    • parseUIC2Tags

      void parseUIC2Tags(long uic2offset) throws IOException
      Populates metadata fields with some contained in MetaMorph UIC2 Tag. (for each plane: 6 integers: zdistance numerator, zdistance denominator, creation date, creation time, modif date, modif time)
      Parameters:
      uic2offset - offset to UIC2 (33629) tag entries not a regular tiff tag (6*N entries, N being the tagCount)
      Throws:
      IOException
    • parseUIC4Tags

      private void parseUIC4Tags(long uic4offset) throws IOException
      UIC4 metadata parser UIC4 Table contains per-plane blocks of metadata stage X/Y positions, camera chip offsets, stage labels...
      Parameters:
      uic4offset - offset of UIC4 table (not tiff-compliant)
      Throws:
      IOException
    • getStageX

      protected ome.units.quantity.Length[] getStageX()
    • getStageY

      protected ome.units.quantity.Length[] getStageY()
    • readStagePositions

      private void readStagePositions() throws IOException
      Throws:
      IOException
    • readRationals

      private void readRationals(String[] labels) throws IOException
      Throws:
      IOException
    • readStageLabels

      void readStageLabels() throws IOException
      Throws:
      IOException
    • readAbsoluteZValid

      void readAbsoluteZValid() throws IOException
      Throws:
      IOException
    • parseUIC1Tags

      private void parseUIC1Tags(long uic1offset, int uic1count) throws IOException
      UIC1 entry parser
      Parameters:
      uic1offset - offset as found in the tiff tag 33628 (UIC1Tag)
      uic1count - number of entries in UIC1 table (not tiff-compliant)
      Throws:
      IOException
    • decodeDate

      public static String decodeDate(int julian)
      Converts a Julian date value into a human-readable string.
    • decodeTime

      public static String decodeTime(int millis)
      Converts a time value in milliseconds into a human-readable string. Note that the date and time are handled separately, so this method is only concerned with the time of day. The time of day in milliseconds is stored as a 32-bit int in Metamorph files, but is expected to be a positive integer less than the number of milliseconds in one day.
      Parameters:
      millis - milliseconds elapsed in the relevant day
      See Also:
    • intFormat

      public static String intFormat(int myint, int digits)
      Formats an integer value with leading 0s if needed.
    • intFormatMax

      public static String intFormatMax(int myint, int maxint)
      Formats an integer with leading 0 using maximum sequence number.
      Parameters:
      myint - integer to format
      maxint - max of "myint"
      Returns:
      String
    • locateFirstValidFile

      private String locateFirstValidFile()
      Locates the first valid file in the STK arrays.
      Returns:
      Path to the first valid file.
    • readRational

      private TiffRational readRational(loci.common.RandomAccessInputStream s) throws IOException
      Throws:
      IOException
    • readRational

      private TiffRational readRational(loci.common.RandomAccessInputStream s, long offset) throws IOException
      Throws:
      IOException
    • setCanLookForND

      private void setCanLookForND(boolean v)
    • readPlaneData

      private void readPlaneData() throws IOException
      Throws:
      IOException
    • getKey

      private String getKey(int id)
    • getWellCoords

      private Map.Entry<Integer,Integer> getWellCoords(String label)
    • readCString

      private static String readCString(loci.common.RandomAccessInputStream s, int n) throws IOException
      Read a null-terminated string. Read at most n characters if the null character is not found.
      Throws:
      IOException
    • getNDVersionSuffix

      private String getNDVersionSuffix(loci.common.Location ndfile) throws IOException
      Parses the given ND file to determined the version and return the expected file suffix
      Parameters:
      ndfile - The ND file which should be parsed
      Returns:
      The file suffix to be used for associated files based on the ND version
      Throws:
      IOException