Class StreamingTileImageData

java.lang.Object
nom.tam.fits.Data
nom.tam.fits.ImageData
nom.tam.image.StreamingTileImageData
All Implemented Interfaces:
FitsElement

public class StreamingTileImageData extends ImageData

Simple streaming image tile implementation. Useful for web applications that provide a cutout service. The idea is that the ImageData object will be extracted from an overlapping HDU (without first reading so as not to fill up the memory), and one of these objects are created for the output.

    Fits source = new Fits(myFile);
    ImageHDU imageHDU = source.getHDU(1);

    // We must manually adjust the header for the cutout image as necessary
    Header tileHeader = ...

    // Define the cutout region
    int[] tileStarts = new int[]{10, 10};
    int[] tileLengths = new int[]{45, 60};
    int[] tileSteps = new int[]{1, 1};

    // Create the cutout
    StreamingTileImageData streamingTileImageData = new StreamingTileImageData(tileHeader, imageHDU.getTiler(),
        tileStarts, tileLengths, tileSteps);

    // Write the cutout to the output
    Fits output = new Fits();
    output.addHDU(FitsFactory.hduFactory(tileHeader, streamingTileImageData));

    // The cutout happens at write time!
    output.write(outputStream);
Since:
1.18
  • Constructor Summary

    Constructors
    Constructor
    Description
    StreamingTileImageData(Header header, ImageTiler tiler, int[] corners, int[] lengths, int[] steps)
    Constructor for a tile image data object.
  • Method Summary

    Modifier and Type
    Method
    Description
    int[]
    Returns the striding step sizes along the various image dimensions.
    void
    Writes the contents of the element to a data sink, adding padding as necessary if the element (such as a header or data segment) is expected to complete the FITS block of 2880 bytes.

    Methods inherited from class ImageData

    convertTo, from, getDimensions, getQuantizer, getTiler, getType, isComplexValued, overrideHeaderAxes, read, setBuffer, setQuantizer, toHDU
    Modifier and Type
    Method
    Description
    convertTo(Class<?> type)
    Converts this image HDU to another image HDU of a different type, possibly using a qunatizer for the integer-decimal conversion of the data elements.
    static ImageData
    from(Object data)
    Creates a new FITS image using the specified primitive numerical Java array containing data.
    final int[]
    Returns the dimensions of this image.
    final Quantizer
    Returns the conversion between decimal and integer data representations.
    Returns the an image tiler instance that can be used to divide this image into tiles that may be processed separately (and in parallel).
    final Class<?>
    Returns the element type of this image in its current representation.
    final boolean
    Checks if the image data is explicitly designated as a complex-valued image.
    static void
    overrideHeaderAxes(Header header, int... sizes)
    (for expert users) Overrides the image size description in the header to the specified Java array dimensions.
    void
    Reads the data or skips over it for reading later, depending on whether reading from a stream or a random acessible input, respectively.
    void
    Sets the buffer that may hold a serialized version of the data for this image.
    void
    Sets the conversion between decimal and integer data representations.
    Returns an approprotae HDU object that encapsulates this FITS data, and contains the minimal mandatory header description for that data.

    Methods inherited from class Data

    calcChecksum, detach, getData, getFileOffset, getKernel, getSize, isDeferred, isEmpty, reset, rewrite, rewriteable
    Modifier and Type
    Method
    Description
    long
    Computes and returns the FITS checksum for this data, for example to compare against the stored DATASUM in the FITS header (e.g. via BasicHDU.getStoredDatasum()).
    void
    Detaches this data object from the input (if any), such as a file or stream, but not before loading data from the previously assigned input into memory.
    Returns the underlying Java representation of the data contained in this HDU's data segment.
    long
    Returns the byte offset at which this element starts ina file.
    final Object
    long
    Returns the size of this elements in the FITS representation.
    boolean
    Checks if the data should be assumed to be in deferred read mode.
    boolean
    Checks if the data content is currently empty, i.e. no actual data is currently stored in memory.
    boolean
    Reset the input stream to point to the beginning of this element
    void
    Rewrite the contents of the element in place.
    boolean
    Checks if we can write this element back to its source.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StreamingTileImageData

      public StreamingTileImageData(Header header, ImageTiler tiler, int[] corners, int[] lengths, int[] steps) throws FitsException
      Constructor for a tile image data object.
      Parameters:
      header - The header representing the desired cutout. It is the responsibility of the caller to adjust the header appropriately.
      tiler - The tiler to slice pixels out with.
      corners - The corners to start tiling.
      lengths - The count of values to extract.
      steps - The number of jumps to make to the next read. Optional, defaults to 1 for each axis.
      Throws:
      FitsException - If the provided Header is unreadable
  • Method Details

    • getSteps

      public int[] getSteps()
      Returns the striding step sizes along the various image dimensions.
      Returns:
      an array containing the steps sizes along the dimensions
    • write

      public void write(ArrayDataOutput o) throws FitsException
      Description copied from interface: FitsElement
      Writes the contents of the element to a data sink, adding padding as necessary if the element (such as a header or data segment) is expected to complete the FITS block of 2880 bytes.
      Specified by:
      write in interface FitsElement
      Overrides:
      write in class ImageData
      Parameters:
      o - The data sink.
      Throws:
      FitsException - if the write was unsuccessful.