Class FakeReader

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

public class FakeReader extends FormatReader
FakeReader is the file format reader for faking input data. It is mainly useful for testing.

Examples:

  • showinf 'multi-series&series=11&sizeZ=3&sizeC=5&sizeT=7&sizeY=50.fake' -series 9
  • showinf '8bit-signed&pixelType=int8&sizeZ=3&sizeC=5&sizeT=7&sizeY=50.fake'
  • showinf '8bit-unsigned&pixelType=uint8&sizeZ=3&sizeC=5&sizeT=7&sizeY=50.fake'
  • showinf '16bit-signed&pixelType=int16&sizeZ=3&sizeC=5&sizeT=7&sizeY=50.fake'
  • showinf '16bit-unsigned&pixelType=uint16&sizeZ=3&sizeC=5&sizeT=7&sizeY=50.fake'
  • showinf '32bit-signed&pixelType=int32&sizeZ=3&sizeC=5&sizeT=7&sizeY=50.fake'
  • showinf '32bit-unsigned&pixelType=uint32&sizeZ=3&sizeC=5&sizeT=7&sizeY=50.fake'
  • showinf '32bit-floating&pixelType=float&sizeZ=3&sizeC=5&sizeT=7&sizeY=50.fake'
  • showinf '64bit-floating&pixelType=double&sizeZ=3&sizeC=5&sizeT=7&sizeY=50.fake'
  • showinf 'SPW&plates=2&plateRows=3&plateCols=3&fields=8&plateAcqs=5.fake'
  • showinf 'SPW&screens=2&plates=1&plateRows=3&plateCols=3&fields=1&plateAcqs=1.fake'
  • showinf 'Plate&screens=0&plates=1&plateRows=3&plateCols=3&fields=8&plateAcqs=5.fake'
  • showinf 'regions&points=10&ellipses=5&rectangles=10.fake'
  • showinf 'pyramid&sizeX=10000&sizeY=10000&resolutions=5&resolutionScale=2.fake' -noflat -resolution 4

  • Field Details

    • ANN_LONG_VALUE

      private static final long ANN_LONG_VALUE
      See Also:
    • ANN_DOUBLE_VALUE

      private static final Double ANN_DOUBLE_VALUE
    • ANNOTATION_PREFIX

      private static final String ANNOTATION_PREFIX
      See Also:
    • ANNOTATION_NAMESPACE

      private static final String ANNOTATION_NAMESPACE
      See Also:
    • ANN_TERM_VALUE

      private static final String ANN_TERM_VALUE
      See Also:
    • ANN_TAG_VALUE

      private static final String ANN_TAG_VALUE
      See Also:
    • ANN_TIME_VALUE

      private static final ome.xml.model.primitives.Timestamp ANN_TIME_VALUE
    • ANN_BOOLEAN_VALUE

      private static final boolean ANN_BOOLEAN_VALUE
      See Also:
    • ANN_COMMENT_VALUE

      private static final String ANN_COMMENT_VALUE
      See Also:
    • ANN_XML_VALUE_START

      private static final String ANN_XML_VALUE_START
      See Also:
    • ANN_XML_VALUE_END

      private static final String ANN_XML_VALUE_END
      See Also:
    • ROI_PREFIX

      private static final String ROI_PREFIX
      See Also:
    • SHAPE_PREFIX

      private static final String SHAPE_PREFIX
      See Also:
    • BOX_SIZE

      public static final int BOX_SIZE
      See Also:
    • ROI_SPACING

      private static final int ROI_SPACING
      See Also:
    • DEFAULT_SIZE_X

      public static final int DEFAULT_SIZE_X
      See Also:
    • DEFAULT_SIZE_Y

      public static final int DEFAULT_SIZE_Y
      See Also:
    • DEFAULT_SIZE_Z

      public static final int DEFAULT_SIZE_Z
      See Also:
    • DEFAULT_SIZE_C

      public static final int DEFAULT_SIZE_C
      See Also:
    • DEFAULT_SIZE_T

      public static final int DEFAULT_SIZE_T
      See Also:
    • DEFAULT_PIXEL_TYPE

      public static final int DEFAULT_PIXEL_TYPE
      See Also:
    • DEFAULT_RGB_CHANNEL_COUNT

      public static final int DEFAULT_RGB_CHANNEL_COUNT
      See Also:
    • DEFAULT_DIMENSION_ORDER

      public static final String DEFAULT_DIMENSION_ORDER
      See Also:
    • DEFAULT_RGB_DIMENSION_ORDER

      public static final String DEFAULT_RGB_DIMENSION_ORDER
      See Also:
    • DEFAULT_RESOLUTION_SCALE

      public static final int DEFAULT_RESOLUTION_SCALE
      See Also:
    • TOKEN_SEPARATOR

      private static final String TOKEN_SEPARATOR
      See Also:
    • SEED

      private static final long SEED
      See Also:
    • sizeX

      private int sizeX
    • sizeY

      private int sizeY
    • sizeZ

      private int sizeZ
    • sizeC

      private int sizeC
    • sizeT

      private int sizeT
    • exposureTime

      private ome.units.quantity.Time exposureTime
      exposure time per plane info
    • physicalSizeX

      private ome.units.quantity.Length physicalSizeX
    • physicalSizeY

      private ome.units.quantity.Length physicalSizeY
    • physicalSizeZ

      private ome.units.quantity.Length physicalSizeZ
    • excitationWavelengths

      private transient ArrayList<ome.units.quantity.Length> excitationWavelengths
    • emissionWavelengths

      private transient ArrayList<ome.units.quantity.Length> emissionWavelengths
    • annBool

      private int annBool
    • annComment

      private int annComment
    • annDouble

      private int annDouble
    • annLong

      private int annLong
    • annMap

      private int annMap
    • annTime

      private int annTime
    • annTag

      private int annTag
    • annTerm

      private int annTerm
    • annXml

      private int annXml
    • annotationCount

      private int annotationCount
    • annotationBoolCount

      private int annotationBoolCount
    • annotationCommentCount

      private int annotationCommentCount
    • annotationDoubleCount

      private int annotationDoubleCount
    • annotationLongCount

      private int annotationLongCount
    • annotationMapCount

      private int annotationMapCount
    • annotationTagCount

      private int annotationTagCount
    • annotationTermCount

      private int annotationTermCount
    • annotationTimeCount

      private int annotationTimeCount
    • annotationXmlCount

      private int annotationXmlCount
    • ellipses

      private int ellipses
    • labels

      private int labels
    • lines

      private int lines
    • masks

      private int masks
    • points

      private int points
    • polygons

      private int polygons
    • polylines

      private int polylines
    • rectangles

      private int rectangles
    • roiCount

      private int roiCount
    • scaleFactor

      private double scaleFactor
      Scale factor for gradient, if any.
    • lut8

      private byte[][][] lut8
      8-bit lookup table, if indexed color, one per channel.
    • lut16

      private short[][][] lut16
      16-bit lookup table, if indexed color, one per channel.
    • indexToValue

      private int[][] indexToValue
      For indexed color, mapping from indices to values and vice versa.
    • valueToIndex

      private int[][] valueToIndex
      For indexed color, mapping from indices to values and vice versa.
    • ac

      private int ac
      Channel of last opened image plane.
    • iniFile

      private String iniFile
      Properties companion file which can be associated with this fake file
    • fakeSeries

      private List<String> fakeSeries
      List of used files if the fake is a SPW structure
    • omeXmlMetadata

      private OMEXMLMetadata omeXmlMetadata
    • omeXmlService

      private OMEXMLService omeXmlService
    • screens

      private transient int screens
    • plates

      private transient int plates
    • plateRows

      private transient int plateRows
    • plateCols

      private transient int plateCols
    • fields

      private transient int fields
    • plateAcqs

      private transient int plateAcqs
    • sleepOpenBytes

      private int sleepOpenBytes
    • sleepInitFile

      private int sleepInitFile
    • labelPlanes

      private boolean labelPlanes
  • Constructor Details

    • FakeReader

      public FakeReader()
      Constructs a new fake reader.
  • Method Details

    • sleep

      static void sleep(String msg, int ms)
    • readSpecialPixels

      public static int[] readSpecialPixels(byte[] plane)
      Read byte-encoded metadata from the given plane.
      See Also:
    • readSpecialPixels

      public static int[] readSpecialPixels(byte[] plane, int pixelType, boolean little)
      Read byte-encoded metadata from the given plane.
      See Also:
    • readSpecialPixels

      public static int[] readSpecialPixels(byte[] plane, int pixelType, boolean little, int rgb, boolean interleaved)
      Read byte-encoded metadata from the given plane.

      FakeReader encodes the following information in the upper-left section of each plane: series, plane number, Z index, C index, T index. Given an image plane generated by FakeReader (or by anything that follows the same encoding rules), this method decodes the above information and returns it as an array of integers.

      Note that the above numbers are encoded as valid pixels, so that the information is still retrievable after conversion to a pixel-oriented image format (this allows to use the class for testing the ImageJ plugin). Among other things, this implies that the maximum encodable values depend on the pixel type.

      Note:

      In the case of indexed color data, the returned values will be the indices of the actual values in the relevant lookup table (see get8BitLookupTable() and get16BitLookupTable()).

      Parameters:
      plane - an image plane as a byte array
      pixelType - the pixel type of the image; see FormatTools
      little - true if the byte order is little-endian, false otherwise
      rgb - the RGB channel count
      interleaved - true if the channels are interleaved, false otherwise
      Returns:
      an array of integers representing, in order: series; plane number; Z index; C index, T index
    • get8BitLookupTable

      public byte[][] get8BitLookupTable() throws FormatException, IOException
      Description copied from interface: IFormatReader
      Gets the 8-bit color lookup table associated with the most recently opened image. If no image planes have been opened, or if IFormatReader.isIndexed() returns false, then this may return null. Also, if IFormatReader.getPixelType() returns anything other than FormatTools.INT8 or FormatTools.UINT8, this method will return null.
      Specified by:
      get8BitLookupTable in interface IFormatReader
      Overrides:
      get8BitLookupTable in class FormatReader
      Throws:
      FormatException
      IOException
    • get16BitLookupTable

      public short[][] get16BitLookupTable() throws FormatException, IOException
      Description copied from interface: IFormatReader
      Gets the 16-bit color lookup table associated with the most recently opened image. If no image planes have been opened, or if IFormatReader.isIndexed() returns false, then this may return null. Also, if IFormatReader.getPixelType() returns anything other than FormatTools.INT16 or FormatTools.UINT16, this method will return null.
      Specified by:
      get16BitLookupTable in interface IFormatReader
      Overrides:
      get16BitLookupTable in class FormatReader
      Throws:
      FormatException
      IOException
    • 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.
    • 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.
    • 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
    • findLogFiles

      private void findLogFiles()
    • 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
    • getOmeXmlMetadata

      public OMEXMLMetadata getOmeXmlMetadata()
    • getOmeXmlService

      public OMEXMLService getOmeXmlService()
    • 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
    • reopenFile

      public void reopenFile() throws IOException
      Description copied from interface: IFormatReader
      Reopen any files that were closed, and which are expected to be open while the reader is open. This assumes that IFormatHandler.setId(java.lang.String) has been called, but close(false) has not been called.
      Specified by:
      reopenFile in interface IFormatReader
      Overrides:
      reopenFile in class FormatReader
      Throws:
      IOException
    • fillPhysicalSizes

      private void fillPhysicalSizes(MetadataStore store)
    • fillExposureTime

      private void fillExposureTime(MetadataStore store)
    • fillChannelWavelengths

      private void fillChannelWavelengths(MetadataStore store)
    • fillAcquisitionDate

      private void fillAcquisitionDate(MetadataStore store, String date, int imageIndex)
    • fillAnnotations

      private void fillAnnotations(MetadataStore store, int imageIndex)
    • fillInstrumentRefs

      private void fillInstrumentRefs(MetadataStore store)
    • getX

      private Double getX(int i)
    • getY

      private Double getY(int i)
    • getPoints

      private String getPoints(int i)
    • fillRegions

      private void fillRegions(MetadataStore store, int imageIndex)
    • parseSeriesTable

      private void parseSeriesTable(loci.common.IniTable table, MetadataStore store, int newSeries)
      Translate key/value pairs from the INI table for the specified series.
    • toSPWCoordinates

      private int[] toSPWCoordinates(int seriesIndex)
      Convert the given series (Image) index to a WellSample, Well, and Plate index. This should match the ordering used by XMLMockObjects.
      Parameters:
      seriesIndex - the index of the series/Image
      Returns:
      an array of length 3 containing the WellSample, Well, and Plate indices (in order), or null if SPW metadata was not defined
    • extractTokensFromFakeSeries

      private String[] extractTokensFromFakeSeries(String path)
    • isSPWStructure

      private boolean isSPWStructure(String path)
    • populateSPW

      private int populateSPW(MetadataStore store, int screens, int plates, int rows, int cols, int fields, int acqs, boolean withMicrobeam)
    • populateInstrument

      private void populateInstrument(MetadataStore store)
    • createIndexMap

      private void createIndexMap(int num)
      Creates a mapping between indices and color values.
    • listFakeSeries

      private List<String> listFakeSeries(String traversedDirectory)
      Traverses a fake file folder structure indicated by traversedDirectory
    • shuffle

      private static void shuffle(int c, int[] array)
      Fisher-Yates shuffle with constant seeds to ensure reproducibility.
    • parseColor

      private int parseColor(String value)
    • parsePosition

      private ome.units.quantity.Length parsePosition(String axis, int s, int index, loci.common.IniTable table)
    • parsePhysicalSize

      private ome.units.quantity.Length parsePhysicalSize(String s, String defaultUnit)
    • parseWavelength

      private ome.units.quantity.Length parseWavelength(String s, String defaultUnit)